예제 #1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (IsMenuUp(input))
            {
                selectedEntry--;

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

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

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

            //Handle mouse
            Vector2 mousePosition = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y);
            int     x             = 0;

            foreach (MenuEntry entry in MenuEntries)
            {
                if (MathsHelper.IsVector2InsideRectangle(mousePosition, entry.GetRectangle(this)))
                {
                    selectedEntry = x;
                }
                x++;
            }

            if (IsMenuSelect(input))
            {
                OnSelectEntry(selectedEntry);
            }
            else if (IsMenuCancel(input))
            {
                OnCancel();
            }
        }