From d4a7ee25eaf04a99c81ac56e3311beefa4a1aa5b Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Fri, 10 Jan 2025 23:23:05 -0600 Subject: [PATCH] misc: chore: use ObservableProperty on input view models --- .../Input/ControllerInputViewModel.cs | 25 +---- .../UI/ViewModels/Input/InputViewModel.cs | 30 +----- .../Input/KeyboardInputViewModel.cs | 25 +---- .../ViewModels/Input/MotionInputViewModel.cs | 92 +++---------------- .../ViewModels/Input/RumbleInputViewModel.cs | 26 +----- 5 files changed, 28 insertions(+), 170 deletions(-) diff --git a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs index 6ee79a371..482fe2981 100644 --- a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -1,21 +1,13 @@ using Avalonia.Svg.Skia; +using CommunityToolkit.Mvvm.ComponentModel; using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Views.Input; namespace Ryujinx.Ava.UI.ViewModels.Input { - public class ControllerInputViewModel : BaseModel + public partial class ControllerInputViewModel : BaseModel { - private GamepadInputConfig _config; - public GamepadInputConfig Config - { - get => _config; - set - { - _config = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private GamepadInputConfig _config; private bool _isLeft; public bool IsLeft @@ -43,16 +35,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool HasSides => IsLeft ^ IsRight; - private SvgImage _image; - public SvgImage Image - { - get => _image; - set - { - _image = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private SvgImage _image; public readonly InputViewModel ParentModel; diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 16f8e46fa..05f479d9f 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -1,9 +1,8 @@ -using Avalonia; using Avalonia.Collections; using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Svg.Skia; using Avalonia.Threading; +using CommunityToolkit.Mvvm.ComponentModel; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Input; using Ryujinx.Ava.UI.Helpers; @@ -32,7 +31,7 @@ using Key = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Ava.UI.ViewModels.Input { - public class InputViewModel : BaseModel, IDisposable + public partial class InputViewModel : BaseModel, IDisposable { private const string Disabled = "disabled"; private const string ProControllerResource = "Ryujinx/Assets/Icons/Controller_ProCon.svg"; @@ -48,8 +47,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private int _controller; private string _controllerImage; private int _device; - private object _configViewModel; - private string _profileName; + [ObservableProperty] private object _configViewModel; + [ObservableProperty] private string _profileName; private bool _isLoaded; private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions()); @@ -73,17 +72,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool IsModified { get; set; } public event Action NotifyChangesEvent; - public object ConfigViewModel - { - get => _configViewModel; - set - { - _configViewModel = value; - - OnPropertyChanged(); - } - } - public PlayerIndex PlayerIdChoose { get => _playerIdChoose; @@ -200,16 +188,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } - public string ProfileName - { - get => _profileName; set - { - _profileName = value; - - OnPropertyChanged(); - } - } - public int Device { get => _device; diff --git a/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs index 0b530eb09..5ff9bb578 100644 --- a/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -1,20 +1,12 @@ using Avalonia.Svg.Skia; +using CommunityToolkit.Mvvm.ComponentModel; using Ryujinx.Ava.UI.Models.Input; namespace Ryujinx.Ava.UI.ViewModels.Input { - public class KeyboardInputViewModel : BaseModel + public partial class KeyboardInputViewModel : BaseModel { - private KeyboardInputConfig _config; - public KeyboardInputConfig Config - { - get => _config; - set - { - _config = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private KeyboardInputConfig _config; private bool _isLeft; public bool IsLeft @@ -42,16 +34,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool HasSides => IsLeft ^ IsRight; - private SvgImage _image; - public SvgImage Image - { - get => _image; - set - { - _image = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private SvgImage _image; public readonly InputViewModel ParentModel; diff --git a/src/Ryujinx/UI/ViewModels/Input/MotionInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/MotionInputViewModel.cs index c9ed8f2d4..7538c0f16 100644 --- a/src/Ryujinx/UI/ViewModels/Input/MotionInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/MotionInputViewModel.cs @@ -1,93 +1,23 @@ +using CommunityToolkit.Mvvm.ComponentModel; + namespace Ryujinx.Ava.UI.ViewModels.Input { - public class MotionInputViewModel : BaseModel + public partial class MotionInputViewModel : BaseModel { - private int _slot; - public int Slot - { - get => _slot; - set - { - _slot = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private int _slot; - private int _altSlot; - public int AltSlot - { - get => _altSlot; - set - { - _altSlot = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private int _altSlot; - private string _dsuServerHost; - public string DsuServerHost - { - get => _dsuServerHost; - set - { - _dsuServerHost = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private string _dsuServerHost; - private int _dsuServerPort; - public int DsuServerPort - { - get => _dsuServerPort; - set - { - _dsuServerPort = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private int _dsuServerPort; - private bool _mirrorInput; - public bool MirrorInput - { - get => _mirrorInput; - set - { - _mirrorInput = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private bool _mirrorInput; - private int _sensitivity; - public int Sensitivity - { - get => _sensitivity; - set - { - _sensitivity = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private int _sensitivity; - private double _gryoDeadzone; - public double GyroDeadzone - { - get => _gryoDeadzone; - set - { - _gryoDeadzone = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private double _gryoDeadzone; - private bool _enableCemuHookMotion; - public bool EnableCemuHookMotion - { - get => _enableCemuHookMotion; - set - { - _enableCemuHookMotion = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private bool _enableCemuHookMotion; } } diff --git a/src/Ryujinx/UI/ViewModels/Input/RumbleInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/RumbleInputViewModel.cs index 8ad33cf4c..c4158fced 100644 --- a/src/Ryujinx/UI/ViewModels/Input/RumbleInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/RumbleInputViewModel.cs @@ -1,27 +1,11 @@ +using CommunityToolkit.Mvvm.ComponentModel; + namespace Ryujinx.Ava.UI.ViewModels.Input { - public class RumbleInputViewModel : BaseModel + public partial class RumbleInputViewModel : BaseModel { - private float _strongRumble; - public float StrongRumble - { - get => _strongRumble; - set - { - _strongRumble = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private float _strongRumble; - private float _weakRumble; - public float WeakRumble - { - get => _weakRumble; - set - { - _weakRumble = value; - OnPropertyChanged(); - } - } + [ObservableProperty] private float _weakRumble; } }