From 9c6fc1c65087da00451e42e82e935ec5198a2d9b Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Tue, 7 Jun 2022 08:05:00 +0000 Subject: [PATCH] add device type to controller device checks --- Ryujinx.Ava/Ui/Models/DeviceType.cs | 9 +++ .../ViewModels/ControllerSettingsViewModel.cs | 63 +++++++++---------- .../Windows/ControllerSettingsWindow.axaml.cs | 6 +- 3 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 Ryujinx.Ava/Ui/Models/DeviceType.cs diff --git a/Ryujinx.Ava/Ui/Models/DeviceType.cs b/Ryujinx.Ava/Ui/Models/DeviceType.cs new file mode 100644 index 000000000..cb1520d0a --- /dev/null +++ b/Ryujinx.Ava/Ui/Models/DeviceType.cs @@ -0,0 +1,9 @@ +namespace Ryujinx.Ava.Ui.Models +{ + public enum DeviceType + { + None, + Keyboard, + Controller + } +} \ No newline at end of file diff --git a/Ryujinx.Ava/Ui/ViewModels/ControllerSettingsViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/ControllerSettingsViewModel.cs index e538faf05..d91b2be33 100644 --- a/Ryujinx.Ava/Ui/ViewModels/ControllerSettingsViewModel.cs +++ b/Ryujinx.Ava/Ui/ViewModels/ControllerSettingsViewModel.cs @@ -56,7 +56,7 @@ namespace Ryujinx.Ava.Ui.ViewModels public IGamepad SelectedGamepad { get; private set; } public ObservableCollection PlayerIndexes { get; set; } - public ObservableCollection<(string Id, string Name)> Devices { get; set; } + public ObservableCollection<(DeviceType Type,string Id, string Name)> Devices { get; set; } public ObservableCollection Controllers { get; set; } public AvaloniaList ProfilesList { get; set; } public AvaloniaList DeviceList { get; set; } @@ -211,9 +211,9 @@ namespace Ryujinx.Ava.Ui.ViewModels return; } - string selected = Devices[_device].Id; + var selected = Devices[_device].Type; - if (selected != Disabled) + if (selected != DeviceType.None) { LoadControllers(); @@ -261,7 +261,7 @@ namespace Ryujinx.Ava.Ui.ViewModels { PlayerIndexes = new ObservableCollection(); Controllers = new ObservableCollection(); - Devices = new ObservableCollection<(string Id, string Name)>(); + Devices = new ObservableCollection<(DeviceType Type, string Id, string Name)>(); ProfilesList = new AvaloniaList(); DeviceList = new AvaloniaList(); @@ -301,19 +301,19 @@ namespace Ryujinx.Ava.Ui.ViewModels } else { - string ident = ""; + var type = DeviceType.None; if (Config is StandardKeyboardInputConfig) { - ident = KeyboardString; + type = DeviceType.Keyboard; } if (Config is StandardControllerInputConfig) { - ident = ControllerString; + type = DeviceType.Controller; } - var item = Devices.FirstOrDefault(x => x.Id == $"{ident}/{Config.Id}"); + var item = Devices.FirstOrDefault(x => x.Type == type && x.Id == Config.Id); if (item != default) { Device = Devices.ToList().FindIndex(x => x.Id == item.Id); @@ -343,14 +343,13 @@ namespace Ryujinx.Ava.Ui.ViewModels } string id = GetCurrentGamepadId(); - string selected = Devices[Device].Id; + var type = Devices[Device].Type; - if (selected == Disabled) + if (type == DeviceType.None) { return; } - - if (selected.StartsWith(KeyboardString)) + else if (type == DeviceType.Keyboard) { if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver) { @@ -391,14 +390,14 @@ namespace Ryujinx.Ava.Ui.ViewModels return string.Empty; } - string selected = Devices[Device].Id; + var device = Devices[Device]; - if (selected == null || selected == Disabled) + if (device.Type == DeviceType.None) { return null; } - return selected.Split("/")[1].Split(" ")[0]; + return device.Id.Split(" ")[0]; } public void LoadControllers() @@ -448,7 +447,7 @@ namespace Ryujinx.Ava.Ui.ViewModels { Devices.Clear(); DeviceList.Clear(); - Devices.Add((Disabled, LocaleManager.Instance["ControllerSettingsDeviceDisabled"])); + Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance["ControllerSettingsDeviceDisabled"])); foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds) { @@ -456,7 +455,7 @@ namespace Ryujinx.Ava.Ui.ViewModels if (gamepad != null) { - Devices.Add(($"keyboard/{id}", $"{GetShortGamepadName(gamepad.Name)} ({id})")); + Devices.Add((DeviceType.Keyboard, id, $"{GetShortGamepadName(gamepad.Name)} ({id})")); } } @@ -466,7 +465,7 @@ namespace Ryujinx.Ava.Ui.ViewModels if (gamepad != null) { - Devices.Add(($"controller/{id}", $"{GetShortGamepadName(gamepad.Name)} ({id})")); + Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({id})")); } } @@ -478,13 +477,13 @@ namespace Ryujinx.Ava.Ui.ViewModels private string GetProfileBasePath() { string path = AppDataManager.ProfilesDirPath; - string selected = Devices[Device == -1 ? 0 : Device].Id; + var type = Devices[Device == -1 ? 0 : Device].Type; - if (selected.StartsWith(KeyboardString)) + if (type == DeviceType.Keyboard) { path = Path.Combine(path, KeyboardString); } - else if (selected.StartsWith(ControllerString)) + else if (type == DeviceType.Controller) { path = Path.Combine(path, ControllerString); } @@ -518,17 +517,17 @@ namespace Ryujinx.Ava.Ui.ViewModels public InputConfig LoadDefaultConfiguration() { - string activeDevice = Disabled; + var activeDevice = Devices.FirstOrDefault(); if (Devices.Count > 0 && Device < Devices.Count && Device >= 0) { - activeDevice = Devices[Device].Id; + activeDevice = Devices[Device]; } InputConfig config; - if (activeDevice.StartsWith(KeyboardString)) + if (activeDevice.Type == DeviceType.Keyboard) { - string id = activeDevice.Split("/")[1]; + string id = activeDevice.Id; config = new StandardKeyboardInputConfig { @@ -579,11 +578,11 @@ namespace Ryujinx.Ava.Ui.ViewModels } }; } - else if (activeDevice.StartsWith(ControllerString)) + else if (activeDevice.Type == DeviceType.Controller) { - bool isNintendoStyle = Devices.ToList().Find(x => x.Id == activeDevice).Name.Contains("Nintendo"); + bool isNintendoStyle = Devices.ToList().Find(x => x.Id == activeDevice.Id).Name.Contains("Nintendo"); - string id = activeDevice.Split("/")[1].Split(" ")[0]; + string id = activeDevice.Id.Split(" ")[0]; config = new StandardControllerInputConfig { @@ -819,17 +818,17 @@ namespace Ryujinx.Ava.Ui.ViewModels } else { - string selected = Devices[Device].Id; + var device = Devices[Device]; - if (selected.StartsWith(KeyboardString)) + if (device.Type == DeviceType.Keyboard) { var inputConfig = Configuration as InputConfiguration; - inputConfig.Id = selected.Split("/")[1]; + inputConfig.Id = device.Id; } else { var inputConfig = Configuration as InputConfiguration; - inputConfig.Id = selected.Split("/")[1].Split(" ")[0]; + inputConfig.Id = device.Id.Split(" ")[0]; } var config = !IsController diff --git a/Ryujinx.Ava/Ui/Windows/ControllerSettingsWindow.axaml.cs b/Ryujinx.Ava/Ui/Windows/ControllerSettingsWindow.axaml.cs index 6a459b5de..456301262 100644 --- a/Ryujinx.Ava/Ui/Windows/ControllerSettingsWindow.axaml.cs +++ b/Ryujinx.Ava/Ui/Windows/ControllerSettingsWindow.axaml.cs @@ -119,13 +119,13 @@ namespace Ryujinx.Ava.Ui.Windows { IButtonAssigner assigner; - string selected = ViewModel.Devices[ViewModel.Device].Id; + var device = ViewModel.Devices[ViewModel.Device]; - if (selected.StartsWith("keyboard")) + if (device.Type == Models.DeviceType.Keyboard) { assigner = new KeyboardKeyAssigner((IKeyboard)ViewModel.SelectedGamepad); } - else if (selected.StartsWith("controller")) + else if (device.Type == Models.DeviceType.Controller) { InputConfig config = ConfigurationState.Instance.Hid.InputConfig.Value.Find(inputConfig => inputConfig.Id == ViewModel.SelectedGamepad.Id);