From 2d73107dc08b55896e7836ac0c2c15a8fb240719 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 Apr 2024 13:34:10 -0400 Subject: [PATCH] Cleanup SettingsViewModel usage --- .../ViewModels/Settings/SettingsViewModel.cs | 1 - .../Settings/SettingsHotkeysView.axaml.cs | 26 ++++++++++--------- .../Views/Settings/SettingsInputView.axaml.cs | 8 +++--- .../Settings/SettingsSystemView.axaml.cs | 8 +++--- .../UI/Views/Settings/SettingsUIView.axaml.cs | 18 ++++++------- .../UI/Windows/SettingsWindow.axaml.cs | 2 +- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs index 893a86b448..827a11966f 100644 --- a/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs @@ -5,7 +5,6 @@ using LibHac.Tools.FsSystem; using Ryujinx.Audio.Backends.OpenAL; using Ryujinx.Audio.Backends.SDL2; using Ryujinx.Audio.Backends.SoundIo; -using Ryujinx.Ava; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models.Input; diff --git a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs index 3f6b00e66f..d62d7916d5 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs @@ -5,20 +5,23 @@ using Avalonia.Interactivity; using Avalonia.LogicalTree; using Ryujinx.Ava.Input; using Ryujinx.Ava.UI.Helpers; +using Ryujinx.Ava.UI.ViewModels.Settings; using Ryujinx.Input; using Ryujinx.Input.Assigner; -using Ryujinx.Ava.UI.ViewModels.Settings; using Key = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Ava.UI.Views.Settings { public partial class SettingsHotkeysView : UserControl { + private readonly SettingsViewModel _viewModel; private ButtonKeyAssigner _currentAssigner; private readonly IGamepadDriver _avaloniaKeyboardDriver; - public SettingsHotkeysView() + public SettingsHotkeysView(SettingsViewModel viewModel) { + _viewModel = viewModel; + InitializeComponent(); foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) @@ -77,37 +80,36 @@ namespace Ryujinx.Ava.UI.Views.Settings { if (e.ButtonValue.HasValue) { - var viewModel = (DataContext) as SettingsViewModel; var buttonValue = e.ButtonValue.Value; switch (button.Name) { case "ToggleVsync": - viewModel.KeyboardHotkey.ToggleVsync = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.ToggleVsync = buttonValue.AsHidType(); break; case "Screenshot": - viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType(); break; case "ShowUI": - viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType(); break; case "Pause": - viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType(); break; case "ToggleMute": - viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType(); break; case "ResScaleUp": - viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType(); break; case "ResScaleDown": - viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType(); break; case "VolumeUp": - viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType(); break; case "VolumeDown": - viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType(); + _viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType(); break; } } diff --git a/src/Ryujinx/UI/Views/Settings/SettingsInputView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsInputView.axaml.cs index 11325545b5..8f44b0ec5b 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsInputView.axaml.cs @@ -5,23 +5,23 @@ namespace Ryujinx.Ava.UI.Views.Settings { public partial class SettingsInputView : UserControl { - private SettingsInputViewModel ViewModel { get; set; } + private readonly SettingsInputViewModel _viewModel; public SettingsInputView(SettingsViewModel viewModel) { - DataContext = ViewModel = new SettingsInputViewModel(this, viewModel); + DataContext = _viewModel = new SettingsInputViewModel(this, viewModel); InitializeComponent(); } public void SaveCurrentProfile() { - ViewModel.Save(); + _viewModel.Save(); } public void Dispose() { - ViewModel.Dispose(); + _viewModel.Dispose(); } } } diff --git a/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml.cs index 6174e0e31b..c78e306229 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml.cs @@ -6,11 +6,11 @@ namespace Ryujinx.Ava.UI.Views.Settings { public partial class SettingsSystemView : UserControl { - public SettingsViewModel ViewModel; + private readonly SettingsViewModel _viewModel; public SettingsSystemView(SettingsViewModel viewModel) { - ViewModel = viewModel; + _viewModel = viewModel; InitializeComponent(); } @@ -22,7 +22,7 @@ namespace Ryujinx.Ava.UI.Views.Settings { e.Handled = true; - ViewModel.ValidateAndSetTimeZone(timeZone.Location); + _viewModel.ValidateAndSetTimeZone(timeZone.Location); } } } @@ -31,7 +31,7 @@ namespace Ryujinx.Ava.UI.Views.Settings { if (sender is AutoCompleteBox box && box.SelectedItem is TimeZone timeZone) { - ViewModel.ValidateAndSetTimeZone(timeZone.Location); + _viewModel.ValidateAndSetTimeZone(timeZone.Location); } } } diff --git a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml.cs index 3a04768efd..96616bfc25 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml.cs @@ -11,11 +11,11 @@ namespace Ryujinx.Ava.UI.Views.Settings { public partial class SettingsUiView : UserControl { - public SettingsViewModel ViewModel; + private readonly SettingsViewModel _viewModel; public SettingsUiView(SettingsViewModel viewModel) { - ViewModel = viewModel; + _viewModel = viewModel; InitializeComponent(); } @@ -23,10 +23,10 @@ namespace Ryujinx.Ava.UI.Views.Settings { string path = PathBox.Text; - if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path)) + if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !_viewModel.GameDirectories.Contains(path)) { - ViewModel.GameDirectories.Add(path); - ViewModel.DirectoryChanged = true; + _viewModel.GameDirectories.Add(path); + _viewModel.DirectoryChanged = true; } else { @@ -39,8 +39,8 @@ namespace Ryujinx.Ava.UI.Views.Settings if (result.Count > 0) { - ViewModel.GameDirectories.Add(result[0].Path.LocalPath); - ViewModel.DirectoryChanged = true; + _viewModel.GameDirectories.Add(result[0].Path.LocalPath); + _viewModel.DirectoryChanged = true; } } } @@ -52,8 +52,8 @@ namespace Ryujinx.Ava.UI.Views.Settings foreach (string path in new List(GameList.SelectedItems.Cast())) { - ViewModel.GameDirectories.Remove(path); - ViewModel.DirectoryChanged = true; + _viewModel.GameDirectories.Remove(path); + _viewModel.DirectoryChanged = true; } if (GameList.ItemCount > 0) diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs index ce8ba8b355..2c84a530da 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Ava.UI.Windows UiPage = new SettingsUiView(ViewModel); InputPage = new SettingsInputView(ViewModel); - HotkeysPage = new SettingsHotkeysView(); + HotkeysPage = new SettingsHotkeysView(ViewModel); SystemPage = new SettingsSystemView(ViewModel); CpuPage = new SettingsCPUView(); GraphicsPage = new SettingsGraphicsView();