Esempio n. 1
0
        void updateGamepadState()
        {
            if (_gamepadFocusElement != null)
            {
                if (Input.gamePads[0].isButtonPressed(gamepadActionButton) ||
                    (keyboardEmulatesGamepad && Input.isKeyPressed(keyboardActionKey)))
                {
                    _gamepadFocusElement.onActionButtonPressed();
                }
                else if (Input.gamePads[0].isButtonReleased(gamepadActionButton) ||
                         (keyboardEmulatesGamepad && Input.isKeyReleased(keyboardActionKey)))
                {
                    _gamepadFocusElement.onActionButtonReleased();
                }
            }

            IGamepadFocusable nextElement = null;
            var direction = Direction.None;

            if (Input.gamePads[0].DpadLeftPressed || Input.gamePads[0].isLeftStickLeftPressed() ||
                (keyboardEmulatesGamepad && Input.isKeyPressed(Keys.Left)))
            {
                direction = Direction.Left;
            }
            else if (Input.gamePads[0].DpadRightPressed || Input.gamePads[0].isLeftStickRightPressed() ||
                     (keyboardEmulatesGamepad && Input.isKeyPressed(Keys.Right)))
            {
                direction = Direction.Right;
            }
            else if (Input.gamePads[0].DpadUpPressed || Input.gamePads[0].isLeftStickUpPressed() ||
                     (keyboardEmulatesGamepad && Input.isKeyPressed(Keys.Up)))
            {
                direction = Direction.Up;
            }
            else if (Input.gamePads[0].DpadDownPressed || Input.gamePads[0].isLeftStickDownPressed() ||
                     (keyboardEmulatesGamepad && Input.isKeyPressed(Keys.Down)))
            {
                direction = Direction.Down;
            }

            // make sure we have a valid direction
            if (direction != Direction.None)
            {
                nextElement = findNextGamepadFocusable(_gamepadFocusElement, direction);
                if (nextElement == null)
                {
                    // we have no next Element so if the current Element has explicit focuasable control send along the unhandled direction
                    if (_gamepadFocusElement.shouldUseExplicitFocusableControl)
                    {
                        _gamepadFocusElement.onUnhandledDirectionPressed(direction);
                    }
                }
                else
                {
                    setGamepadFocusElement(nextElement);
                }
            }
        }