diff --git a/src/Ryujinx.Common/ReactiveObject.cs b/src/Ryujinx.Common/ReactiveObject.cs index 8df1e20fe..7ff16f0cb 100644 --- a/src/Ryujinx.Common/ReactiveObject.cs +++ b/src/Ryujinx.Common/ReactiveObject.cs @@ -53,6 +53,17 @@ namespace Ryujinx.Common { public static void LogValueChange(LogClass logClass, ReactiveEventArgs eventArgs, string valueName) { + if ((eventArgs.NewValue == null || eventArgs.OldValue == null)) + { + if (!(eventArgs.NewValue == null && eventArgs.OldValue == null)) + goto Log; + } + else if (!eventArgs.NewValue!.Equals(eventArgs.OldValue)) + goto Log; + + return; + + Log: string message = string.Create(CultureInfo.InvariantCulture, $"{valueName} set to: {eventArgs.NewValue}"); Logger.Info?.Print(logClass, message); diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index 03e3d44e9..2678bbf98 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -1,6 +1,7 @@ using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Threading; +using CommunityToolkit.Mvvm.ComponentModel; using Gommon; using LibHac.Tools.FsSystem; using Ryujinx.Audio.Backends.OpenAL; @@ -46,9 +47,9 @@ namespace Ryujinx.Ava.UI.ViewModels private int _resolutionScale; private int _graphicsBackendMultithreadingIndex; private float _volume; - private bool _isVulkanAvailable = true; - private bool _gameDirectoryChanged; - private bool _autoloadDirectoryChanged; + [ObservableProperty] private bool _isVulkanAvailable = true; + [ObservableProperty] private bool _gameDirectoryChanged; + [ObservableProperty] private bool _autoloadDirectoryChanged; private readonly List _gpuIds = new(); private int _graphicsBackendIndex; private int _scalingFilter; @@ -63,7 +64,7 @@ namespace Ryujinx.Ava.UI.ViewModels private int _networkInterfaceIndex; private int _multiplayerModeIndex; private string _ldnPassphrase; - private string _ldnServer; + [ObservableProperty] private string _ldnServer; public SettingsHacksViewModel DirtyHacks { get; } @@ -111,43 +112,10 @@ namespace Ryujinx.Ava.UI.ViewModels } } - public bool IsVulkanAvailable - { - get => _isVulkanAvailable; - set - { - _isVulkanAvailable = value; - - OnPropertyChanged(); - } - } - public bool IsOpenGLAvailable => !OperatingSystem.IsMacOS(); public bool IsAppleSiliconMac => OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64; - public bool GameDirectoryChanged - { - get => _gameDirectoryChanged; - set - { - _gameDirectoryChanged = value; - - OnPropertyChanged(); - } - } - - public bool AutoloadDirectoryChanged - { - get => _autoloadDirectoryChanged; - set - { - _autoloadDirectoryChanged = value; - - OnPropertyChanged(); - } - } - public bool IsMacOS => OperatingSystem.IsMacOS(); public bool EnableDiscordIntegration { get; set; } @@ -182,19 +150,12 @@ namespace Ryujinx.Ava.UI.ViewModels _customVSyncInterval = newInterval; _customVSyncIntervalPercentageProxy = value; OnPropertiesChanged( - nameof(CustomVSyncInterval), + nameof(CustomVSyncInterval), nameof(CustomVSyncIntervalPercentageText)); } } - public string CustomVSyncIntervalPercentageText - { - get - { - string text = CustomVSyncIntervalPercentageProxy + "%"; - return text; - } - } + public string CustomVSyncIntervalPercentageText => CustomVSyncIntervalPercentageProxy + "%"; public bool EnableCustomVSyncInterval { @@ -356,7 +317,6 @@ namespace Ryujinx.Ava.UI.ViewModels set { _networkInterfaceIndex = value != -1 ? value : 0; - ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _networkInterfaces[NetworkInterfaceList[_networkInterfaceIndex]]; } } @@ -366,7 +326,6 @@ namespace Ryujinx.Ava.UI.ViewModels set { _multiplayerModeIndex = value; - ConfigurationState.Instance.Multiplayer.Mode.Value = (MultiplayerMode)_multiplayerModeIndex; } } @@ -375,16 +334,6 @@ namespace Ryujinx.Ava.UI.ViewModels public bool IsInvalidLdnPassphraseVisible { get; set; } - public string LdnServer - { - get => _ldnServer; - set - { - _ldnServer = value; - OnPropertyChanged(); - } - } - public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this() { _virtualFileSystem = virtualFileSystem; @@ -647,16 +596,14 @@ namespace Ryujinx.Ava.UI.ViewModels config.ShowTitleBar.Value = ShowTitleBar; config.HideCursor.Value = (HideCursorMode)HideCursor; - if (_gameDirectoryChanged) + if (GameDirectoryChanged) { - List gameDirs = new(GameDirectories); - config.UI.GameDirs.Value = gameDirs; + config.UI.GameDirs.Value = [..GameDirectories]; } - if (_autoloadDirectoryChanged) + if (AutoloadDirectoryChanged) { - List autoloadDirs = new(AutoloadDirectories); - config.UI.AutoloadDirs.Value = autoloadDirs; + config.UI.AutoloadDirs.Value = [..AutoloadDirectories]; } config.UI.BaseStyle.Value = BaseStyleIndex switch @@ -766,8 +713,8 @@ namespace Ryujinx.Ava.UI.ViewModels SaveSettingsEvent?.Invoke(); - _gameDirectoryChanged = false; - _autoloadDirectoryChanged = false; + GameDirectoryChanged = false; + AutoloadDirectoryChanged = false; } private static void RevertIfNotSaved()