Пример #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>
        public static void GetDirectionPressDirectInput(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 && !(direction == Direction.FFUp || direction == Direction.FFDown || direction == Direction.FFRight || direction == Direction.FFLeft || direction == Direction.FFHoriCenter || direction == Direction.FFVertCenter))
            {
                switch (state.Value)
                {
                case -1:
                    InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                    InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                    break;

                case 0:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    playerButtons.Down  = false;
                    playerButtons.Left  = false;
                    playerButtons.Right = false;
                    break;

                case 4500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    playerButtons.Down = false;
                    playerButtons.Left = false;
                    break;

                case 9000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    playerButtons.Down = false;
                    playerButtons.Left = false;
                    playerButtons.Up   = false;
                    break;

                case 13500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Right);
                    playerButtons.Left = false;
                    playerButtons.Up   = false;
                    break;

                case 18000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    playerButtons.Right = false;
                    playerButtons.Left  = false;
                    playerButtons.Up    = false;
                    break;

                case 22500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Down);
                    playerButtons.Right = false;
                    playerButtons.Up    = false;
                    break;

                case 27000:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    playerButtons.Down  = false;
                    playerButtons.Right = false;
                    playerButtons.Up    = false;
                    break;

                case 31500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.Left);
                    InputCode.SetPlayerDirection(playerButtons, Direction.Up);
                    playerButtons.Down  = false;
                    playerButtons.Right = false;
                    break;
                }
            }
            else if (button.Button >= 32 && button.Button <= 44 && (direction == Direction.FFUp ||
                                                                    direction == Direction.FFDown ||
                                                                    direction == Direction.FFRight ||
                                                                    direction == Direction.FFLeft ||
                                                                    direction == Direction.FFHoriCenter ||
                                                                    direction == Direction.FFVertCenter))
            {
                switch (state.Value)
                {
                case -1:
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                    break;

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

                case 4500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFUp);
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFRight);
                    break;

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

                case 13500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFDown);
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFRight);
                    break;

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

                case 22500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFLeft);
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFDown);
                    break;

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

                case 31500:
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFLeft);
                    InputCode.SetPlayerDirection(playerButtons, Direction.FFUp);
                    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);
                        }
                        if (direction == Direction.FFLeft || direction == Direction.FFRight)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                        }
                        if (direction == Direction.FFUp || direction == Direction.FFDown)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                        }
                    }
                }
                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);
                        }
                        if (direction == Direction.FFLeft || direction == Direction.FFRight)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                        }
                        if (direction == Direction.FFUp || direction == Direction.FFDown)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                        }
                    }
                }
            }

            // 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);
                    }
                    if (direction == Direction.FFLeft && !playerButtons.FFRightPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                    }
                    if (direction == Direction.FFRight && !playerButtons.FFLeftPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                    }
                    if (direction == Direction.FFUp && !playerButtons.FFDownPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                    }
                    if (direction == Direction.FFDown && !playerButtons.FFUpPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                    }
                }
            }
        }
Пример #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>
        public static void GetDirectionPressXinput(PlayerButtons playerButtons, XInputButton button, State state, Direction direction, int index)
        {
            if (button?.XInputIndex != index)
            {
                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);
                        }
                        if (direction == Direction.FFLeft || direction == Direction.FFRight)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                        }
                        if (direction == Direction.FFUp || direction == Direction.FFDown)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                        }
                    }
                }
                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);
                        }
                        if (direction == Direction.FFLeft || direction == Direction.FFRight)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                        }
                        if (direction == Direction.FFUp || direction == Direction.FFDown)
                        {
                            InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                        }
                    }
                }
            }

            // 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);
                    }
                    if (direction == Direction.FFLeft && !playerButtons.FFRightPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                    }
                    if (direction == Direction.FFRight && !playerButtons.FFLeftPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter);
                    }
                    if (direction == Direction.FFUp && !playerButtons.FFDownPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                    }
                    if (direction == Direction.FFDown && !playerButtons.FFUpPressed())
                    {
                        InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter);
                    }
                }
            }

            if (button.IsLeftTrigger && state.Gamepad.LeftTrigger != 0)
            {
                InputCode.SetPlayerDirection(playerButtons, direction);
            }
            else if (button.IsLeftTrigger && state.Gamepad.LeftTrigger == 0)
            {
                if (direction == Direction.Left || direction == Direction.Right)
                {
                    InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                }
                if (direction == Direction.Up || direction == Direction.Down)
                {
                    InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                }
            }

            if (button.IsRightTrigger && state.Gamepad.RightTrigger != 0)
            {
                InputCode.SetPlayerDirection(playerButtons, direction);
            }
            else if (button.IsRightTrigger && state.Gamepad.RightTrigger == 0)
            {
                if (direction == Direction.Left || direction == Direction.Right)
                {
                    InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter);
                }
                if (direction == Direction.Up || direction == Direction.Down)
                {
                    InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter);
                }
            }
        }