Evaluate() public method

Evaluates the action against a given InputState.
public Evaluate ( InputState state, System controllingPlayer, PlayerIndex &player ) : bool
state InputState The InputState to test for the action.
controllingPlayer System The player to test, or null to allow any player.
player PlayerIndex If controllingPlayer is null, this is the player that performed the action.
return bool
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex = default(PlayerIndex);

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (menuSelect.Evaluate(input, ControllingPlayer, ref playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                {
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));
                }

                ExitScreen();
            }
            else if (menuCancel.Evaluate(input, ControllingPlayer, ref playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                {
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));
                }

                ExitScreen();
            }
        }
Esempio n. 2
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)
        {
            // For input tests we pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex = default(PlayerIndex);


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

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

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

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

            if (menuSelect.Evaluate(input, ControllingPlayer, ref playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (menuCancel.Evaluate(input, ControllingPlayer, ref playerIndex))
            {
                OnCancel(playerIndex);
            }
        }