Added Basic Controller Support

This commit is contained in:
John Clemis 2018-06-27 12:45:15 -05:00
parent 900a84ae0a
commit 0cef1e6b5d
3 changed files with 47 additions and 1 deletions

View file

@ -12,6 +12,8 @@ namespace Ryujinx
{
public static JoyCon FakeJoyCon { get; private set; }
public static float GamePad_Deadzone;
public static void Read(Logger Log)
{
string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
@ -28,6 +30,8 @@ namespace Ryujinx
Log.SetEnable(LogLevel.Warning, Convert.ToBoolean(Parser.Value("Logging_Enable_Warn")));
Log.SetEnable(LogLevel.Error, Convert.ToBoolean(Parser.Value("Logging_Enable_Error")));
GamePad_Deadzone = (float)Convert.ToDouble(Parser.Value("GamePad_Deadzone"));
string[] FilteredLogClasses = Parser.Value("Logging_Filtered_Classes").Split(',', StringSplitOptions.RemoveEmptyEntries);
//When the classes are specified on the list, we only

View file

@ -19,6 +19,9 @@ Logging_Enable_Error = true
#Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS`
Logging_Filtered_Classes =
#Controller Analog Stick Deadzone
GamePad_Deadzone = 0.05
#https://github.com/opentk/opentk/blob/develop/src/OpenTK/Input/Key.cs
Controls_Left_FakeJoycon_Stick_Up = 105
Controls_Left_FakeJoycon_Stick_Down = 101

View file

@ -55,6 +55,7 @@ namespace Ryujinx
int LeftJoystickDY = 0;
int RightJoystickDX = 0;
int RightJoystickDY = 0;
float deadzone = Config.GamePad_Deadzone;
if (Keyboard.HasValue)
{
@ -62,7 +63,7 @@ namespace Ryujinx
if (Keyboard[Key.Escape]) this.Exit();
//RightJoystick
//LeftJoystick
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue;
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue;
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft]) LeftJoystickDX = -short.MaxValue;
@ -95,6 +96,44 @@ namespace Ryujinx
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonZR]) CurrentButton |= HidControllerButtons.KEY_ZR;
}
//Mapping it relative to the positions of the buttons on the controller
GamePadState gamePad = GamePad.GetState(0);
//RightButtons
if (gamePad.Buttons.B == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_A;
if (gamePad.Buttons.A == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_B;
if (gamePad.Buttons.Y == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_X;
if (gamePad.Buttons.X == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_Y;
if (gamePad.Buttons.RightStick == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_RSTICK;
if (gamePad.Buttons.Start == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_PLUS;
if (gamePad.Buttons.RightShoulder == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_R;
if (gamePad.Triggers.Right >= 0.5) CurrentButton |= HidControllerButtons.KEY_ZR;
//LeftButtons
if (gamePad.Buttons.LeftStick == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_LSTICK;
if (gamePad.DPad.IsUp) CurrentButton |= HidControllerButtons.KEY_DUP;
if (gamePad.DPad.IsDown) CurrentButton |= HidControllerButtons.KEY_DDOWN;
if (gamePad.DPad.IsLeft) CurrentButton |= HidControllerButtons.KEY_DLEFT;
if (gamePad.DPad.IsRight) CurrentButton |= HidControllerButtons.KEY_DRIGHT;
if (gamePad.Buttons.Back == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_MINUS;
if (gamePad.Buttons.LeftShoulder == ButtonState.Pressed) CurrentButton |= HidControllerButtons.KEY_L;
if (gamePad.Triggers.Left >= 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 (gamePad.ThumbSticks.Right.Y >= deadzone || gamePad.ThumbSticks.Right.Y <= -deadzone)
RightJoystickDX = (int)(-gamePad.ThumbSticks.Right.Y * short.MaxValue);
//LeftJoystick
if (gamePad.ThumbSticks.Left.X >= deadzone || gamePad.ThumbSticks.Left.X <= -deadzone)
LeftJoystickDX = (int)(gamePad.ThumbSticks.Left.X * short.MaxValue);
if (gamePad.ThumbSticks.Left.Y >= deadzone || gamePad.ThumbSticks.Left.Y <= -deadzone)
LeftJoystickDY = (int)(gamePad.ThumbSticks.Left.Y * short.MaxValue);
LeftJoystick = new HidJoystickPosition
{
DX = LeftJoystickDX,