mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-27 12:33:00 +00:00
Fix some input controller issues (mapping sticks and duplicate controller names) (#31)
Co-authored-by: reggie <reggie@latte.to>
This commit is contained in:
parent
0e5ce0bd20
commit
b4cac89c1f
2 changed files with 65 additions and 25 deletions
|
@ -313,6 +313,32 @@ 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 +369,28 @@ 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))
|
|
||||||
|
if (joyconStickConfig != null)
|
||||||
|
{
|
||||||
|
if (joyconStickConfig.InvertStickX)
|
||||||
{
|
{
|
||||||
resultX = -resultX;
|
resultX = -resultX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickY) ||
|
if (joyconStickConfig.InvertStickY)
|
||||||
(inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickY))
|
|
||||||
{
|
{
|
||||||
resultY = -resultY;
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
private PlayerIndex _playerId;
|
private PlayerIndex _playerId;
|
||||||
private int _controller;
|
private int _controller;
|
||||||
private int _controllerNumber;
|
|
||||||
private string _controllerImage;
|
private string _controllerImage;
|
||||||
private int _device;
|
private int _device;
|
||||||
private object _configViewModel;
|
private object _configViewModel;
|
||||||
|
@ -439,6 +438,24 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
public void LoadDevices()
|
public void LoadDevices()
|
||||||
{
|
{
|
||||||
|
string GetGamepadName(IGamepad gamepad, int controllerNumber)
|
||||||
|
{
|
||||||
|
return $"{GetShortGamepadName(gamepad.Name)} ({controllerNumber})";
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetUniqueGamepadName(IGamepad gamepad, ref int controllerNumber)
|
||||||
|
{
|
||||||
|
string name = GetGamepadName(gamepad, controllerNumber);
|
||||||
|
|
||||||
|
if (Devices.Any(controller => controller.Name == name))
|
||||||
|
{
|
||||||
|
controllerNumber++;
|
||||||
|
name = GetGamepadName(gamepad, controllerNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
lock (Devices)
|
lock (Devices)
|
||||||
{
|
{
|
||||||
Devices.Clear();
|
Devices.Clear();
|
||||||
|
@ -455,23 +472,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int controllerNumber = 0;
|
||||||
foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds)
|
foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds)
|
||||||
{
|
{
|
||||||
using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id);
|
using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id);
|
||||||
|
|
||||||
if (gamepad != null)
|
if (gamepad != null)
|
||||||
{
|
{
|
||||||
if (Devices.Any(controller => GetShortGamepadId(controller.Id) == GetShortGamepadId(gamepad.Id)))
|
string name = GetUniqueGamepadName(gamepad, ref controllerNumber);
|
||||||
{
|
Devices.Add((DeviceType.Controller, id, name));
|
||||||
_controllerNumber++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({_controllerNumber})"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_controllerNumber = 0;
|
|
||||||
|
|
||||||
DeviceList.AddRange(Devices.Select(x => x.Name));
|
DeviceList.AddRange(Devices.Select(x => x.Name));
|
||||||
Device = Math.Min(Device, DeviceList.Count);
|
Device = Math.Min(Device, DeviceList.Count);
|
||||||
}
|
}
|
||||||
|
@ -685,7 +697,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
var index = ProfilesList.IndexOf(ProfileName);
|
int index = ProfilesList.IndexOf(ProfileName);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
ProfilesList.RemoveAt(index);
|
ProfilesList.RemoveAt(index);
|
||||||
|
|
Loading…
Reference in a new issue