Added custom setting function for each game
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Humanizer;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using Ryujinx.Audio.Backends.OpenAL;
|
||||
using Ryujinx.Audio.Backends.SDL2;
|
||||
@@ -26,6 +28,7 @@ using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading.Tasks;
|
||||
@@ -67,6 +70,49 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
[ObservableProperty] private string _ldnServer;
|
||||
|
||||
public SettingsHacksViewModel DirtyHacks { get; }
|
||||
public string GamePath { get; }
|
||||
public string GameName { get; }
|
||||
|
||||
private Bitmap _gameIcon;
|
||||
|
||||
private string _gameTitle;
|
||||
private string _gameId;
|
||||
public Bitmap GameIcon
|
||||
{
|
||||
get => _gameIcon;
|
||||
set
|
||||
{
|
||||
if (_gameIcon != value)
|
||||
{
|
||||
_gameIcon = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GameTitle
|
||||
{
|
||||
get => _gameTitle;
|
||||
set
|
||||
{
|
||||
if (_gameTitle != value)
|
||||
{
|
||||
_gameTitle = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GameId
|
||||
{
|
||||
get => _gameId;
|
||||
set
|
||||
{
|
||||
if (_gameId != value)
|
||||
{
|
||||
_gameId = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int ResolutionScale
|
||||
{
|
||||
@@ -342,6 +388,37 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager, string gamePath, string gameName, string gameId, byte[] gameIconData) : this()
|
||||
{
|
||||
_virtualFileSystem = virtualFileSystem;
|
||||
_contentManager = contentManager;
|
||||
|
||||
if (gameIconData != null && gameIconData.Length > 0)
|
||||
{
|
||||
using (var ms = new MemoryStream(gameIconData))
|
||||
{
|
||||
GameIcon = new Bitmap(ms);
|
||||
}
|
||||
}
|
||||
|
||||
GameTitle = gameName;
|
||||
GameId = gameId;
|
||||
|
||||
string gameDir = Program.GetDirGameUserConfig(gameId,false,true);
|
||||
if (ConfigurationFileFormat.TryLoad(gameDir, out ConfigurationFileFormat configurationFileFormat))
|
||||
{
|
||||
ConfigurationState.Instance.Load(configurationFileFormat, gameDir, gameId);
|
||||
LoadCurrentConfiguration(); // Needed to load custom configuration
|
||||
}
|
||||
|
||||
if (Program.PreviewerDetached)
|
||||
{
|
||||
Task.Run(LoadTimeZones);
|
||||
|
||||
DirtyHacks = new SettingsHacksViewModel(this);
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsViewModel()
|
||||
{
|
||||
GameDirectories = [];
|
||||
@@ -468,27 +545,30 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
{
|
||||
ConfigurationState config = ConfigurationState.Instance;
|
||||
|
||||
// User Interface
|
||||
EnableDiscordIntegration = config.EnableDiscordIntegration;
|
||||
CheckUpdatesOnStart = config.CheckUpdatesOnStart;
|
||||
ShowConfirmExit = config.ShowConfirmExit;
|
||||
RememberWindowState = config.RememberWindowState;
|
||||
ShowTitleBar = config.ShowTitleBar;
|
||||
HideCursor = (int)config.HideCursor.Value;
|
||||
|
||||
GameDirectories.Clear();
|
||||
GameDirectories.AddRange(config.UI.GameDirs.Value);
|
||||
|
||||
AutoloadDirectories.Clear();
|
||||
AutoloadDirectories.AddRange(config.UI.AutoloadDirs.Value);
|
||||
|
||||
BaseStyleIndex = config.UI.BaseStyle.Value switch
|
||||
if (string.IsNullOrEmpty(GameId))
|
||||
{
|
||||
"Auto" => 0,
|
||||
"Light" => 1,
|
||||
"Dark" => 2,
|
||||
_ => 0
|
||||
};
|
||||
// User Interface
|
||||
EnableDiscordIntegration = config.EnableDiscordIntegration;
|
||||
CheckUpdatesOnStart = config.CheckUpdatesOnStart;
|
||||
ShowConfirmExit = config.ShowConfirmExit;
|
||||
RememberWindowState = config.RememberWindowState;
|
||||
ShowTitleBar = config.ShowTitleBar;
|
||||
HideCursor = (int)config.HideCursor.Value;
|
||||
|
||||
GameDirectories.Clear();
|
||||
GameDirectories.AddRange(config.UI.GameDirs.Value);
|
||||
|
||||
AutoloadDirectories.Clear();
|
||||
AutoloadDirectories.AddRange(config.UI.AutoloadDirs.Value);
|
||||
|
||||
BaseStyleIndex = config.UI.BaseStyle.Value switch
|
||||
{
|
||||
"Auto" => 0,
|
||||
"Light" => 1,
|
||||
"Dark" => 2,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
// Input
|
||||
EnableDockedMode = config.System.EnableDockedMode;
|
||||
@@ -569,7 +649,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
LdnServer = config.Multiplayer.LdnServer;
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
public void SaveSettings2()
|
||||
{
|
||||
ConfigurationState config = ConfigurationState.Instance;
|
||||
|
||||
@@ -583,12 +663,12 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
if (GameDirectoryChanged)
|
||||
{
|
||||
config.UI.GameDirs.Value = [..GameDirectories];
|
||||
config.UI.GameDirs.Value = [.. GameDirectories];
|
||||
}
|
||||
|
||||
if (AutoloadDirectoryChanged)
|
||||
{
|
||||
config.UI.AutoloadDirs.Value = [..AutoloadDirectories];
|
||||
config.UI.AutoloadDirs.Value = [.. AutoloadDirectories];
|
||||
}
|
||||
|
||||
config.UI.BaseStyle.Value = BaseStyleIndex switch
|
||||
@@ -599,6 +679,50 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
_ => "Auto"
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(GameId))
|
||||
{
|
||||
config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
ConfigurationState config = ConfigurationState.Instance;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(GameId))
|
||||
{
|
||||
// User Interface
|
||||
config.EnableDiscordIntegration.Value = EnableDiscordIntegration;
|
||||
config.CheckUpdatesOnStart.Value = CheckUpdatesOnStart;
|
||||
config.ShowConfirmExit.Value = ShowConfirmExit;
|
||||
config.RememberWindowState.Value = RememberWindowState;
|
||||
config.ShowTitleBar.Value = ShowTitleBar;
|
||||
config.HideCursor.Value = (HideCursorMode)HideCursor;
|
||||
|
||||
if (GameDirectoryChanged)
|
||||
{
|
||||
config.UI.GameDirs.Value = [.. GameDirectories];
|
||||
}
|
||||
|
||||
if (AutoloadDirectoryChanged)
|
||||
{
|
||||
config.UI.AutoloadDirs.Value = [.. AutoloadDirectories];
|
||||
}
|
||||
|
||||
config.UI.BaseStyle.Value = BaseStyleIndex switch
|
||||
{
|
||||
0 => "Auto",
|
||||
1 => "Light",
|
||||
2 => "Dark",
|
||||
_ => "Auto"
|
||||
};
|
||||
}
|
||||
|
||||
// Input
|
||||
config.System.EnableDockedMode.Value = EnableDockedMode;
|
||||
config.Hid.EnableKeyboard.Value = EnableKeyboard;
|
||||
@@ -693,7 +817,9 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
config.Hacks.EnableShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelayEnabled;
|
||||
config.Hacks.ShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelay;
|
||||
|
||||
config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
|
||||
|
||||
config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
|
||||
|
||||
|
||||
MainWindow.UpdateGraphicsConfig();
|
||||
RyujinxApp.MainWindow.ViewModel.VSyncModeSettingChanged();
|
||||
@@ -706,7 +832,11 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
private static void RevertIfNotSaved()
|
||||
{
|
||||
Program.ReloadConfig();
|
||||
// maybe this is an unnecessary check(all options need to be tested)
|
||||
if (string.IsNullOrEmpty(Program.GlobalConfigurationPath))
|
||||
{
|
||||
Program.ReloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyButton()
|
||||
@@ -714,6 +844,25 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public void DeleteConfigGame()
|
||||
{
|
||||
string gameDir = Program.GetDirGameUserConfig(GameId,false,false);
|
||||
|
||||
if (File.Exists(gameDir))
|
||||
{
|
||||
File.Delete(gameDir);
|
||||
}
|
||||
RevertIfNotSaved();
|
||||
CloseWindow?.Invoke();
|
||||
}
|
||||
|
||||
public void SaveUserConfig()
|
||||
{
|
||||
SaveSettings();
|
||||
RevertIfNotSaved();
|
||||
CloseWindow?.Invoke();
|
||||
}
|
||||
|
||||
public void OkButton()
|
||||
{
|
||||
SaveSettings();
|
||||
|
||||
Reference in New Issue
Block a user