From ededc3eeaf522bcab5d6a660adf7b12d37cdd8bd Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 11 Oct 2026 04:00:56 +0800 Subject: [PATCH] fix(uxassist): initialize alternating poles when enabling dragging Initialize Tesla Tower previews on late enable, retry after data loading, and capture original pole prototypes only once for reliable restoration. Refs #51 --- UXAssist/CHANGELOG.md | 2 ++ UXAssist/Common/GameConstants/ItemIds.cs | 3 +++ UXAssist/Patches/Factory/BuildToolPatch.cs | 13 ++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/UXAssist/CHANGELOG.md b/UXAssist/CHANGELOG.md index eb7741b..8c2bd5d 100644 --- a/UXAssist/CHANGELOG.md +++ b/UXAssist/CHANGELOG.md @@ -4,6 +4,7 @@ ## Changlog * 1.6.2 - Unrelease + * `Drag building power poles`: Fix invalid alternating previews when enabling the option after loading a save, and restore original spacing when disabling it. * Close building and belt hover popups when opening the pause menu so they cannot obscure menu controls. * `Protect veins from exhaustion`: Exclude protected veins from mining-rate estimates, mining resource counts, and miner hover counts while retaining their remaining reserves. * `Dismantle blueprint selected buildings`: Respect sandbox instant-dismantle settings when discarding logistics station contents, and return them normally outside instant dismantling. @@ -432,6 +433,7 @@ ## 更新日志 * 1.6.2 - Unreleased + * `拖建电线杆`:修复载入存档后才启用功能时交替放置的预览异常,并在关闭时恢复原有间距。 * 打开暂停菜单时关闭建筑和传送带的悬浮提示,避免提示遮挡菜单。 * `保护矿脉不会枯竭`:开采速度估算、开采中资源数量和采矿机悬浮信息不再把受保护的矿脉计入开采;仍保留剩余储量显示。 * `拆除蓝图选中的建筑`:按沙盒模式的瞬间拆除设置销毁物流站库存;常规拆除时仍正常返还库存。 diff --git a/UXAssist/Common/GameConstants/ItemIds.cs b/UXAssist/Common/GameConstants/ItemIds.cs index 436e93e..fa239b1 100644 --- a/UXAssist/Common/GameConstants/ItemIds.cs +++ b/UXAssist/Common/GameConstants/ItemIds.cs @@ -57,6 +57,9 @@ public static class ItemIds public const int FrameMaterial = 1503; public const int DysonSphereComponent = 1802; + /* Power nodes */ + public const int TeslaTower = 2201; + /* Power generators */ public const int WindTurbine = 2203; diff --git a/UXAssist/Patches/Factory/BuildToolPatch.cs b/UXAssist/Patches/Factory/BuildToolPatch.cs index 3ffd4f6..10d4b70 100644 --- a/UXAssist/Patches/Factory/BuildToolPatch.cs +++ b/UXAssist/Patches/Factory/BuildToolPatch.cs @@ -6,6 +6,7 @@ using HarmonyLib; using UnityEngine; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.GameConstants; using GameLogicProc = UXAssist.Common.GameLogic; namespace UXAssist.Patches.Factory; @@ -383,7 +384,8 @@ internal static class BuildToolPatch { GameLogicProc.OnGameBegin += OnGameBegin; GameLogicProc.OnGameEnd += OnGameEnd; - FixProto(); + GameLogicProc.OnDataLoaded += OnGameBegin; + OnGameBegin(); } protected override void OnDisable() @@ -391,6 +393,7 @@ internal static class BuildToolPatch UnfixProto(); GameLogicProc.OnGameEnd -= OnGameEnd; GameLogicProc.OnGameBegin -= OnGameBegin; + GameLogicProc.OnDataLoaded -= OnGameBegin; } public static void AlternatelyChanged() @@ -406,7 +409,11 @@ internal static class BuildToolPatch private static void FixProto() { - if (DSPGame.IsMenuDemo) return; + if (DSPGame.IsMenuDemo || _powerPoleProto == null || OldDragBuild.Count > 0) return; + foreach (var id in PowerPoleIds) + { + if (LDB.items?.Select(id)?.prefabDesc == null) return; + } OldDragBuild.Clear(); OldDragBuildDist.Clear(); foreach (var id in PowerPoleIds) @@ -443,7 +450,7 @@ internal static class BuildToolPatch private static void OnGameBegin() { - _powerPoleProto ??= LDB.items.Select(2201); + _powerPoleProto ??= LDB.items?.Select(ItemIds.TeslaTower); FixProto(); }