From ce31a47934756252dc1237e7c782afebe8636b5f Mon Sep 17 00:00:00 2001 From: GreemDev Date: Mon, 9 Jun 2025 17:57:26 -0500 Subject: [PATCH] misc: Code styling changes & cleanups --- src/Ryujinx/Program.cs | 12 ++--- .../Systems/AppLibrary/ApplicationLibrary.cs | 2 +- .../UI/ViewModels/Input/InputViewModel.cs | 46 +++++-------------- .../UI/ViewModels/MainWindowViewModel.cs | 22 ++++----- .../UI/ViewModels/SettingsViewModel.cs | 24 +++++----- src/Ryujinx/UI/Views/Input/InputView.axaml | 1 - src/Ryujinx/UI/Views/Input/InputView.axaml.cs | 5 +- .../UI/Views/Settings/SettingsInputView.axaml | 2 +- .../GameSpecificSettingsWindow.axaml.cs | 4 +- 9 files changed, 42 insertions(+), 76 deletions(-) diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 077639b41..09759d7cc 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -25,7 +25,6 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Silk.NET.Vulkan; namespace Ryujinx.Ava { @@ -36,7 +35,7 @@ namespace Ryujinx.Ava public static string Version { get; private set; } public static string ConfigurationPath { get; private set; } public static string GlobalConfigurationPath { get; private set; } - public static bool UseExtraConfig{ get; private set; } + public static bool UseExtraConfig { get; set; } public static bool PreviewerDetached { get; private set; } public static bool UseHardwareAcceleration { get; private set; } public static string BackendThreadingArg { get; private set; } @@ -162,7 +161,7 @@ namespace Ryujinx.Ava } - public static string GetDirGameUserConfig(string gameId, bool rememberGlobalDir = false, bool changeFolderForGame = false) + public static string GetDirGameUserConfig(string gameId, bool changeFolderForGame = false) { if (string.IsNullOrEmpty(gameId)) { @@ -180,12 +179,7 @@ namespace Ryujinx.Ava return gameDir; } - public static void SetUseExtraConfig(bool value) - { - UseExtraConfig = value; - } - - public static void ReloadConfig(bool rememberGlobalDir = false) + public static void ReloadConfig() { string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ReleaseInformation.ConfigName); diff --git a/src/Ryujinx/Systems/AppLibrary/ApplicationLibrary.cs b/src/Ryujinx/Systems/AppLibrary/ApplicationLibrary.cs index b5367ffee..1db2332b8 100644 --- a/src/Ryujinx/Systems/AppLibrary/ApplicationLibrary.cs +++ b/src/Ryujinx/Systems/AppLibrary/ApplicationLibrary.cs @@ -556,7 +556,7 @@ namespace Ryujinx.Ava.Systems.AppLibrary data.Favorite = appMetadata.Favorite; data.TimePlayed = appMetadata.TimePlayed; data.LastPlayed = appMetadata.LastPlayed; - data.HasIndependentConfiguration = File.Exists(Program.GetDirGameUserConfig(data.IdBaseString, false, false)); // Just check user config + data.HasIndependentConfiguration = File.Exists(Program.GetDirGameUserConfig(data.IdBaseString)); // Just check user config } data.FileExtension = Path.GetExtension(applicationPath).TrimStart('.').ToUpper(); diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index eccd6eec2..aa8333d68 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -50,6 +50,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private string _controllerImage; private int _device; private object _configViewModel; + private bool _isChangeTrackingActive; + private string _chosenProfile; + [ObservableProperty] private bool _isModified; [ObservableProperty] private string _profileName; [ObservableProperty] private bool _notificationIsVisible; // Automatically call the NotificationView property with OnPropertyChanged() [ObservableProperty] private string _notificationText; // Automatically call the NotificationText property with OnPropertyChanged() @@ -84,9 +87,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public AvaloniaList ProfilesList { get; set; } public AvaloniaList DeviceList { get; set; } - public bool _useExtraConfig; - - public bool _useGlobalInput; + public bool UseGlobalConfig; // XAML Flags public bool ShowSettings => _device > 0; @@ -98,31 +99,16 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool HasLed => SelectedGamepad.Features.HasFlag(GamepadFeaturesFlag.Led); public bool CanClearLed => SelectedGamepad.Name.ContainsIgnoreCase("DualSense"); - public bool _isChangeTrackingActive; - - public bool _isModified; - - public bool IsModified - { - get => _isModified; - set - { - _isModified = value; - OnPropertyChanged(); - } - } - public event Action NotifyChangesEvent; - - public string _profileChoose; + public string ProfileChoose { - get => _profileChoose; + get => _chosenProfile; set { // When you select a profile, the settings from the profile will be applied. // To save the settings, you still need to click the apply button - _profileChoose = value; + _chosenProfile = value; LoadProfile(); OnPropertyChanged(); } @@ -294,14 +280,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public InputConfig Config { get; set; } - public InputViewModel(UserControl owner, bool UseGlobalInput = false) : this() + public InputViewModel(UserControl owner, bool useGlobal = false) : this() { if (Program.PreviewerDetached) { _mainWindow = RyujinxApp.MainWindow; - _useExtraConfig = Program.UseExtraConfig; - AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; @@ -309,7 +293,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); - _useGlobalInput = UseGlobalInput; + UseGlobalConfig = useGlobal; _isLoaded = false; @@ -347,7 +331,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private void LoadConfiguration(InputConfig inputConfig = null) { - if (_useGlobalInput && _useExtraConfig) + if (UseGlobalConfig && Program.UseExtraConfig) { Config = inputConfig ?? ConfigurationState.InstanceExtra.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId); } @@ -983,7 +967,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input List newConfig = []; - if (_useGlobalInput && _useExtraConfig) + if (UseGlobalConfig && Program.UseExtraConfig) { newConfig.AddRange(ConfigurationState.InstanceExtra.Hid.InputConfig.Value); } @@ -1035,7 +1019,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input // NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event. _mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); - if (_useGlobalInput && _useExtraConfig) + if (UseGlobalConfig && Program.UseExtraConfig) { // In User Settings when "Use Global Input" is enabled, it saves global input to global setting ConfigurationState.InstanceExtra.Hid.InputConfig.Value = newConfig; @@ -1046,12 +1030,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input ConfigurationState.Instance.Hid.InputConfig.Value = newConfig; ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); } - - } - - public void NotifyChange(string property) - { - OnPropertyChanged(property); } public void NotifyChanges() diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index be9441b06..8b9b04511 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -1575,16 +1575,14 @@ namespace Ryujinx.Ava.UI.ViewModels public bool InitializeUserConfig(ApplicationData application) { // Code where conditions will be met before loading the user configuration (Global Config) - string BackendThreadingInit = Program.BackendThreadingArg; - - BackendThreadingInit ??= ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString(); + string backendThreadingInit = Program.BackendThreadingArg ?? ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString(); // If a configuration is found in the "/games/xxxxxxxxxxxxxx" folder, the program will load the user setting. string idGame = application.IdBaseString; if (ConfigurationFileFormat.TryLoad(Program.GetDirGameUserConfig(idGame), out ConfigurationFileFormat configurationFileFormat)) { // Loads the user configuration, having previously changed the global configuration to the user configuration - ConfigurationState.Instance.Load(configurationFileFormat, Program.GetDirGameUserConfig(idGame, true, true), idGame); + ConfigurationState.Instance.Load(configurationFileFormat, Program.GetDirGameUserConfig(idGame, true), idGame); if (ConfigurationFileFormat.TryLoad(Program.GlobalConfigurationPath, out ConfigurationFileFormat configurationFileFormatExtra)) { @@ -1595,15 +1593,13 @@ namespace Ryujinx.Ava.UI.ViewModels } // Code where conditions will be executed after loading user configuration - if (ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString() != BackendThreadingInit) + if (ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString() != backendThreadingInit) { - - List Arguments = new() - { - "--bt", ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString() // BackendThreading - }; - - Rebooter.RebootAppWithGame(application.Path, Arguments); + Rebooter.RebootAppWithGame(application.Path, + [ + "--bt", + ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString() + ]); return true; } @@ -1998,7 +1994,7 @@ namespace Ryujinx.Ava.UI.ViewModels // just checking for file presence viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists( - Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString, false, false)); + Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString)); viewModel.RefreshView(); }); diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index 7c80381e6..654eb0c43 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -147,19 +147,19 @@ namespace Ryujinx.Ava.UI.ViewModels public bool DisableInputWhenOutOfFocus { get; set; } public int FocusLostActionType { get; set; } - public bool EnableConfigGlobal + public bool UseGlobalInputConfig { get => _useInputGlobalConfig; set { _useInputGlobalConfig = value; LocalGlobalInputSwitchEvent?.Invoke(_useInputGlobalConfig); - OnPropertyChanged(nameof(PanelOpacityInput)); + OnPropertyChanged(nameof(InputPanelOpacity)); OnPropertyChanged(); } } - public double PanelOpacityInput => EnableConfigGlobal ? 0.5 : 1; + public double InputPanelOpacity => UseGlobalInputConfig ? 0.5 : 1; public VSyncMode VSyncMode { @@ -387,7 +387,7 @@ namespace Ryujinx.Ava.UI.ViewModels public bool IsInvalidLdnPassphraseVisible { get; set; } - public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this(false) + public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this() { _virtualFileSystem = virtualFileSystem; _contentManager = contentManager; @@ -408,7 +408,7 @@ namespace Ryujinx.Ava.UI.ViewModels string gameName, string gameId, byte[] gameIconData, - bool enableToLoadCustomConfig) : this(enableToLoadCustomConfig) + bool customConfig) : this() { _virtualFileSystem = virtualFileSystem; _contentManager = contentManager; @@ -424,11 +424,11 @@ namespace Ryujinx.Ava.UI.ViewModels _gameTitle = gameName; _gameId = gameId; - if (enableToLoadCustomConfig) // During the game. If there is no user config, then load the global config window + if (customConfig) // During the game. If there is no user config, then load the global config window { - string gameDir = Program.GetDirGameUserConfig(gameId, true, true); + string gameDir = Program.GetDirGameUserConfig(gameId, true); - Program.SetUseExtraConfig(true); + Program.UseExtraConfig = true; if (ConfigurationFileFormat.TryLoad(Program.GlobalConfigurationPath, out ConfigurationFileFormat configurationFileFormatExtra)) { @@ -451,7 +451,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } - public SettingsViewModel(bool noLoadGlobalConfig = false) + public SettingsViewModel() { GameDirectories = []; AutoloadDirectories = []; @@ -603,7 +603,7 @@ namespace Ryujinx.Ava.UI.ViewModels }; // Input - EnableConfigGlobal = config.System.UseInputGlobalConfig; + UseGlobalInputConfig = config.System.UseInputGlobalConfig; EnableDockedMode = config.System.EnableDockedMode; EnableKeyboard = config.Hid.EnableKeyboard; EnableMouse = config.Hid.EnableMouse; @@ -710,7 +710,7 @@ namespace Ryujinx.Ava.UI.ViewModels }; // Input - config.System.UseInputGlobalConfig.Value = EnableConfigGlobal; + config.System.UseInputGlobalConfig.Value = UseGlobalInputConfig; config.System.EnableDockedMode.Value = EnableDockedMode; config.Hid.EnableKeyboard.Value = EnableKeyboard; config.Hid.EnableMouse.Value = EnableMouse; @@ -840,7 +840,7 @@ namespace Ryujinx.Ava.UI.ViewModels public void DeleteConfigGame() { - string gameDir = Program.GetDirGameUserConfig(GameId, false, false); + string gameDir = Program.GetDirGameUserConfig(GameId); if (File.Exists(gameDir)) { diff --git a/src/Ryujinx/UI/Views/Input/InputView.axaml b/src/Ryujinx/UI/Views/Input/InputView.axaml index 13c0df768..dea508f10 100644 --- a/src/Ryujinx/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx/UI/Views/Input/InputView.axaml @@ -203,7 +203,6 @@ - + IsChecked="{Binding UseGlobalInputConfig}"> diff --git a/src/Ryujinx/UI/Windows/GameSpecificSettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/GameSpecificSettingsWindow.axaml.cs index 65ded0877..dc9ce56d6 100644 --- a/src/Ryujinx/UI/Windows/GameSpecificSettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/GameSpecificSettingsWindow.axaml.cs @@ -46,7 +46,7 @@ namespace Ryujinx.Ava.UI.Windows private void Load() { - Pages.Children.Clear(); + Pages.Children.Clear(); NavPanel.SelectionChanged += NavPanelOnSelectionChanged; NavPanel.SelectedItem = NavPanel.MenuItems.ElementAt(0); } @@ -97,7 +97,7 @@ namespace Ryujinx.Ava.UI.Windows protected override void OnClosing(WindowClosingEventArgs e) { - Program.SetUseExtraConfig(false); + Program.UseExtraConfig = false; InputPage.Dispose(); // You need to unload the gamepad settings, otherwise the controls will be blocked base.OnClosing(e); }