Fix issues with Invert X / Y and Rotate when mapping different physical stick to JoyCon logical stick

This commit is contained in:
Aaron Murgatroyd 2023-12-17 01:27:57 +10:00 committed by TheToid
parent 268c9aecf8
commit 89c2c6c76b

View file

@ -313,6 +313,33 @@ namespace Ryujinx.Input.SDL2
return value * ConvertRate; return value * ConvertRate;
} }
private JoyconConfigControllerStick<GamepadInputId, Common.Configuration.Hid.Controller.StickInputId> GetLogicalJoyStickConfig(StickInputId inputId)
{
switch(inputId)
{
case StickInputId.Left:
if (_configuration.RightJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Left)
{
return _configuration.RightJoyconStick;
}
else
{
return _configuration.LeftJoyconStick;
}
case StickInputId.Right:
if (_configuration.LeftJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Right)
{
return _configuration.LeftJoyconStick;
}
else
{
return _configuration.RightJoyconStick;
}
}
return null;
}
public (float, float) GetStick(StickInputId inputId) public (float, float) GetStick(StickInputId inputId)
{ {
if (inputId == StickInputId.Unbound) if (inputId == StickInputId.Unbound)
@ -343,26 +370,21 @@ namespace Ryujinx.Input.SDL2
if (HasConfiguration) if (HasConfiguration)
{ {
if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickX) || var joyconStickConfig = GetLogicalJoyStickConfig(inputId);
(inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickX))
{
resultX = -resultX;
}
if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickY) || if (joyconStickConfig != null)
(inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickY))
{ {
resultY = -resultY; if (joyconStickConfig.InvertStickX) resultX = -resultX;
} if (joyconStickConfig.InvertStickY) resultY = -resultY;
if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.Rotate90CW) || if (joyconStickConfig.Rotate90CW)
(inputId == StickInputId.Right && _configuration.RightJoyconStick.Rotate90CW))
{ {
float temp = resultX; float temp = resultX;
resultX = resultY; resultX = resultY;
resultY = -temp; resultY = -temp;
} }
} }
}
return (resultX, resultY); return (resultX, resultY);
} }