From a9286d28394d694704ea276c45c4e5666f1b98d4 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Wed, 4 Jun 2025 11:44:13 +0800 Subject: [PATCH] UXAssist: add a minor option to auto logistics config --- UXAssist/Patches/LogisticsPatch.cs | 31 ++++++++++++++++++++++++++++++ UXAssist/UI/MyWindow.cs | 4 ++-- UXAssist/UIConfigWindow.cs | 7 +++++-- UXAssist/UXAssist.cs | 2 ++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/UXAssist/Patches/LogisticsPatch.cs b/UXAssist/Patches/LogisticsPatch.cs index bd55f83..647e1e1 100644 --- a/UXAssist/Patches/LogisticsPatch.cs +++ b/UXAssist/Patches/LogisticsPatch.cs @@ -29,6 +29,7 @@ public static class LogisticsPatch public static ConfigEntry AutoConfigPLSMinPilerValue; // 0~4; 0 = Maximum in tech, 1~4 = piler stacking count public static ConfigEntry AutoConfigPLSDroneCount; // 0~50 // ILS config + public static ConfigEntry SetDefaultRemoteLogicToStorage; public static ConfigEntry AutoConfigILSChargePower; // 2~20, display as 15000000.0 * value public static ConfigEntry AutoConfigILSMaxTripDrone; // 1~180, by degress public static ConfigEntry AutoConfigILSMaxTripShip; // 1~41; 1~20 = value LY, 21-40 = 2*value-20LY, 41 = Unlimited @@ -54,6 +55,7 @@ public static class LogisticsPatch { AutoConfigLogisticsEnabled.SettingChanged += (_, _) => AutoConfigLogistics.Enable(AutoConfigLogisticsEnabled.Value); AutoConfigLimitAutoReplenishCount.SettingChanged += (_, _) => AutoConfigLogistics.ToggleLimitAutoReplenishCount(); + SetDefaultRemoteLogicToStorage.SettingChanged += (_, _) => AutoConfigLogisticsSetDefaultRemoteLogicToStorage.Enable(SetDefaultRemoteLogicToStorage.Value); LogisticsCapacityTweaksEnabled.SettingChanged += (_, _) => LogisticsCapacityTweaks.Enable(LogisticsCapacityTweaksEnabled.Value); AllowOverflowInLogisticsEnabled.SettingChanged += (_, _) => AllowOverflowInLogistics.Enable(AllowOverflowInLogisticsEnabled.Value); LogisticsConstrolPanelImprovementEnabled.SettingChanged += (_, _) => LogisticsConstrolPanelImprovement.Enable(LogisticsConstrolPanelImprovementEnabled.Value); @@ -64,6 +66,7 @@ public static class LogisticsPatch public static void Start() { AutoConfigLogistics.Enable(AutoConfigLogisticsEnabled.Value); + AutoConfigLogisticsSetDefaultRemoteLogicToStorage.Enable(SetDefaultRemoteLogicToStorage.Value); LogisticsCapacityTweaks.Enable(LogisticsCapacityTweaksEnabled.Value); AllowOverflowInLogistics.Enable(AllowOverflowInLogisticsEnabled.Value); LogisticsConstrolPanelImprovement.Enable(LogisticsConstrolPanelImprovementEnabled.Value); @@ -80,6 +83,7 @@ public static class LogisticsPatch GameLogic.OnGameBegin -= RealtimeLogisticsInfoPanel.OnGameBegin; AutoConfigLogistics.Enable(false); + AutoConfigLogisticsSetDefaultRemoteLogicToStorage.Enable(false); LogisticsCapacityTweaks.Enable(false); AllowOverflowInLogistics.Enable(false); LogisticsConstrolPanelImprovement.Enable(false); @@ -275,6 +279,33 @@ public static class LogisticsPatch } } + public class AutoConfigLogisticsSetDefaultRemoteLogicToStorage : PatchImpl + { + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIControlPanelStationStorage), nameof(UIControlPanelStationStorage.OnItemPickerReturn))] + [HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.OnItemPickerReturn))] + private static IEnumerable UIStationStorage_OnItemPickerReturn_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(StationComponent), nameof(StationComponent.isStellar))), + new CodeMatch(ci => ci.opcode == OpCodes.Brtrue_S || ci.opcode == OpCodes.Brtrue), + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(ci => ci.opcode == OpCodes.Br_S || ci.opcode == OpCodes.Br), + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(GameMain), nameof(GameMain.mainPlayer))) + ); + if (matcher.IsValid) { + matcher.RemoveInstructions(7).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I4_0) + ); + } + return matcher.InstructionEnumeration(); + } + } + public class LogisticsCapacityTweaks : PatchImpl { private static KeyCode _lastKey = KeyCode.None; diff --git a/UXAssist/UI/MyWindow.cs b/UXAssist/UI/MyWindow.cs index 9b5cb71..c49e280 100644 --- a/UXAssist/UI/MyWindow.cs +++ b/UXAssist/UI/MyWindow.cs @@ -490,8 +490,8 @@ public class MyWindowWithTabs : MyWindow var textTrans = btn.transform.Find("Text"); var btnText = textTrans.GetComponent(); var shadow = textTrans.GetComponent() ?? textTrans.gameObject.AddComponent(); - shadow.effectColor = new Color(0f, 0f, 0f, 0.6f); - shadow.effectDistance = new Vector2(1f, -2f); + shadow.effectColor = new Color(0f, 0f, 0f, 0.4f); + shadow.effectDistance = new Vector2(1f, -1f); btnText.text = label.Translate(); btnText.fontSize = 16; btn.data = index; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index 0afc594..eff447c 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -87,6 +87,7 @@ public static class UIConfigWindow I18N.Add("PLS", "PLS", "行星物流站"); I18N.Add("ILS", "ILS", "星际物流站"); I18N.Add("Advanced Mining Machine", "Advanced Mining Machine", "大型采矿机"); + I18N.Add("Set default remote logic to storage", "Set default remote logic to storage", "设置默认远程逻辑为仓储"); I18N.Add("Max. Charging Power", "Max. Charging Power", "最大充能功率"); I18N.Add("Count of Bots filled", "Count of Bots filled", "填充的配送机数量"); I18N.Add("Drone transport range", "Drone transport range", "运输机最远路程"); @@ -557,9 +558,11 @@ public static class UIConfigWindow } y += 36f; wnd.AddCheckBox(x, y, tab3, LogisticsPatch.AutoConfigLogisticsEnabled, "Auto-config logistic stations"); - y += 24f; - wnd.AddCheckBox(10f, y, tab3, LogisticsPatch.AutoConfigLimitAutoReplenishCount, "Limit auto-replenish count to values below", 13).WithSmallerBox(); + y += 26f; + wnd.AddCheckBox(x + 10f, y, tab3, LogisticsPatch.AutoConfigLimitAutoReplenishCount, "Limit auto-replenish count to values below", 13).WithSmallerBox(); y += 18f; + wnd.AddCheckBox(x + 10f, y, tab3, LogisticsPatch.SetDefaultRemoteLogicToStorage, "Set default remote logic to storage", 13).WithSmallerBox(); + y += 16f; var maxWidth = 0f; wnd.AddText2(10f, y, tab3, "Dispenser", 14, "text-dispenser"); y += 18f; diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index d2a54ff..c315f5d 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -142,6 +142,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave "Auto-config logistic stations"); LogisticsPatch.AutoConfigLimitAutoReplenishCount = Config.Bind("Factory", "AutoConfigLimitAutoReplenishCount", false, "Limit auto-replenish count to config values"); + LogisticsPatch.SetDefaultRemoteLogicToStorage = Config.Bind("Factory", "AutoConfigSetDefaultRemoteLogicToStorage", false, + "Set default remote logic to storage"); LogisticsPatch.AutoConfigDispenserChargePower = Config.Bind("Factory", "AutoConfigDispenserChargePower", 30, new ConfigDescription("LD: Max. Charging Power", new AcceptableValueRange(3, 30))); LogisticsPatch.AutoConfigDispenserCourierCount = Config.Bind("Factory", "AutoConfigDispenserCourierCount", 10, new ConfigDescription("LD: Count of Bots filled", new AcceptableValueRange(0, 10))); LogisticsPatch.AutoConfigBattleBaseChargePower = Config.Bind("Factory", "AutoConfigBattleBaseChargePower", 8, new ConfigDescription("Battlefield Analysis Base: Max. Charging Power", new AcceptableValueRange(4, 40)));