From 73ebcf1aa35256eeb8d88d31f4ad255b86f1fe86 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 28 Sep 2025 17:36:19 +0800 Subject: [PATCH] more works --- UXAssist/ModsCompat/PlanetVeinUtilization.cs | 24 +++++++ UXAssist/Patches/UIPatch.cs | 72 +++++++++++++------- UXAssist/UIConfigWindow.cs | 8 ++- UXAssist/UXAssist.cs | 12 +++- 4 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 UXAssist/ModsCompat/PlanetVeinUtilization.cs diff --git a/UXAssist/ModsCompat/PlanetVeinUtilization.cs b/UXAssist/ModsCompat/PlanetVeinUtilization.cs new file mode 100644 index 0000000..c841af3 --- /dev/null +++ b/UXAssist/ModsCompat/PlanetVeinUtilization.cs @@ -0,0 +1,24 @@ +using BepInEx.Bootstrap; +using HarmonyLib; + +namespace UXAssist.ModsCompat; + +class PlanetVeinUtilization +{ + public const string PlanetVeinUtilizationGuid = "testpostpleaseignore.dsp.planet_vein_utilization"; + + public static bool Run(Harmony harmony) + { + if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(PlanetVeinUtilizationGuid, out var pluginInfo)) return false; + var assembly = pluginInfo.Instance.GetType().Assembly; + var classType = assembly.GetType("PlanetVeinUtilization.PlanetVeinUtilization"); + harmony.Patch(AccessTools.Method(classType, "Awake"), + new HarmonyMethod(typeof(PlanetVeinUtilization).GetMethod("PatchPlanetVeinUtilizationAwake"))); + return true; + } + + public static bool PatchPlanetVeinUtilizationAwake() + { + return false; + } +} diff --git a/UXAssist/Patches/UIPatch.cs b/UXAssist/Patches/UIPatch.cs index 75fbd8e..4f62d38 100644 --- a/UXAssist/Patches/UIPatch.cs +++ b/UXAssist/Patches/UIPatch.cs @@ -5,15 +5,23 @@ using HarmonyLib; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using BepInEx.Configuration; [PatchGuid(PluginInfo.PLUGIN_GUID)] public class UIPatch : PatchImpl { + public static ConfigEntry PlanetVeinUtilizationEnabled; + + public static void Init() + { + PlanetVeinUtilizationEnabled.SettingChanged += (_, _) => PlanetVeinUtilization.Enable(PlanetVeinUtilizationEnabled.Value); + } + public static void Start() { Enable(true); Functions.UIFunctions.InitMenuButtons(); - PlanetVeinUtilization.Enable(true); + PlanetVeinUtilization.Enable(PlanetVeinUtilizationEnabled.Value); } public static void Uninit() @@ -24,9 +32,6 @@ public class UIPatch : PatchImpl private class PlanetVeinUtilization : PatchImpl { - - private static bool planetPanelInitialized = false; - private static bool starPanelInitialized = false; private static readonly VeinTypeInfo[] planetVeinCount = new VeinTypeInfo[(int)EVeinType.Max]; private static readonly VeinTypeInfo[] starVeinCount = new VeinTypeInfo[(int)EVeinType.Max]; private static readonly Dictionary tmpGroups = []; @@ -35,6 +40,37 @@ public class UIPatch : PatchImpl { InitializeVeinCountArray(planetVeinCount); InitializeVeinCountArray(starVeinCount); + foreach (VeinTypeInfo vti in planetVeinCount) + { + vti.Reset(); + vti.textCtrl?.gameObject.SetActive(true); + } + UIPlanetDetail_RefreshDynamicProperties_Postfix(UIRoot.instance.uiGame.planetDetail); + foreach (VeinTypeInfo vti in starVeinCount) + { + vti.Reset(); + vti.textCtrl?.gameObject.SetActive(true); + } + UIStarDetail_RefreshDynamicProperties_Postfix(UIRoot.instance.uiGame.starDetail); + } + + private static Vector2 GetAdjustedSizeDelta(Vector2 origSizeDelta) + { + return new Vector2(origSizeDelta.x + 40f, origSizeDelta.y); + } + + protected override void OnDisable() + { + foreach (VeinTypeInfo vti in planetVeinCount) + { + vti.Reset(); + vti.textCtrl?.gameObject.SetActive(false); + } + foreach (VeinTypeInfo vti in starVeinCount) + { + vti.Reset(); + vti.textCtrl?.gameObject.SetActive(false); + } } #region Helper functions @@ -102,22 +138,12 @@ public class UIPatch : PatchImpl veinCountArray[i] = new VeinTypeInfo(); } } - - private static Vector2 GetAdjustedSizeDelta(Vector2 origSizeDelta) - { - return new Vector2(origSizeDelta.x + 45f, origSizeDelta.y); - } #endregion #region UIPlanetDetail patches [HarmonyPrefix, HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))] public static void UIPlanetDetail_OnPlanetDataSet_Prefix(UIPlanetDetail __instance) { - if (!planetPanelInitialized) - { - planetPanelInitialized = true; - __instance.rectTrans.sizeDelta = GetAdjustedSizeDelta(__instance.rectTrans.sizeDelta); - } foreach (VeinTypeInfo vti in planetVeinCount) { vti.Reset(); @@ -168,9 +194,9 @@ public class UIPatch : PatchImpl { FormatResource(refId, uiresAmountEntry, vt); } - else + else if (vt.textCtrl != null) { - vt.textCtrl?.gameObject.SetActive(false); + vt.textCtrl.text = ""; } } } @@ -181,11 +207,6 @@ public class UIPatch : PatchImpl [HarmonyPrefix, HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))] public static void UIStaretail_OnStarDataSet_Prefix(UIStarDetail __instance) { - if (!starPanelInitialized) - { - starPanelInitialized = true; - __instance.rectTrans.sizeDelta = GetAdjustedSizeDelta(__instance.rectTrans.sizeDelta); - } foreach (VeinTypeInfo vti in starVeinCount) { vti.Reset(); @@ -235,9 +256,9 @@ public class UIPatch : PatchImpl { FormatResource(refId, uiresAmountEntry, vt); } - else + else if (vt.textCtrl != null) { - vt.textCtrl?.gameObject.SetActive(false); + vt.textCtrl.text = ""; } } } @@ -255,7 +276,10 @@ public class UIPatch : PatchImpl { numVeinGroups = 0; numVeinGroupsWithCollector = 0; - if (textCtrl != null) textCtrl.text = ""; + if (textCtrl != null) + { + textCtrl.text = ""; + } } } diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index dd8d74e..cbe8207 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -24,7 +24,7 @@ public static class UIConfigWindow I18N.Add("Logistics", "Logistics", "物流"); I18N.Add("Player/Mecha", "Player/Mecha", "玩家/机甲"); I18N.Add("Dyson Sphere", "Dyson Sphere", "戴森球"); - I18N.Add("Tech/Combat", "Tech/Combat", "科研/战斗"); + I18N.Add("Tech/Combat/UI", "Tech/Combat/UI", "科研/战斗/UI"); I18N.Add("Enable game window resize", "Enable game window resize (maximum box and thick frame)", "可调整游戏窗口大小(可最大化和拖动边框)"); I18N.Add("Remeber window position and size on last exit", "Remeber window position and size on last exit", "记住上次退出时的窗口位置和大小"); I18N.Add("Scale up mouse cursor", "Scale up mouse cursor", "放大鼠标指针"); @@ -153,6 +153,7 @@ public static class UIConfigWindow I18N.Add("Set \"Sorter Cargo Stacking\" to unresearched state", "Set \"Sorter Cargo Stacking\" to unresearched state", "将\"分拣器货物叠加\"设为未研究状态"); I18N.Add("Unlock all techs with metadata", "Unlock all techs with metadata", "使用元数据解锁所有科技"); I18N.Add("Open Dark Fog Communicator", "Open Dark Fog Communicator", "打开黑雾通讯器"); + I18N.Add("Planet vein utilization", "Planet vein utilization in star map", "宇宙视图行星/星系矿脉数量显示"); I18N.Apply(); MyConfigWindow.OnUICreated += CreateUI; MyConfigWindow.OnUpdateUI += UpdateUI; @@ -754,9 +755,12 @@ public static class UIConfigWindow wnd.AddSlider(x + txt.preferredWidth + 5f, y + 6f, tab5, DysonSpherePatch.AutoConstructMultiplier, [1, 2, 5, 10, 20, 50, 100], "0", 100f); _dysonTab = tab5; - var tab6 = wnd.AddTab(trans, "Tech/Combat"); + var tab6 = wnd.AddTab(trans, "Tech/Combat/UI"); x = 10; y = 10; + wnd.AddCheckBox(x, y, tab6, UIPatch.PlanetVeinUtilizationEnabled, "Planet vein utilization"); + y += 36f; + y += 36f; wnd.AddCheckBox(x, y, tab6, TechPatch.BatchBuyoutTechEnabled, "Buy out techs with their prerequisites"); y += 36f; wnd.AddCheckBox(x, y, tab6, TechPatch.SorterCargoStackingEnabled, "Restore upgrades of \"Sorter Cargo Stacking\" on panel"); diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index e3d25ec..a38a608 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -22,6 +22,7 @@ namespace UXAssist; [BepInDependency(DSPModSavePlugin.MODGUID)] [CommonAPISubmoduleDependency(nameof(CustomKeyBindSystem))] [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] +[BepInDependency(ModsCompat.PlanetVeinUtilization.PlanetVeinUtilizationGuid, BepInDependency.DependencyFlags.SoftDependency)] public class UXAssist : BaseUnityPlugin, IModCanSave { public new static readonly ManualLogSource Logger = @@ -29,6 +30,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave private static ConfigFile _dummyConfig; private Type[] _patches, _compats; + private readonly Harmony _harmony = new(PluginInfo.PLUGIN_GUID); #region IModCanSave private const ushort ModSaveVersion = 1; @@ -51,6 +53,11 @@ public class UXAssist : BaseUnityPlugin, IModCanSave } #endregion + UXAssist() + { + ModsCompat.PlanetVeinUtilization.Run(_harmony); + } + private void Awake() { _dummyConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, PluginInfo.PLUGIN_GUID + "_dummy.cfg"), false) @@ -203,6 +210,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave DysonSpherePatch.OnlyConstructNodesEnabled = Config.Bind("DysonSphere", "OnlyConstructNodes", false, "Construct only nodes but frames"); DysonSpherePatch.AutoConstructMultiplier = Config.Bind("DysonSphere", "AutoConstructMultiplier", 1, "Dyson Sphere auto-construct speed multiplier"); + UIPatch.PlanetVeinUtilizationEnabled = Config.Bind("UI", "PlanetVeinUtilization", false, + "Planet vein utilization"); I18N.Init(); I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置"); @@ -228,7 +237,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave _patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null)); - object[] parameters = [UIPatch.GetHarmony()]; + object[] parameters = [_harmony]; _compats?.Do(type => type.GetMethod("Start")?.Invoke(null, parameters)); } @@ -236,7 +245,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave { _patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null)); - UIPatch.Enable(false); MyWindowManager.Enable(false); GameLogic.Enable(false); }