1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-17 22:46:40 +00:00

Cleanup SettingsViewModel usage

This commit is contained in:
Isaac Marovitz 2024-04-19 13:34:10 -04:00
parent 2281b3b59e
commit 2d73107dc0
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
6 changed files with 32 additions and 31 deletions

View file

@ -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;

View file

@ -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<Key>();
_viewModel.KeyboardHotkey.ToggleVsync = buttonValue.AsHidType<Key>();
break;
case "Screenshot":
viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>();
break;
case "ShowUI":
viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>();
break;
case "Pause":
viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>();
break;
case "ToggleMute":
viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>();
break;
case "ResScaleUp":
viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>();
break;
case "ResScaleDown":
viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>();
break;
case "VolumeUp":
viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>();
break;
case "VolumeDown":
viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>();
_viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>();
break;
}
}

View file

@ -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();
}
}
}

View file

@ -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);
}
}
}

View file

@ -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<string>(GameList.SelectedItems.Cast<string>()))
{
ViewModel.GameDirectories.Remove(path);
ViewModel.DirectoryChanged = true;
_viewModel.GameDirectories.Remove(path);
_viewModel.DirectoryChanged = true;
}
if (GameList.ItemCount > 0)

View file

@ -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();