From b65833448525ee67b11d121ca43ca703970c61d6 Mon Sep 17 00:00:00 2001 From: John Clemis Date: Sat, 14 Jul 2018 14:32:04 -0500 Subject: [PATCH] Add mapping per Axis + An attempt to fix peoples problems with the Keyboard input acting up with Controller Input enabled. --- Ryujinx/Config.cs | 6 ++- Ryujinx/Ryujinx.conf | 8 ++-- Ryujinx/Ui/GLScreen.cs | 67 ++++++++++++++++++++++++---------- Ryujinx/Ui/JoyConController.cs | 6 ++- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 940753ba5..d96956053 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -107,7 +107,8 @@ namespace Ryujinx { Left = new JoyConControllerLeft { - Stick = Parser.Value("Controls_Left_JoyConController_Stick"), + Stick_AxisX = Parser.Value("Controls_Left_JoyConController_Stick_AxisX"), + Stick_AxisY = Parser.Value("Controls_Left_JoyConController_Stick_AxisY"), StickButton = Parser.Value("Controls_Left_JoyConController_Stick_Button"), DPadUp = Parser.Value("Controls_Left_JoyConController_DPad_Up"), DPadDown = Parser.Value("Controls_Left_JoyConController_DPad_Down"), @@ -120,7 +121,8 @@ namespace Ryujinx Right = new JoyConControllerRight { - Stick = Parser.Value("Controls_Right_JoyConController_Stick"), + Stick_AxisX = Parser.Value("Controls_Right_JoyConController_Stick_AxisX"), + Stick_AxisY = Parser.Value("Controls_Right_JoyConController_Stick_AxisY"), StickButton = Parser.Value("Controls_Right_JoyConController_Stick_Button"), ButtonA = Parser.Value("Controls_Right_JoyConController_Button_A"), ButtonB = Parser.Value("Controls_Right_JoyConController_Button_B"), diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index 59f7f859e..0aec5ed2c 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -58,7 +58,7 @@ Controls_Right_JoyConKeyboard_Button_Plus = 121 Controls_Right_JoyConKeyboard_Button_R = 103 Controls_Right_JoyConKeyboard_Button_ZR = 97 -#Controller Controls +#Controller Controls (The default configuration is what works for a PS4 Controller using DS4 Windows) Controls_Left_JoyConController_Stick_Button = LStick Controls_Left_JoyConController_DPad_Up = DPadUp @@ -78,5 +78,7 @@ Controls_Right_JoyConController_Button_Plus = Start Controls_Right_JoyConController_Button_R = RShoulder Controls_Right_JoyConController_Button_ZR = RTrigger -Controls_Left_JoyConController_Stick = LJoystick -Controls_Right_JoyConController_Stick = RJoystick \ No newline at end of file +Controls_Left_JoyConController_Stick_AxisX = JoystickAxis0 +Controls_Left_JoyConController_Stick_AxisY = JoystickAxis1 +Controls_Right_JoyConController_Stick_AxisX = -JoystickAxis3 +Controls_Right_JoyConController_Stick_AxisY = -JoystickAxis2 diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 9b5dda4f0..856ff6735 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -174,13 +174,41 @@ namespace Ryujinx } } - private Vector2 GetJoystickAxisFromString(GamePadState GamePad, string Joystick) + private float GetJoystickAxisFromString(GamePadState GamePad, string Joystick) { switch (Joystick.ToUpper()) { - case "LJOYSTICK": return GamePad.ThumbSticks.Left; - case "RJOYSTICK": return new Vector2(-GamePad.ThumbSticks.Right.Y, -GamePad.ThumbSticks.Right.X); - default: throw new ArgumentException(); + case "JOYSTICKAXIS0": return GamePad.ThumbSticks.Left.X; + case "JOYSTICKAXIS1": return GamePad.ThumbSticks.Left.Y; + case "JOYSTICKAXIS2": return GamePad.ThumbSticks.Right.X; + case "JOYSTICKAXIS3": return GamePad.ThumbSticks.Right.Y; + case "-JOYSTICKAXIS0": return -GamePad.ThumbSticks.Left.X; + case "-JOYSTICKAXIS1": return -GamePad.ThumbSticks.Left.Y; + case "-JOYSTICKAXIS2": return -GamePad.ThumbSticks.Right.X; + case "-JOYSTICKAXIS3": return -GamePad.ThumbSticks.Right.Y; + default: throw new ArgumentException(); + } + } + + private bool IsGamePadActive(int Index) + { + return IsGamePadActive(GamePad.GetState(Index)); + } + + private bool IsGamePadActive(GamePadState GamePad) + { + if (GamePad.IsConnected) + { + return GamePad.Buttons.IsAnyButtonPressed + || (GamePad.Triggers.Left >= 0.8f || GamePad.Triggers.Right >= 0.8f) + || ((GamePad.ThumbSticks.Left.X >= 0.1f || GamePad.ThumbSticks.Left.X <= -0.1f) + || (GamePad.ThumbSticks.Left.Y >= 0.1f || GamePad.ThumbSticks.Left.Y <= -0.1f) + || (GamePad.ThumbSticks.Right.X >= 0.1f || GamePad.ThumbSticks.Right.X <= -0.1f) + || (GamePad.ThumbSticks.Right.Y >= 0.1f || GamePad.ThumbSticks.Right.Y <= -0.1f)); + } + else + { + return false; } } @@ -194,10 +222,9 @@ namespace Ryujinx int LeftJoystickDY = 0; int RightJoystickDX = 0; int RightJoystickDY = 0; - float AnalogStickDeadzone = Config.GamePadDeadzone; //Keyboard Input - if (Keyboard.HasValue) + if (Keyboard.HasValue && !IsGamePadActive(Config.GamePadIndex)) { KeyboardState Keyboard = this.Keyboard.Value; @@ -237,9 +264,11 @@ namespace Ryujinx } //Controller Input - if (Config.GamePadEnable) + if (Config.GamePadEnable && !Keyboard.HasValue && IsGamePadActive(Config.GamePadIndex)) { GamePadState GamePad = OpenTK.Input.GamePad.GetState(Config.GamePadIndex); + float AnalogStickDeadzone = Config.GamePadDeadzone; + //LeftButtons if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadUp)) CurrentButton |= HidControllerButtons.KEY_DUP; if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadDown)) CurrentButton |= HidControllerButtons.KEY_DDOWN; @@ -261,22 +290,22 @@ namespace Ryujinx if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonZR)) CurrentButton |= HidControllerButtons.KEY_ZR; //LeftJoystick - if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X >= AnalogStickDeadzone - || GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X <= -AnalogStickDeadzone) - LeftJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X * short.MaxValue); + if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisX) >= AnalogStickDeadzone + || GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisX) <= -AnalogStickDeadzone) + LeftJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisX) * short.MaxValue); - if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y >= AnalogStickDeadzone - || GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y <= -AnalogStickDeadzone) - LeftJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y * short.MaxValue); + if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisY) >= AnalogStickDeadzone + || GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisY) <= -AnalogStickDeadzone) + LeftJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick_AxisY) * short.MaxValue); //RightJoystick - if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X >= AnalogStickDeadzone - || GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X <= -AnalogStickDeadzone) - RightJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X * short.MaxValue); + if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisX) >= AnalogStickDeadzone + || GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisX) <= -AnalogStickDeadzone) + RightJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisX) * short.MaxValue); - if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y >= AnalogStickDeadzone - || GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y <= -AnalogStickDeadzone) - RightJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y * short.MaxValue); + if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisY) >= AnalogStickDeadzone + || GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisY) <= -AnalogStickDeadzone) + RightJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick_AxisY) * short.MaxValue); } LeftJoystick = new HidJoystickPosition diff --git a/Ryujinx/Ui/JoyConController.cs b/Ryujinx/Ui/JoyConController.cs index e525017d3..b212dd0e5 100644 --- a/Ryujinx/Ui/JoyConController.cs +++ b/Ryujinx/Ui/JoyConController.cs @@ -6,7 +6,8 @@ namespace Ryujinx.UI.Input { public struct JoyConControllerLeft { - public string Stick; + public string Stick_AxisX; + public string Stick_AxisY; public string StickButton; public string DPadUp; public string DPadDown; @@ -19,7 +20,8 @@ namespace Ryujinx.UI.Input public struct JoyConControllerRight { - public string Stick; + public string Stick_AxisX; + public string Stick_AxisY; public string StickButton; public string ButtonA; public string ButtonB;