diff --git a/src/Ryujinx/UI/ViewModels/Settings/SettingsCpuViewModel.cs b/src/Ryujinx/UI/ViewModels/Settings/SettingsCpuViewModel.cs new file mode 100644 index 000000000..a2896d2d0 --- /dev/null +++ b/src/Ryujinx/UI/ViewModels/Settings/SettingsCpuViewModel.cs @@ -0,0 +1,74 @@ +using Ryujinx.Common.Configuration; +using Ryujinx.UI.Common.Configuration; +using System; +using System.Runtime.InteropServices; + +namespace Ryujinx.Ava.UI.ViewModels.Settings +{ + public class SettingsCpuViewModel: BaseModel + { + public event Action DirtyEvent; + + public bool IsHypervisorAvailable => OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64; + + private bool _enablePptc; + public bool EnablePptc + { + get => _enablePptc; + set + { + _enablePptc = value; + DirtyEvent?.Invoke(); + } + } + + private bool _useHypervisor; + public bool UseHypervisor + { + get => _useHypervisor; + set + { + _useHypervisor = value; + DirtyEvent?.Invoke(); + } + } + + private int _memoryMode; + public int MemoryMode + { + get => _memoryMode; + set + { + _memoryMode = value; + DirtyEvent?.Invoke(); + } + } + + public SettingsCpuViewModel() + { + ConfigurationState config = ConfigurationState.Instance; + + EnablePptc = config.System.EnablePtc; + MemoryMode = (int)config.System.MemoryManagerMode.Value; + UseHypervisor = config.System.UseHypervisor; + } + + public bool CheckIfModified(ConfigurationState config) + { + bool isDirty = false; + + isDirty |= config.System.EnablePtc.Value != EnablePptc; + isDirty |= config.System.MemoryManagerMode.Value != (MemoryManagerMode)MemoryMode; + isDirty |= config.System.UseHypervisor.Value != UseHypervisor; + + return isDirty; + } + + public void Save(ConfigurationState config) + { + config.System.EnablePtc.Value = EnablePptc; + config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode; + config.System.UseHypervisor.Value = UseHypervisor; + } + } +} diff --git a/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs index 15dd03160..6957e4f09 100644 --- a/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Settings/SettingsViewModel.cs @@ -52,8 +52,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings public event Action DirtyEvent; public event Action ToggleButtons; - public bool IsHypervisorAvailable => OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64; - public bool DirectoryChanged { get => _directoryChanged; @@ -122,17 +120,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings } } - private bool _enablePptc; - public bool EnablePptc - { - get => _enablePptc; - set - { - _enablePptc = value; - CheckIfModified(); - } - } - private bool _enableInternetAccess; public bool EnableInternetAccess { @@ -177,16 +164,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings } } - public bool UseHypervisor { get; set; } - public string TimeZone { get; set; } public int Language { get; set; } public int Region { get; set; } - public int MemoryMode { get; set; } public int BaseStyleIndex { get; set; } - private readonly SettingsGraphicsViewModel _graphicsViewModel; private readonly SettingsAudioViewModel _audioViewModel; + private readonly SettingsCpuViewModel _cpuViewModel; + private readonly SettingsGraphicsViewModel _graphicsViewModel; private readonly SettingsLoggingViewModel _loggingViewModel; public DateTimeOffset CurrentDate { get; set; } @@ -226,6 +211,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings VirtualFileSystem virtualFileSystem, ContentManager contentManager, SettingsAudioViewModel audioViewModel, + SettingsCpuViewModel cpuViewModel, SettingsGraphicsViewModel graphicsViewModel, SettingsLoggingViewModel loggingViewModel) : this() { @@ -233,10 +219,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings _contentManager = contentManager; _audioViewModel = audioViewModel; + _cpuViewModel = cpuViewModel; _graphicsViewModel = graphicsViewModel; _loggingViewModel = loggingViewModel; _audioViewModel.DirtyEvent += CheckIfModified; + _cpuViewModel.DirtyEvent += CheckIfModified; _graphicsViewModel.DirtyEvent += CheckIfModified; _loggingViewModel.DirtyEvent += CheckIfModified; @@ -294,10 +282,10 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings isDirty |= config.System.ExpandRam.Value != ExpandDramSize; isDirty |= config.System.IgnoreMissingServices.Value != IgnoreMissingServices; - // CPU - isDirty |= config.System.EnablePtc.Value != EnablePptc; - isDirty |= config.System.MemoryManagerMode.Value != (MemoryManagerMode)MemoryMode; - isDirty |= config.System.UseHypervisor.Value != UseHypervisor; + if (_cpuViewModel != null) + { + isDirty |= _cpuViewModel.CheckIfModified(config); + } if (_graphicsViewModel != null) { @@ -406,11 +394,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings ExpandDramSize = config.System.ExpandRam; IgnoreMissingServices = config.System.IgnoreMissingServices; - // CPU - EnablePptc = config.System.EnablePtc; - MemoryMode = (int)config.System.MemoryManagerMode.Value; - UseHypervisor = config.System.UseHypervisor; - // Network EnableInternetAccess = config.System.EnableInternetAccess; // LAN interface index is loaded asynchronously in PopulateNetworkInterfaces() @@ -454,13 +437,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings config.System.ExpandRam.Value = ExpandDramSize; config.System.IgnoreMissingServices.Value = IgnoreMissingServices; - // CPU - config.System.EnablePtc.Value = EnablePptc; - config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode; - config.System.UseHypervisor.Value = UseHypervisor; - - _graphicsViewModel?.Save(config); _audioViewModel?.Save(config); + _cpuViewModel?.Save(config); + _graphicsViewModel?.Save(config); // Network config.System.EnableInternetAccess.Value = EnableInternetAccess; diff --git a/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml index 480b5183a..97bd4a1cd 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml @@ -1,5 +1,5 @@  + x:DataType="viewModels:SettingsCpuViewModel"> diff --git a/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml.cs index a475971a1..6a53ad224 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsCpuView.axaml.cs @@ -1,11 +1,15 @@ using Avalonia.Controls; +using Ryujinx.Ava.UI.ViewModels.Settings; namespace Ryujinx.Ava.UI.Views.Settings { - public partial class SettingsCPUView : UserControl + public partial class SettingsCpuView : UserControl { - public SettingsCPUView() + public SettingsCpuViewModel ViewModel; + + public SettingsCpuView() { + DataContext = ViewModel = new SettingsCpuViewModel(); InitializeComponent(); } } diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs index 2929faa07..16d661a9f 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Ava.UI.Windows public readonly SettingsInputView InputPage; public readonly SettingsHotkeysView HotkeysPage; public readonly SettingsSystemView SystemPage; - public readonly SettingsCPUView CpuPage; + public readonly SettingsCpuView CpuPage; public readonly SettingsGraphicsView GraphicsPage; public readonly SettingsAudioView AudioPage; public readonly SettingsNetworkView NetworkPage; @@ -30,6 +30,7 @@ namespace Ryujinx.Ava.UI.Windows Title = $"{LocaleManager.Instance[LocaleKeys.Settings]}"; AudioPage = new SettingsAudioView(); + CpuPage = new SettingsCpuView(); GraphicsPage = new SettingsGraphicsView(); LoggingPage = new SettingsLoggingView(); @@ -37,6 +38,7 @@ namespace Ryujinx.Ava.UI.Windows virtualFileSystem, contentManager, AudioPage.ViewModel, + CpuPage.ViewModel, GraphicsPage.ViewModel, LoggingPage.ViewModel); @@ -44,7 +46,6 @@ namespace Ryujinx.Ava.UI.Windows InputPage = new SettingsInputView(ViewModel); HotkeysPage = new SettingsHotkeysView(ViewModel); SystemPage = new SettingsSystemView(ViewModel); - CpuPage = new SettingsCPUView(); NetworkPage = new SettingsNetworkView(); DataContext = ViewModel;