From 56dc5005c45649bffca5c9bfe0a54c4d0f3e7ebd Mon Sep 17 00:00:00 2001 From: John Clemis Date: Wed, 27 Jun 2018 19:05:17 -0500 Subject: [PATCH] Added Basic Joystick Configuration --- Ryujinx/Config.cs | 6 ++++++ Ryujinx/Ryujinx.conf | 5 ++++- Ryujinx/Ui/GLScreen.cs | 49 +++++++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 86fe6ec7f..1a38ffa6e 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -35,6 +35,9 @@ namespace Ryujinx public static string Controls_Left_FakeJoycon_GamePadStick_Button; public static string Controls_Left_FakeJoycon_GamePadTrigger_ZL; + public static string Controls_Right_FakeJoycon_GamePadJoystick_R; + public static string Controls_Left_FakeJoycon_GamePadJoystick_L; + public static void Read(Logger Log) { string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); @@ -73,6 +76,9 @@ namespace Ryujinx Controls_Left_FakeJoycon_GamePadStick_Button = Parser.Value("Controls_Left_FakeJoycon_GamePadStick_Button"); Controls_Left_FakeJoycon_GamePadTrigger_ZL = Parser.Value("Controls_Left_FakeJoycon_GamePadTrigger_ZL"); + Controls_Right_FakeJoycon_GamePadJoystick_R = Parser.Value("Controls_Right_FakeJoycon_GamePadJoystick_R"); + Controls_Left_FakeJoycon_GamePadJoystick_L = Parser.Value("Controls_Left_FakeJoycon_GamePadJoystick_L"); + string[] FilteredLogClasses = Parser.Value("Logging_Filtered_Classes").Split(',', StringSplitOptions.RemoveEmptyEntries); //When the classes are specified on the list, we only diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index c4e0847c3..1b41b6380 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -72,4 +72,7 @@ Controls_Left_FakeJoycon_GamePadDPad_Right = DPadRight Controls_Left_FakeJoycon_GamePadButton_Minus = Back Controls_Left_FakeJoycon_GamePadButton_L = LShoulder Controls_Left_FakeJoycon_GamePadStick_Button = LStick -Controls_Left_FakeJoycon_GamePadTrigger_ZL = LTrigger \ No newline at end of file +Controls_Left_FakeJoycon_GamePadTrigger_ZL = LTrigger + +Controls_Right_FakeJoycon_GamePadJoystick_R = RJoystick +Controls_Left_FakeJoycon_GamePadJoystick_L = LJoystick \ No newline at end of file diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index a114e0521..279e6e94c 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -121,6 +121,26 @@ namespace Ryujinx return result; } + private Vector2 getJoystickAxisFromString(GamePadState gamePad, string str) + { + Vector2 result = new Vector2(0, 0); + + switch (str) + { + case "LJoystick": + result = gamePad.ThumbSticks.Left; + break; + case "RJoystick": + result = gamePad.ThumbSticks.Right; + break; + default: + Console.Error.WriteLine("Invalid Joystick Axis \"" + str + "\"! Defaulting the Vector2 to 0, 0."); + break; + } + + return result; + } + protected override void OnUpdateFrame(FrameEventArgs e) { HidControllerButtons CurrentButton = 0; @@ -187,12 +207,13 @@ namespace Ryujinx == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_X; if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadButton_Y) == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_Y; - if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadStick_Button) + if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadStick_Button) == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_RSTICK; - if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadButton_Plus) + if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadButton_Plus) == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_PLUS; - if (gamePad.Buttons.RightShoulder == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_R; - if (getGamePadTriggerFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadTrigger_ZR) + if (getGamePadButtonFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadButton_R) + == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_R; + if (getGamePadTriggerFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadTrigger_ZR) >= 0.5) CurrentButton |= HidControllerButtons.KEY_ZR; //LeftButtons @@ -214,18 +235,22 @@ namespace Ryujinx >= 0.5) CurrentButton |= HidControllerButtons.KEY_ZL; //RightJoystick - if (gamePad.ThumbSticks.Right.X >= deadzone || gamePad.ThumbSticks.Right.X <= -deadzone) - RightJoystickDY = (int)(-gamePad.ThumbSticks.Right.X * short.MaxValue); + if (getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).X >= deadzone + || getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).X <= -deadzone) + RightJoystickDY = (int)(-getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).X * short.MaxValue); - if (gamePad.ThumbSticks.Right.Y >= deadzone || gamePad.ThumbSticks.Right.Y <= -deadzone) - RightJoystickDX = (int)(-gamePad.ThumbSticks.Right.Y * short.MaxValue); + if (getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).Y >= deadzone + || getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).Y <= -deadzone) + RightJoystickDX = (int)(-getJoystickAxisFromString(gamePad, Config.Controls_Right_FakeJoycon_GamePadJoystick_R).Y * short.MaxValue); //LeftJoystick - if (gamePad.ThumbSticks.Left.X >= deadzone || gamePad.ThumbSticks.Left.X <= -deadzone) - LeftJoystickDX = (int)(gamePad.ThumbSticks.Left.X * short.MaxValue); + if (getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).X >= deadzone + || getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).X <= -deadzone) + LeftJoystickDX = (int)(getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).X * short.MaxValue); - if (gamePad.ThumbSticks.Left.Y >= deadzone || gamePad.ThumbSticks.Left.Y <= -deadzone) - LeftJoystickDY = (int)(gamePad.ThumbSticks.Left.Y * short.MaxValue); + if (getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).Y >= deadzone + || getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).Y <= -deadzone) + LeftJoystickDY = (int)(getJoystickAxisFromString(gamePad, Config.Controls_Left_FakeJoycon_GamePadJoystick_L).Y * short.MaxValue); } LeftJoystick = new HidJoystickPosition