示例#1
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;

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

                if (SelectedEntry < 0)
                {
                    SelectedEntry = MenuEntries.Count - 1;
                }
            }

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

                if (SelectedEntry >= MenuEntries.Count)
                {
                    SelectedEntry = 0;
                }
            }

            if (MenuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(SelectedEntry, playerIndex);
            }
            else if (MenuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }