예제 #1
0
파일: Manager.cs 프로젝트: sc2ad/CelesteBot
        public static GamePadState CalculateInputs()
        {
            kbState = Keyboard.GetState();

            GamePadDPad pad = new GamePadDPad(
                ButtonState.Released,
                ButtonState.Released,
                IsKeyDown(Keys.OemQuotes) ? ButtonState.Pressed : ButtonState.Released,
                IsKeyDown(Keys.OemBackslash) ? ButtonState.Pressed : ButtonState.Released);
            GamePadThumbSticks sticks   = new GamePadThumbSticks(new Vector2(0, 0), new Vector2(0, 0));
            GamePadState       padState = new GamePadState(
                sticks,
                new GamePadTriggers(0, 0),
                new GamePadButtons(
                    IsTile(GetTileInFrontOfPlayer()) ? Buttons.A : (Buttons)0
                    | (Buttons)0
                    | (Buttons)0
                    | (Buttons)0
                    | (Buttons)0
                    | (Buttons)0
                    | (Buttons)0
                    ),
                pad
                );

            return(padState);
        }
예제 #2
0
        private static void SetFeather(InputFrame input, ref GamePadDPad pad, ref GamePadThumbSticks sticks)
        {
            pad = new GamePadDPad(ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            Vector2 aim = AnalogHelper.GetFeather(input);

            sticks = new GamePadThumbSticks(aim, new Vector2(0, 0));
        }
예제 #3
0
        private static void SetFeather(InputRecord input, ref GamePadDPad pad, ref GamePadThumbSticks sticks)
        {
            pad = new GamePadDPad(ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            Vector2 aim = ValidateFeatherInput(input);

            sticks = new GamePadThumbSticks(aim, new Vector2(0, 0));
        }
예제 #4
0
        public static void SetInputs(InputRecord input)
        {
            GamePadDPad        pad;
            GamePadThumbSticks sticks;

            pad = new GamePadDPad(
                input.HasActions(Actions.Up) ? ButtonState.Pressed : ButtonState.Released,
                input.HasActions(Actions.Down) ? ButtonState.Pressed : ButtonState.Released,
                input.HasActions(Actions.Left) ? ButtonState.Pressed : ButtonState.Released,
                input.HasActions(Actions.Right) ? ButtonState.Pressed : ButtonState.Released
                );
            sticks = new GamePadThumbSticks(new Vector2(0, 0), new Vector2(0, 0));
            GamePadState state = new GamePadState(
                sticks,
                new GamePadTriggers(),
                new GamePadButtons(
                    (input.HasActions(Actions.Jump) ? Buttons.A : 0)
                    | (input.HasActions(Actions.Map) ? Buttons.Y : 0)
                    | (input.HasActions(Actions.Feathers) ? Buttons.B : 0)
                    | (input.HasActions(Actions.Attack) ? Buttons.X : 0)
                    | (input.HasActions(Actions.ToggleRight) ? Buttons.RightShoulder : 0)
                    | (input.HasActions(Actions.Menu) ? Buttons.Start : 0)
                    | (input.HasActions(Actions.ToggleLeft) ? Buttons.LeftShoulder : 0)
                    ),
                pad
                );

            Input.TasGamepadState = state;
        }
예제 #5
0
        //* ────________________________________*
        //* methods ───────────────────────────────-*

        //* -----------------------------------------------------------------------*
        /// <summary>
        /// 前回の状態と現在の状態より、ボタン入力があったかどうかを取得します。
        /// </summary>
        ///
        /// <param name="now">現在のキー入力状態。</param>
        /// <param name="prev">前回のキー入力状態。</param>
        /// <returns>ボタン入力があった場合、<c>true</c>。</returns>
        protected override bool isInput(GamePadState now, GamePadState prev)
        {
            bool result = now.IsConnected && prev.IsConnected;

            if (result)
            {
                GamePadButtons     btns  = now.Buttons;
                GamePadDPad        dpad  = now.DPad;
                GamePadThumbSticks nStks = now.ThumbSticks;
                GamePadThumbSticks pStks = prev.ThumbSticks;
                // TODO : トリガ忘れてね?
                result =
                    btns != prev.Buttons && (
                        btns.A == ButtonState.Pressed ||
                        btns.B == ButtonState.Pressed ||
                        btns.Back == ButtonState.Pressed ||
                        btns.BigButton == ButtonState.Pressed ||
                        btns.LeftShoulder == ButtonState.Pressed ||
                        btns.LeftStick == ButtonState.Pressed ||
                        btns.RightShoulder == ButtonState.Pressed ||
                        btns.RightStick == ButtonState.Pressed ||
                        btns.Start == ButtonState.Pressed ||
                        btns.X == ButtonState.Pressed ||
                        btns.Y == ButtonState.Pressed) ||
                    dpad != prev.DPad && (
                        dpad.Up == ButtonState.Pressed ||
                        dpad.Down == ButtonState.Pressed ||
                        dpad.Left == ButtonState.Pressed ||
                        dpad.Right == ButtonState.Pressed) ||
                    nStks != pStks && (
                        (nStks.Left.Length() >= threshold && pStks.Left.Length() < threshold) ||
                        (nStks.Right.Length() >= threshold && pStks.Right.Length() < threshold));
            }
            return(result);
        }
예제 #6
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;
            }
        }
예제 #7
0
 public GamePadDPad(ButtonState upValue, ButtonState downValue, ButtonState leftValue, ButtonState rightValue)
 {
     this       = new GamePadDPad();
     this.Up    = upValue;
     this.Down  = downValue;
     this.Left  = leftValue;
     this.Right = rightValue;
 }
예제 #8
0
        static InputExtensions()
        {
            oldKeyState = newKeyState = Keyboard.GetState();
            var padState = GamePad.GetState(PlayerIndex.One);

            oldDPadState   = newDPadState = padState.DPad;
            oldButtonState = newButtonState = padState.Buttons;
        }
예제 #9
0
 public GamePadDPad(ButtonState upValue, ButtonState downValue, ButtonState leftValue, ButtonState rightValue)
 {
   this = new GamePadDPad();
   this.Up = upValue;
   this.Down = downValue;
   this.Left = leftValue;
   this.Right = rightValue;
 }
예제 #10
0
        public void ValidateToGamePadDPadFromJoystickHatStates()
        {
            GamePadDPad o = new GamePadDPad();

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.None);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.None, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.None, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.None, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.None, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.Up);
            Assert.AreEqual(ButtonState.Pressed, o.Up, "For JoystickHatStates.Up, o.Up = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.Up, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.Up, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.Up, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.RightUp);
            Assert.AreEqual(ButtonState.Pressed, o.Up, "For JoystickHatStates.RightUp, o.Up = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Pressed, o.Right, "For JoystickHatStates.RightUp, o.Right = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.RightUp, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.RightUp, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.Right);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.Right, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Right, "For JoystickHatStates.Right, o.Right = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.Right, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.Right, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.RightDown);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.RightDown, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Right, "For JoystickHatStates.RightDown, o.Right = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Pressed, o.Down, "For JoystickHatStates.RightDown, o.Down = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.RightDown, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.Down);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.Down, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.Down, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Down, "For JoystickHatStates.Down, o.Down = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Left, "For JoystickHatStates.Down, o.Left = ButtonState.Released");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.LeftDown);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.LeftDown, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.LeftDown, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Down, "For JoystickHatStates.LeftDown, o.Down = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Pressed, o.Left, "For JoystickHatStates.LeftDown, o.Left = ButtonState.Pressed");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.Left);
            Assert.AreEqual(ButtonState.Released, o.Up, "For JoystickHatStates.Left, o.Up = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.Left, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.Left, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Left, "For JoystickHatStates.Left, o.Left = ButtonState.Pressed");

            GamePadDPad.ToGamePadDPad(ref o, JoystickHatStates.LeftUp);
            Assert.AreEqual(ButtonState.Pressed, o.Up, "For JoystickHatStates.LeftUp, o.Up = ButtonState.Pressed");
            Assert.AreEqual(ButtonState.Released, o.Right, "For JoystickHatStates.LeftUp, o.Right = ButtonState.Released");
            Assert.AreEqual(ButtonState.Released, o.Down, "For JoystickHatStates.LeftUp, o.Down = ButtonState.Released");
            Assert.AreEqual(ButtonState.Pressed, o.Left, "For JoystickHatStates.LeftUp, o.Left = ButtonState.Pressed");
        }
예제 #11
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);
            }
예제 #12
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();
        }
예제 #13
0
        internal static Collection <JadePressedState> DPadPressedStateArray(GamePadDPad dpad)
        {
            Collection <JadePressedState> states = new Collection <JadePressedState>();

            states.Add(ConvertState(dpad.Down));
            states.Add(ConvertState(dpad.Left));
            states.Add(ConvertState(dpad.Right));
            states.Add(ConvertState(dpad.Up));
            return(states);
        }
예제 #14
0
 /// <summary>
 ///   Creates a default orthographic camera and lets it respond as if
 ///   the game pad's directional pad was in the specified state
 /// </summary>
 /// <param name="directionalPad">State of the game pad's directional pad</param>
 /// <returns>The camera after it has responded to the provided controls</returns>
 private Camera handleControlsOnDefaultCamera(GamePadDPad directionalPad)
 {
     return(handleControlsOnDefaultCamera(
                new KeyboardState(),
                new GamePadState(
                    new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(),
                    directionalPad
                    )
                ));
 }
예제 #15
0
 private static void SetDPad(InputFrame input, ref GamePadDPad pad, ref GamePadThumbSticks sticks)
 {
     pad = new GamePadDPad(
         input.HasActions(Actions.Up) ? ButtonState.Pressed : ButtonState.Released,
         input.HasActions(Actions.Down) ? ButtonState.Pressed : ButtonState.Released,
         input.HasActions(Actions.Left) ? ButtonState.Pressed : ButtonState.Released,
         input.HasActions(Actions.Right) ? ButtonState.Pressed : ButtonState.Released
         );
     sticks = new GamePadThumbSticks(new Vector2(0, 0), new Vector2(0, 0));
 }
예제 #16
0
        public static void SetInputs(InputRecord input)
        {
            GamePadDPad        pad;
            GamePadThumbSticks sticks;

            if (input.HasActions(Actions.Feather))
            {
                pad    = new GamePadDPad(ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
                sticks = new GamePadThumbSticks(new Vector2(input.GetX(), input.GetY()), new Vector2(0, 0));
            }
            else
            {
                pad = new GamePadDPad(
                    input.HasActions(Actions.Up) ? ButtonState.Pressed : ButtonState.Released,
                    input.HasActions(Actions.Down) ? ButtonState.Pressed : ButtonState.Released,
                    input.HasActions(Actions.Left) ? ButtonState.Pressed : ButtonState.Released,
                    input.HasActions(Actions.Right) ? ButtonState.Pressed : ButtonState.Released
                    );
                sticks = new GamePadThumbSticks(new Vector2(0, 0), new Vector2(0, 0));
            }
            GamePadState state = new GamePadState(
                sticks,
                new GamePadTriggers(input.HasActions(Actions.Journal) ? 1f : 0f, 0),
                new GamePadButtons(
                    (input.HasActions(Actions.Jump) ? Buttons.A : (Buttons)0)
                    | (input.HasActions(Actions.Jump2) ? Buttons.Y : (Buttons)0)
                    | (input.HasActions(Actions.Dash) ? Buttons.B : (Buttons)0)
                    | (input.HasActions(Actions.Dash2) ? Buttons.X : (Buttons)0)
                    | (input.HasActions(Actions.Grab) ? Buttons.RightShoulder : (Buttons)0)
                    | (input.HasActions(Actions.Start) ? Buttons.Start : (Buttons)0)
                    | (input.HasActions(Actions.Restart) ? Buttons.LeftShoulder : (Buttons)0)
                    ),
                pad
                );

            bool found = false;

            for (int i = 0; i < 4; i++)
            {
                MInput.GamePads[i].Update();
                if (MInput.GamePads[i].Attached)
                {
                    found = true;
                    MInput.GamePads[i].CurrentState = state;
                }
            }

            if (!found)
            {
                MInput.GamePads[0].CurrentState = state;
                MInput.GamePads[0].Attached     = true;
            }
            MInput.UpdateVirtualInputs();
        }
예제 #17
0
        public static void Update()
        {
            oldKeyState = newKeyState;
            newKeyState = Keyboard.GetState();

            var padState = GamePad.GetState(PlayerIndex.One);

            oldDPadState   = newDPadState;
            newDPadState   = padState.DPad;
            oldButtonState = newButtonState;
            newButtonState = padState.Buttons;
        }
예제 #18
0
            public int[] GetDPad(int dpadIndex)
            {
                if (this.DPadCount != 0)
                {
                    throw new System.IndexOutOfRangeException();
                }
                GamePadDPad dpad = this.state.DPad;

                return(new int[] {
                    dpad.Left == ButtonState.Pressed ? -1 : (dpad.Right == ButtonState.Pressed ? 1 : 0),
                    dpad.Up == ButtonState.Pressed ? -1 : (dpad.Down == ButtonState.Pressed ? 1 : 0),
                });
            }
예제 #19
0
 internal GamePadDPad(Buttons b)
 {
   this = new GamePadDPad();
   if ((b & Buttons.DPadDown) == Buttons.DPadDown)
     this.Down = ButtonState.Pressed;
   if ((b & Buttons.DPadLeft) == Buttons.DPadLeft)
     this.Left = ButtonState.Pressed;
   if ((b & Buttons.DPadRight) == Buttons.DPadRight)
     this.Right = ButtonState.Pressed;
   if ((b & Buttons.DPadUp) != Buttons.DPadUp)
     return;
   this.Up = ButtonState.Pressed;
 }
예제 #20
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;
        }
예제 #21
0
        private bool InputGetDPadButtonState(GamePadDPad pad, GmpdButton btn)
        {
            switch (btn)
            {
            case (GmpdButton.DPadDown): return(ButtonStateToBool(pad.Down)); break;

            case (GmpdButton.DPadUp): return(ButtonStateToBool(pad.Up)); break;

            case (GmpdButton.DPadLeft): return(ButtonStateToBool(pad.Left)); break;

            case (GmpdButton.DPadRight): return(ButtonStateToBool(pad.Right)); break;
            }
            return(false);
        }
        public void CanConvertBetweeenDirectionalPadAndPov(
            int pov, bool up, bool down, bool left, bool right
            )
        {
            GamePadDPad dpad = new GamePadDPad(
                up ? ButtonState.Pressed : ButtonState.Released,
                down ? ButtonState.Pressed : ButtonState.Released,
                left ? ButtonState.Pressed : ButtonState.Released,
                right ? ButtonState.Pressed : ButtonState.Released
                );

            Assert.AreEqual(pov, ExtendedGamePadState.PovFromDpad(dpad));
            Assert.AreEqual(dpad, ExtendedGamePadState.DpadFromPov(pov));
        }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the GamePadState class with the specified stick,
 /// trigger, and button values.
 /// </summary>
 /// <param name="leftThumbStick">
 /// Left stick value. Each axis is clamped between 1.0 and 1.0.
 /// </param>
 /// <param name="rightThumbStick">
 /// Right stick value. Each axis is clamped between 1.0 and 1.0.
 /// </param>
 /// <param name="leftTrigger">
 /// Left trigger value. This value is clamped between 0.0 and 1.0.
 /// </param>
 /// <param name="rightTrigger">
 /// Right trigger value. This value is clamped between 0.0 and 1.0.
 /// </param>
 /// <param name="buttons">
 /// Array or parameter list of Buttons to initialize as pressed.
 /// </param>
 public GamePadState(
     Vector2 leftThumbStick,
     Vector2 rightThumbStick,
     float leftTrigger,
     float rightTrigger,
     params Buttons[] buttons
     ) : this(
         new GamePadThumbSticks(leftThumbStick, rightThumbStick),
         new GamePadTriggers(leftTrigger, rightTrigger),
         GamePadButtons.FromButtonArray(buttons),
         GamePadDPad.FromButtonArray(buttons)
         )
 {
 }
예제 #24
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;
 }
예제 #25
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;
        }
        /// <summary>Converts a directional pad state into a PoV controller state</summary>
        /// <param name="dpad">Directional pad state that will be converted</param>
        /// <returns>The equivalent PoV controller pad state</returns>
        /// <remarks>
        ///   Conflicting states (eg. directional pad 'down' and 'up' at the same time)
        ///   are resolved as if the specific axis was neutral.
        /// </remarks>
        public static int PovFromDpad(GamePadDPad dpad)
        {
            const ButtonState pressed  = ButtonState.Pressed;
            const ButtonState released = ButtonState.Released;

            if ((dpad.Up == pressed) && (dpad.Down == released))
            {
                if ((dpad.Left == pressed) && (dpad.Right == released))
                {
                    return(31500); // Left up
                }
                else if ((dpad.Right == pressed) && (dpad.Left == released))
                {
                    return(4500); // Right up
                }
                else
                {
                    return(0); // Up
                }
            }
            else if ((dpad.Down == pressed) && (dpad.Up == released))
            {
                if ((dpad.Left == pressed) && (dpad.Right == released))
                {
                    return(22500); // Left down
                }
                else if ((dpad.Right == pressed) && (dpad.Left == released))
                {
                    return(13500); // Right down
                }
                else
                {
                    return(18000); // Down
                }
            }
            else if ((dpad.Left == pressed) && (dpad.Right == released))
            {
                return(27000); // Left
            }
            else if ((dpad.Right == pressed) && (dpad.Left == released))
            {
                return(9000); // Right
            }
            else
            {
                return(-1); // Neutral
            }
        }
예제 #27
0
        public static GamePadState GetState(int index, GamePadDeadZone deadZoneMode)
        {
            var          gamePad = GamePads[index];
            GamePadState state   = GamePadState.Default;

            if (gamePad != null && gamePad._isConnected)
            {
                // Check if the device was disconnected
                var dvc = InputDevice.GetDevice(gamePad._deviceId);
                if (dvc == null)
                {
                    Android.Util.Log.Debug("MonoGame", "Detected controller disconnect [" + index + "] ");
                    gamePad._isConnected = false;
                    return(state);
                }

                GamePadThumbSticks thumbSticks = new GamePadThumbSticks(gamePad._leftStick, gamePad._rightStick);

                var dpad = new GamePadDPad(
                    HasFlagToState(gamePad._buttons, Buttons.DPadUp),
                    HasFlagToState(gamePad._buttons, Buttons.DPadDown),
                    HasFlagToState(gamePad._buttons, Buttons.DPadLeft),
                    HasFlagToState(gamePad._buttons, Buttons.DPadRight));

                state = new GamePadState(
                    thumbSticks,
                    new GamePadTriggers(gamePad._leftTrigger, gamePad._rightTrigger),
                    new GamePadButtons(gamePad._buttons),
                    dpad);
            }
            // we need to add the default "no gamepad connected but the user hit back"
            // behaviour here
            else
            {
                if (index == 0 && Back)
                {
                    // Consume state
                    Back  = false;
                    state = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(Buttons.Back), new GamePadDPad());
                }
                else
                {
                    state = new GamePadState();
                }
            }

            return(state);
        }
예제 #28
0
 private static void SetState(InputRecord input, ref GamePadState state, ref GamePadDPad pad, ref GamePadThumbSticks sticks)
 {
     state = new GamePadState(
         sticks,
         new GamePadTriggers(input.HasActions(Actions.Journal) ? 1f : 0f, 0),
         new GamePadButtons(
             (input.HasActions(Actions.Jump) ? Buttons.A : 0)
             | (input.HasActions(Actions.Jump2) ? Buttons.Y : 0)
             | (input.HasActions(Actions.Dash) ? Buttons.B : 0)
             | (input.HasActions(Actions.Dash2) ? Buttons.X : 0)
             | (input.HasActions(Actions.Grab) ? grabButton : 0)
             | (input.HasActions(Actions.Start) ? Buttons.Start : 0)
             | (input.HasActions(Actions.Restart) ? Buttons.LeftShoulder : 0)
             ),
         pad
         );
 }
예제 #29
0
        //* ────________________________________*
        //* methods ───────────────────────────────-*

        //* -----------------------------------------------------------------------*
        /// <summary>方向ボタンの状態を更新します。</summary>
        ///
        /// <param name="state">最新の入力情報。</param>
        /// <param name="entity">この状態を適用されているオブジェクト。</param>
        /// <param name="privateMembers">
        /// オブジェクトと状態クラスのみがアクセス可能なフィールド。
        /// </param>
        /// <param name="gameTime">前フレームが開始してからの経過時間。</param>
        protected override void refleshAxis(
            GamePadState state, CInputXBOX360 entity,
            CInputXBOX360.CPrivateMembers privateMembers, GameTime gameTime)
        {
            GamePadDPad dpad = state.DPad;

            for (int i = entity.dirInputState.Length; --i >= 0;)
            {
                entity.dirInputState[i].refresh(matchList[i](dpad));
            }
            EDirectionFlags axisFlags;
            Vector2         axisVector;

            CHelper.createVector(entity.dirInputState, out axisVector, out axisFlags);
            privateMembers.axisVector = axisVector;
            privateMembers.axisFlag   = axisFlags;
        }
예제 #30
0
        public static void SetInputs(InputFrame input)
        {
            GamePadDPad        pad    = default;
            GamePadThumbSticks sticks = default;
            GamePadState       state  = default;

            if (input.HasActions(Actions.Feather))
            {
                SetFeather(input, ref pad, ref sticks);
            }
            else
            {
                SetDPad(input, ref pad, ref sticks);
            }

            SetState(input, ref state, ref pad, ref sticks);

            bool found = false;

            for (int i = 0; i < 4; i++)
            {
                MInput.GamePads[i].Update();
                if (MInput.GamePads[i].Attached)
                {
                    found = true;
                    MInput.GamePads[i].CurrentState = state;
                }
            }

            if (!found)
            {
                MInput.GamePads[0].CurrentState = state;
                MInput.GamePads[0].Attached     = true;
            }

            if (input.HasActions(Actions.Confirm))
            {
                MInput.Keyboard.CurrentState = new KeyboardState(Keys.Enter);
            }
            else
            {
                MInput.Keyboard.CurrentState = new KeyboardState();
            }

            UpdateVirtualInputs();
        }
예제 #31
0
        public static float InputGetDPadAxisState(GamePadDPad pad, GmpdAxis gAxis)
        {
            float valToReturn = 0.0f;

            if (GmpdAxis.DpadX == gAxis)
            {
                valToReturn  = (pad.Left == ButtonState.Pressed ? -1f : 0f);
                valToReturn += (pad.Right == ButtonState.Pressed ? 1f : 0f);
            }
            else if (GmpdAxis.DpadY == gAxis)
            {
                valToReturn  = (pad.Up == ButtonState.Pressed ? 1f : 0f);
                valToReturn += (pad.Down == ButtonState.Pressed ? -1f : 0f);
            }

            return(valToReturn);
        }
        private static ButtonState XInputGetDPadState(GamePadDPad xiDPad, XboxDPad xciDPad)
        {
            ButtonState stateToReturn = ButtonState.Released;

            switch (xciDPad)
            {
            case XboxDPad.Up:                               stateToReturn = xiDPad.Up; break;

            case XboxDPad.Down:                     stateToReturn = xiDPad.Down; break;

            case XboxDPad.Left:                     stateToReturn = xiDPad.Left; break;

            case XboxDPad.Right:                    stateToReturn = xiDPad.Right; break;
            }

            return(stateToReturn);
        }
예제 #33
0
 public JoystickState(
     bool isConnected,
     float posX, float posY, float posZ,
     float posR, float posU, float posV,
     int buttons, int buttonNum, bool[] buttonMap, GamePadDPad dPad)
 {
     this.isConnected = isConnected;
     this.positionX   = posX;
     this.positionY   = posY;
     this.positionZ   = posZ;
     this.positionR   = posR;
     this.positionU   = posU;
     this.positionV   = posV;
     this.buttons     = buttons;
     this.buttonNum   = buttonNum;
     this.buttonMap   = buttonMap;
     this.dpad        = dPad;
 }
예제 #34
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);
            }