예제 #1
0
        public override void Initialize()
        {
            _inputListenerManager = new InputListenerComponent(Game);
            Game.Components.Add(_inputListenerManager);

            _mouseListener = new MouseListener();
            _inputListenerManager.Listeners.Add(_mouseListener);

            _mouseListener.MouseMoved      += Mouse_MouseMoved;
            _mouseListener.MouseDown       += Mouse_MouseDownOrUp;
            _mouseListener.MouseUp         += Mouse_MouseDownOrUp;
            _mouseListener.MouseWheelMoved += Mouse_MouseScroll;

            _keyboardListener = new KeyboardListener();
            _inputListenerManager.Listeners.Add(_keyboardListener);
            _keyboardListener.KeyPressed  += Keyboard_KeyDown;
            _keyboardListener.KeyReleased += Keyboard_KeyUp;

            GamePadListener.CheckControllerConnections   = true;
            GamePadListener.ControllerConnectionChanged += GamePad_ConnectionChanged;

            EventManager.Instance.RegisterListener <GamePadConnectedEvent>(this);
            EventManager.Instance.RegisterListener <GamePadDisconnectedEvent>(this);

            base.Initialize();
        }
예제 #2
0
        public InputHandler(Game game)
        {
            MouseListener    = new MouseListener();
            KeyboardListener = new KeyboardListener();

            _inputListener = new InputListenerComponent(game, MouseListener, KeyboardListener);
        }
 public GuiInputService(InputListenerComponent inputListener)
 {
     inputListener.Listeners.Add(KeyboardListener = new KeyboardListener());
     inputListener.Listeners.Add(MouseListener    = new MouseListener());
     inputListener.Listeners.Add(GamePadListener  = new GamePadListener());
     inputListener.Listeners.Add(TouchListener    = new TouchListener());
 }
예제 #4
0
        protected override void Initialize()
        {
            // Settings
            Settings.Instance.Load();

            Mouse.WindowHandle = Window.Handle;

            IsMouseVisible = true;

            _inputListenerManager = new InputListenerComponent(this);
            Components.Add(_inputListenerManager);

            _mouseListener = new MouseListener();
            _inputListenerManager.Listeners.Add(_mouseListener);

            _mouseListener.MouseMoved += Mouse_MouseMoved;
            _mouseListener.MouseDown  += Mouse_MouseDownOrUp;
            _mouseListener.MouseUp    += Mouse_MouseDownOrUp;

            _gamePadListener = new GamePadListener();
            _inputListenerManager.Listeners.Add(_gamePadListener);

            GamePadListener.CheckControllerConnections   = true;
            GamePadListener.ControllerConnectionChanged += GamePad_ControllerConnectionChanged;

            base.Initialize();
        }
예제 #5
0
 public State()
 {
     if (gui == null)
     {
         inputListener = new InputListenerComponent(GameApp);
         inputManager  = new MonoGame.Extended.NuclexGui.GuiInputService(inputListener);
         gui           = new GuiManager(GameApp.Services, inputManager);
         gui.Initialize();
     }
     gui.Screen = new GuiScreen();
 }
예제 #6
0
        public static GuiManager CreateTitleGui(GameCore game, GuiManager titleGui, InputListenerComponent inputManager)
        {
            //Create GUI
            var guiInputService = new GuiInputService(inputManager);

            titleGui = new GuiManager(game.Services, guiInputService);

            titleGui.Screen = new GuiScreen(GameCore.SCREEN_WIDTH, GameCore.SCREEN_HEIGHT);

            titleGui.Screen.Desktop.Bounds = new UniRectangle(new UniScalar(0f, 0), new UniScalar(0f, 0), new UniScalar(1f, 0), new UniScalar(1f, 0));

            titleGui.Initialize();

            //Create buttons
            var buttonWidth   = 150;
            var buttonHeight  = 50;
            var buttonX       = (GameCore.WINDOW_WIDTH / 2) - (buttonWidth / 2);
            var buttonY       = 200;
            var buttonDivider = 100;
            var StartButton   = new GuiButtonControl
            {
                Name   = "Start",
                Bounds = new UniRectangle(new UniScalar(buttonX), new UniScalar(buttonY), new UniScalar(buttonWidth), new UniScalar(buttonHeight)),
                Text   = "Start"
            };

            var HighScoresButton = new GuiButtonControl
            {
                Name   = "HighScores",
                Bounds = new UniRectangle(new UniScalar(buttonX), new UniScalar(buttonY + buttonDivider),
                                          new UniScalar(buttonWidth), new UniScalar(buttonHeight)),
                Text = "High Scores"
            };

            var ExitButton = new GuiButtonControl
            {
                Name   = "Exit",
                Bounds = new UniRectangle(new UniScalar(buttonX), new UniScalar(buttonY + (buttonDivider * 2)),
                                          new UniScalar(buttonWidth), new UniScalar(buttonHeight)),
                Text = "Exit"
            };

            //Add functon to pressed
            StartButton.Pressed      += game.StartButtonPressed;
            HighScoresButton.Pressed += game.HighScoresButtonPressed;
            ExitButton.Pressed       += game.ExitButtonPressed;

            //Add buttons to gui
            titleGui.Screen.Desktop.Children.Add(StartButton);
            titleGui.Screen.Desktop.Children.Add(HighScoresButton);
            titleGui.Screen.Desktop.Children.Add(ExitButton);

            return(titleGui);
        }
예제 #7
0
        public GameController(Minesweeper game)
        {
            Instance = this;
            _game    = game;

            //Setup GUI
            _inputManager = new InputListenerComponent(game);
            var guiInputService = new GuiInputService(_inputManager);

            _gui = new GuiManager(game.Services, guiInputService);

            //Setup dictionary to hold tiles and their game objects
            _tileToGameObjectMap = new Dictionary <Tile, GameObject>();
            _gameObjectToTileMap = new Dictionary <GameObject, Tile>();
        }
        public Game1() : base()
        {
            //_graphicsDeviceManager = new GraphicsDeviceManager(this);
            // Content.RootDirectory = "Content";
            IsMouseVisible           = true;
            Window.AllowUserResizing = true;
            _backgroundColor         = Color.DarkKhaki;

            // First, we create an input manager.
            _inputManager = new InputListenerComponent(this);

            // Then, we create GUI.
            var guiInputService = new GuiInputService(_inputManager);

            _gui = new GuiManager(Services, guiInputService);
        }
예제 #9
0
        public TitleState()
        {
            background = AppContentManager.Load <Texture2D>("Title/Title");


            if (gui == null)
            {
                inputListener = new InputListenerComponent(GameApp);
                inputManager  = new MonoGame.Extended.NuclexGui.GuiInputService(inputListener);
                gui           = new GuiManager(GameApp.Services, inputManager);
                gui.Initialize();
            }
            gui.Screen   = new GuiScreen();
            btnStartGame = new GuiButtonControl
            {
                Name   = "Start Game",
                Bounds = new UniRectangle(new UniVector(new UniScalar(540), new UniScalar(200)), new UniVector(new UniScalar(200), new UniScalar(70))),
                Text   = "Start Game"
            };
            btnQuitGame = new GuiButtonControl
            {
                Name   = "Quit Game",
                Bounds = new UniRectangle(new UniVector(new UniScalar(540), new UniScalar(300)), new UniVector(new UniScalar(200), new UniScalar(70))),
                Text   = "Quit Game"
            };
            btnQuitGame.Pressed += BtnQuitGame_Pressed;
            gui.Screen.Desktop.Children.Add(btnQuitGame);

            windowStarting = new GuiWindowControl()
            {
                Name   = "Starting",
                Bounds = new UniRectangle(new UniVector(new UniScalar(240), new UniScalar(200)), new UniVector(new UniScalar(800), new UniScalar(100))),
                Title  = "Starting Game..."
            };

            btnStartGame.Pressed += OnStartGamePressed;
            gui.Screen.Desktop.Children.Add(btnStartGame);

            lblStatus = new GuiLabelControl()
            {
                Bounds = new UniRectangle(new UniVector(new UniScalar(10), new UniScalar(0)), new UniVector(new UniScalar(800), new UniScalar(100))),
                Text   = ""
            };

            windowStarting.Children.Add(lblStatus);
        }
예제 #10
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = @"Content";

            IsMouseVisible  = true;
            IsFixedTimeStep = false;

            // Create components
            screenManagerComponent = new ScreenManagerComponent(this);
            Components.Add(screenManagerComponent);

            KeyboardListener       = new KeyboardListener();
            MouseListener          = new MouseListener();
            InputListenerComponent = new InputListenerComponent(this, KeyboardListener, MouseListener);
            Components.Add(InputListenerComponent);
        }
예제 #11
0
        protected override void Initialize()
        {
            base.Initialize();

            //Init video adapter
            videoAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, SCREEN_WIDTH, SCREEN_HEIGHT);

            //Set mouse to visible
            IsMouseVisible = true;

            //Get high scores
            HighScoreData = GetHighScores();

            //Create input manager for GUI
            inputManager = new InputListenerComponent(this);

            //Set gamestate to 0 for titlescreen
            ChangeState(GameCore.STATE_TITLE);
        }
예제 #12
0
 public GuiController(GameCore game, World world)
 {
     this.game     = game;
     this.world    = world;
     inputListener = new InputListenerComponent(game);
 }
예제 #13
0
        public Game1()
        {
            // сначала наследуемые
            this.Window.AllowUserResizing  = true;
            this.Window.AllowAltF4         = true;
            this.Window.ClientSizeChanged += this.Window_ClientSizeChanged;
            this.IsMouseVisible            = true;
            this.Content.RootDirectory     = "Content";

            // объявленные нами
            this._graphicsDeviceManager = new GraphicsDeviceManager(this);
            this._backgroundColor       = Color.CornflowerBlue;
            this._inputManager          = new InputListenerComponent(this);

            // Then, we create GUI.
            this._inputService = new GuiInputService(_inputManager);
            this._gui          = new GuiManager(this.Services, this._inputService);

            // Create a GUI screen and attach it as a default to GuiManager.
            // That screen will also act as a root parent for every other control that we create.
            this._gui.Screen = new GuiScreen(1280, 1024);
            this._gui.Screen.Desktop.Bounds = new UniRectangle(
                new UniScalar(0f, 0),
                new UniScalar(0f, 0),
                new UniScalar(1f, 0),
                new UniScalar(1f, 0));

            /*BoxingViewportAdapter viewportAdapter =
             *  new BoxingViewportAdapter(this.Window, this.GraphicsDevice, 800, 480);
             * this._camera = new Camera2D(viewportAdapter);*/

            this._connection = new HubConnection("http://localhost:8080/signalr");
            this._connection.DeadlockErrorTimeout    = TimeSpan.FromSeconds(15);
            this._connection.TransportConnectTimeout = TimeSpan.FromSeconds(15);

            this._proxy = this._connection.CreateHubProxy("GlobalHub")
                          .AsHubProxy <IServerContract, IClientContract>();
            this._proxy.SubscribeOn <string>(
                c => c.OnShowMessage,
                s =>
            {
                MessageScene msg = new MessageScene();
                msg.SetText(s);
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
            });

            this._proxy.SubscribeOn <char>(
                c => c.OnCanDoStep,
                ch => this._gameWindow.AddNewChar(ch));

            this._proxy.SubscribeOn <string, string, char>(
                c => c.OnGameStarted,
                (gameId, enemyNick, startChar) =>
            {
                this.CurrentGameId    = gameId;
                this.CurrentEnemyNick = enemyNick;
                this.ShowGameWindow(startChar, false);
            });

            this._proxy.SubscribeOn <string, string>(
                c => c.OnGameFinished,
                (result, reason) =>
            {
                MessageScene msg = new MessageScene();
                msg.SetText(result + ":\n" + reason);
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
                this._gameWindow?.Close();
            });
        }
예제 #14
0
        public static GuiManager CreateInputHighScoreGui(GameCore game, GuiManager inputHighScoreGui, InputListenerComponent inputManager)
        {
            //Create gui
            var guiInputService = new GuiInputService(inputManager);

            inputHighScoreGui = new GuiManager(game.Services, guiInputService);

            inputHighScoreGui.Screen = new GuiScreen(GameCore.SCREEN_WIDTH, GameCore.SCREEN_HEIGHT);

            inputHighScoreGui.Screen.Desktop.Bounds = new UniRectangle(new UniScalar(0f, 0), new UniScalar(0f, 0), new UniScalar(1f, 0), new UniScalar(1f, 0));

            //Create Submit button
            var buttonWidth  = 150;
            var buttonHeight = 50;
            var buttonX      = (GameCore.WINDOW_WIDTH / 2) - (buttonWidth / 2);
            var buttonY      = (GameCore.WINDOW_HEIGHT - 200);

            var submitButton = new GuiButtonControl
            {
                Name   = "Submit",
                Bounds = new UniRectangle(new UniScalar(buttonX), new UniScalar(buttonY), new UniScalar(buttonWidth), new UniScalar(buttonHeight)),
                Text   = "Submit"
            };

            var inputWidth  = 200;
            var inputHeight = 20;
            var inputX      = (GameCore.WINDOW_WIDTH / 2) - (inputWidth / 2);
            var inputY      = (GameCore.WINDOW_HEIGHT - 400);

            var textInput = new GuiInputControl
            {
                Name   = "Text Input",
                Bounds = new UniRectangle(new UniScalar(inputX), new UniScalar(inputY), new UniScalar(inputWidth), new UniScalar(inputHeight)),
                Text   = "Name"
            };

            submitButton.Pressed += game.SubmitButtonPressed;

            inputHighScoreGui.Screen.Desktop.Children.Add(submitButton);
            inputHighScoreGui.Screen.Desktop.Children.Add(textInput);
            inputHighScoreGui.Initialize();

            return(inputHighScoreGui);
        }
예제 #15
0
        public static GuiManager CreateHighScoresGui(GameCore game, GuiManager highScoresGui, InputListenerComponent inputManager)
        {
            //Create gui
            var guiInputService = new GuiInputService(inputManager);

            highScoresGui = new GuiManager(game.Services, guiInputService);

            highScoresGui.Screen = new GuiScreen(GameCore.SCREEN_WIDTH, GameCore.SCREEN_HEIGHT);

            highScoresGui.Screen.Desktop.Bounds = new UniRectangle(new UniScalar(0f, 0), new UniScalar(0f, 0), new UniScalar(1f, 0), new UniScalar(1f, 0));

            //Create back button
            var buttonWidth  = 150;
            var buttonHeight = 50;
            var buttonX      = (GameCore.WINDOW_WIDTH / 2) - (buttonWidth / 2);
            var buttonY      = (GameCore.WINDOW_HEIGHT - 70);

            var backButton = new GuiButtonControl
            {
                Name   = "Back",
                Bounds = new UniRectangle(new UniScalar(buttonX), new UniScalar(buttonY), new UniScalar(buttonWidth), new UniScalar(buttonHeight)),
                Text   = "Back"
            };

            backButton.Pressed += game.BackButtonPressed;
            highScoresGui.Screen.Desktop.Children.Add(backButton);
            highScoresGui.Initialize();

            return(highScoresGui);
        }
예제 #16
0
        public StartupSystem(Game game, Screen hostScreen)
            : base(game, hostScreen)
        {
            var kbListener = new KeyboardListener(new KeyboardListenerSettings
            {
                InitialDelayMilliseconds = 500,
                RepeatDelayMilliseconds  = 50,
                RepeatPress = true
            });

            _inputListener = new InputListenerComponent(GameRoot, kbListener);
            _input         = new InputHandler(GameRoot);
            GameRoot.Components.Add(_inputListener);
            GameRoot.Components.Add(_input);
            kbListener.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Left)
                {
                    _cursorPosition--;
                }
                if (args.Key == Keys.Right)
                {
                    _cursorPosition++;
                }
                if (args.Key == Keys.Insert)
                {
                    _isInsert = !_isInsert;
                }

                if (args.Key == Keys.Delete && _inputText.Length > 0 && _cursorPosition < _inputText.Length)
                {
                    _inputText = _inputText.Remove(_cursorPosition, 1);
                }

                _cursorPosition = MathHelper.Clamp(_cursorPosition, 0, _inputText.Length);
            };
            kbListener.KeyTyped += (sender, args) =>
            {
                if (args.Character != null && args.Key != Keys.Back && args.Key != Keys.Tab)
                {
                    if (_isInsert && _cursorPosition < _inputText.Length)
                    {
                        _inputText = _inputText.Remove(_cursorPosition, 1);
                    }

                    if (_inputText.Length < 33)
                    {
                        _inputText = _inputText.Insert(_cursorPosition, args.Character.ToString());
                        _cursorPosition++;
                    }
                }

                if (args.Key == Keys.Back && _inputText.Length > 0)
                {
                    _inputText = _inputText.Remove(_inputText.Length - 1, 1);
                    _cursorPosition--;
                }

                if (args.Key == Keys.Enter)
                {
                    ProcessInputString();
                    _cursorPosition = 0;
                    _inputText      = "";
                }
            };

            _viewport = new BoxingViewportAdapter(GameRoot.Window, GameRoot.GraphicsDevice, 256, 256);
        }