Example #1
0
        /// <summary>
        /// Get directional press from button, POV and analog.
        /// </summary>
        /// <param name="playerButtons"></param>
        /// <param name="button"></param>
        /// <param name="state"></param>
        /// <param name="direction"></param>
        private static void GetDirectionPress(PlayerButtons playerButtons, XInputButton button, State state, Direction direction)
        {
            if (button == null)
            {
                return;
            }

            // Analog Axis, we expect that the both direction are on same axis!!!!
            if (button.IsLeftThumbX || button.IsLeftThumbY || button.IsRightThumbX || button.IsRightThumbY)
            {
                var calcVal = 0;
                if (button.IsLeftThumbY)
                {
                    calcVal = state.Gamepad.LeftThumbY;
                }
                if (button.IsLeftThumbX)
                {
                    calcVal = state.Gamepad.LeftThumbX;
                }
                if (button.IsRightThumbX)
                {
                    calcVal = state.Gamepad.RightThumbX;
                }
                if (button.IsRightThumbY)
                {
                    calcVal = state.Gamepad.RightThumbY;
                }
                if (button.IsAxisMinus)
                {
                    if (calcVal >= 0 + 15000)
                    {
                    }
                    else if (calcVal <= 0 - 15000)
                    {
                        InputCode.SetPlayerDirection(playerButtons, direction);
                    }
                    else
                    {
                        if (direction == Direction.Left || direction == Direction.Right)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                        }
                        if (direction == Direction.Up || direction == Direction.Down)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                        }
                    }
                }
                else
                {
                    if (calcVal >= 0 + 15000)
                    {
                        InputCode.SetPlayerDirection(playerButtons, direction);
                    }
                    else if (calcVal <= 0 - 15000)
                    {
                    }
                    else
                    {
                        if (direction == Direction.Left || direction == Direction.Right)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                        }
                        if (direction == Direction.Up || direction == Direction.Down)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                        }
                    }
                }
            }

            // Normal button
            if (button.IsButton)
            {
                if ((button.ButtonCode & (short)state.Gamepad.Buttons) != 0)
                {
                    InputCode.SetPlayerDirection(playerButtons, direction);
                }
                else
                {
                    if (direction == Direction.Left && !playerButtons.RightPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    }
                    if (direction == Direction.Right && !playerButtons.LeftPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    }
                    if (direction == Direction.Up && !playerButtons.DownPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    }
                    if (direction == Direction.Down && !playerButtons.UpPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Get directional press from button, POV and analog.
        /// </summary>
        /// <param name="playerButtons"></param>
        /// <param name="button"></param>
        /// <param name="state"></param>
        /// <param name="direction"></param>
        private static void GetDirectionPress(PlayerButtons playerButtons, JoystickButton button, JoystickUpdate state, Direction direction)
        {
            if (button == null)
            {
                return;
            }
            if ((JoystickOffset)button.Button != state.Offset)
            {
                return;
            }
            // POV
            if (button.Button >= 32 && button.Button <= 44)
            {
                switch (state.Value)
                {
                case -1:
                    InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    break;

                case 0:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    break;

                case 4500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    break;

                case 9000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    break;

                case 13500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    break;

                case 18000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    break;

                case 22500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    break;

                case 27000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    break;

                case 31500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    break;
                }
            }

            // Analog Axis, we expect that the both direction are on same axis!!!!
            if (state.Offset == JoystickOffset.X || state.Offset == JoystickOffset.Y ||
                state.Offset == JoystickOffset.Z || state.Offset == JoystickOffset.RotationX ||
                state.Offset == JoystickOffset.RotationY || state.Offset == JoystickOffset.RotationZ ||
                state.Offset == JoystickOffset.Sliders0 || state.Offset == JoystickOffset.Sliders1 ||
                state.Offset == JoystickOffset.AccelerationX || state.Offset == JoystickOffset.AccelerationY ||
                state.Offset == JoystickOffset.AccelerationZ)
            {
                if (button.IsAxisMinus)
                {
                    if (state.Value >= 32064 + 15000)
                    {
                    }
                    else if (state.Value <= 32064 - 15000)
                    {
                        InputCode.SetPlayerDirection(playerButtons, direction);
                    }
                    else
                    {
                        if (direction == Direction.Left || direction == Direction.Right)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                        }
                        if (direction == Direction.Up || direction == Direction.Down)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                        }
                    }
                }
                else
                {
                    if (state.Value >= 32064 + 15000)
                    {
                        InputCode.SetPlayerDirection(playerButtons, direction);
                    }
                    else if (state.Value <= 32064 - 15000)
                    {
                    }
                    else
                    {
                        if (direction == Direction.Left || direction == Direction.Right)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                        }
                        if (direction == Direction.Up || direction == Direction.Down)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                        }
                    }
                }
            }

            // Normal button
            if (button.Button >= 48 && button.Button <= 175)
            {
                if (state.Value != 0)
                {
                    InputCode.SetPlayerDirection(playerButtons, direction);
                }
                else
                {
                    if (direction == Direction.Left && !playerButtons.RightPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    }
                    if (direction == Direction.Right && !playerButtons.LeftPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    }
                    if (direction == Direction.Up && !playerButtons.DownPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    }
                    if (direction == Direction.Down && !playerButtons.UpPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    }
                }
            }
        }