Code style fixes

This commit is contained in:
Isaac Marovitz 2023-08-12 12:20:27 +01:00 committed by Isaac Marovitz
parent 02b355eebf
commit 9a8a926851
2 changed files with 25 additions and 29 deletions

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
@ -44,15 +45,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private PlayerIndex _playerId; private PlayerIndex _playerId;
private int _controller; private int _controller;
private int _controllerNumber = 0; private int _controllerNumber;
private string _controllerImage; private string _controllerImage;
private int _device; private int _device;
private object _configViewModel; private object _configViewModel;
private string _profileName; private string _profileName;
private bool _isLoaded; private bool _isLoaded;
private readonly UserControl _owner;
private static readonly InputConfigJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
public IGamepadDriver AvaloniaKeyboardDriver { get; } public IGamepadDriver AvaloniaKeyboardDriver { get; }
public IGamepad SelectedGamepad { get; private set; } public IGamepad SelectedGamepad { get; private set; }
@ -177,11 +177,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
{ {
get get
{ {
SvgImage image = new SvgImage(); SvgImage image = new();
if (!string.IsNullOrWhiteSpace(_controllerImage)) if (!string.IsNullOrWhiteSpace(_controllerImage))
{ {
SvgSource source = new SvgSource(); SvgSource source = new();
source.Load(EmbeddedResources.GetStream(_controllerImage)); source.Load(EmbeddedResources.GetStream(_controllerImage));
@ -235,22 +235,17 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
public InputViewModel(UserControl owner) : this() public InputViewModel(UserControl owner) : this()
{ {
_owner = owner;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
_mainWindow = _mainWindow =
(MainWindow)((IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current (MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current
.ApplicationLifetime).MainWindow; .ApplicationLifetime).MainWindow;
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner);
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
if (_mainWindow.ViewModel.AppHost != null) _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates();
{
_mainWindow.ViewModel.AppHost.NpadManager.BlockInputUpdates();
}
_isLoaded = false; _isLoaded = false;
@ -342,7 +337,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
{ {
return; return;
} }
else if (type == DeviceType.Keyboard)
if (type == DeviceType.Keyboard)
{ {
if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver) if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver)
{ {
@ -439,7 +435,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
const string Hyphen = "-"; const string Hyphen = "-";
const int Offset = 1; const int Offset = 1;
return str.Substring(str.IndexOf(Hyphen) + Offset); return str[(str.IndexOf(Hyphen) + Offset)..];
} }
public void LoadDevices() public void LoadDevices()
@ -553,7 +549,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
ButtonL = Key.E, ButtonL = Key.E,
ButtonZl = Key.Q, ButtonZl = Key.Q,
ButtonSl = Key.Unbound, ButtonSl = Key.Unbound,
ButtonSr = Key.Unbound ButtonSr = Key.Unbound,
}, },
LeftJoyconStick = LeftJoyconStick =
new JoyconConfigKeyboardStick<Key> new JoyconConfigKeyboardStick<Key>
@ -562,7 +558,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
StickDown = Key.S, StickDown = Key.S,
StickLeft = Key.A, StickLeft = Key.A,
StickRight = Key.D, StickRight = Key.D,
StickButton = Key.F StickButton = Key.F,
}, },
RightJoycon = new RightJoyconCommonConfig<Key> RightJoycon = new RightJoyconCommonConfig<Key>
{ {
@ -574,7 +570,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
ButtonR = Key.U, ButtonR = Key.U,
ButtonZr = Key.O, ButtonZr = Key.O,
ButtonSl = Key.Unbound, ButtonSl = Key.Unbound,
ButtonSr = Key.Unbound ButtonSr = Key.Unbound,
}, },
RightJoyconStick = new JoyconConfigKeyboardStick<Key> RightJoyconStick = new JoyconConfigKeyboardStick<Key>
{ {
@ -582,8 +578,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
StickDown = Key.K, StickDown = Key.K,
StickLeft = Key.J, StickLeft = Key.J,
StickRight = Key.L, StickRight = Key.L,
StickButton = Key.H StickButton = Key.H,
} },
}; };
} }
else if (activeDevice.Type == DeviceType.Controller) else if (activeDevice.Type == DeviceType.Controller)
@ -613,14 +609,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
ButtonL = ConfigGamepadInputId.LeftShoulder, ButtonL = ConfigGamepadInputId.LeftShoulder,
ButtonZl = ConfigGamepadInputId.LeftTrigger, ButtonZl = ConfigGamepadInputId.LeftTrigger,
ButtonSl = ConfigGamepadInputId.Unbound, ButtonSl = ConfigGamepadInputId.Unbound,
ButtonSr = ConfigGamepadInputId.Unbound ButtonSr = ConfigGamepadInputId.Unbound,
}, },
LeftJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId> LeftJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
{ {
Joystick = ConfigStickInputId.Left, Joystick = ConfigStickInputId.Left,
StickButton = ConfigGamepadInputId.LeftStick, StickButton = ConfigGamepadInputId.LeftStick,
InvertStickX = false, InvertStickX = false,
InvertStickY = false InvertStickY = false,
}, },
RightJoycon = new RightJoyconCommonConfig<ConfigGamepadInputId> RightJoycon = new RightJoyconCommonConfig<ConfigGamepadInputId>
{ {
@ -632,28 +628,28 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
ButtonR = ConfigGamepadInputId.RightShoulder, ButtonR = ConfigGamepadInputId.RightShoulder,
ButtonZr = ConfigGamepadInputId.RightTrigger, ButtonZr = ConfigGamepadInputId.RightTrigger,
ButtonSl = ConfigGamepadInputId.Unbound, ButtonSl = ConfigGamepadInputId.Unbound,
ButtonSr = ConfigGamepadInputId.Unbound ButtonSr = ConfigGamepadInputId.Unbound,
}, },
RightJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId> RightJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
{ {
Joystick = ConfigStickInputId.Right, Joystick = ConfigStickInputId.Right,
StickButton = ConfigGamepadInputId.RightStick, StickButton = ConfigGamepadInputId.RightStick,
InvertStickX = false, InvertStickX = false,
InvertStickY = false InvertStickY = false,
}, },
Motion = new StandardMotionConfigController Motion = new StandardMotionConfigController
{ {
MotionBackend = MotionInputBackendType.GamepadDriver, MotionBackend = MotionInputBackendType.GamepadDriver,
EnableMotion = true, EnableMotion = true,
Sensitivity = 100, Sensitivity = 100,
GyroDeadzone = 1 GyroDeadzone = 1,
}, },
Rumble = new RumbleConfigController Rumble = new RumbleConfigController
{ {
StrongRumble = 1f, StrongRumble = 1f,
WeakRumble = 1f, WeakRumble = 1f,
EnableRumble = false EnableRumble = false,
} },
}; };
} }
else else
@ -700,7 +696,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
try try
{ {
config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig); config = JsonHelper.DeserializeFromFile(path, _serializerContext.InputConfig);
} }
catch (JsonException) { } catch (JsonException) { }
catch (InvalidOperationException) catch (InvalidOperationException)
@ -766,7 +762,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
config.ControllerType = Controllers[_controller].Type; config.ControllerType = Controllers[_controller].Type;
string jsonString = JsonHelper.Serialize(config, SerializerContext.InputConfig); string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig);
await File.WriteAllTextAsync(path, jsonString); await File.WriteAllTextAsync(path, jsonString);

View file

@ -23,7 +23,7 @@ namespace Ryujinx.Ava.UI.Views.Input
foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) foreach (ILogical visual in SettingButtons.GetLogicalDescendants())
{ {
if (visual is ToggleButton button && !(visual is CheckBox)) if (visual is ToggleButton button and not CheckBox)
{ {
button.IsCheckedChanged += Button_IsCheckedChanged; button.IsCheckedChanged += Button_IsCheckedChanged;
} }