Esempio n. 1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // We cancel the current menu screen if the user presses the back button
            PlayerIndex player;

            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            if (input.IsNewKeyPress(Keys.Escape, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            if (input.IsMenuDown(ControllingPlayer))
            {
                if (selectedEntry < menuEntries.Count - 1)
                {
                    selectedEntry += 1;
                }
            }

            if (input.IsMenuUp(ControllingPlayer))
            {
                if (selectedEntry > 0)
                {
                    selectedEntry -= 1;
                }
            }

            if (input.IsMenuSelect(ControllingPlayer, out player))
            {
                menuEntries[selectedEntry].OnSelectEntry(player);
            }

            if (input.MouseGesture.HasFlag(MouseGestureType.LeftClick))
            {
                Point clickLocation = new Point((int)input.CurrentMousePosition.X, (int)input.CurrentMousePosition.Y);
                // iterate the entries to see if any were tapped
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (GetMenuEntryHitBounds(menuEntry).Contains(clickLocation))
                    {
                        // select the entry. since gestures are only available on Windows Phone,
                        // we can safely pass PlayerIndex.One to all entries since there is only
                        // one player on Windows Phone.
                        OnSelectEntry(i, PlayerIndex.One);
                    }
                }
            }

            if (input.MouseGesture.HasFlag(MouseGestureType.Move))
            {
                Point clickLocation = new Point((int)input.CurrentMousePosition.X, (int)input.CurrentMousePosition.Y);
                // iterate the entries to see if any were tapped
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (GetMenuEntryHitBounds(menuEntry).Contains(clickLocation))
                    {
                        // select the entry. since gestures are only available on Windows Phone,
                        // we can safely pass PlayerIndex.One to all entries since there is only
                        // one player on Windows Phone.
                        //OnSelectEntry(i, PlayerIndex.One);
                        selectedEntry = i;
                    }
                }
            }

            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < menuEntries.Count; i++)
                    {
                        MenuEntry menuEntry = menuEntries[i];

                        if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
                        {
                            // select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only
                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
        }