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)
        {
            // Variables that will be set during input checking
            int toggleDirection;

            if (typingInput) // The user is typing input
            {
                bool inputAccepted = input.IsMenuSelect();
                bool inputCancelled = input.IsMenuCancel();
                bool inputBackspace = input.IsBackspace();
                String keysTyped = input.TypeableInput();

                if (inputAccepted || inputCancelled)
                {
                    typingInput = false;
                }
                if (inputAccepted || inputCancelled || inputBackspace || keysTyped != String.Empty)
                {
                    OnTyped(selectedEntry, inputAccepted, inputCancelled, inputBackspace, keysTyped);
                }
            }
            else // The user is performing normal menu input
            {
                // Move to the previous menu entry?
                if (input.IsMenuUp())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry--;
                        if (selectedEntry < 0)
                        {
                            selectedEntry = menuEntries.Count - 1;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Move to the next menu entry?
                if (input.IsMenuDown())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry++;
                        if (selectedEntry >= menuEntries.Count)
                        {
                            selectedEntry = 0;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Accept or cancel the menu?
                if (menuEntries[selectedEntry].Toggleable && input.IsMenuToggle(out toggleDirection))
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, input.IsMenuSelect(), false, toggleDirection);
                }
                else if (input.IsMenuSelect())
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, true, false, 0);
                }
                else if (input.IsMenuCancel())
                {
                    menuCancelSoundEffect.Play();
                    OnCancel();
                }
            }
            return;
        }
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input.IsMenuSelect())
            {
                okSoundEffect.Play();

                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                {
                    Accepted(this, new PlayerInputEventArgs(true));
                }

                ExitScreen();
            }
            else if (input.IsMenuCancel())
            {
                cancelSoundEffect.Play();

                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                {
                    Cancelled(this, new PlayerInputEventArgs(false, true));
                }

                ExitScreen();
            }
            return;
        }