1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 23:33:33 +08:00

UXAssist: add profile based option

This commit is contained in:
2025-03-25 21:36:22 +08:00
parent 0f80dac134
commit adcce8e298
4 changed files with 39 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ namespace UXAssist.Functions;
public static class WindowFunctions
{
private static bool _initialized;
public static string ProfileName { get; private set; }
private const string GameWindowClass = "UnityWndClass";
@@ -34,6 +35,8 @@ public static class WindowFunctions
public static void Init()
{
if (_initialized) return;
_initialized = true;
I18N.Add("Cores: {0}\nThreads: {1}", "Cores: {0}\nThreads: {1}", "核心数: {0}\n线程数: {1}");
I18N.Add("\nP-Cores: {0}\nE-Cores: {1}", "\nP-Cores: {0}\nE-Cores: {1}", "\n性能核心: {0}\n能效核心: {1}");
I18N.Add("\nPriority: {0}", "\nProcess priority: {0}", "\n进程优先级: {0}");

View File

@@ -22,6 +22,7 @@ public class GamePatch : PatchImpl<GamePatch>
public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled;
public static ConfigEntry<Vector4> LastWindowRect;
public static ConfigEntry<bool> ProfileBasedSaveFolderEnabled;
public static ConfigEntry<bool> ProfileBasedOptionEnabled;
public static ConfigEntry<string> DefaultProfileName;
public static ConfigEntry<double> GameUpsFactor;
@@ -85,6 +86,7 @@ public class GamePatch : PatchImpl<GamePatch>
// AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => RefreshSavePath();
ProfileBasedOptionEnabled.SettingChanged += (_, _) => RefreshSavePath();
DefaultProfileName.SettingChanged += (_, _) => RefreshSavePath();
GameUpsFactor.SettingChanged += (_, _) =>
{
@@ -97,6 +99,7 @@ public class GamePatch : PatchImpl<GamePatch>
FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value);
};
RefreshSavePath();
}
public static void Start()
@@ -140,7 +143,13 @@ public class GamePatch : PatchImpl<GamePatch>
private static void RefreshSavePath()
{
var profileName = WindowFunctions.ProfileName;
if (profileName == null)
{
// We should initialize WindowFunctions before using WindowFunctions.ProfileName
WindowFunctions.Init();
profileName = WindowFunctions.ProfileName;
if (profileName == null) return;
}
if (UIRoot.instance.loadGameWindow.gameObject.activeSelf)
{
@@ -154,15 +163,30 @@ public class GamePatch : PatchImpl<GamePatch>
string gameSavePath;
if (ProfileBasedSaveFolderEnabled.Value && string.Compare(DefaultProfileName.Value, profileName, StringComparison.OrdinalIgnoreCase) != 0)
gameSavePath = $"{GameConfig.overrideDocumentFolder}{GameConfig.gameName}/Save/{profileName}/";
gameSavePath = $"{GameConfig.gameDocumentFolder}Save/{profileName}/";
else
gameSavePath = $"{GameConfig.overrideDocumentFolder}{GameConfig.gameName}/Save/";
gameSavePath = $"{GameConfig.gameDocumentFolder}Save/";
if (string.Compare(GameConfig.gameSavePath, gameSavePath, StringComparison.OrdinalIgnoreCase) == 0) return;
GameConfig.gameSavePath = gameSavePath;
if (!Directory.Exists(GameConfig.gameSavePath))
{
Directory.CreateDirectory(GameConfig.gameSavePath);
}
string optionPath;
if (ProfileBasedOptionEnabled.Value && string.Compare(DefaultProfileName.Value, profileName, StringComparison.OrdinalIgnoreCase) != 0)
{
var path = $"{GameConfig.gameDocumentFolder}Option";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
optionPath = $"{path}/{profileName}.xml";
}
else
optionPath = $"{GameConfig.gameDocumentFolder}options.xml";
if (string.Compare(GameConfig.gameXMLOption, optionPath, StringComparison.OrdinalIgnoreCase) == 0) return;
GameConfig.gameXMLOption = optionPath;
}
[HarmonyPrefix, HarmonyPatch(typeof(GameMain), nameof(GameMain.HandleApplicationQuit))]

View File

@@ -34,6 +34,9 @@ public static class UIConfigWindow
I18N.Add("Profile-based save folder", "Mod manager profile based save folder", "基于mod管理器配置档案名的存档文件夹");
I18N.Add("Profile-based save folder tips", "Save files are stored in 'Save\\<ProfileName>' folder.\nWill use original save location if matching default profile name",
"存档文件会存储在'Save\\<ProfileName>'文件夹中\n如果匹配默认配置档案名则使用原始存档位置");
I18N.Add("Profile-based option", "Mod manager profile based option", "基于mod管理器配置档案名的选项设置");
I18N.Add("Profile-based option tips", "Options are stored in 'Option\\<ProfileName>.xml'.\nWill use original save location if matching default profile name",
"配置选项会存储在'Option\\<ProfileName>.xml'里\n如果匹配默认配置档案名则使用原始存档位置");
I18N.Add("Default profile name", "Default profile name", "默认配置档案名");
I18N.Add("Logical Frame Rate", "Logical Frame Rate", "逻辑帧倍率");
I18N.Add("Reset", "Reset", "重置");
@@ -179,7 +182,10 @@ public static class UIConfigWindow
y += 36f;
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedSaveFolderEnabled, "Profile-based save folder");
wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based save folder", "Profile-based save folder tips", "btn-profile-based-save-folder-tips");
y += 30f;
y += 36f;
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedOptionEnabled, "Profile-based option");
wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based option", "Profile-based option tips", "btn-profile-based-option-tips");
y += 36f;
wnd.AddText2(x + 2f, y, tab1, "Default profile name", 15, "text-default-profile-name");
y += 24f;
wnd.AddInputField(x + 2f, y, 200f, tab1, GamePatch.DefaultProfileName, 15, "input-profile-save-folder");

View File

@@ -78,6 +78,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
"Mouse cursor scale up multiplier");
GamePatch.ProfileBasedSaveFolderEnabled = Config.Bind("Game", "ProfileBasedSaveFolder", false,
"Profile-based save folder");
GamePatch.ProfileBasedOptionEnabled = Config.Bind("Game", "ProfileBasedOption", false,
"Profile-based option");
GamePatch.DefaultProfileName = Config.Bind("Game", "DefaultProfileName", "Default",
"Default profile name, used when profile-based save folder is enabled. Use original game save folder if matched");
/*