private void CheckButtonClick(InputState input, MenuButton button)
 {
     // If we clicked the mouse
     if (input.IsNewLeftMouseClick())
     {
         // We check the mouse to see if we're in the confines of the button and the button is enabled and we can use the mouse.
         if (input.LastMouseState.X > button.RectangleCollider.Left &&
             input.LastMouseState.X < button.RectangleCollider.Right &&
             input.LastMouseState.Y < button.RectangleCollider.Bottom &&
             input.LastMouseState.Y > button.RectangleCollider.Top &&
             button.IsEnabled)
         {
             // Fire the button's selected event.
             button.OnSelectEntry(PlayerIndex.One);
         }
     }
 }
Example #2
0
        public override void HandleInput(InputState input)
        {
            if (!passThrough)
            {
                // We need input to not be null.
                if (input == null)
                    throw new ArgumentNullException("input");

                // Get the keyboard and gamepad states.
                KeyboardState keyboardState = Keyboard.GetState();
                GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

				// If the number keys on the keyboard is greater than 0 (in case they're pressing 2 keys at once)...
                // or the mouse is clicked
                if (keyboardState.GetPressedKeys().Length > 0 || input.IsNewLeftMouseClick())
                {
                    // Proceed to the main menu.
                    GotoMainMenu();
                }

                // If the start, a, b, x, or y buttons are being pressed...
                if (gamePadState.IsButtonDown(Buttons.Start) || gamePadState.IsButtonDown(Buttons.A) || gamePadState.IsButtonDown(Buttons.B) || gamePadState.IsButtonDown(Buttons.X) || gamePadState.IsButtonDown(Buttons.Y))
                {
                    // Proceed to the main menu.
                    GotoMainMenu();
                }
            }
        }
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            mouseState = Mouse.GetState();

            mousePosition = new Vector2(mouseState.X, mouseState.Y);

            if (input.IsNewKeyPress(Keys.Left, ControllingPlayer, out playerIndex) && !useMouse)
            {
                MoveMenuLeft();
                useMouse = false;
            }
            else if (input.IsNewKeyPress(Keys.Right, ControllingPlayer, out playerIndex) && !useMouse)
            {
                MoveMenuRight();
                useMouse = false;
            }
            else if (input.IsMenuUp(ControllingPlayer) && !useMouse)
            {
                MoveMenuLeft();
            }
            else if (input.IsMenuDown(ControllingPlayer) && !useMouse)
            {
                MoveMenuRight();
            }
            else if (input.IsNewLeftMouseClick())
            {
                foreach (MenuButton button in MenuEntries)
                {
                    CheckButtonClick(input, button);
                }
            }
            else if (input.IsMenuSelect(ControllingPlayer, out playerIndex) && !useMouse)
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex) && !useMouse)
            {
                OnCancel(playerIndex);
            }

            for (int b = 0; b < menuEntries.Count; b++)
            {
                MenuButton button = menuEntries[b];

                button.IsHovering = false;

                CheckButtonHover(input, button);

                if (button.IsHovering)
                {
                    selectedEntry = b;
                }
            }

            // If the current mouse position doesn't equal the last, then our mouse is active!
            if (input.LastMouseState.X != mousePosition.X || input.LastMouseState.Y != mousePosition.Y)
            {
                useMouse = true;
            }

            if (!useMouse)
            {

            }
        }