misc: Code styling changes & cleanups

This commit is contained in:
GreemDev 2025-06-09 17:57:26 -05:00
parent d31d1f91cf
commit ce31a47934
9 changed files with 42 additions and 76 deletions

View file

@ -25,7 +25,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Silk.NET.Vulkan;
namespace Ryujinx.Ava namespace Ryujinx.Ava
{ {
@ -36,7 +35,7 @@ namespace Ryujinx.Ava
public static string Version { get; private set; } public static string Version { get; private set; }
public static string ConfigurationPath { get; private set; } public static string ConfigurationPath { get; private set; }
public static string GlobalConfigurationPath { 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 PreviewerDetached { get; private set; }
public static bool UseHardwareAcceleration { get; private set; } public static bool UseHardwareAcceleration { get; private set; }
public static string BackendThreadingArg { 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)) if (string.IsNullOrEmpty(gameId))
{ {
@ -180,12 +179,7 @@ namespace Ryujinx.Ava
return gameDir; return gameDir;
} }
public static void SetUseExtraConfig(bool value) public static void ReloadConfig()
{
UseExtraConfig = value;
}
public static void ReloadConfig(bool rememberGlobalDir = false)
{ {
string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ReleaseInformation.ConfigName); string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ReleaseInformation.ConfigName);

View file

@ -556,7 +556,7 @@ namespace Ryujinx.Ava.Systems.AppLibrary
data.Favorite = appMetadata.Favorite; data.Favorite = appMetadata.Favorite;
data.TimePlayed = appMetadata.TimePlayed; data.TimePlayed = appMetadata.TimePlayed;
data.LastPlayed = appMetadata.LastPlayed; 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(); data.FileExtension = Path.GetExtension(applicationPath).TrimStart('.').ToUpper();

View file

@ -50,6 +50,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private string _controllerImage; private string _controllerImage;
private int _device; private int _device;
private object _configViewModel; private object _configViewModel;
private bool _isChangeTrackingActive;
private string _chosenProfile;
[ObservableProperty] private bool _isModified;
[ObservableProperty] private string _profileName; [ObservableProperty] private string _profileName;
[ObservableProperty] private bool _notificationIsVisible; // Automatically call the NotificationView property with OnPropertyChanged() [ObservableProperty] private bool _notificationIsVisible; // Automatically call the NotificationView property with OnPropertyChanged()
[ObservableProperty] private string _notificationText; // Automatically call the NotificationText 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<string> ProfilesList { get; set; } public AvaloniaList<string> ProfilesList { get; set; }
public AvaloniaList<string> DeviceList { get; set; } public AvaloniaList<string> DeviceList { get; set; }
public bool _useExtraConfig; public bool UseGlobalConfig;
public bool _useGlobalInput;
// XAML Flags // XAML Flags
public bool ShowSettings => _device > 0; 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 HasLed => SelectedGamepad.Features.HasFlag(GamepadFeaturesFlag.Led);
public bool CanClearLed => SelectedGamepad.Name.ContainsIgnoreCase("DualSense"); 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 event Action NotifyChangesEvent;
public string _profileChoose;
public string ProfileChoose public string ProfileChoose
{ {
get => _profileChoose; get => _chosenProfile;
set set
{ {
// When you select a profile, the settings from the profile will be applied. // 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 // To save the settings, you still need to click the apply button
_profileChoose = value; _chosenProfile = value;
LoadProfile(); LoadProfile();
OnPropertyChanged(); OnPropertyChanged();
} }
@ -294,14 +280,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
public InputConfig Config { get; set; } public InputConfig Config { get; set; }
public InputViewModel(UserControl owner, bool UseGlobalInput = false) : this() public InputViewModel(UserControl owner, bool useGlobal = false) : this()
{ {
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
_mainWindow = RyujinxApp.MainWindow; _mainWindow = RyujinxApp.MainWindow;
_useExtraConfig = Program.UseExtraConfig;
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner);
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
@ -309,7 +293,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
_mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates();
_useGlobalInput = UseGlobalInput; UseGlobalConfig = useGlobal;
_isLoaded = false; _isLoaded = false;
@ -347,7 +331,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private void LoadConfiguration(InputConfig inputConfig = null) 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); Config = inputConfig ?? ConfigurationState.InstanceExtra.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
} }
@ -983,7 +967,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
List<InputConfig> newConfig = []; List<InputConfig> newConfig = [];
if (_useGlobalInput && _useExtraConfig) if (UseGlobalConfig && Program.UseExtraConfig)
{ {
newConfig.AddRange(ConfigurationState.InstanceExtra.Hid.InputConfig.Value); 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. // 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); _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 // In User Settings when "Use Global Input" is enabled, it saves global input to global setting
ConfigurationState.InstanceExtra.Hid.InputConfig.Value = newConfig; ConfigurationState.InstanceExtra.Hid.InputConfig.Value = newConfig;
@ -1046,12 +1030,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
ConfigurationState.Instance.Hid.InputConfig.Value = newConfig; ConfigurationState.Instance.Hid.InputConfig.Value = newConfig;
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
} }
}
public void NotifyChange(string property)
{
OnPropertyChanged(property);
} }
public void NotifyChanges() public void NotifyChanges()

View file

@ -1575,16 +1575,14 @@ namespace Ryujinx.Ava.UI.ViewModels
public bool InitializeUserConfig(ApplicationData application) public bool InitializeUserConfig(ApplicationData application)
{ {
// Code where conditions will be met before loading the user configuration (Global Config) // Code where conditions will be met before loading the user configuration (Global Config)
string BackendThreadingInit = Program.BackendThreadingArg; string backendThreadingInit = Program.BackendThreadingArg ?? ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString();
BackendThreadingInit ??= ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString();
// If a configuration is found in the "/games/xxxxxxxxxxxxxx" folder, the program will load the user setting. // If a configuration is found in the "/games/xxxxxxxxxxxxxx" folder, the program will load the user setting.
string idGame = application.IdBaseString; string idGame = application.IdBaseString;
if (ConfigurationFileFormat.TryLoad(Program.GetDirGameUserConfig(idGame), out ConfigurationFileFormat configurationFileFormat)) if (ConfigurationFileFormat.TryLoad(Program.GetDirGameUserConfig(idGame), out ConfigurationFileFormat configurationFileFormat))
{ {
// Loads the user configuration, having previously changed the global configuration to the user configuration // 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)) 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 // 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)
{ {
Rebooter.RebootAppWithGame(application.Path,
List<string> Arguments = new() [
{ "--bt",
"--bt", ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString() // BackendThreading ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString()
}; ]);
Rebooter.RebootAppWithGame(application.Path, Arguments);
return true; return true;
} }
@ -1998,7 +1994,7 @@ namespace Ryujinx.Ava.UI.ViewModels
// just checking for file presence // just checking for file presence
viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists( viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists(
Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString, false, false)); Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString));
viewModel.RefreshView(); viewModel.RefreshView();
}); });

View file

@ -147,19 +147,19 @@ namespace Ryujinx.Ava.UI.ViewModels
public bool DisableInputWhenOutOfFocus { get; set; } public bool DisableInputWhenOutOfFocus { get; set; }
public int FocusLostActionType { get; set; } public int FocusLostActionType { get; set; }
public bool EnableConfigGlobal public bool UseGlobalInputConfig
{ {
get => _useInputGlobalConfig; get => _useInputGlobalConfig;
set set
{ {
_useInputGlobalConfig = value; _useInputGlobalConfig = value;
LocalGlobalInputSwitchEvent?.Invoke(_useInputGlobalConfig); LocalGlobalInputSwitchEvent?.Invoke(_useInputGlobalConfig);
OnPropertyChanged(nameof(PanelOpacityInput)); OnPropertyChanged(nameof(InputPanelOpacity));
OnPropertyChanged(); OnPropertyChanged();
} }
} }
public double PanelOpacityInput => EnableConfigGlobal ? 0.5 : 1; public double InputPanelOpacity => UseGlobalInputConfig ? 0.5 : 1;
public VSyncMode VSyncMode public VSyncMode VSyncMode
{ {
@ -387,7 +387,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public bool IsInvalidLdnPassphraseVisible { get; set; } public bool IsInvalidLdnPassphraseVisible { get; set; }
public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this(false) public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this()
{ {
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
_contentManager = contentManager; _contentManager = contentManager;
@ -408,7 +408,7 @@ namespace Ryujinx.Ava.UI.ViewModels
string gameName, string gameName,
string gameId, string gameId,
byte[] gameIconData, byte[] gameIconData,
bool enableToLoadCustomConfig) : this(enableToLoadCustomConfig) bool customConfig) : this()
{ {
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
_contentManager = contentManager; _contentManager = contentManager;
@ -424,11 +424,11 @@ namespace Ryujinx.Ava.UI.ViewModels
_gameTitle = gameName; _gameTitle = gameName;
_gameId = gameId; _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)) 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 = []; GameDirectories = [];
AutoloadDirectories = []; AutoloadDirectories = [];
@ -603,7 +603,7 @@ namespace Ryujinx.Ava.UI.ViewModels
}; };
// Input // Input
EnableConfigGlobal = config.System.UseInputGlobalConfig; UseGlobalInputConfig = config.System.UseInputGlobalConfig;
EnableDockedMode = config.System.EnableDockedMode; EnableDockedMode = config.System.EnableDockedMode;
EnableKeyboard = config.Hid.EnableKeyboard; EnableKeyboard = config.Hid.EnableKeyboard;
EnableMouse = config.Hid.EnableMouse; EnableMouse = config.Hid.EnableMouse;
@ -710,7 +710,7 @@ namespace Ryujinx.Ava.UI.ViewModels
}; };
// Input // Input
config.System.UseInputGlobalConfig.Value = EnableConfigGlobal; config.System.UseInputGlobalConfig.Value = UseGlobalInputConfig;
config.System.EnableDockedMode.Value = EnableDockedMode; config.System.EnableDockedMode.Value = EnableDockedMode;
config.Hid.EnableKeyboard.Value = EnableKeyboard; config.Hid.EnableKeyboard.Value = EnableKeyboard;
config.Hid.EnableMouse.Value = EnableMouse; config.Hid.EnableMouse.Value = EnableMouse;
@ -840,7 +840,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public void DeleteConfigGame() public void DeleteConfigGame()
{ {
string gameDir = Program.GetDirGameUserConfig(GameId, false, false); string gameDir = Program.GetDirGameUserConfig(GameId);
if (File.Exists(gameDir)) if (File.Exists(gameDir))
{ {

View file

@ -203,7 +203,6 @@
</StackPanel> </StackPanel>
<ContentControl IsVisible="{Binding NotificationIsVisible}"> <ContentControl IsVisible="{Binding NotificationIsVisible}">
<ContentControl.Content> <ContentControl.Content>
<StackPanel> <StackPanel>
<TextBlock <TextBlock
Margin="5,20,0,0" Margin="5,20,0,0"

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Ava.UI.Views.Input
public InputView() public InputView()
{ {
ViewModel = new InputViewModel(this, ConfigurationState.Instance.System.UseInputGlobalConfig.Value); ViewModel = new InputViewModel(this, ConfigurationState.Instance.System.UseInputGlobalConfig);
InitializeComponent(); InitializeComponent();
} }
@ -27,9 +27,8 @@ namespace Ryujinx.Ava.UI.Views.Input
public void ToggleLocalGlobalInput(bool enableConfigGlobal) public void ToggleLocalGlobalInput(bool enableConfigGlobal)
{ {
Dispose(); Dispose();
ViewModel = new InputViewModel(this, enableConfigGlobal); // Create new Input Page with other input configs ViewModel = new InputViewModel(this, enableConfigGlobal); // Create new Input Page with global input configs
InitializeComponent(); InitializeComponent();
} }

View file

@ -44,7 +44,7 @@
<CheckBox <CheckBox
ToolTip.Tip="{ext:Locale UseGlobalInputTooltip}" ToolTip.Tip="{ext:Locale UseGlobalInputTooltip}"
MinWidth="0" MinWidth="0"
IsChecked="{Binding EnableConfigGlobal}"> IsChecked="{Binding UseGlobalInputConfig}">
<TextBlock <TextBlock
Text="{ext:Locale SettingsTabInputUseGlobalInput}" /> Text="{ext:Locale SettingsTabInputUseGlobalInput}" />
</CheckBox> </CheckBox>

View file

@ -46,7 +46,7 @@ namespace Ryujinx.Ava.UI.Windows
private void Load() private void Load()
{ {
Pages.Children.Clear(); Pages.Children.Clear();
NavPanel.SelectionChanged += NavPanelOnSelectionChanged; NavPanel.SelectionChanged += NavPanelOnSelectionChanged;
NavPanel.SelectedItem = NavPanel.MenuItems.ElementAt(0); NavPanel.SelectedItem = NavPanel.MenuItems.ElementAt(0);
} }
@ -97,7 +97,7 @@ namespace Ryujinx.Ava.UI.Windows
protected override void OnClosing(WindowClosingEventArgs e) 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 InputPage.Dispose(); // You need to unload the gamepad settings, otherwise the controls will be blocked
base.OnClosing(e); base.OnClosing(e);
} }