コード例 #1
0
ファイル: MenuScreen.cs プロジェクト: ebshimizu/XNAUtils
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            Vector2 screenPos = input.MousePosition;
            cursorPosition = ScreenManager.camera.screenToWorldUI(screenPos);

            // 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 = PlayerIndex.One;

            if (!useMouse)
            {
                // 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;
                }
            }
            else
            {
                int index = 0;
                Vector2 pos = new Vector2(0f, position.Y);

                foreach (MenuEntry entry in MenuEntries)
                {
                    pos.X = position.X - entry.GetWidth(this) / 2;
                    Rectangle menuBounds = new Rectangle((int)pos.X, (int)pos.Y, entry.GetWidth(this), entry.GetHeight(this));
                    if (menuBounds.Contains((int)cursorPosition.X, (int)cursorPosition.Y))
                    {
                        selectedEntry = index;

                        if (input.IsLeftMouseClick())
                        {
                            OnSelectEntry(selectedEntry, playerIndex);
                            break;
                        }
                    }

                    index++;
                    pos.Y += entry.GetHeight(this) * lineHeight;
                }
            }

            if (input.IsConfirm(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
コード例 #2
0
ファイル: GameScreen.cs プロジェクト: ebshimizu/XNAUtils
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
コード例 #3
0
ファイル: GameplayScreen.cs プロジェクト: ebshimizu/XNAUtils
        /// <summary>
        /// Handles input for the screen.
        /// </summary>
        /// <param name="input">InputState manager object.</param>
        public override void HandleInput(InputState input)
        {
            // If escape is pressed, pause the game
            if (input.IsPauseGame(null))
            {
                paused = true;
            }

            Vector2 screenPos = input.MousePosition;
            cursorWorldPos = camera.screenToWorldUI(screenPos);

            base.HandleInput(input);
        }