/// <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(PokkenButtons 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); InputCode.SetPlayerDirection(playerButtons, Direction.FFHoriCenter); InputCode.SetPlayerDirection(playerButtons, Direction.FFVertCenter); break; case 0: InputCode.SetPlayerDirection(playerButtons, Direction.Up); InputCode.SetPlayerDirection(playerButtons, Direction.FFUp); playerButtons.Down = false; playerButtons.Left = false; playerButtons.Right = false; break; case 4500: InputCode.SetPlayerDirection(playerButtons, Direction.Up); InputCode.SetPlayerDirection(playerButtons, Direction.Right); InputCode.SetPlayerDirection(playerButtons, Direction.FFUp); InputCode.SetPlayerDirection(playerButtons, Direction.FFRight); playerButtons.Down = false; playerButtons.Left = false; break; case 9000: InputCode.SetPlayerDirection(playerButtons, Direction.Right); InputCode.SetPlayerDirection(playerButtons, Direction.FFRight); playerButtons.Down = false; playerButtons.Left = false; playerButtons.Up = false; break; case 13500: InputCode.SetPlayerDirection(playerButtons, Direction.Down); InputCode.SetPlayerDirection(playerButtons, Direction.Right); InputCode.SetPlayerDirection(playerButtons, Direction.FFDown); InputCode.SetPlayerDirection(playerButtons, Direction.FFRight); playerButtons.Up = false; playerButtons.Left = false; break; case 18000: InputCode.SetPlayerDirection(playerButtons, Direction.Down); InputCode.SetPlayerDirection(playerButtons, Direction.FFDown); playerButtons.Up = false; playerButtons.Left = false; playerButtons.Right = false; break; case 22500: InputCode.SetPlayerDirection(playerButtons, Direction.Left); InputCode.SetPlayerDirection(playerButtons, Direction.Down); InputCode.SetPlayerDirection(playerButtons, Direction.FFLeft); InputCode.SetPlayerDirection(playerButtons, Direction.FFDown); playerButtons.Up = false; playerButtons.Right = false; break; case 27000: InputCode.SetPlayerDirection(playerButtons, Direction.Left); InputCode.SetPlayerDirection(playerButtons, Direction.FFLeft); playerButtons.Down = false; playerButtons.Up = false; playerButtons.Right = false; break; case 31500: InputCode.SetPlayerDirection(playerButtons, Direction.Left); InputCode.SetPlayerDirection(playerButtons, Direction.Up); InputCode.SetPlayerDirection(playerButtons, Direction.FFLeft); InputCode.SetPlayerDirection(playerButtons, Direction.FFUp); playerButtons.Down = false; playerButtons.Right = false; 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); } } } }
/// <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(PokkenButtons pokkenButtons, 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(pokkenButtons, direction); } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(pokkenButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(pokkenButtons, Direction.VerticalCenter); } } } else { if (calcVal >= 0 + 15000) { InputCode.SetPlayerDirection(pokkenButtons, direction); } else if (calcVal <= 0 - 15000) { } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(pokkenButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(pokkenButtons, Direction.VerticalCenter); } } } } // Normal button if (button.IsButton) { if ((button.ButtonCode & (short)state.Gamepad.Buttons) != 0) { InputCode.SetPlayerDirection(pokkenButtons, direction); } else { if (direction == Direction.Left && !pokkenButtons.RightPressed()) { InputCode.SetPlayerDirection(pokkenButtons, Direction.HorizontalCenter); } if (direction == Direction.Right && !pokkenButtons.LeftPressed()) { InputCode.SetPlayerDirection(pokkenButtons, Direction.HorizontalCenter); } if (direction == Direction.Up && !pokkenButtons.DownPressed()) { InputCode.SetPlayerDirection(pokkenButtons, Direction.VerticalCenter); } if (direction == Direction.Down && !pokkenButtons.UpPressed()) { InputCode.SetPlayerDirection(pokkenButtons, Direction.VerticalCenter); } } } }