Example #1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            var before = selectedEntry;

            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;
            }

            selectedEntry = (int)MathHelper.Clamp(selectedEntry, 0, MenuEntries.Count - 1);

            if (!menuEntries[selectedEntry].HandleMouseInput(input))
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    if(menuEntries[i].HandleMouseInput(input))
                    {
                        selectedEntry = i;
                        break;
                    }
                }

            if(selectedEntry != before)
            {
                menuEntries[before].State = UIState.Active;
                menuEntries[selectedEntry].State = UIState.Selected;

                AudioSettings settings = (ScreenManager.Game as HalfCakedGame).CurrentProfile.Audio;

                if(EntryFocusChanged != null)
                    EntryFocusChanged.Play(settings.SoundEffectsVolume / 500f, 0f, 0f);
            }

            // Accept or cancel the menu? 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;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex, 0);
            }
            else if (menuEntries[selectedEntry].ChangesValue && input.IsNextButton(ControllingPlayer))
            {
                OnSelectEntry(selectedEntry, playerIndex, 1);
            }
            else if (menuEntries[selectedEntry].ChangesValue && (input.IsPreviousButton(ControllingPlayer)))
            {
                OnSelectEntry(selectedEntry, playerIndex, -1);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
Example #2
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            var before = selectedEntry;

            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

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

            int yPosition = 150;
            bool pressed = false;
            for (int i = 0; i < menuEntries.Count; i++)
            {
                if (input.LastMouseState.Y > yPosition - menuEntries[i].GetHeight(this)/2 && input.IsNewMouseState() &&
                    input.LastMouseState.Y < yPosition + menuEntries[i].GetHeight(this)/2)
                {
                    selectedEntry = i;
                    pressed = input.IsNewLeftMouseClick();
                    break;
                }
                yPosition += menuEntries[i].GetHeight(this);
            }

            if(selectedEntry != before)
            {
                AudioSettings settings = (ScreenManager.Game as HalfCakedGame).CurrentProfile.Audio;
                EntryFocusChanged.Play(settings.SoundEffectsVolume / 500f, 0f, 0f);
            }

            // Accept or cancel the menu? 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;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex) || pressed)
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }