diff --git a/UXAssist/CHANGELOG.md b/UXAssist/CHANGELOG.md index 051f08d..c00a6f6 100644 --- a/UXAssist/CHANGELOG.md +++ b/UXAssist/CHANGELOG.md @@ -4,6 +4,7 @@ ## Changlog * 1.6.4 + * `Reverse conveyor belt`: Enable it on the Factory tab and press `Alt+R` over a built belt to reverse it without opening its panel. The shortcut can be changed in the system options. * `Hide battle-related techs in Peace mode`: Fix an array index error when opening the tech tree after switching from a Peace-mode save to a Combat-mode save in the same game process, including when disabling the option after loading another Peace-mode save. * `Auto-cruise`: Fix the mecha diving back into the ground right after taking off from a moon that is close to its gas giant. * 1.6.3 @@ -448,6 +449,7 @@ ## 更新日志 * 1.6.4 + * `反转传送带`:在「工厂」页启用后,将鼠标移到已建成的传送带上,按 `Alt+R` 直接反转,无需打开面板;可在系统选项中修改快捷键。 * `在和平模式下隐藏战斗相关科技`:修复在同一次游戏运行中从和平模式存档切换到战斗模式存档后打开科技树时的数组越界,以及再次加载和平模式存档后关闭选项时的同类问题。 * `自动巡航`:修复从紧邻气态巨星的卫星上起飞后,机甲又扎回地面的问题。 * 1.6.3 diff --git a/UXAssist/Common/Config/FactoryConfigProvider.cs b/UXAssist/Common/Config/FactoryConfigProvider.cs index bf0fb10..0603b0a 100644 --- a/UXAssist/Common/Config/FactoryConfigProvider.cs +++ b/UXAssist/Common/Config/FactoryConfigProvider.cs @@ -26,6 +26,7 @@ public static class FactoryConfigProvider public static ConfigEntry TankFastFillInAndTakeOutEnabled => FactoryPatch.TankFastFillInAndTakeOutEnabled; public static ConfigEntry TankFastFillInAndTakeOutMultiplier => FactoryPatch.TankFastFillInAndTakeOutMultiplier; public static ConfigEntry CutConveyorBeltEnabled => FactoryPatch.CutConveyorBeltEnabled; + public static ConfigEntry ReverseConveyorBeltEnabled => FactoryPatch.ReverseConveyorBeltEnabled; public static ConfigEntry TweakBuildingBufferEnabled => FactoryPatch.TweakBuildingBufferEnabled; public static ConfigEntry AssemblerBufferTimeMultiplier => FactoryPatch.AssemblerBufferTimeMultiplier; public static ConfigEntry AssemblerBufferMininumMultiplier => FactoryPatch.AssemblerBufferMininumMultiplier; diff --git a/UXAssist/Common/I18NKeys.cs b/UXAssist/Common/I18NKeys.cs index a7fe8a8..54b9f5b 100644 --- a/UXAssist/Common/I18NKeys.cs +++ b/UXAssist/Common/I18NKeys.cs @@ -60,6 +60,7 @@ public static class I18NKeys public const string KEYToggleDoNotRenderEntities = "KEYToggleDoNotRenderEntities"; public const string KEYOffgridForPaths = "KEYOffgridForPaths"; public const string KEYCutConveyorBelt = "KEYCutConveyorBelt"; + public const string KEYReverseConveyorBelt = "KEYReverseConveyorBelt"; public const string KEYDismantleBlueprintSelection = "KEYDismantleBlueprintSelection"; public const string KEYSelectAllBuildingsInBlueprintCopy = "KEYSelectAllBuildingsInBlueprintCopy"; public const string KEYUPSSpeedDown = "KEYUPSSpeedDown"; @@ -111,6 +112,7 @@ public static class I18NKeys public const string FastFillInToAndTakeOutFromTanks = "Fast fill in to and take out from tanks"; public const string SpeedRatio = "Speed Ratio"; public const string CutConveyorBeltWithShortcutKey = "Cut conveyor belt (with shortcut key)"; + public const string ReverseConveyorBeltWithShortcutKey = "Reverse conveyor belt (with shortcut key)"; public const string ProtectVeinsFromExhaustion = "Protect veins from exhaustion"; public const string ProtectVeinsFromExhaustionTips = "Protect veins from exhaustion tips"; public const string DoNotRenderFactoryEntities = "Do not render factory entities"; @@ -301,6 +303,7 @@ public static class I18NKeys I18N.Add(KEYToggleDoNotRenderEntities, "[UXA] Toggle Do Not Render Factory Entities", "[UXA] 切换不渲染工厂建筑实体"); I18N.Add(KEYOffgridForPaths, "[UXA] Build belts offgrid", "[UXA] 脱离网格建造传送带"); I18N.Add(KEYCutConveyorBelt, "[UXA] Cut conveyor belt", "[UXA] 切割传送带"); + I18N.Add(KEYReverseConveyorBelt, "[UXA] Reverse conveyor belt", "[UXA] 反转传送带"); I18N.Add(KEYDismantleBlueprintSelection, "[UXA] Dismantle blueprint selected buildings", "[UXA] 拆除蓝图选中的建筑"); I18N.Add(KEYSelectAllBuildingsInBlueprintCopy, "[UXA] Select all buildings in Blueprint Copy Mode", "[UXA] 蓝图复制时选择所有建筑"); I18N.Add(KEYUPSSpeedDown, "[UXA] Decrease logical frame rate", "[UXA] 降低逻辑帧率"); @@ -370,6 +373,7 @@ Hold Ctrl/Shift/Alt to change the count rapidly. I18N.Add(FastFillInToAndTakeOutFromTanks, "Fast fill in to and take out from tanks", "储液罐快速注入和抽取液体"); I18N.Add(SpeedRatio, "Speed Ratio", "速度倍率"); I18N.Add(CutConveyorBeltWithShortcutKey, "Cut conveyor belt (with shortcut key)", "切割传送带(使用快捷键)"); + I18N.Add(ReverseConveyorBeltWithShortcutKey, "Reverse conveyor belt (with shortcut key)", "反转传送带(使用快捷键)"); I18N.Add(ProtectVeinsFromExhaustion, "Protect veins from exhaustion", "保护矿脉不会耗尽"); I18N.Add(ProtectVeinsFromExhaustionTips, """ By default, the vein amount is protected at 100, and oil speed is protected at 1.0/s, you can set them yourself in config file. diff --git a/UXAssist/Functions/FactoryFunctions.cs b/UXAssist/Functions/FactoryFunctions.cs index 8d2c960..20a0fe3 100644 --- a/UXAssist/Functions/FactoryFunctions.cs +++ b/UXAssist/Functions/FactoryFunctions.cs @@ -24,6 +24,43 @@ public static class FactoryFunctions cargoTraffic.AlterBeltConnections(beltId, 0, i0, i1, i2); } + public static void ReverseConveyorBelt(PlanetFactory factory, int beltId) + { + var traffic = factory?.cargoTraffic; + var player = GameMain.mainPlayer; + var window = UIRoot.instance?.uiGame?.beltWindow; + if (traffic == null || player == null || window == null || beltId <= 0 || beltId >= traffic.beltPool.Length) return; + + ref var belt = ref traffic.beltPool[beltId]; + if (belt.id != beltId) return; + var path = traffic.GetCargoPath(belt.segPathId); + // Match the native reverse button's limit of 2 to 1023 belts in one path. + const int maxBeltCount = 1023; + if (path == null || path.belts.Count < 2 || path.belts.Count > maxBeltCount) return; + + var oldFactory = window.factory; + var oldTraffic = window.traffic; + var oldPlayer = window.player; + var oldBeltId = window._beltId; + try + { + window.factory = factory; + window.traffic = traffic; + window.player = player; + // The beltId setter refreshes the visible inspector, so bind the backing field directly. + window._beltId = beltId; + // Nebula intercepts this native entry point to synchronize reversals. + window.OnReverseButtonClick(0); + } + finally + { + window._beltId = oldBeltId; + window.factory = oldFactory; + window.traffic = oldTraffic; + window.player = oldPlayer; + } + } + public static bool ObjectIsBeltOrInserter(PlanetFactory factory, int objId) { if (objId == 0) return false; diff --git a/UXAssist/Patches/Factory/FactoryPatch.cs b/UXAssist/Patches/Factory/FactoryPatch.cs index 314483e..0e6dc58 100644 --- a/UXAssist/Patches/Factory/FactoryPatch.cs +++ b/UXAssist/Patches/Factory/FactoryPatch.cs @@ -39,6 +39,7 @@ public static class FactoryPatch public static ConfigEntry TankFastFillInAndTakeOutEnabled; public static ConfigEntry TankFastFillInAndTakeOutMultiplier; public static ConfigEntry CutConveyorBeltEnabled; + public static ConfigEntry ReverseConveyorBeltEnabled; public static ConfigEntry TweakBuildingBufferEnabled; public static ConfigEntry AssemblerBufferTimeMultiplier; public static ConfigEntry AssemblerBufferMininumMultiplier; @@ -56,6 +57,7 @@ public static class FactoryPatch internal static PressKeyBind _doNotRenderEntitiesKey; internal static PressKeyBind _offgridfForPathsKey; internal static PressKeyBind _cutConveyorBeltKey; + internal static PressKeyBind _reverseConveyorBeltKey; internal static PressKeyBind _dismantleBlueprintSelectionKey; internal static PressKeyBind _selectAllBuildingsInBlueprintCopyKey; @@ -86,6 +88,14 @@ public static class FactoryPatch name = "CutConveyorBelt", canOverride = true } + ); + _reverseConveyorBeltKey = KeyBindings.RegisterKeyBinding(new BuiltinKey + { + key = new CombineKey((int)KeyCode.R, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, + name = "ReverseConveyorBelt", + canOverride = true + } ); _dismantleBlueprintSelectionKey = KeyBindings.RegisterKeyBinding(new BuiltinKey { @@ -215,6 +225,13 @@ public static class FactoryPatch Functions.FactoryFunctions.CutConveyorBelt(cargoTraffic, beltId); } } + if (ReverseConveyorBeltEnabled.Value && _reverseConveyorBeltKey.keyValue + && GameMain.isRunning && !GameMain.isPaused && !VFInput.onGUI) + { + var raycast = GameMain.mainPlayer?.controller?.cmd.raycast; + if (raycast != null && raycast.castEntity.id > 0 && raycast.castEntity.beltId > 0) + Functions.FactoryFunctions.ReverseConveyorBelt(raycast.planet?.factory, raycast.castEntity.beltId); + } if (ShortcutKeysForBlueprintCopyEnabled.Value) { if (_dismantleBlueprintSelectionKey.keyValue) diff --git a/UXAssist/README.md b/UXAssist/README.md index 5e7397f..378fba4 100644 --- a/UXAssist/README.md +++ b/UXAssist/README.md @@ -60,6 +60,9 @@ * Cut conveyor belt * Press shortcut key to cut conveyor belt under cursor. * The default shortcut key is Alt+X, you can set it in system options panel. + * Reverse conveyor belt + * Enable it on the Factory tab, hover over a built belt, and press `Alt+R` to reverse it without opening its panel. + * Change the shortcut in the system options. Reversal follows the native button's scope and limits. * Treat stack items as single in monitor components * Quick build and dismantle stacking labs/storages/tanks * Fast fill in to and take out from tanks @@ -268,6 +271,9 @@ * 切割传送带 * 按快捷键切割光标位置的传送带 * 默认快捷键是Alt+X,可以在系统选项面板中设置 + * 反转传送带 + * 在「工厂」页启用后,将鼠标移到已建成的传送带上,按 `Alt+R` 直接反转,无需打开面板。 + * 可在系统选项中修改快捷键,反转范围和限制与原版按钮一致。 * 在流速计中将堆叠物品视为单个物品 * 快速建造和拆除堆叠研究站/储物仓/储液罐 * 储液罐快速注入和抽取液体 diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index d9b519c..bdf705b 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -245,6 +245,8 @@ public static class UIConfigWindow y += 36f; wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.CutConveyorBeltEnabled, I18NKeys.CutConveyorBeltWithShortcutKey); y += 36f; + wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.ReverseConveyorBeltEnabled, I18NKeys.ReverseConveyorBeltWithShortcutKey); + y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.TreatStackingAsSingleEnabled, I18NKeys.TreatStackItemsAsSingleInMonitorComponents); y += 36f; wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.QuickBuildAndDismantleLabsEnabled, I18NKeys.QuickBuildAndDismantleStackingLabs); diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index bd6fbae..05d8d89 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -149,6 +149,8 @@ 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.ReverseConveyorBeltEnabled = Config.Bind("Factory", "ReverseConveyorBeltShortcut", false, + "Reverse 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)));