From 5674d601ecdda50fbb204672917bc1f0bc7924b8 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 13 Apr 2025 20:05:20 +0800 Subject: [PATCH] WIP for UXAssist new features --- UXAssist/Common/KeyBindings.cs | 7 ++ UXAssist/Common/PatchImpl.cs | 12 +- UXAssist/Patches/FactoryPatch.cs | 144 ++++++++++++++++++------ UXAssist/Patches/PlayerPatch.cs | 45 +++++++- UXAssist/UI/MyWindow.cs | 12 +- UXAssist/UIConfigWindow.cs | 182 ++++++++++++++++++++----------- UXAssist/UXAssist.cs | 12 +- 7 files changed, 302 insertions(+), 112 deletions(-) diff --git a/UXAssist/Common/KeyBindings.cs b/UXAssist/Common/KeyBindings.cs index c505db1..a2322ad 100644 --- a/UXAssist/Common/KeyBindings.cs +++ b/UXAssist/Common/KeyBindings.cs @@ -29,4 +29,11 @@ public static class KeyBindings return new CombineKey((int)shortcut.MainKey, mod, ECombineKeyAction.OnceClick, false); } + + public static bool IsKeyPressing(this PressKeyBind keyBind) + { + var defBind = keyBind.defaultBind; + var overrideKey = VFInput.override_keys[defBind.id]; + return overrideKey.IsNull() ? defBind.key.GetKey() : overrideKey.GetKey(); + } } diff --git a/UXAssist/Common/PatchImpl.cs b/UXAssist/Common/PatchImpl.cs index 37c8601..63362ed 100644 --- a/UXAssist/Common/PatchImpl.cs +++ b/UXAssist/Common/PatchImpl.cs @@ -27,25 +27,27 @@ public class PatchSetCallbackFlagAttribute(PatchCallbackFlag flag) : Attribute public class PatchImpl where T : PatchImpl, new() { - private static T Instance { get; } = new(); - - private Harmony _patch; + protected static T Instance { get; } = new(); + + protected Harmony _patch; public static void Enable(bool enable) { var thisInstance = Instance; if (enable) { + if (thisInstance._patch != null) return; var guid = typeof(T).GetCustomAttribute()?.Guid ?? $"PatchImpl.{typeof(T).FullName ?? typeof(T).ToString()}"; var callOnEnableBefore = typeof(T).GetCustomAttributes().Any(n => n.Flag == PatchCallbackFlag.CallOnEnableBeforePatch); if (callOnEnableBefore) thisInstance.OnEnable(); - thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid); + thisInstance._patch = Harmony.CreateAndPatchAll(typeof(T), guid); if (!callOnEnableBefore) thisInstance.OnEnable(); return; } + if (thisInstance._patch == null) return; var callOnDisableAfter = typeof(T).GetCustomAttributes().Any(n => n.Flag == PatchCallbackFlag.CallOnDisableAfterUnpatch); if (!callOnDisableAfter) thisInstance.OnDisable(); - thisInstance._patch?.UnpatchSelf(); + thisInstance._patch.UnpatchSelf(); thisInstance._patch = null; if (callOnDisableAfter) thisInstance.OnDisable(); } diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index 8e38c41..4c1a9ea 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -34,6 +34,11 @@ public class FactoryPatch : PatchImpl public static ConfigEntry TankFastFillInAndTakeOutEnabled; public static ConfigEntry TankFastFillInAndTakeOutMultiplier; public static ConfigEntry CutConveyorBeltEnabled; + public static ConfigEntry TweakBuildingBufferEnabled; + public static ConfigEntry ReceiverBufferCount; + public static ConfigEntry AssemblerBufferTimeMultiplier; + public static ConfigEntry AssemblerBufferMininumMultiplier; + private static PressKeyBind _doNotRenderEntitiesKey; private static PressKeyBind _offgridfForPathsKey; private static PressKeyBind _cutConveyorBeltKey; @@ -43,30 +48,30 @@ public class FactoryPatch : PatchImpl public static void Init() { _doNotRenderEntitiesKey = KeyBindings.RegisterKeyBinding(new BuiltinKey - { - key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), - conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, - name = "ToggleDoNotRenderEntities", - canOverride = true - } + { + key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), + conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, + name = "ToggleDoNotRenderEntities", + canOverride = true + } ); I18N.Add("KEYToggleDoNotRenderEntities", "Toggle Do Not Render Factory Entities", "切换不渲染工厂建筑实体"); _offgridfForPathsKey = KeyBindings.RegisterKeyBinding(new BuiltinKey - { - key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), - conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.UI | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, - name = "OffgridForPaths", - canOverride = true - } + { + key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), + conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.UI | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, + name = "OffgridForPaths", + canOverride = true + } ); I18N.Add("KEYOffgridForPaths", "Build belts offgrid", "脱离网格建造传送带"); _cutConveyorBeltKey = KeyBindings.RegisterKeyBinding(new BuiltinKey - { - key = new CombineKey((int)KeyCode.X, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), - conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, - name = "CutConveyorBelt", - canOverride = true - } + { + key = new CombineKey((int)KeyCode.X, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, + name = "CutConveyorBelt", + canOverride = true + } ); I18N.Add("KEYCutConveyorBelt", "Cut conveyor belt", "切割传送带"); @@ -89,8 +94,12 @@ public class FactoryPatch : PatchImpl DragBuildPowerPolesAlternatelyEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.AlternatelyChanged(); BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value); TankFastFillInAndTakeOutEnabled.SettingChanged += (_, _) => TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value); - TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => { UpdateTankFastFillInAndTakeOutMultiplierRealValue(); }; + TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => UpdateTankFastFillInAndTakeOutMultiplierRealValue(); CutConveyorBeltEnabled.SettingChanged += (_, _) => CutConveyorBelt.Enable(CutConveyorBeltEnabled.Value); + TweakBuildingBufferEnabled.SettingChanged += (_, _) => TweakBuildingBuffer.Enable(TweakBuildingBufferEnabled.Value); + AssemblerBufferTimeMultiplier.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshAssemblerBufferMultipliers(); + AssemblerBufferMininumMultiplier.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshAssemblerBufferMultipliers(); + ReceiverBufferCount.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshReceiverBufferCount(); } public static void Start() @@ -110,6 +119,7 @@ public class FactoryPatch : PatchImpl BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value); TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value); CutConveyorBelt.Enable(CutConveyorBeltEnabled.Value); + TweakBuildingBuffer.Enable(TweakBuildingBufferEnabled.Value); Enable(true); UpdateTankFastFillInAndTakeOutMultiplierRealValue(); @@ -119,6 +129,7 @@ public class FactoryPatch : PatchImpl { Enable(false); + TweakBuildingBuffer.Enable(false); CutConveyorBelt.Enable(false); TankFastFillInAndTakeOut.Enable(false); BeltSignalsForBuyOut.Enable(false); @@ -234,7 +245,7 @@ public class FactoryPatch : PatchImpl _sail = null; _nightlightInitialized = false; } - + private static void GameMain_End_Postfix() { if (_sunlight) @@ -705,13 +716,6 @@ public class FactoryPatch : PatchImpl return matcher.InstructionEnumeration(); } - private static bool CheckOffgridForPathsKeyPressed() - { - ref var bind = ref _offgridfForPathsKey.defaultBind; - ref var key = ref VFInput.override_keys[bind.id]; - return key.IsNull() ? bind.key.GetKey() : key.GetKey(); - } - [HarmonyTranspiler] [HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.UpdateRaycast))] public static IEnumerable AllowOffGridConstructionForPath(IEnumerable instructions, ILGenerator generator) @@ -736,7 +740,8 @@ public class FactoryPatch : PatchImpl var jmp0 = generator.DefineLabel(); var jmp1 = generator.DefineLabel(); matcher.InsertAndAdvance( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(OffGridBuilding), nameof(CheckOffgridForPathsKeyPressed))), + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(_offgridfForPathsKey))), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), new CodeInstruction(OpCodes.Brfalse, jmp0), new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0), @@ -1963,12 +1968,10 @@ public class FactoryPatch : PatchImpl private class CutConveyorBelt : PatchImpl { - [HarmonyPostfix] [HarmonyPatch(typeof(PlayerController), nameof(PlayerController.GameTick))] private static void PlayerController_GameTick_Postfix(PlayerController __instance) { - if (DSPGame.IsMenuDemo) return; if (!_cutConveyorBeltKey.keyValue) return; var raycast = __instance.cmd.raycast; if (raycast == null) return; @@ -1979,4 +1982,83 @@ public class FactoryPatch : PatchImpl Functions.FactoryFunctions.CutConveyorBelt(cargoTraffic, beltId); } } -} \ No newline at end of file + + private class TweakBuildingBuffer : PatchImpl + { + public static void RefreshReceiverBufferCount() + { + if (!TweakBuildingBufferEnabled.Value) return; + /* re-patch to use new value */ + var patch = Instance._patch; + patch.Unpatch(AccessTools.Method(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma)), AccessTools.Method(typeof(TweakBuildingBuffer), nameof(PowerGeneratorComponent_GameTick_Gamma_Transpiler))); + patch.Patch(AccessTools.Method(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma)), null, null, new HarmonyMethod(typeof(TweakBuildingBuffer), nameof(PowerGeneratorComponent_GameTick_Gamma_Transpiler))); + } + + public static void RefreshAssemblerBufferMultipliers() + { + if (!TweakBuildingBufferEnabled.Value) return; + /* re-patch to use new value */ + var patch = Instance._patch; + patch.Unpatch(AccessTools.Method(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds)), AccessTools.Method(typeof(TweakBuildingBuffer), nameof(AssemblerComponent_UpdateNeeds_Transpiler))); + patch.Patch(AccessTools.Method(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds)), null, null, new HarmonyMethod(typeof(TweakBuildingBuffer), nameof(AssemblerComponent_UpdateNeeds_Transpiler))); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma))] + private static IEnumerable PowerGeneratorComponent_GameTick_Gamma_Transpiler(IEnumerable instructions, ILGenerator generator) + { + /* + * Patch: + * bool flag3 = keyFrame && useIon && (float)this.catalystPoint < 72000f; + * To: + * bool flag3 = keyFrame && useIon && this.catalystPoint < 3600 * ReceiverBufferCount.Value; + */ + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.catalystPoint))), + new CodeMatch(OpCodes.Conv_R4), + new CodeMatch(OpCodes.Ldc_R4, 72000f), + new CodeMatch(OpCodes.Clt) + ); + matcher.Advance(2).RemoveInstructions(2).Insert(new CodeInstruction(OpCodes.Ldc_I4, ReceiverBufferCount.Value * 3600)); + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds))] + private static IEnumerable AssemblerComponent_UpdateNeeds_Transpiler(IEnumerable instructions, ILGenerator generator) + { + /* + * Patch: + * int num2 = this.speedOverride * 180 / this.timeSpend + 1; + * if (num2 < 2) + * { + * num2 = 2; + * } + * To: + * int num2 = this.speedOverride * 60 * (AssemblerBufferTimeMultiplier.Value - 1) * 60 / this.timeSpend + 1; + * if (num2 < AssemblerBufferMininumMultiplier.Value) + * { + * num2 = AssemblerBufferMininumMultiplier.Value; + * } + */ + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(AssemblerComponent), nameof(AssemblerComponent.speedOverride))), + new CodeMatch(OpCodes.Ldc_I4, 180), + new CodeMatch(OpCodes.Mul) + ); + matcher.Advance(2).Operand = (AssemblerBufferTimeMultiplier.Value - 1) * 60; + matcher.Advance(2).MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_2), + new CodeMatch(ci => ci.opcode == OpCodes.Bge_S || ci.opcode == OpCodes.Bge), + new CodeMatch(OpCodes.Ldc_I4_2) + ); + matcher.Operand = AssemblerBufferMininumMultiplier.Value; + matcher.Advance(2).Operand = AssemblerBufferMininumMultiplier.Value; + return matcher.InstructionEnumeration(); + } + } +} diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index 61de7bf..79d2d21 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -8,7 +8,7 @@ using UXAssist.Common; namespace UXAssist.Patches; -public static class PlayerPatch +public class PlayerPatch: PatchImpl { public static ConfigEntry EnhancedMechaForgeCountControlEnabled; public static ConfigEntry HideTipsForSandsChangesEnabled; @@ -17,7 +17,8 @@ public static class PlayerPatch public static ConfigEntry AutoBoostEnabled; public static ConfigEntry DistanceToWarp; private static PressKeyBind _autoDriveKey; - + private static PressKeyBind _showAllAstrosNameKey; + public static void Init() { _autoDriveKey = KeyBindings.RegisterKeyBinding(new BuiltinKey @@ -27,8 +28,20 @@ public static class PlayerPatch name = "ToggleAutoCruise", canOverride = true }); + I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航"); I18N.Add("AutoCruiseOn", "Auto-cruise enabled", "已启用自动巡航"); I18N.Add("AutoCruiseOff", "Auto-cruise disabled", "已禁用自动巡航"); + + _showAllAstrosNameKey = KeyBindings.RegisterKeyBinding(new BuiltinKey + { + key = new CombineKey(0, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND, + name = "ShowAllAstrosName", + canOverride = true + } + ); + I18N.Add("KEYShowAllAstrosName", "Keep pressing to show all astros' name", "按住显示所有星球名称"); + EnhancedMechaForgeCountControlEnabled.SettingChanged += (_, _) => EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value); HideTipsForSandsChangesEnabled.SettingChanged += (_, _) => HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value); AutoNavigationEnabled.SettingChanged += (_, _) => AutoNavigation.Enable(AutoNavigationEnabled.Value); @@ -39,6 +52,7 @@ public static class PlayerPatch EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value); HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value); AutoNavigation.Enable(AutoNavigationEnabled.Value); + Enable(true); } public static void OnUpdate() @@ -48,14 +62,35 @@ public static class PlayerPatch AutoNavigation.ToggleAutoCruise(); } } - + public static void Uninit() { + Enable(false); EnhancedMechaForgeCountControl.Enable(false); HideTipsForSandsChanges.Enable(false); AutoNavigation.Enable(false); } + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIStarmapStar), nameof(UIStarmapStar._OnLateUpdate))] + private static IEnumerable UIStarmapStar__OnLateUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + Label? br = null; + matcher.MatchForward(false, + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapStar), nameof(UIStarmapStar.projectedCoord))), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(ci => ci.Branches(out br)) + ); + matcher.Advance(3); + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllAstrosNameKey))), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), + new CodeInstruction(OpCodes.Brtrue, br.Value) + ); + return matcher.InstructionEnumeration(); + } + private class EnhancedMechaForgeCountControl: PatchImpl { [HarmonyTranspiler] @@ -319,7 +354,7 @@ public static class PlayerPatch ); return matcher.InstructionEnumeration(); } - + [HarmonyTranspiler] [HarmonyPatch(typeof(VFInput), nameof(VFInput._sailSpeedUp), MethodType.Getter)] private static IEnumerable VFInput_sailSpeedUp_Transpiler(IEnumerable instructions, ILGenerator generator) @@ -335,7 +370,7 @@ public static class PlayerPatch return matcher.InstructionEnumeration(); } - /* Disable Lock Cursor Mode on entering sail panel + /* Disable Lock Cursor Mode on entering sail panel [HarmonyPrefix] [HarmonyPatch(typeof(UISailPanel), nameof(UISailPanel._OnOpen))] public static void OnOpen_Prefix() diff --git a/UXAssist/UI/MyWindow.cs b/UXAssist/UI/MyWindow.cs index 3b785db..5b8059a 100644 --- a/UXAssist/UI/MyWindow.cs +++ b/UXAssist/UI/MyWindow.cs @@ -42,7 +42,7 @@ public class MyWindow : ManualBehaviour _baseObject = go; } - + public static T Create(string name, string title = "") where T : MyWindow { var go = Instantiate(_baseObject, UIRoot.instance.uiGame.transform.parent); @@ -236,7 +236,7 @@ public class MyWindow : ManualBehaviour MaxY = Math.Max(MaxY, y + cb.Height); return cb; } - + public MyComboBox AddComboBox(float x, float y, RectTransform parent, string label = "", int fontSize = 15) { var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithPrompt(label).WithFontSize(fontSize); @@ -271,6 +271,12 @@ public class MyWindow : ManualBehaviour } } + public class RangeValueMapper(int min, int max) : ValueMapper + { + public override int Min => min; + public override int Max => max; + } + public MySlider AddSlider(float x, float y, RectTransform parent, ConfigEntry config, ValueMapper valueMapper, string format = "G", float width = 0f) { var slider = MySlider.CreateSlider(x, y, parent, OnConfigValueChanged(config), valueMapper.Min, valueMapper.Max, format, width); @@ -362,7 +368,7 @@ public class MyWindow : ManualBehaviour MaxY = Math.Max(MaxY, y + rect.sizeDelta.y); return inputField; } - + public InputField AddInputField(float x, float y, float width, RectTransform parent, ConfigEntry config, int fontSize = 16, string objName = "input") { var stationWindow = UIRoot.instance.uiGame.stationWindow; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index 1a15aae..31a2088 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -89,6 +89,10 @@ public static class UIConfigWindow "打开面板时自动将鼠标指向物品设为筛选条件\n在控制面板物流塔列表中右键点击物品图标快速设置为筛选条件"); I18N.Add("Real-time logistic stations info panel", "Real-time logistic stations info panel", "物流运输站实时信息面板"); I18N.Add("Show status bars for storage items", "Show status bars for storage items", "显示存储物品状态条"); + I18N.Add("Tweak building buffers", "Tweak building buffers", "调整建筑输入缓冲"); + I18N.Add("Assembler buffer time multiplier(in seconds)", "Assembler buffer time multiplier(in seconds)", "工厂配方缓冲时间倍率(秒)"); + I18N.Add("Assembler buffer minimum multiplier", "Assembler buffer minimum multiplier", "工厂配方缓冲最小倍率"); + I18N.Add("Ray Receiver Graviton Lens buffer count", "Ray Receiver Graviton Lens buffer count", "射线接收器透镜缓冲数量"); I18N.Add("Auto navigation on sailings", "Auto navigation on sailings", "宇宙航行时自动导航"); I18N.Add("Enable auto-cruise", "Enable auto-cruise", "启用自动巡航"); I18N.Add("Auto boost", "Auto boost", "自动加速"); @@ -251,32 +255,43 @@ public static class UIConfigWindow checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryPatch.TreatStackingAsSingleEnabled, "Treat stack items as single in monitor components"); y += 36f; wnd.AddCheckBox(x, y, tab2, FactoryPatch.QuickBuildAndDismantleLabsEnabled, "Quick build and dismantle stacking labs"); - y += 36f; - var cb = wnd.AddCheckBox(x, y, tab2, FactoryPatch.TankFastFillInAndTakeOutEnabled, "Fast fill in to and take out from tanks"); - x += cb.Width + 5f; - txt = wnd.AddText2(x, y + 2f, tab2, "Speed Ratio", 13, "text-tank-fast-fill-speed-ratio"); - var tankSlider = wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryPatch.TankFastFillInAndTakeOutMultiplier, [2, 5, 10, 20, 50, 100, 500, 1000], "G", 100f).WithSmallerHandle(); - EventHandler tankSettingChanged = (_, _) => + { - tankSlider.SetEnable(FactoryPatch.TankFastFillInAndTakeOutEnabled.Value); - }; - FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged += tankSettingChanged; - wnd.OnFree += () => { FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged -= tankSettingChanged; }; - tankSettingChanged(null, null); - - x = 0; + y += 36f; + wnd.AddCheckBox(x, y, tab2, FactoryPatch.DragBuildPowerPolesEnabled, "Drag building power poles in maximum connection range"); + y += 30f; + var alternatelyCheckBox = wnd.AddCheckBox(x + 20f, y, tab2, FactoryPatch.DragBuildPowerPolesAlternatelyEnabled, "Build Tesla Tower and Wireless Power Tower alternately", 13); + FactoryPatch.DragBuildPowerPolesEnabled.SettingChanged += AlternatelyCheckBoxChanged; + wnd.OnFree += () => { FactoryPatch.DragBuildPowerPolesEnabled.SettingChanged -= AlternatelyCheckBoxChanged; }; + AlternatelyCheckBoxChanged(null, null); + + void AlternatelyCheckBoxChanged(object o, EventArgs e) + { + alternatelyCheckBox.SetEnable(FactoryPatch.DragBuildPowerPolesEnabled.Value); + } + } + y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryPatch.ProtectVeinsFromExhaustionEnabled, "Protect veins from exhaustion"); wnd.AddTipsButton2(x + checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab2, "Protect veins from exhaustion", "Protect veins from exhaustion tips", "protect-veins-tips"); - y += 36f; - wnd.AddCheckBox(x, y, tab2, FactoryPatch.DragBuildPowerPolesEnabled, "Drag building power poles in maximum connection range"); - y += 36f; - var alternatelyCheckBox = wnd.AddCheckBox(x + 20f, y, tab2, FactoryPatch.DragBuildPowerPolesAlternatelyEnabled, "Build Tesla Tower and Wireless Power Tower alternately", 13); - EventHandler alternatelyCheckBoxChanged = (_, _) => { alternatelyCheckBox.SetEnable(FactoryPatch.DragBuildPowerPolesEnabled.Value); }; - FactoryPatch.DragBuildPowerPolesEnabled.SettingChanged += alternatelyCheckBoxChanged; - wnd.OnFree += () => { FactoryPatch.DragBuildPowerPolesEnabled.SettingChanged -= alternatelyCheckBoxChanged; }; - alternatelyCheckBoxChanged(null, null); + { + y += 36f; + var cb = wnd.AddCheckBox(x, y, tab2, FactoryPatch.TankFastFillInAndTakeOutEnabled, "Fast fill in to and take out from tanks"); + x += cb.Width + 5f; + txt = wnd.AddText2(x, y + 2f, tab2, "Speed Ratio", 13, "text-tank-fast-fill-speed-ratio"); + var tankSlider = wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryPatch.TankFastFillInAndTakeOutMultiplier, [2, 5, 10, 20, 50, 100, 500, 1000], "G", 100f).WithSmallerHandle(); + FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged += TankSettingChanged; + wnd.OnFree += () => { FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged -= TankSettingChanged; }; + TankSettingChanged(null, null); + + void TankSettingChanged(object o, EventArgs e) + { + tankSlider.SetEnable(FactoryPatch.TankFastFillInAndTakeOutEnabled.Value); + } + } + + x = 0; y += 36f; wnd.AddCheckBox(x, y, tab2, FactoryPatch.DoNotRenderEntitiesEnabled, "Do not render factory entities"); y += 36f; @@ -307,35 +322,70 @@ public static class UIConfigWindow y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, LogisticsPatch.LogisticsConstrolPanelImprovementEnabled, "Logistics Control Panel Improvement"); wnd.AddTipsButton2(x + checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab2, "Logistics Control Panel Improvement", "Logistics Control Panel Improvement tips", "lcp-improvement-tips"); - y += 36f; - var cb0 = wnd.AddCheckBox(x, y, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelEnabled, "Real-time logistic stations info panel"); - y += 36f; - var cb1 = wnd.AddCheckBox(x + 20f, y, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelBarsEnabled, "Show status bars for storage items", 13); - EventHandler anySettingsChanged = (_, _) => - { - if (AuxilaryfunctionWrapper.ShowStationInfo == null) - { - cb0.SetEnable(true); - cb1.SetEnable(LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value); - return; - } - var on = !AuxilaryfunctionWrapper.ShowStationInfo.Value; - cb0.SetEnable(on); - cb1.SetEnable(on & LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value); - if (!on) - { - LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value = false; - } - }; - if (AuxilaryfunctionWrapper.ShowStationInfo != null) { - AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged += anySettingsChanged; - wnd.OnFree += () => { AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged -= anySettingsChanged; }; + y += 36f; + var realtimeLogisticsInfoPanelCheckBox = wnd.AddCheckBox(x, y, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelEnabled, "Real-time logistic stations info panel"); + y += 30f; + var realtimeLogisticsInfoPanelBarsCheckBox = wnd.AddCheckBox(x + 20f, y, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelBarsEnabled, "Show status bars for storage items", 13); + if (AuxilaryfunctionWrapper.ShowStationInfo != null) + { + AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged += RealtimeLogisticsInfoPanelChanged; + wnd.OnFree += () => { AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged -= RealtimeLogisticsInfoPanelChanged; }; + } + LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.SettingChanged += RealtimeLogisticsInfoPanelChanged; + wnd.OnFree += () => { LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.SettingChanged -= RealtimeLogisticsInfoPanelChanged; }; + RealtimeLogisticsInfoPanelChanged(null, null); + + void RealtimeLogisticsInfoPanelChanged(object o, EventArgs e) + { + if (AuxilaryfunctionWrapper.ShowStationInfo == null) + { + realtimeLogisticsInfoPanelCheckBox.SetEnable(true); + realtimeLogisticsInfoPanelBarsCheckBox.SetEnable(LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value); + return; + } + + var on = !AuxilaryfunctionWrapper.ShowStationInfo.Value; + realtimeLogisticsInfoPanelCheckBox.SetEnable(on); + realtimeLogisticsInfoPanelBarsCheckBox.SetEnable(on & LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value); + if (!on) + { + LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value = false; + } + } + } + + { + y += 36f; + wnd.AddCheckBox(x, y, tab2, FactoryPatch.TweakBuildingBufferEnabled, "Tweak building buffers"); + y += 30f; + txt = wnd.AddText2(x + 20f, y, tab2, "Assembler buffer time multiplier(in seconds)", 13); + var nx1 = txt.preferredWidth + 5f; + y += 30f; + txt = wnd.AddText2(x + 20f, y, tab2, "Assembler buffer minimum multiplier", 13); + var nx2 = txt.preferredWidth + 5f; + y += 30f; + txt = wnd.AddText2(x + 20f, y, tab2, "Ray Receiver Graviton Lens buffer count", 13); + var nx3 = txt.preferredWidth + 5f; + y -= 60f; + var mx = Mathf.Max(nx1, nx2, nx3) + 20f; + var assemblerBufferTimeMultiplierSlider = wnd.AddSlider(x + mx, y + 5f, tab2, FactoryPatch.AssemblerBufferTimeMultiplier, new MyWindow.RangeValueMapper(2, 10), "0", 80f).WithSmallerHandle(); + y += 30f; + var assemblerBufferMininumMultiplierSlider = wnd.AddSlider(x + mx, y + 5f, tab2, FactoryPatch.AssemblerBufferMininumMultiplier, new MyWindow.RangeValueMapper(2, 10), "0", 80f).WithSmallerHandle(); + y += 30f; + var receiverBufferCountSlider = wnd.AddSlider(x + mx, y + 5f, tab2, FactoryPatch.ReceiverBufferCount, new MyWindow.RangeValueMapper(1, 20), "0", 80f).WithSmallerHandle(); + FactoryPatch.TweakBuildingBufferEnabled.SettingChanged += TweakBuildingBufferChanged; + wnd.OnFree += () => { FactoryPatch.TweakBuildingBufferEnabled.SettingChanged -= TweakBuildingBufferChanged; }; + TweakBuildingBufferChanged(null, null); + + void TweakBuildingBufferChanged(object o, EventArgs e) + { + assemblerBufferTimeMultiplierSlider.SetEnable(FactoryPatch.TweakBuildingBufferEnabled.Value); + assemblerBufferMininumMultiplierSlider.SetEnable(FactoryPatch.TweakBuildingBufferEnabled.Value); + receiverBufferCountSlider.SetEnable(FactoryPatch.TweakBuildingBufferEnabled.Value); + } } - LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.SettingChanged += anySettingsChanged; - wnd.OnFree += () => { LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.SettingChanged -= anySettingsChanged; }; - anySettingsChanged(null, null); var tab3 = wnd.AddTab(trans, "Player/Mecha"); x = 0f; @@ -348,24 +398,28 @@ public static class UIConfigWindow y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab3, PlayerPatch.EnhancedMechaForgeCountControlEnabled, "Enhanced count control for hand-make"); wnd.AddTipsButton2(x + checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab3, "Enhanced count control for hand-make", "Enhanced count control for hand-make tips", "enhanced-count-control-tips"); - y += 36f; - wnd.AddCheckBox(x, y, tab3, PlayerPatch.AutoNavigationEnabled, "Auto navigation on sailings"); - y += 26f; - var navcb1 = wnd.AddCheckBox(x + 20f, y, tab3, PlayerPatch.AutoCruiseEnabled, "Enable auto-cruise", 13); - y += 26f; - var navcb2 = wnd.AddCheckBox(x + 20f, y, tab3, PlayerPatch.AutoBoostEnabled, "Auto boost", 13); - y += 32f; - txt = wnd.AddText2(x + 20f, y, tab3, "Distance to use warp", 15, "text-distance-to-warp"); - var navSlider = wnd.AddSlider(x + 20f + txt.preferredWidth + 5f, y + 6f, tab3, PlayerPatch.DistanceToWarp, new DistanceMapper(), "0.0", 100f); - EventHandler navSettingChanged = (_, _) => + { - navcb1.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); - navcb2.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); - navSlider.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); - }; - PlayerPatch.AutoNavigationEnabled.SettingChanged += navSettingChanged; - wnd.OnFree += () => { PlayerPatch.AutoNavigationEnabled.SettingChanged -= navSettingChanged; }; - navSettingChanged(null, null); + y += 36f; + wnd.AddCheckBox(x, y, tab3, PlayerPatch.AutoNavigationEnabled, "Auto navigation on sailings"); + y += 26f; + var autoCruiseCheckBox = wnd.AddCheckBox(x + 20f, y, tab3, PlayerPatch.AutoCruiseEnabled, "Enable auto-cruise", 13); + y += 26f; + var autoBoostCheckBox = wnd.AddCheckBox(x + 20f, y, tab3, PlayerPatch.AutoBoostEnabled, "Auto boost", 13); + y += 32f; + txt = wnd.AddText2(x + 20f, y, tab3, "Distance to use warp", 15, "text-distance-to-warp"); + var navDistanceSlider = wnd.AddSlider(x + 20f + txt.preferredWidth + 5f, y + 6f, tab3, PlayerPatch.DistanceToWarp, new DistanceMapper(), "0.0", 100f); + PlayerPatch.AutoNavigationEnabled.SettingChanged += NavSettingChanged; + wnd.OnFree += () => { PlayerPatch.AutoNavigationEnabled.SettingChanged -= NavSettingChanged; }; + NavSettingChanged(null, null); + + void NavSettingChanged(object o, EventArgs e) + { + autoCruiseCheckBox.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); + autoBoostCheckBox.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); + navDistanceSlider.SetEnable(PlayerPatch.AutoNavigationEnabled.Value); + } + } var tab4 = wnd.AddTab(trans, "Dyson Sphere"); x = 0f; diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index f6d9fc0..fa0846a 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -138,6 +138,11 @@ public class UXAssist : BaseUnityPlugin, IModCanSave FactoryPatch.TankFastFillInAndTakeOutMultiplier = Config.Bind("Factory", "TankFastFillInAndTakeOutMultiplier", 1000, "Speed multiplier for fast filling in to and takeing out from tanks"); FactoryPatch.CutConveyorBeltEnabled = Config.Bind("Factory", "CutConveyorBeltShortcut", false, "Cut conveyor belt (with shortcut key)"); + FactoryPatch.TweakBuildingBufferEnabled = Config.Bind("Factory", "TweakBuildingBuffer", false, + "Tweak buffer count for assemblers and power generators"); + FactoryPatch.AssemblerBufferTimeMultiplier = Config.Bind("Factory", "AssemblerBufferTimeMultiplier", 4, new ConfigDescription("Assembler buffer time multiplier in seconds", new AcceptableValueRange(2, 10))); + FactoryPatch.AssemblerBufferMininumMultiplier = Config.Bind("Factory", "AssemblerBufferMininumMultiplier", 4, new ConfigDescription("Assembler buffer minimum multiplier", new AcceptableValueRange(2, 10))); + FactoryPatch.ReceiverBufferCount = Config.Bind("Factory", "ReceiverBufferCount", 1, new ConfigDescription("Ray Receiver Graviton Lens buffer count", new AcceptableValueRange(1, 20))); LogisticsPatch.LogisticsCapacityTweaksEnabled = Config.Bind("Factory", "LogisticsCapacityTweaks", true, "Logistics capacity related tweaks"); LogisticsPatch.AllowOverflowInLogisticsEnabled = Config.Bind("Factory", "AllowOverflowInLogistics", false, @@ -169,15 +174,14 @@ 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"); - + I18N.Init(); I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置"); I18N.Add("KEYOpenUXAssistConfigWindow", "Open UXAssist Config Window", "打开UX助手设置面板"); - I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航"); // UI Patches GameLogic.Enable(true); - + UIConfigWindow.Init(); _patches = Util.GetTypesFiltered(Assembly.GetExecutingAssembly(), @@ -334,7 +338,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave { InitMenuButtons(); } - + [HarmonyPostfix] [HarmonyPatch(typeof(UIPlanetGlobe), nameof(UIPlanetGlobe.DistributeButtons))] private static void UIPlanetGlobe_DistributeButtons_Postfix(UIPlanetGlobe __instance)