예제 #1
0
 public GamepadState(GamepadThumbsticks thumbSticksState, GamePadTriggers triggersState, GamepadButton buttonsState)
     : this()
 {
     Thumbsticks  = thumbSticksState;
     Triggers     = triggersState;
     ButtonsState = buttonsState;
 }
예제 #2
0
 public GamePadValues(GamePadThumbSticks thumbSticks, GamePadTriggers triggers)
     : this(
         thumbSticks.Left.X, thumbSticks.Left.Y,
         thumbSticks.Right.X, thumbSticks.Right.Y,
         triggers.Left, triggers.Right)
 {
 }
예제 #3
0
 public GamepadState(GamePadThumbSticks thumbSticks, GamePadTriggers triggers, GamePadButtonsSet buttons)
 {
     Connected   = true;
     ThumbSticks = thumbSticks;
     Triggers    = triggers;
     Buttons     = buttons;
 }
예제 #4
0
        public static void Update()
        {
            for (int player = 0; player < States.Length; player++)
            {
                GamePadState stateX = GamePad.GetState((PlayerIndex)player);
                DInputState  stateD = States[player];
                stateD.connected = stateX.IsConnected;
                if (!stateD.connected)
                {
                    continue;
                }
                // TODO: Finalize DInput mappings

                GamePadThumbSticks sticks = stateX.ThumbSticks;
                stateD.leftX  = sticks.Left.X;
                stateD.leftY  = sticks.Left.Y;
                stateD.leftZ  = 0f; // ???
                stateD.rightX = sticks.Right.X;
                stateD.rightY = sticks.Right.Y;
                stateD.rightZ = 0f; // ???

                GamePadTriggers triggers = stateX.Triggers;
                stateD.slider1 = stateX.Triggers.Left;
                stateD.slider2 = stateX.Triggers.Right;

                GamePadDPad dpad = stateX.DPad;
                stateD.left  = dpad.Left == ButtonState.Pressed;
                stateD.right = dpad.Right == ButtonState.Pressed;
                stateD.up    = dpad.Up == ButtonState.Pressed;
                stateD.down  = dpad.Down == ButtonState.Pressed;

                GamePadButtons buttonsX = stateX.Buttons;
                List <bool>    buttonsD = stateD.buttons ?? new List <bool>();
                for (int i = buttonsD.Count; i < 13; i++)
                {
                    buttonsD.Add(false);
                }
                while (buttonsD.Count > 13)
                {
                    buttonsD.RemoveAt(0);
                }

                buttonsD[0]  = buttonsX.X == ButtonState.Pressed;
                buttonsD[1]  = buttonsX.A == ButtonState.Pressed;
                buttonsD[2]  = buttonsX.B == ButtonState.Pressed;
                buttonsD[3]  = buttonsX.Y == ButtonState.Pressed;
                buttonsD[4]  = buttonsX.LeftShoulder == ButtonState.Pressed;
                buttonsD[5]  = buttonsX.RightShoulder == ButtonState.Pressed;
                buttonsD[6]  = triggers.Left >= 0.999f;
                buttonsD[7]  = triggers.Right >= 0.999f;
                buttonsD[8]  = buttonsX.Back == ButtonState.Pressed;
                buttonsD[9]  = buttonsX.Start == ButtonState.Pressed;
                buttonsD[10] = buttonsX.BigButton == ButtonState.Pressed; // ???
                buttonsD[11] = buttonsX.LeftStick == ButtonState.Pressed;
                buttonsD[12] = buttonsX.RightStick == ButtonState.Pressed;

                stateD.buttons = buttonsD;
            }
        }
예제 #5
0
            internal GamePadState(bool isConnected, RawState rawState, GamePadDeadZone deadZone)
            {
                this.isConnected = isConnected;

                if (!isConnected)
                {
                    rawState.dwPacketNumber        = 0;
                    rawState.Gamepad.dwButtons     = 0;
                    rawState.Gamepad.bLeftTrigger  = 0;
                    rawState.Gamepad.bRightTrigger = 0;
                    rawState.Gamepad.sThumbLX      = 0;
                    rawState.Gamepad.sThumbLY      = 0;
                    rawState.Gamepad.sThumbRX      = 0;
                    rawState.Gamepad.sThumbRY      = 0;
                }

                packetNumber = rawState.dwPacketNumber;
                buttons      = new GamePadButtons(
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Guide) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
                    );
                dPad = new GamePadDPad(
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
                    );

                switch (deadZone)
                {
                case GamePadDeadZone.IndependentAxes:
                    rawState.Gamepad.sThumbLX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLX, (short)Imports.Constants.LeftStickDeadZone);
                    rawState.Gamepad.sThumbLY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLY, (short)Imports.Constants.LeftStickDeadZone);
                    rawState.Gamepad.sThumbRX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRX, (short)Imports.Constants.RightStickDeadZone);
                    rawState.Gamepad.sThumbRY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRY, (short)Imports.Constants.RightStickDeadZone);
                    break;
                }

                thumbSticks = new GamePadThumbSticks(
                    new GamePadThumbSticks.StickValue(
                        rawState.Gamepad.sThumbLX < 0 ? rawState.Gamepad.sThumbLX / 32768.0f : rawState.Gamepad.sThumbLX / 32767.0f,
                        rawState.Gamepad.sThumbLY < 0 ? rawState.Gamepad.sThumbLY / 32768.0f : rawState.Gamepad.sThumbLY / 32767.0f),
                    new GamePadThumbSticks.StickValue(
                        rawState.Gamepad.sThumbRX < 0 ? rawState.Gamepad.sThumbRX / 32768.0f : rawState.Gamepad.sThumbRX / 32767.0f,
                        rawState.Gamepad.sThumbRY < 0 ? rawState.Gamepad.sThumbRY / 32768.0f : rawState.Gamepad.sThumbRY / 32767.0f)
                    );
                triggers = new GamePadTriggers(rawState.Gamepad.bLeftTrigger / 255.0f, rawState.Gamepad.bRightTrigger / 255.0f);
            }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Microsoft.Xna.Framework.Input.GamePadState"/> struct
        /// using the specified GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
        /// </summary>
        /// <param name="thumbSticks">Initial thumbstick state.</param>
        /// <param name="triggers">Initial trigger state..</param>
        /// <param name="buttons">Initial button state.</param>
        /// <param name="dPad">Initial directional pad state.</param>
        public GamePadState(GamePadThumbSticks thumbSticks, GamePadTriggers triggers, GamePadButtons buttons, GamePadDPad dPad) : this()
        {
            ThumbSticks = thumbSticks;
            Triggers    = triggers;
            Buttons     = buttons;
            DPad        = dPad;
            IsConnected = true;

            PlatformConstruct();
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the GamePadState class using the specified
 /// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
 /// </summary>
 /// <param name="thumbSticks">Initial thumbstick state.</param>
 /// <param name="triggers">Initial trigger state.</param>
 /// <param name="buttons">Initial button state.</param>
 /// <param name="dPad">Initial directional pad state.</param>
 public GamePadState(
     GamePadThumbSticks thumbSticks,
     GamePadTriggers triggers,
     GamePadButtons buttons
     ) : this()
 {
     ThumbSticks  = thumbSticks;
     Triggers     = triggers;
     Buttons      = buttons;
     IsConnected  = true;
     PacketNumber = 0;
 }
 private void updateGamePads()
 {
     for (uint playerIndex = 0; playerIndex < input.getPlayersCount(); ++playerIndex)
     {
         AsGamePad          gamePad  = AsGamePad.player(playerIndex);
         GamePadTriggers    triggers = input.Triggers(playerIndex);
         GamePadThumbSticks sticks   = input.ThumbSticks(playerIndex);
         gamePad.update(triggers.Left, triggers.Right);
         gamePad.getLeftStick().update(sticks.Left.X, sticks.Left.Y);
         gamePad.getRightStick().update(sticks.Right.X, sticks.Right.Y);
     }
 }
예제 #9
0
    void Positions()
    {
        // Just some shortcuts.
        GamePadThumbSticks currentTS = currentState.ThumbSticks;
        GamePadTriggers    currentT  = currentState.Triggers;

        leftStickPos.x  = currentTS.Left.X; leftStickPos.y = currentTS.Left.Y;
        rightStickPos.x = currentTS.Right.X; rightStickPos.y = currentTS.Right.Y;

        leftShoulderPos  = currentT.Left;
        rightShoulderPos = currentT.Right;
    }
예제 #10
0
 public static bool GamePadLeftTriggerDown(GamePadTriggers trigger)
 {
     if (gamePadLeftTriggerPressed && trigger.Left < 0.5)
     {
         gamePadLeftTriggerPressed = false;
     }
     else if (!gamePadLeftTriggerPressed && trigger.Left > 0.5)
     {
         gamePadLeftTriggerPressed = true;
         return(true);
     }
     return(false);
 }
예제 #11
0
        public GamepadStateWeighted(GamePadState state_, float stickDZ_ = 0.1f)
        {
            StickDZ       = stickDZ_;
            _gamepadState = state_;

            Triggers    = state_.Triggers;
            ThumbSticks = state_.ThumbSticks;
            Buttons     = state_.Buttons;
            DPad        = state_.DPad;

            IsConnected  = state_.IsConnected;
            PacketNumber = state_.PacketNumber;
        }
예제 #12
0
        public void TriggersTest([Range(-0.5f, 1.5f, 0.5f)] float left, [Range(1.5f, -0.5f, -0.5f)] float right)
        {
            var triggers = new GamePadTriggers(left, right);

            Assert.AreEqual(MathHelper.Clamp(left, 0f, 1f), triggers.Left);
            Assert.AreEqual(MathHelper.Clamp(right, 0f, 1f), triggers.Right);

#if !XNA
            var triggers2 = new GamePadTriggers(left, right);
            Assert.AreEqual(triggers, triggers2);
            Assert.AreEqual(triggers.GetHashCode(), triggers2.GetHashCode());
#endif
        }
예제 #13
0
        /// <summary>
        /// Initializes a new instance of the GamePadState class using the specified
        /// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
        /// </summary>
        /// <param name="thumbSticks">Initial thumbstick state.</param>
        /// <param name="triggers">Initial trigger state.</param>
        /// <param name="buttons">Initial button state.</param>
        /// <param name="dPad">Initial directional pad state.</param>
        public GamePadState(
			GamePadThumbSticks thumbSticks,
			GamePadTriggers triggers,
			GamePadButtons buttons,
			GamePadDPad dPad
		)
            : this()
        {
            ThumbSticks = thumbSticks;
            Triggers = triggers;
            Buttons = buttons;
            DPad = dPad;
            IsConnected = true;
            PacketNumber = 0;
        }
예제 #14
0
        private static Buttons TriggersToFlags(GamePadTriggers triggers)
        {
            Buttons flags = 0;

            if (triggers.Left > 0)
            {
                flags |= Buttons.LeftTrigger;
            }
            if (triggers.Right > 0)
            {
                flags |= Buttons.RightTrigger;
            }

            return(flags);
        }
        private static float XInputGetAxisState(GamePadTriggers xiTriggers, XboxAxis xciAxis)
        {
            float stateToReturn = 0.0f;

            switch (xciAxis)
            {
            case XboxAxis.LeftTrigger:              stateToReturn = xiTriggers.Left; break;

            case XboxAxis.RightTrigger:     stateToReturn = xiTriggers.Right; break;

            default:                                                stateToReturn = 0.0f; break;
            }

            return(stateToReturn);
        }
예제 #16
0
 internal GamePadState(bool isConnected, RawState rawState)
 {
     this.isConnected = isConnected;
     if (!isConnected)
     {
         rawState.dwPacketNumber        = 0u;
         rawState.Gamepad.dwButtons     = 0;
         rawState.Gamepad.bLeftTrigger  = 0;
         rawState.Gamepad.bRightTrigger = 0;
         rawState.Gamepad.sThumbLX      = 0;
         rawState.Gamepad.sThumbLY      = 0;
         rawState.Gamepad.sThumbRX      = 0;
         rawState.Gamepad.sThumbRY      = 0;
     }
     packetNumber = rawState.dwPacketNumber;
     buttons      = new GamePadButtons(((rawState.Gamepad.dwButtons & 0x10) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x20) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x40) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x80) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x100) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x200) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x1000) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x2000) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x4000) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 0x8000) == 0) ? ButtonState.Released : ButtonState.Pressed);
     dPad         = new GamePadDPad(((rawState.Gamepad.dwButtons & 1) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 2) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 4) == 0) ? ButtonState.Released : ButtonState.Pressed, ((rawState.Gamepad.dwButtons & 8) == 0) ? ButtonState.Released : ButtonState.Pressed);
     thumbSticks  = new GamePadThumbSticks(new GamePadThumbSticks.StickValue((float)rawState.Gamepad.sThumbLX / 32767f, (float)rawState.Gamepad.sThumbLY / 32767f), new GamePadThumbSticks.StickValue((float)rawState.Gamepad.sThumbRX / 32767f, (float)rawState.Gamepad.sThumbRY / 32767f));
     triggers     = new GamePadTriggers((float)(int)rawState.Gamepad.bLeftTrigger / 255f, (float)(int)rawState.Gamepad.bRightTrigger / 255f);
 }
예제 #17
0
        /// <summary>Reset the tracked state.</summary>
        /// <param name="state">The state from which to reset, or <c>null</c> to get the latest state.</param>
        public GamePadStateBuilder Reset(GamePadState?state = null)
        {
            this.State       = state ??= GamePad.GetState(PlayerIndex.One);
            this.IsConnected = state.Value.IsConnected;

            if (!this.IsConnected)
            {
                return(this);
            }

            GamePadDPad        pad      = state.Value.DPad;
            GamePadButtons     buttons  = state.Value.Buttons;
            GamePadTriggers    triggers = state.Value.Triggers;
            GamePadThumbSticks sticks   = state.Value.ThumbSticks;

            this.ButtonStates = new Dictionary <SButton, ButtonState>
            {
                [SButton.DPadUp]    = pad.Up,
                [SButton.DPadDown]  = pad.Down,
                [SButton.DPadLeft]  = pad.Left,
                [SButton.DPadRight] = pad.Right,

                [SButton.ControllerA]     = buttons.A,
                [SButton.ControllerB]     = buttons.B,
                [SButton.ControllerX]     = buttons.X,
                [SButton.ControllerY]     = buttons.Y,
                [SButton.LeftStick]       = buttons.LeftStick,
                [SButton.RightStick]      = buttons.RightStick,
                [SButton.LeftShoulder]    = buttons.LeftShoulder,
                [SButton.RightShoulder]   = buttons.RightShoulder,
                [SButton.ControllerBack]  = buttons.Back,
                [SButton.ControllerStart] = buttons.Start,
                [SButton.BigButton]       = buttons.BigButton
            };
            this.LeftTrigger   = triggers.Left;
            this.RightTrigger  = triggers.Right;
            this.LeftStickPos  = sticks.Left;
            this.RightStickPos = sticks.Right;

            return(this);
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the GamePadState class using the specified
        /// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
        /// </summary>
        /// <param name="thumbSticks">Initial thumbstick state.</param>
        /// <param name="triggers">Initial trigger state.</param>
        /// <param name="buttons">Initial button state.</param>
        /// <param name="dPad">Initial directional pad state.</param>
        public GamePadState(
            GamePadThumbSticks thumbSticks,
            GamePadTriggers triggers,
            GamePadButtons buttons,
            GamePadDPad dPad
            ) : this()
        {
            if (triggers.Left > GamePad.TriggerThreshold)
            {
                buttons.buttons |= Input.Buttons.LeftTrigger;
            }
            if (triggers.Right > GamePad.TriggerThreshold)
            {
                buttons.buttons |= Input.Buttons.RightTrigger;
            }
            buttons.buttons |= StickToButtons(
                thumbSticks.Left,
                Input.Buttons.LeftThumbstickLeft,
                Input.Buttons.LeftThumbstickRight,
                Input.Buttons.LeftThumbstickUp,
                Input.Buttons.LeftThumbstickDown,
                GamePad.LeftDeadZone
                );
            buttons.buttons |= StickToButtons(
                thumbSticks.Right,
                Input.Buttons.RightThumbstickLeft,
                Input.Buttons.RightThumbstickRight,
                Input.Buttons.RightThumbstickUp,
                Input.Buttons.RightThumbstickDown,
                GamePad.RightDeadZone
                );

            ThumbSticks  = thumbSticks;
            Triggers     = triggers;
            Buttons      = buttons;
            DPad         = dPad;
            IsConnected  = true;
            PacketNumber = 0;
        }
예제 #19
0
 internal GamePadState(
     bool isConnected,
     GamePadState.RawState rawState,
     GamePadDeadZone deadZone)
 {
     this.isConnected = isConnected;
     if (!isConnected)
     {
         rawState.dwPacketNumber        = 0U;
         rawState.Gamepad.wButtons      = (ushort)0;
         rawState.Gamepad.bLeftTrigger  = (byte)0;
         rawState.Gamepad.bRightTrigger = (byte)0;
         rawState.Gamepad.sThumbLX      = (short)0;
         rawState.Gamepad.sThumbLY      = (short)0;
         rawState.Gamepad.sThumbRX      = (short)0;
         rawState.Gamepad.sThumbRY      = (short)0;
     }
     this.packetNumber = rawState.dwPacketNumber;
     this.buttons      = new GamePadButtons(((int)rawState.Gamepad.wButtons & 16) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 32) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 64) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 128) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 256) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 512) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 1024) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 4096) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 8192) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 16384) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 32768) != 0 ? ButtonState.Pressed : ButtonState.Released);
     this.dPad         = new GamePadDPad(((int)rawState.Gamepad.wButtons & 1) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 2) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 4) != 0 ? ButtonState.Pressed : ButtonState.Released, ((int)rawState.Gamepad.wButtons & 8) != 0 ? ButtonState.Pressed : ButtonState.Released);
     this.thumbSticks  = new GamePadThumbSticks(Utils.ApplyLeftStickDeadZone(rawState.Gamepad.sThumbLX, rawState.Gamepad.sThumbLY, deadZone), Utils.ApplyRightStickDeadZone(rawState.Gamepad.sThumbRX, rawState.Gamepad.sThumbRY, deadZone));
     this.triggers     = new GamePadTriggers(Utils.ApplyTriggerDeadZone(rawState.Gamepad.bLeftTrigger, deadZone), Utils.ApplyTriggerDeadZone(rawState.Gamepad.bRightTrigger, deadZone));
 }
예제 #20
0
        void IInputManager.Update(GameTime gameTime)
        {
            //foreach (CollidablePairHandler p in aheadBox.CollisionInformation.Pairs)
            //    {
            //        foreach (ContactInformation c in p.Contacts)
            //        {
            //            System.Diagnostics.Debug.WriteLine("{0} {1}", (c.Contact.Position - ship.ShipPosition).Length(), c.Contact.Normal);
            //        }
            //    }

            Vector2 leftThumbStick  = Vector2.Zero;
            Vector2 rightThumbStick = Vector2.Zero;

            Buttons pressedButtons = setButtons();

            turnVal          = setTurn();
            leftThumbStick.X = turnVal;

            accelVal = setAcceleration();

            GamePadThumbSticks sticks  = new GamePadThumbSticks(leftThumbStick, rightThumbStick);
            GamePadButtons     buttons = new GamePadButtons(pressedButtons);
            GamePadTriggers    triggers;

            if (accelVal >= 0f)
            {
                triggers = new GamePadTriggers(0f, accelVal);
            }
            else
            {
                triggers = new GamePadTriggers(-accelVal, 0f);
            }
            GamePadDPad dpad = new GamePadDPad();

            lastState    = currentState;
            currentState = new GamePadState(sticks, triggers, buttons, dpad);
        }
예제 #21
0
        public override ref readonly GamepadState GetGamepadState()
        {
            if (gamepad_device == null)
            {
                return(ref GamepadState.Default);
            }

            var device = gamepad_device.Device;

            var thumbsticks_state = new GamepadThumbsticks(
                new Vector2(
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX)),
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY))
                    ),
                new Vector2(
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX)),
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY))
                    ),
                GamepadDeadZoneMode
                );

            var triggers_state = new GamePadTriggers(
                NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                 SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)),
                NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                 SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT))
                );

            var buttons_state = gamepad_device.State.ButtonsState =
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A) == 1
                    ? GamepadButton.A
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B) == 1
                    ? GamepadButton.B
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK) == 1
                    ? GamepadButton.Back
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE) == 1
                    ? GamepadButton.BigButton
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER) == 1
                    ? GamepadButton.LeftShoulder
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) == 1
                    ? GamepadButton.RightShoulder
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK) ==
                 1
                    ? GamepadButton.LeftStick
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK) ==
                 1
                    ? GamepadButton.RightStick
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START) == 1
                    ? GamepadButton.Start
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X) == 1
                    ? GamepadButton.X
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y) == 1
                    ? GamepadButton.Y
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP) ==
                 1
                    ? GamepadButton.DPadUp
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN) == 1
                    ? GamepadButton.DPadDown
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT) == 1
                    ? GamepadButton.DPadLeft
                    : 0) |
                (SDL.SDL_GameControllerGetButton(device,
                                                 SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT) == 1
                    ? GamepadButton.DPadRight
                    : 0) |
                (triggers_state.Left > 0f ? GamepadButton.LeftTrigger : 0) |
                (triggers_state.Right > 0f ? GamepadButton.RightTrigger : 0);


            gamepad_state.ButtonsState = buttons_state;
            gamepad_state.Thumbsticks  = thumbsticks_state;
            gamepad_state.Triggers     = triggers_state;

            return(ref gamepad_state);
        }
예제 #22
0
        /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary>
        /// <param name="button">The button to suppress.</param>
        public void SuppressButton(SButton button)
        {
            // keyboard
            if (this.Button.TryGetKeyboard(out Keys key))
            {
                Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Except(new[] { key }).ToArray());
            }

            // controller
            else if (this.Button.TryGetController(out Buttons controllerButton))
            {
                var newState    = GamePad.GetState(PlayerIndex.One);
                var thumbsticks = Game1.oldPadState.ThumbSticks;
                var triggers    = Game1.oldPadState.Triggers;
                var buttons     = Game1.oldPadState.Buttons;
                var dpad        = Game1.oldPadState.DPad;

                switch (controllerButton)
                {
                // d-pad
                case Buttons.DPadDown:
                    dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right);
                    break;

                case Buttons.DPadLeft:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right);
                    break;

                case Buttons.DPadRight:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right);
                    break;

                case Buttons.DPadUp:
                    dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right);
                    break;

                // trigger
                case Buttons.LeftTrigger:
                    triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right);
                    break;

                case Buttons.RightTrigger:
                    triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right);
                    break;

                // thumbstick
                case Buttons.LeftThumbstickDown:
                case Buttons.LeftThumbstickLeft:
                case Buttons.LeftThumbstickRight:
                case Buttons.LeftThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right);
                    break;

                case Buttons.RightThumbstickDown:
                case Buttons.RightThumbstickLeft:
                case Buttons.RightThumbstickRight:
                case Buttons.RightThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left);
                    break;

                // buttons
                default:
                    var mask =
                        (buttons.A == ButtonState.Pressed ? Buttons.A : 0)
                        | (buttons.B == ButtonState.Pressed ? Buttons.B : 0)
                        | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0)
                        | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0)
                        | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0)
                        | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0)
                        | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0)
                        | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0)
                        | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0)
                        | (buttons.X == ButtonState.Pressed ? Buttons.X : 0)
                        | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0);
                    mask    = mask ^ controllerButton;
                    buttons = new GamePadButtons(mask);
                    break;
                }

                Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad);
            }
        }
예제 #23
0
            internal GamePadState(bool isConnected, RawState rawState, GamePadDeadZone deadZone)
            {
                this.isConnected = isConnected;

                if (!isConnected)
                {
                    rawState.dwPacketNumber = 0;
                    rawState.Gamepad.dwButtons = 0;
                    rawState.Gamepad.bLeftTrigger = 0;
                    rawState.Gamepad.bRightTrigger = 0;
                    rawState.Gamepad.sThumbLX = 0;
                    rawState.Gamepad.sThumbLY = 0;
                    rawState.Gamepad.sThumbRX = 0;
                    rawState.Gamepad.sThumbRY = 0;
                }

                packetNumber = rawState.dwPacketNumber;
                buttons = new GamePadButtons(
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Guide) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
                );
                dPad = new GamePadDPad(
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                    (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
                );

                switch (deadZone)
                {
                    case GamePadDeadZone.IndependentAxes:
                        rawState.Gamepad.sThumbLX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLX, (short)Imports.Constants.LeftStickDeadZone);
                        rawState.Gamepad.sThumbLY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLY, (short)Imports.Constants.LeftStickDeadZone);
                        rawState.Gamepad.sThumbRX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRX, (short)Imports.Constants.RightStickDeadZone);
                        rawState.Gamepad.sThumbRY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRY, (short)Imports.Constants.RightStickDeadZone);
                        break;
                }

                thumbSticks = new GamePadThumbSticks(
                    new GamePadThumbSticks.StickValue(
                        rawState.Gamepad.sThumbLX < 0 ? rawState.Gamepad.sThumbLX / 32768.0f : rawState.Gamepad.sThumbLX / 32767.0f,
                        rawState.Gamepad.sThumbLY < 0 ? rawState.Gamepad.sThumbLY / 32768.0f : rawState.Gamepad.sThumbLY / 32767.0f),
                    new GamePadThumbSticks.StickValue(
                        rawState.Gamepad.sThumbRX < 0 ? rawState.Gamepad.sThumbRX / 32768.0f : rawState.Gamepad.sThumbRX / 32767.0f,
                        rawState.Gamepad.sThumbRY < 0 ? rawState.Gamepad.sThumbRY / 32768.0f : rawState.Gamepad.sThumbRY / 32767.0f)
                );
                triggers = new GamePadTriggers(rawState.Gamepad.bLeftTrigger / 255.0f, rawState.Gamepad.bRightTrigger / 255.0f);
            }
예제 #24
0
        public static GamepadState GetGamepadState(int index)
        {
            if (!_gamepads.ContainsKey(index))
            {
                return(GamepadState.Default);
            }

            var gamepad = _gamepads[index];

            var device = gamepad.Device;

            var thumbsticksState = new GamepadThumbsticks(

                new Vector2(
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX)),
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY))
                    ),

                new Vector2(
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX)),
                    NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device,
                                                                     SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY))
                    ),

                GamepadDeadzoneMode
                );

            var triggersState = new GamePadTriggers(
                NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)),
                NormalizeAxisValue(SDL.SDL_GameControllerGetAxis(device, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT))
                );

            var buttonsState = gamepad.State.ButtonsState =
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A) == 1)
                    ? GamepadButton.A
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B) == 1)
                    ? GamepadButton.B
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK) == 1)
                    ? GamepadButton.Back
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE) == 1)
                    ? GamepadButton.BigButton
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device,
                                                  SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER) == 1)
                    ? GamepadButton.LeftShoulder
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device,
                                                  SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) == 1)
                    ? GamepadButton.RightShoulder
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK) ==
                  1)
                    ? GamepadButton.LeftStick
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK) ==
                  1)
                    ? GamepadButton.RightStick
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START) == 1)
                    ? GamepadButton.Start
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X) == 1)
                    ? GamepadButton.X
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y) == 1)
                    ? GamepadButton.Y
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP) == 1)
                    ? GamepadButton.DPadUp
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN) == 1)
                    ? GamepadButton.DPadDown
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT) == 1)
                    ? GamepadButton.DPadLeft
                    : 0) |
                ((SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT) == 1)
                    ? GamepadButton.DPadRight
                    : 0) |
                ((triggersState.Left > 0f) ? GamepadButton.LeftTrigger : 0) |
                ((triggersState.Right > 0f) ? GamepadButton.RightTrigger : 0);



            return(new GamepadState(thumbsticksState, triggersState, buttonsState));
        }
        public static GamePadState ConvertWin10ToGamepadState(Gamepad pad)
        {
            var reading = pad.GetCurrentReading();
            var buttons = new GamePadButtons(
                reading.ButtonPressed(GamepadButtons.Menu),
                reading.ButtonPressed(GamepadButtons.View),
                reading.ButtonPressed(GamepadButtons.LeftThumbstick),
                reading.ButtonPressed(GamepadButtons.RightThumbstick),
                reading.ButtonPressed(GamepadButtons.LeftShoulder),
                reading.ButtonPressed(GamepadButtons.RightShoulder),
                ButtonState.Released,
                reading.ButtonPressed(GamepadButtons.A),
                reading.ButtonPressed(GamepadButtons.B),
                reading.ButtonPressed(GamepadButtons.X),
                reading.ButtonPressed(GamepadButtons.Y));

            var dpad = new GamePadDPad(
                reading.ButtonPressed(GamepadButtons.DPadUp),
                reading.ButtonPressed(GamepadButtons.DPadDown),
                reading.ButtonPressed(GamepadButtons.DPadLeft),
                reading.ButtonPressed(GamepadButtons.DPadRight));

            float leftx  = (float)reading.LeftThumbstickX;
            float lefty  = (float)reading.LeftThumbstickY;
            float rightx = (float)reading.RightThumbstickX;
            float righty = (float)reading.RightThumbstickY;

            const float deadzone = 0.1f;

            if (Mathf.Abs(leftx) < deadzone)
            {
                leftx = 0;
            }

            if (Mathf.Abs(lefty) < deadzone)
            {
                lefty = 0;
            }

            if (Mathf.Abs(rightx) < deadzone)
            {
                rightx = 0;
            }

            if (Mathf.Abs(righty) < deadzone)
            {
                righty = 0;
            }

            var sticks = new GamePadThumbSticks(
                new GamePadThumbSticks.StickValue(leftx, lefty),
                new GamePadThumbSticks.StickValue(rightx, righty)
                );

            var triggers = new GamePadTriggers(
                (float)reading.LeftTrigger,
                (float)reading.RightTrigger
                );

            return(new GamePadState(true, 0, buttons, dpad, sticks, triggers));
        }
예제 #26
0
        /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary>
        /// <param name="button">The button to suppress.</param>
        public void SuppressButton(SButton button)
        {
            if (button == this.Button)
            {
                this.IsSuppressed = true;
            }

            // keyboard
            if (button.TryGetKeyboard(out Keys key))
            {
                Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Union(new[] { key }).ToArray());
            }

            // controller
            else if (button.TryGetController(out Buttons controllerButton))
            {
                var newState    = GamePad.GetState(PlayerIndex.One);
                var thumbsticks = Game1.oldPadState.ThumbSticks;
                var triggers    = Game1.oldPadState.Triggers;
                var buttons     = Game1.oldPadState.Buttons;
                var dpad        = Game1.oldPadState.DPad;

                switch (controllerButton)
                {
                // d-pad
                case Buttons.DPadDown:
                    dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right);
                    break;

                case Buttons.DPadLeft:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right);
                    break;

                case Buttons.DPadRight:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right);
                    break;

                case Buttons.DPadUp:
                    dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right);
                    break;

                // trigger
                case Buttons.LeftTrigger:
                    triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right);
                    break;

                case Buttons.RightTrigger:
                    triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right);
                    break;

                // thumbstick
                case Buttons.LeftThumbstickDown:
                case Buttons.LeftThumbstickLeft:
                case Buttons.LeftThumbstickRight:
                case Buttons.LeftThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right);
                    break;

                case Buttons.RightThumbstickDown:
                case Buttons.RightThumbstickLeft:
                case Buttons.RightThumbstickRight:
                case Buttons.RightThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left);
                    break;

                // buttons
                default:
                    var mask =
                        (buttons.A == ButtonState.Pressed ? Buttons.A : 0)
                        | (buttons.B == ButtonState.Pressed ? Buttons.B : 0)
                        | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0)
                        | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0)
                        | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0)
                        | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0)
                        | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0)
                        | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0)
                        | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0)
                        | (buttons.X == ButtonState.Pressed ? Buttons.X : 0)
                        | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0);
                    mask    = mask ^ controllerButton;
                    buttons = new GamePadButtons(mask);
                    break;
                }

                Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad);
            }

            // mouse
            else if (button == SButton.MouseLeft || button == SButton.MouseMiddle || button == SButton.MouseRight || button == SButton.MouseX1 || button == SButton.MouseX2)
            {
                Game1.oldMouseState = new MouseState(
                    x: Game1.oldMouseState.X,
                    y: Game1.oldMouseState.Y,
                    scrollWheel: Game1.oldMouseState.ScrollWheelValue,
                    leftButton: button == SButton.MouseLeft ? ButtonState.Pressed : Game1.oldMouseState.LeftButton,
                    middleButton: button == SButton.MouseMiddle ? ButtonState.Pressed : Game1.oldMouseState.MiddleButton,
                    rightButton: button == SButton.MouseRight ? ButtonState.Pressed : Game1.oldMouseState.RightButton,
                    xButton1: button == SButton.MouseX1 ? ButtonState.Pressed : Game1.oldMouseState.XButton1,
                    xButton2: button == SButton.MouseX2 ? ButtonState.Pressed : Game1.oldMouseState.XButton2
                    );
            }
        }
예제 #27
0
        public void SuppressButton(SButton button)
        {
            // SuppressButton copyright Pathoschild (https://github.com/Pathoschild)
            // Used and modified with permission
            // keyboard
            if (button.TryGetKeyboard(out Keys key))
            {
                Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Union(new[] { key }).ToArray());
            }

            // controller
            else if (button.TryGetController(out Buttons controllerButton))
            {
                var newState    = GamePad.GetState(PlayerIndex.One);
                var thumbsticks = Game1.oldPadState.ThumbSticks;
                var triggers    = Game1.oldPadState.Triggers;
                var buttons     = Game1.oldPadState.Buttons;
                var dpad        = Game1.oldPadState.DPad;

                switch (controllerButton)
                {
                // d-pad
                case Buttons.DPadDown:
                    dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right);
                    break;

                case Buttons.DPadLeft:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right);
                    break;

                case Buttons.DPadRight:
                    dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right);
                    break;

                case Buttons.DPadUp:
                    dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right);
                    break;

                // trigger
                case Buttons.LeftTrigger:
                    triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right);
                    break;

                case Buttons.RightTrigger:
                    triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right);
                    break;

                // thumbstick
                case Buttons.LeftThumbstickDown:
                case Buttons.LeftThumbstickLeft:
                case Buttons.LeftThumbstickRight:
                case Buttons.LeftThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right);
                    break;

                case Buttons.RightThumbstickDown:
                case Buttons.RightThumbstickLeft:
                case Buttons.RightThumbstickRight:
                case Buttons.RightThumbstickUp:
                    thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left);
                    break;

                // buttons
                default:
                    var mask =
                        (buttons.A == ButtonState.Pressed ? Buttons.A : 0)
                        | (buttons.B == ButtonState.Pressed ? Buttons.B : 0)
                        | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0)
                        | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0)
                        | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0)
                        | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0)
                        | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0)
                        | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0)
                        | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0)
                        | (buttons.X == ButtonState.Pressed ? Buttons.X : 0)
                        | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0);
                    mask    = mask ^ controllerButton;
                    buttons = new GamePadButtons(mask);
                    break;
                }

                Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad);
            }
            // mouse
            else if (button.TryGetStardewInput(out InputButton inputButton))
            {
                if (inputButton.mouseLeft)
                {
                    Game1.oldMouseState = new MouseState(
                        Game1.oldMouseState.X,
                        Game1.oldMouseState.Y,
                        Game1.oldMouseState.ScrollWheelValue,
                        ButtonState.Pressed,
                        Game1.oldMouseState.MiddleButton,
                        Game1.oldMouseState.RightButton,
                        Game1.oldMouseState.XButton1,
                        Game1.oldMouseState.XButton2
                        );
                }
                else if (inputButton.mouseRight)
                {
                    Game1.oldMouseState = new MouseState(
                        Game1.oldMouseState.X,
                        Game1.oldMouseState.Y,
                        Game1.oldMouseState.ScrollWheelValue,
                        Game1.oldMouseState.LeftButton,
                        Game1.oldMouseState.MiddleButton,
                        ButtonState.Pressed,
                        Game1.oldMouseState.XButton1,
                        Game1.oldMouseState.XButton2
                        );
                }
            }
        }
 public TriggerStateEventArgs(GamePadNumber controllerNum, GamePadTriggers trigger, float triggerValue)
     : base(controllerNum)
 {
     this.Trigger = trigger;
     this.TriggerValue = triggerValue;
 }