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.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);

View file

@ -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();

View file

@ -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<string> ProfilesList { get; set; }
public AvaloniaList<string> 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<InputConfig> 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()

View file

@ -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<string> 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();
});

View file

@ -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))
{

View file

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

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Ava.UI.Views.Input
public InputView()
{
ViewModel = new InputViewModel(this, ConfigurationState.Instance.System.UseInputGlobalConfig.Value);
ViewModel = new InputViewModel(this, ConfigurationState.Instance.System.UseInputGlobalConfig);
InitializeComponent();
}
@ -27,9 +27,8 @@ namespace Ryujinx.Ava.UI.Views.Input
public void ToggleLocalGlobalInput(bool enableConfigGlobal)
{
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();
}

View file

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

View file

@ -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);
}