diff --git a/AGENTS.md b/AGENTS.md index 3216962..30ab709 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -152,7 +152,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod` - **Illegal Dyson shell generation:** Estimated triangle vertex counts mirror the original `DysonShell.GenerateGeometry` rasterization as closely as possible, but can still differ from the final frame-generated shell polygon at numerical boundaries. Max-output generation must treat `QuickAddDysonShell` failure as a candidate rejection and try the next candidate rather than assuming the estimate is exact. - **Fail-soft patch application:** `PatchImpl.Enable(true)` applies Harmony patches inside a try/catch. Runtime patching can fail through no fault of ours (Harmony re-runs other mods' transpilers on shared target methods), and an escaping exception would abort the calling `ConfigEntry.SettingChanged` delegate chain, desyncing config UI from config values. On failure it logs a `LogError` with the feature type name, rolls back via `UnpatchSelf()`, and leaves `_patch` null so a later `Enable(true)` can retry. - **Convergent in-game UI state:** In-game overlay widgets whose visibility depends on game state (e.g. `AutoConstructUI`) must not rely solely on one-shot event-driven refreshes (`SettingChanged` handlers, patch `OnEnable`/`OnDisable`), because a thrown exception earlier in a delegate chain or a failed patch application silently drops the refresh. `AutoConstructUI.OnUpdate()` reconciles button visibility and the pending-construction count with actual game state every 30 frames (also effective while paused); the `AutoConstructPatch` postfix on `PlayerAction_Rts.GameTick` only implements the fly-to-target behavior, and `AutoConstructPatch.OnEnable` logs its visibility predicate inputs once per enable as a remote-diagnosis aid. -- **Auto-navigation modes:** The legacy auto-navigation and the new navigation algorithm are mutually exclusive; legacy mode wins if both configuration values load as enabled. The shared `ToggleAutoCruise` key dispatches to only the selected implementation. New-navigation teardown is unconditional for configuration, target, capability, and lifecycle failures, while the manual-input option controls only user-override behavior. Its session state and cloned status label are reset through `GameLogic.OnGameEnd` and patch teardown. +- **Auto-navigation modes:** The legacy auto-navigation and the new navigation algorithm are mutually exclusive; legacy mode wins if both configuration values load as enabled. The shared `ToggleAutoCruise` key dispatches to only the selected implementation. New-navigation teardown is unconditional for configuration, target, capability, and lifecycle failures, while the manual-input option controls only user-override behavior. Its session state and cloned status label are reset through `GameLogic.OnGameEnd` and patch teardown. When the new algorithm is selected but inactive, the cloned status label prompts the player with the currently configured `ToggleAutoCruise` key; it shows the active status while navigation is running. - **Auto-cruise flight input:** In the original `PlayerMove_Fly.GameTick`, `PlayerController.input0.y = 1` matches manual forward movement and `input1.y = 1` matches manual upward thrust. The legacy auto-cruise `Fly` handler must preserve these signs so the mecha leaves a planet with the same orientation and motion as manual control. - **UI clone initialization and text measurement:** UXAssist UI factories and dependent mods' direct UI clones treat runtime DSP objects as style sources only; after `Instantiate`, they explicitly reset stateful `UIButton`, `Text`, `Image`, `InputField`, `Slider`, and `UIComboBox` fields that can otherwise carry source state. Use `UXAssist.UI.Util.GetPreferredWidth` for dynamic text width because it invalidates DSP's custom text-generator cache before reading `preferredWidth`; do not replace it with a generic `TextGenerator` or canvas-wide rebuild without validating the rendered result. - **Transpiler patches:** Performance-critical mods (LabOpt, MechaDronesTweaks) use `[HarmonyTranspiler]` to rewrite IL instructions directly for maximum efficiency. All transpilers in UXAssist, CheatEnabler, and UniverseGenTweaks carry a standard header comment (`// Harmony transpiler:`, `// Target:`, `// Fallback:`) documenting the target method and fallback behavior. `UXAssist.Common.Patching.TranspilerGuard` provides a reusable `CodeMatcher.Finish` helper that returns original instructions when a matcher becomes invalid. diff --git a/UXAssist/Common/I18NKeys.cs b/UXAssist/Common/I18NKeys.cs index 03bdb61..1af3057 100644 --- a/UXAssist/Common/I18NKeys.cs +++ b/UXAssist/Common/I18NKeys.cs @@ -165,6 +165,7 @@ public static class I18NKeys public const string DarkFogHiveFollowDistance = "Dark Fog Hive follow distance"; public const string DarkFogCarrierFollowDistance = "Dark Fog Carrier follow distance"; public const string AutoNavigationActive = "Auto-navigation active"; + public const string AutoNavigationEnableHint = "Press {0} to enable auto-navigation"; public const string AutoNavigationStarted = "Auto-navigation started"; public const string AutoNavigationStopped = "Auto-navigation stopped"; public const string TreatStackItemsAsSingleInMonitorComponents = "Treat stack items as single in monitor components"; @@ -432,6 +433,7 @@ You can set 2 shortcut keys in Settings panel: I18N.Add(DarkFogHiveFollowDistance, "Dark Fog Hive follow distance (AU)", "黑雾巢穴跟踪距离(AU)"); I18N.Add(DarkFogCarrierFollowDistance, "Dark Fog Carrier follow distance (m)", "黑雾火种跟踪距离(m)"); I18N.Add(AutoNavigationActive, "Auto-navigation active", "自动导航中"); + I18N.Add(AutoNavigationEnableHint, "Press {0} to enable auto-navigation", "按 {0} 启用自动导航"); I18N.Add(AutoNavigationStarted, "Auto-navigation started", "自动导航启动"); I18N.Add(AutoNavigationStopped, "Auto-navigation stopped", "自动导航关闭"); I18N.Add(TreatStackItemsAsSingleInMonitorComponents, "Treat stack items as single in monitor components", "在流速计中将堆叠物品视为单个物品"); diff --git a/UXAssist/Common/KeyBindings.cs b/UXAssist/Common/KeyBindings.cs index a2322ad..156affc 100644 --- a/UXAssist/Common/KeyBindings.cs +++ b/UXAssist/Common/KeyBindings.cs @@ -30,6 +30,19 @@ public static class KeyBindings return new CombineKey((int)shortcut.MainKey, mod, ECombineKeyAction.OnceClick, false); } + public static string GetKeyBindingText(PressKeyBind keyBind) + { + var defaultBind = keyBind.defaultBind; + var key = defaultBind.key; + if (VFInput.override_keys != null && (uint)defaultBind.id < (uint)VFInput.override_keys.Length) + { + var overrideKey = VFInput.override_keys[defaultBind.id]; + if (!overrideKey.IsNull()) key = overrideKey; + } + + return key.ToString(); + } + public static bool IsKeyPressing(this PressKeyBind keyBind) { var defBind = keyBind.defaultBind; diff --git a/UXAssist/Functions/UI/AutoCruiseUI.cs b/UXAssist/Functions/UI/AutoCruiseUI.cs index f511323..50259ca 100644 --- a/UXAssist/Functions/UI/AutoCruiseUI.cs +++ b/UXAssist/Functions/UI/AutoCruiseUI.cs @@ -26,6 +26,8 @@ internal static class AutoCruiseUI public static void OnUpdate() { + if (Time.frameCount % 30 == 0) + Patches.PlayerPatch.AutoNavigationG.UpdateUiTip(); } public static void InitToggleAutoCruiseCheckButton() diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index fb18aa7..a5d89b1 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -724,14 +724,19 @@ public class PlayerPatch : PatchImpl public static void StartG( ) { - if (UiTipText != null || UIRoot.instance?.uiGame?.generalTips?.modeText == null) + if (UiTipText != null) + { + UpdateUiTip(); + return; + } + if (UIRoot.instance?.uiGame?.generalTips?.modeText == null) return; Text originText = UIRoot.instance.uiGame.generalTips.modeText; UiTipText = Object.Instantiate(originText, originText.transform.parent); UiTipText.gameObject.SetActive(false); UiTipText.rectTransform.anchoredPosition = new Vector2(0f, 160f); UiTipText.fontStyle = FontStyle.Normal; - UiTipText.text = I18NKeys.AutoNavigationActive.Translate(); + UpdateUiTip(); } public static void Toggle() @@ -740,6 +745,7 @@ public class PlayerPatch : PatchImpl StopAutoNavigation(); else StartAutoNavigation( ); + UpdateUiTip(); } private static void StartAutoNavigation( ) @@ -750,7 +756,7 @@ public class PlayerPatch : PatchImpl EnableTag = true; Reset( ); UIRealtimeTip.Popup(I18NKeys.AutoNavigationStarted.Translate(), sound: false); - UiTipText?.gameObject.SetActive(true); + UpdateUiTip(); } private static void StopAutoNavigation(bool showTip = true) @@ -760,7 +766,7 @@ public class PlayerPatch : PatchImpl PauseTag = false; if (wasEnabled && showTip && !DSPGame.IsMenuDemo && GameMain.isRunning) UIRealtimeTip.Popup(I18NKeys.AutoNavigationStopped.Translate(), sound: false); - UiTipText?.gameObject.SetActive(false); + UpdateUiTip(); } private static void Reset( ) @@ -785,7 +791,26 @@ public class PlayerPatch : PatchImpl Reset(); } - private static void NavigationModeChanged(object sender, EventArgs args) => NormalizeNavigationMode(); + private static void NavigationModeChanged(object sender, EventArgs args) + { + NormalizeNavigationMode(); + UpdateUiTip(); + } + + public static void UpdateUiTip() + { + if (UiTipText == null) + return; + + bool showTip = GameMain.isRunning && !DSPGame.IsMenuDemo && UseNewNavigationAlgorithm.Value && !AutoNavigationEnabled.Value; + UiTipText.gameObject.SetActive(showTip); + if (!showTip) + return; + + UiTipText.text = EnableTag + ? I18NKeys.AutoNavigationActive.Translate() + : string.Format(I18NKeys.AutoNavigationEnableHint.Translate(), KeyBindings.GetKeyBindingText(_autoDriveKey)); + } private static void NormalizeNavigationMode() {