Migrate Hotkeys to SettingsHoykeysViewModel

This commit is contained in:
Isaac Marovitz 2024-04-19 16:24:46 -04:00
parent 378cbf129d
commit ddbdd0246a
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
5 changed files with 74 additions and 29 deletions

View file

@ -0,0 +1,45 @@
using Ryujinx.Ava.UI.Models.Input;
using Ryujinx.UI.Common.Configuration;
using System;
namespace Ryujinx.Ava.UI.ViewModels.Settings
{
public class SettingsHotkeysViewModel : BaseModel
{
public event Action DirtyEvent;
public HotkeyConfig KeyboardHotkey { get; set; }
public SettingsHotkeysViewModel()
{
ConfigurationState config = ConfigurationState.Instance;
KeyboardHotkey = new HotkeyConfig(config.Hid.Hotkeys.Value);
KeyboardHotkey.PropertyChanged += (_, _) => DirtyEvent?.Invoke();
}
public bool CheckIfModified(ConfigurationState config)
{
bool isDirty = false;
var hotkeys = KeyboardHotkey.GetConfig();
isDirty |= config.Hid.Hotkeys.Value.ToggleVsync != hotkeys.ToggleVsync;
isDirty |= config.Hid.Hotkeys.Value.Screenshot != hotkeys.Screenshot;
isDirty |= config.Hid.Hotkeys.Value.ShowUI != hotkeys.ShowUI;
isDirty |= config.Hid.Hotkeys.Value.Pause != hotkeys.Pause;
isDirty |= config.Hid.Hotkeys.Value.ToggleMute != hotkeys.ToggleMute;
isDirty |= config.Hid.Hotkeys.Value.ResScaleUp != hotkeys.ResScaleUp;
isDirty |= config.Hid.Hotkeys.Value.ResScaleDown != hotkeys.ResScaleDown;
isDirty |= config.Hid.Hotkeys.Value.VolumeUp != hotkeys.VolumeUp;
isDirty |= config.Hid.Hotkeys.Value.VolumeDown != hotkeys.VolumeDown;
return isDirty;
}
public void Save(ConfigurationState config)
{
config.Hid.Hotkeys.Value = KeyboardHotkey.GetConfig();
}
}
}

View file

@ -14,7 +14,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone; using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
@ -173,6 +172,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
private readonly SettingsCpuViewModel _cpuViewModel; private readonly SettingsCpuViewModel _cpuViewModel;
private readonly SettingsGraphicsViewModel _graphicsViewModel; private readonly SettingsGraphicsViewModel _graphicsViewModel;
private readonly SettingsLoggingViewModel _loggingViewModel; private readonly SettingsLoggingViewModel _loggingViewModel;
private readonly SettingsHotkeysViewModel _hotkeysViewModel;
public DateTimeOffset CurrentDate { get; set; } public DateTimeOffset CurrentDate { get; set; }
public TimeSpan CurrentTime { get; set; } public TimeSpan CurrentTime { get; set; }
@ -185,8 +185,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
get => new(_networkInterfaces.Keys); get => new(_networkInterfaces.Keys);
} }
public HotkeyConfig KeyboardHotkey { get; set; }
public int NetworkInterfaceIndex public int NetworkInterfaceIndex
{ {
get => _networkInterfaceIndex; get => _networkInterfaceIndex;
@ -213,6 +211,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
SettingsAudioViewModel audioViewModel, SettingsAudioViewModel audioViewModel,
SettingsCpuViewModel cpuViewModel, SettingsCpuViewModel cpuViewModel,
SettingsGraphicsViewModel graphicsViewModel, SettingsGraphicsViewModel graphicsViewModel,
SettingsHotkeysViewModel hotkeysViewModel,
SettingsLoggingViewModel loggingViewModel) : this() SettingsLoggingViewModel loggingViewModel) : this()
{ {
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
@ -221,11 +220,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
_audioViewModel = audioViewModel; _audioViewModel = audioViewModel;
_cpuViewModel = cpuViewModel; _cpuViewModel = cpuViewModel;
_graphicsViewModel = graphicsViewModel; _graphicsViewModel = graphicsViewModel;
_hotkeysViewModel = hotkeysViewModel;
_loggingViewModel = loggingViewModel; _loggingViewModel = loggingViewModel;
_audioViewModel.DirtyEvent += CheckIfModified; _audioViewModel.DirtyEvent += CheckIfModified;
_cpuViewModel.DirtyEvent += CheckIfModified; _cpuViewModel.DirtyEvent += CheckIfModified;
_graphicsViewModel.DirtyEvent += CheckIfModified; _graphicsViewModel.DirtyEvent += CheckIfModified;
_hotkeysViewModel.DirtyEvent += CheckIfModified;
_loggingViewModel.DirtyEvent += CheckIfModified; _loggingViewModel.DirtyEvent += CheckIfModified;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
@ -282,6 +283,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
isDirty |= config.System.ExpandRam.Value != ExpandDramSize; isDirty |= config.System.ExpandRam.Value != ExpandDramSize;
isDirty |= config.System.IgnoreMissingServices.Value != IgnoreMissingServices; isDirty |= config.System.IgnoreMissingServices.Value != IgnoreMissingServices;
if (_audioViewModel != null)
{
isDirty |= _audioViewModel.CheckIfModified(config);
}
if (_cpuViewModel != null) if (_cpuViewModel != null)
{ {
isDirty |= _cpuViewModel.CheckIfModified(config); isDirty |= _cpuViewModel.CheckIfModified(config);
@ -292,10 +298,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
isDirty |= _graphicsViewModel.CheckIfModified(config); isDirty |= _graphicsViewModel.CheckIfModified(config);
} }
if (_audioViewModel != null) if (_hotkeysViewModel != null)
{ {
isDirty |= _audioViewModel.CheckIfModified(config); isDirty |= _hotkeysViewModel.CheckIfModified(config);
} }
// Network // Network
isDirty |= config.System.EnableInternetAccess.Value != EnableInternetAccess; isDirty |= config.System.EnableInternetAccess.Value != EnableInternetAccess;
@ -376,9 +383,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
BaseStyleIndex = config.UI.BaseStyle == "Light" ? 0 : 1; BaseStyleIndex = config.UI.BaseStyle == "Light" ? 0 : 1;
// Keyboard Hotkeys
KeyboardHotkey = new HotkeyConfig(config.Hid.Hotkeys.Value);
// System // System
Region = (int)config.System.Region.Value; Region = (int)config.System.Region.Value;
Language = (int)config.System.Language.Value; Language = (int)config.System.Language.Value;
@ -419,8 +423,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
config.UI.BaseStyle.Value = BaseStyleIndex == 0 ? "Light" : "Dark"; config.UI.BaseStyle.Value = BaseStyleIndex == 0 ? "Light" : "Dark";
// Keyboard Hotkeys
config.Hid.Hotkeys.Value = KeyboardHotkey.GetConfig();
// System // System
config.System.Region.Value = (Region)Region; config.System.Region.Value = (Region)Region;
@ -440,6 +442,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
_audioViewModel?.Save(config); _audioViewModel?.Save(config);
_cpuViewModel?.Save(config); _cpuViewModel?.Save(config);
_graphicsViewModel?.Save(config); _graphicsViewModel?.Save(config);
_hotkeysViewModel?.Save(config);
// Network // Network
config.System.EnableInternetAccess.Value = EnableInternetAccess; config.System.EnableInternetAccess.Value = EnableInternetAccess;

View file

@ -8,11 +8,11 @@
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Settings" xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Settings"
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers" xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
mc:Ignorable="d" mc:Ignorable="d"
x:DataType="viewModels:SettingsViewModel" x:DataType="viewModels:SettingsHotkeysViewModel"
x:CompileBindings="True" x:CompileBindings="True"
Focusable="True"> Focusable="True">
<Design.DataContext> <Design.DataContext>
<viewModels:SettingsViewModel /> <viewModels:SettingsHotkeysViewModel />
</Design.DataContext> </Design.DataContext>
<UserControl.Resources> <UserControl.Resources>
<helpers:KeyValueConverter x:Key="Key" /> <helpers:KeyValueConverter x:Key="Key" />

View file

@ -14,18 +14,14 @@ namespace Ryujinx.Ava.UI.Views.Settings
{ {
public partial class SettingsHotkeysView : UserControl public partial class SettingsHotkeysView : UserControl
{ {
private readonly SettingsViewModel _viewModel; public SettingsHotkeysViewModel ViewModel;
private ButtonKeyAssigner _currentAssigner; private ButtonKeyAssigner _currentAssigner;
private readonly IGamepadDriver _avaloniaKeyboardDriver; private readonly IGamepadDriver _avaloniaKeyboardDriver;
public SettingsHotkeysView() public SettingsHotkeysView()
{ {
DataContext = ViewModel = new SettingsHotkeysViewModel();
}
public SettingsHotkeysView(SettingsViewModel viewModel)
{
_viewModel = viewModel;
InitializeComponent(); InitializeComponent();
@ -90,31 +86,31 @@ namespace Ryujinx.Ava.UI.Views.Settings
switch (button.Name) switch (button.Name)
{ {
case "ToggleVsync": case "ToggleVsync":
_viewModel.KeyboardHotkey.ToggleVsync = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.ToggleVsync = buttonValue.AsHidType<Key>();
break; break;
case "Screenshot": case "Screenshot":
_viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>();
break; break;
case "ShowUI": case "ShowUI":
_viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>();
break; break;
case "Pause": case "Pause":
_viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>();
break; break;
case "ToggleMute": case "ToggleMute":
_viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>();
break; break;
case "ResScaleUp": case "ResScaleUp":
_viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>();
break; break;
case "ResScaleDown": case "ResScaleDown":
_viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>();
break; break;
case "VolumeUp": case "VolumeUp":
_viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>();
break; break;
case "VolumeDown": case "VolumeDown":
_viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>(); ViewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>();
break; break;
} }
} }

View file

@ -32,6 +32,7 @@ namespace Ryujinx.Ava.UI.Windows
AudioPage = new SettingsAudioView(); AudioPage = new SettingsAudioView();
CpuPage = new SettingsCpuView(); CpuPage = new SettingsCpuView();
GraphicsPage = new SettingsGraphicsView(); GraphicsPage = new SettingsGraphicsView();
HotkeysPage = new SettingsHotkeysView();
LoggingPage = new SettingsLoggingView(); LoggingPage = new SettingsLoggingView();
ViewModel = new SettingsViewModel( ViewModel = new SettingsViewModel(
@ -40,11 +41,11 @@ namespace Ryujinx.Ava.UI.Windows
AudioPage.ViewModel, AudioPage.ViewModel,
CpuPage.ViewModel, CpuPage.ViewModel,
GraphicsPage.ViewModel, GraphicsPage.ViewModel,
HotkeysPage.ViewModel,
LoggingPage.ViewModel); LoggingPage.ViewModel);
UiPage = new SettingsUiView(ViewModel); UiPage = new SettingsUiView(ViewModel);
InputPage = new SettingsInputView(ViewModel); InputPage = new SettingsInputView(ViewModel);
HotkeysPage = new SettingsHotkeysView(ViewModel);
SystemPage = new SettingsSystemView(ViewModel); SystemPage = new SettingsSystemView(ViewModel);
NetworkPage = new SettingsNetworkView(); NetworkPage = new SettingsNetworkView();