Пример #1
0
        /// <summary>
        /// Evaluates the action against a given InputState.
        /// </summary>
        /// <param name="state">The InputState to test for the action.</param>
        /// <param name="controllingPlayer">The player to test, or null to allow any player.</param>
        /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param>
        /// <returns>True if the action occured, false otherwise.</returns>
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delgate methods to map from the state which takes
            // care of our "newPressOnly" logic
            ButtonPress buttonTest;
            KeyPress keyTest;
            if (newPressOnly)
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }
            else
            {
                buttonTest = state.IsButtonDown;
                keyTest = state.IsKeyDown;
            }

            // Now we simply need to invoke the appropriate methods for each button
            // and key in our collections
            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }
            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            // If we got here, the action is not matched
            player = PlayerIndex.One;
            return false;
        }
Пример #2
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            base.HandleInput(gameTime, input);

            PlayerIndex idx;

            if (menuCancel.Evaluate(input, null, out idx))
            {
                CallExit();
            }
        }
Пример #3
0
 /// <summary>
 /// Allows the screen to handle user input. Only called when
 /// this screen is active.
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="input"></param>
 public virtual void HandleInput(GameTime gameTime, InputState input)
 {
 }
Пример #4
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting or cancelling
        /// the menu.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            //Move to the previous menu entry?
            if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry--;

                if (!string.IsNullOrEmpty(selectionChangeSound))
                    SoundManager.Play(selectionChangeSound);

                if (selectedEntry < 0)
                {
                    selectedEntry = menuEntries.Count - 1;
                }
            }

            //Move to the next menu entry?
            if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry++;

                if (!string.IsNullOrEmpty(selectionChangeSound))
                    SoundManager.Play(selectionChangeSound);

                if (selectedEntry >= menuEntries.Count)
                {
                    selectedEntry = 0;
                }
            }

            if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);

                if (!string.IsNullOrEmpty(selectionSound))
                {
                    SoundManager.Play(selectionSound);
                }
            }

            else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);

                if (!string.IsNullOrEmpty(cancelSound))
                {
                    SoundManager.Play(cancelSound);
                }
            }
        }