Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some input controller issues (mapping sticks and duplicate controller names) #31

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions src/Ryujinx.Input.SDL2/SDL2Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,32 @@ private static float ConvertRawStickValue(short value)
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)
{
if (inputId == StickInputId.Unbound)
Expand Down Expand Up @@ -343,24 +369,26 @@ private static float ConvertRawStickValue(short value)

if (HasConfiguration)
{
if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickX) ||
(inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickX))
{
resultX = -resultX;
}
var joyconStickConfig = GetLogicalJoyStickConfig(inputId);

if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickY) ||
(inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickY))
if (joyconStickConfig != null)
{
resultY = -resultY;
}
if (joyconStickConfig.InvertStickX)
{
resultX = -resultX;
}

if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.Rotate90CW) ||
(inputId == StickInputId.Right && _configuration.RightJoyconStick.Rotate90CW))
{
float temp = resultX;
resultX = resultY;
resultY = -temp;
if (joyconStickConfig.InvertStickY)
{
resultY = -resultY;
}

if (joyconStickConfig.Rotate90CW)
{
float temp = resultX;
resultX = resultY;
resultY = -temp;
}
}
}

Expand Down
32 changes: 22 additions & 10 deletions src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class InputViewModel : BaseModel, IDisposable

private PlayerIndex _playerId;
private int _controller;
private int _controllerNumber;
private string _controllerImage;
private int _device;
private object _configViewModel;
Expand Down Expand Up @@ -439,6 +438,24 @@ private static string GetShortGamepadId(string str)

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)
{
Devices.Clear();
Expand All @@ -455,23 +472,18 @@ public void LoadDevices()
}
}

int controllerNumber = 0;
foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds)
{
using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id);

if (gamepad != null)
{
if (Devices.Any(controller => GetShortGamepadId(controller.Id) == GetShortGamepadId(gamepad.Id)))
{
_controllerNumber++;
}

Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({_controllerNumber})"));
string name = GetUniqueGamepadName(gamepad, ref controllerNumber);
Devices.Add((DeviceType.Controller, id, name));
}
}

_controllerNumber = 0;

DeviceList.AddRange(Devices.Select(x => x.Name));
Device = Math.Min(Device, DeviceList.Count);
}
Expand Down Expand Up @@ -685,7 +697,7 @@ public async void LoadProfile()

if (!File.Exists(path))
{
var index = ProfilesList.IndexOf(ProfileName);
int index = ProfilesList.IndexOf(ProfileName);
if (index != -1)
{
ProfilesList.RemoveAt(index);
Expand Down
Loading