Migrate Hotkeys to SettingsHoykeysViewModel
This commit is contained in:
parent
378cbf129d
commit
ddbdd0246a
5 changed files with 74 additions and 29 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
|
||||
|
||||
|
@ -173,6 +172,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
private readonly SettingsCpuViewModel _cpuViewModel;
|
||||
private readonly SettingsGraphicsViewModel _graphicsViewModel;
|
||||
private readonly SettingsLoggingViewModel _loggingViewModel;
|
||||
private readonly SettingsHotkeysViewModel _hotkeysViewModel;
|
||||
|
||||
public DateTimeOffset CurrentDate { get; set; }
|
||||
public TimeSpan CurrentTime { get; set; }
|
||||
|
@ -185,8 +185,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
get => new(_networkInterfaces.Keys);
|
||||
}
|
||||
|
||||
public HotkeyConfig KeyboardHotkey { get; set; }
|
||||
|
||||
public int NetworkInterfaceIndex
|
||||
{
|
||||
get => _networkInterfaceIndex;
|
||||
|
@ -213,6 +211,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
SettingsAudioViewModel audioViewModel,
|
||||
SettingsCpuViewModel cpuViewModel,
|
||||
SettingsGraphicsViewModel graphicsViewModel,
|
||||
SettingsHotkeysViewModel hotkeysViewModel,
|
||||
SettingsLoggingViewModel loggingViewModel) : this()
|
||||
{
|
||||
_virtualFileSystem = virtualFileSystem;
|
||||
|
@ -221,11 +220,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
_audioViewModel = audioViewModel;
|
||||
_cpuViewModel = cpuViewModel;
|
||||
_graphicsViewModel = graphicsViewModel;
|
||||
_hotkeysViewModel = hotkeysViewModel;
|
||||
_loggingViewModel = loggingViewModel;
|
||||
|
||||
_audioViewModel.DirtyEvent += CheckIfModified;
|
||||
_cpuViewModel.DirtyEvent += CheckIfModified;
|
||||
_graphicsViewModel.DirtyEvent += CheckIfModified;
|
||||
_hotkeysViewModel.DirtyEvent += CheckIfModified;
|
||||
_loggingViewModel.DirtyEvent += CheckIfModified;
|
||||
|
||||
if (Program.PreviewerDetached)
|
||||
|
@ -282,6 +283,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
isDirty |= config.System.ExpandRam.Value != ExpandDramSize;
|
||||
isDirty |= config.System.IgnoreMissingServices.Value != IgnoreMissingServices;
|
||||
|
||||
if (_audioViewModel != null)
|
||||
{
|
||||
isDirty |= _audioViewModel.CheckIfModified(config);
|
||||
}
|
||||
|
||||
if (_cpuViewModel != null)
|
||||
{
|
||||
isDirty |= _cpuViewModel.CheckIfModified(config);
|
||||
|
@ -292,10 +298,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
isDirty |= _graphicsViewModel.CheckIfModified(config);
|
||||
}
|
||||
|
||||
if (_audioViewModel != null)
|
||||
if (_hotkeysViewModel != null)
|
||||
{
|
||||
isDirty |= _audioViewModel.CheckIfModified(config);
|
||||
isDirty |= _hotkeysViewModel.CheckIfModified(config);
|
||||
}
|
||||
|
||||
// Network
|
||||
isDirty |= config.System.EnableInternetAccess.Value != EnableInternetAccess;
|
||||
|
||||
|
@ -376,9 +383,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
|
||||
BaseStyleIndex = config.UI.BaseStyle == "Light" ? 0 : 1;
|
||||
|
||||
// Keyboard Hotkeys
|
||||
KeyboardHotkey = new HotkeyConfig(config.Hid.Hotkeys.Value);
|
||||
|
||||
// System
|
||||
Region = (int)config.System.Region.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";
|
||||
|
||||
// Keyboard Hotkeys
|
||||
config.Hid.Hotkeys.Value = KeyboardHotkey.GetConfig();
|
||||
|
||||
// System
|
||||
config.System.Region.Value = (Region)Region;
|
||||
|
@ -440,6 +442,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
|
|||
_audioViewModel?.Save(config);
|
||||
_cpuViewModel?.Save(config);
|
||||
_graphicsViewModel?.Save(config);
|
||||
_hotkeysViewModel?.Save(config);
|
||||
|
||||
// Network
|
||||
config.System.EnableInternetAccess.Value = EnableInternetAccess;
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Settings"
|
||||
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
||||
mc:Ignorable="d"
|
||||
x:DataType="viewModels:SettingsViewModel"
|
||||
x:DataType="viewModels:SettingsHotkeysViewModel"
|
||||
x:CompileBindings="True"
|
||||
Focusable="True">
|
||||
<Design.DataContext>
|
||||
<viewModels:SettingsViewModel />
|
||||
<viewModels:SettingsHotkeysViewModel />
|
||||
</Design.DataContext>
|
||||
<UserControl.Resources>
|
||||
<helpers:KeyValueConverter x:Key="Key" />
|
||||
|
|
|
@ -14,18 +14,14 @@ namespace Ryujinx.Ava.UI.Views.Settings
|
|||
{
|
||||
public partial class SettingsHotkeysView : UserControl
|
||||
{
|
||||
private readonly SettingsViewModel _viewModel;
|
||||
public SettingsHotkeysViewModel ViewModel;
|
||||
|
||||
private ButtonKeyAssigner _currentAssigner;
|
||||
private readonly IGamepadDriver _avaloniaKeyboardDriver;
|
||||
|
||||
public SettingsHotkeysView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SettingsHotkeysView(SettingsViewModel viewModel)
|
||||
{
|
||||
_viewModel = viewModel;
|
||||
DataContext = ViewModel = new SettingsHotkeysViewModel();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -90,31 +86,31 @@ namespace Ryujinx.Ava.UI.Views.Settings
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace Ryujinx.Ava.UI.Windows
|
|||
AudioPage = new SettingsAudioView();
|
||||
CpuPage = new SettingsCpuView();
|
||||
GraphicsPage = new SettingsGraphicsView();
|
||||
HotkeysPage = new SettingsHotkeysView();
|
||||
LoggingPage = new SettingsLoggingView();
|
||||
|
||||
ViewModel = new SettingsViewModel(
|
||||
|
@ -40,11 +41,11 @@ namespace Ryujinx.Ava.UI.Windows
|
|||
AudioPage.ViewModel,
|
||||
CpuPage.ViewModel,
|
||||
GraphicsPage.ViewModel,
|
||||
HotkeysPage.ViewModel,
|
||||
LoggingPage.ViewModel);
|
||||
|
||||
UiPage = new SettingsUiView(ViewModel);
|
||||
InputPage = new SettingsInputView(ViewModel);
|
||||
HotkeysPage = new SettingsHotkeysView(ViewModel);
|
||||
SystemPage = new SettingsSystemView(ViewModel);
|
||||
NetworkPage = new SettingsNetworkView();
|
||||
|
||||
|
|
Loading…
Reference in a new issue