Fix for duplicate controller names under Ava when two controllers of the same type are attached (#29)

This commit is contained in:
TheToid 2024-10-22 01:25:14 +10:00 committed by GitHub
parent 9ae89d55ca
commit 0f3c7f920b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 26 deletions

View file

@ -291,12 +291,29 @@ 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)
return (0.0f, 0.0f); return (0.0f, 0.0f);
(short stickX, short stickY) = GetStickXY(inputId); (short stickX, short stickY) = GetStickXY(inputId);
float resultX = ConvertRawStickValue(stickX); float resultX = ConvertRawStickValue(stickX);
@ -304,24 +321,22 @@ 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 ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.Rotate90CW) || if (joyconStickConfig.InvertStickY)
(inputId == StickInputId.Right && _configuration.RightJoyconStick.Rotate90CW)) resultY = -resultY;
{
float temp = resultX; if (joyconStickConfig.Rotate90CW)
resultX = resultY; {
resultY = -temp; float temp = resultX;
resultX = resultY;
resultY = -temp;
}
} }
} }

View file

@ -433,12 +433,28 @@ 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();
DeviceList.Clear(); DeviceList.Clear();
Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled])); Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled]));
int controllerNumber = 0;
foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds) foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds)
{ {
using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id); using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id);
@ -455,17 +471,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
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);
} }
@ -679,7 +689,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);