From 574919f1f0ec0f23e928f1ee33fe95d1ea967ad9 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Wed, 2 Sep 2026 18:47:37 +0800 Subject: [PATCH] fix(UXAssist): reset cloned UI state --- AGENTS.md | 1 + CheatEnabler/UIConfigWindow.cs | 4 +- UXAssist/Functions/UI/AutoConstructUI.cs | 3 + UXAssist/Functions/UI/MenuButtonUI.cs | 9 ++ UXAssist/Functions/UI/MilkyWayUI.cs | 11 ++- .../Logistics/RealtimeInfoPanelPatch.cs | 27 +++++- UXAssist/Patches/PlayerPatch.cs | 2 + UXAssist/Patches/UIPatch.cs | 6 ++ UXAssist/UI/LayoutHelper.cs | 11 ++- UXAssist/UI/MyCheckButton.cs | 6 ++ UXAssist/UI/MyCheckbox.cs | 32 ++++++- UXAssist/UI/MyComboBox.cs | 23 ++++- UXAssist/UI/MyCornerComboBox.cs | 20 +++++ UXAssist/UI/MyFlatButton.cs | 17 +++- UXAssist/UI/MyKeyBinder.cs | 17 +++- UXAssist/UI/MySideSlider.cs | 8 ++ UXAssist/UI/MySlider.cs | 11 +++ UXAssist/UI/MyWindow.cs | 22 ++++- UXAssist/UI/Util.cs | 24 ++++++ UXAssist/UIConfigWindow.cs | 85 ++++++++++--------- .../Patches/GalaxySelectUIPatch.cs | 27 ++++++ 21 files changed, 308 insertions(+), 58 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d25383a..91b585d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -153,6 +153,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod` - **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. +- **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. - **Mod-compatibility reflection:** Use `UXAssist.Common.ModCompat.ModCompatHelper` for BepInEx plugin detection, external mod type/method/field resolution, and property-setter lookup. Preserve the old public type identity with a forwarding or inherited compatibility facade when a refactor moves a type that external mods may locate through reflection; build and verify that the legacy reflection target forwards to the refactored implementation. Use `UXAssist.Common.Utils.DysonSphereReflection` for the DSPOptimizations-compatible `DysonSphereLayer` private fields (`totalNodeSP`, `totalFrameSP`, `totalCP`) instead of resolving them locally in each consumer. - **Build quality gates:** Root `.editorconfig` defines suggestion-only C# style conventions. `Directory.Build.props` enables `TreatWarningsAsErrors` with `NoWarn>0618` for the expected obsolete-API usage, so any new warning fails the build. `.github/workflows/build.yml` runs a Release build and packages the three main mods on every push/PR. diff --git a/CheatEnabler/UIConfigWindow.cs b/CheatEnabler/UIConfigWindow.cs index 4bac4dd..9eb5787 100644 --- a/CheatEnabler/UIConfigWindow.cs +++ b/CheatEnabler/UIConfigWindow.cs @@ -278,7 +278,7 @@ public static class UIConfigWindow }); y += 30f; var txt2 = wnd.AddText2(x, y, tab4, "Shells count", 15, "text-shells-count"); - var input2 = AddShellsCountInput(wnd, x + txt2.preferredWidth + 5f, y, tab4, "input-shells-count-quick"); + var input2 = AddShellsCountInput(wnd, x + UXAssist.UI.Util.GetPreferredWidth(txt2) + 5f, y, tab4, "input-shells-count-quick"); Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged += onIllegalDysonShellFunctionsChanged; wnd.OnFree += () => { Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged -= onIllegalDysonShellFunctionsChanged; }; @@ -337,4 +337,4 @@ public static class UIConfigWindow _clearBanBtn.gameObject.SetActive(banEnabled); } } -} \ No newline at end of file +} diff --git a/UXAssist/Functions/UI/AutoConstructUI.cs b/UXAssist/Functions/UI/AutoConstructUI.cs index a9a146d..f5ae49d 100644 --- a/UXAssist/Functions/UI/AutoConstructUI.cs +++ b/UXAssist/Functions/UI/AutoConstructUI.cs @@ -78,6 +78,9 @@ internal static class AutoConstructUI ConstructCountText.color = new Color(1f, 1f, 1f, 0.4f); ConstructCountText.alignment = TextAnchor.MiddleLeft; ConstructCountText.fontSize = 16; + ConstructCountText.fontStyle = FontStyle.Normal; + ConstructCountText.horizontalOverflow = HorizontalWrapMode.Overflow; + ConstructCountText.verticalOverflow = VerticalWrapMode.Overflow; rectTrans = ConstructCountText.rectTransform; rectTrans.SetParent(ConstructCountPanel.transform); rectTrans.sizeDelta = new Vector2(150f, 20f); diff --git a/UXAssist/Functions/UI/MenuButtonUI.cs b/UXAssist/Functions/UI/MenuButtonUI.cs index 3d5072b..ad847c4 100644 --- a/UXAssist/Functions/UI/MenuButtonUI.cs +++ b/UXAssist/Functions/UI/MenuButtonUI.cs @@ -77,6 +77,12 @@ internal static class MenuButtonUI var parent = src.transform.parent; var btn = GameObject.Instantiate(src, parent); btn.name = "button-uxassist-config"; + btn.button.enabled = true; + btn.button.interactable = true; + btn.text.color = Color.white; + btn.text.fontStyle = FontStyle.Normal; + btn.selectBg.color = new Color(1f, 1f, 1f, 0f); + btn.selectBar.color = new Color(1f, 1f, 1f, 0f); var l = btn.text.GetComponent(); if (l != null) { @@ -103,10 +109,13 @@ internal static class MenuButtonUI _buttonOnPlanetGlobe = b.gameObject; var rect = (RectTransform)_buttonOnPlanetGlobe.transform; var btn = _buttonOnPlanetGlobe.GetComponent(); + global::UXAssist.UI.Util.ResetButton(btn); var img = _buttonOnPlanetGlobe.transform.Find("button-2/icon")?.GetComponent(); if (img != null) { img.sprite = icon; + img.color = Color.white; + img.enabled = icon != null; } if (_buttonOnPlanetGlobe != null && btn != null) diff --git a/UXAssist/Functions/UI/MilkyWayUI.cs b/UXAssist/Functions/UI/MilkyWayUI.cs index c183e2b..23ef38a 100644 --- a/UXAssist/Functions/UI/MilkyWayUI.cs +++ b/UXAssist/Functions/UI/MilkyWayUI.cs @@ -187,6 +187,9 @@ internal static class MilkyWayUI txt.color = new Color(1f, 1f, 1f, 0.4f); txt.alignment = TextAnchor.MiddleLeft; txt.fontSize = 15; + txt.fontStyle = FontStyle.Normal; + txt.horizontalOverflow = HorizontalWrapMode.Overflow; + txt.verticalOverflow = VerticalWrapMode.Overflow; txt.rectTransform.sizeDelta = new Vector2(0, 18); return txt; } @@ -266,10 +269,10 @@ internal static class MilkyWayUI textFields[i * 4 + 1].text = _topTenPlayerData[i].name; textFields[i * 4 + 2].text = SeedToString(_topTenPlayerData[i].seedKey); textFields[i * 4 + 3].text = String.Format("{0}W", ToKMG(_topTenPlayerData[i].genCap * 60L)); - maxWidth0 = Math.Max(maxWidth0, textFields[i * 4].preferredWidth); - maxWidth1 = Math.Max(maxWidth1, textFields[i * 4 + 1].preferredWidth); - maxWidth2 = Math.Max(maxWidth2, textFields[i * 4 + 2].preferredWidth); - maxWidth3 = Math.Max(maxWidth3, textFields[i * 4 + 3].preferredWidth); + maxWidth0 = Math.Max(maxWidth0, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4])); + maxWidth1 = Math.Max(maxWidth1, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 1])); + maxWidth2 = Math.Max(maxWidth2, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 2])); + maxWidth3 = Math.Max(maxWidth3, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 3])); button.gameObject.SetActive(true); textFields[i * 4].gameObject.SetActive(true); textFields[i * 4 + 1].gameObject.SetActive(true); diff --git a/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs b/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs index 29b6d81..dc930bc 100644 --- a/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs +++ b/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs @@ -353,6 +353,9 @@ internal static class RealtimeLogisticsInfoPanel var y = -5f - 35f * index; var itemIcon = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); itemIcon.name = "icon" + index; + var itemIconImage = itemIcon.GetComponent(); + itemIconImage.color = Color.white; + itemIconImage.enabled = true; rectTrans = (RectTransform)itemIcon.transform; rectTrans.sizeDelta = new Vector2(30f, 30f); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -362,6 +365,7 @@ internal static class RealtimeLogisticsInfoPanel var sliderBg = Object.Instantiate(sliderBgPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); sliderBg.name = "sliderBg" + index; + sliderBg.GetComponent().enabled = true; rectTrans = (RectTransform)sliderBg.transform; rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -398,7 +402,11 @@ internal static class RealtimeLogisticsInfoPanel var text = countText.GetComponent(); text.fontSize = 18; text.text = ""; + text.color = Color.white; text.alignment = TextAnchor.UpperRight; + text.fontStyle = FontStyle.Normal; + text.horizontalOverflow = HorizontalWrapMode.Overflow; + text.verticalOverflow = VerticalWrapMode.Overflow; rectTrans = (RectTransform)countText.transform; rectTrans.sizeDelta = new Vector2(70f, 20f); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -409,7 +417,10 @@ internal static class RealtimeLogisticsInfoPanel var stateLocal = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); stateLocal.name = "iconLocal" + index; - stateLocal.GetComponent().material = null; + var stateLocalImage = stateLocal.GetComponent(); + stateLocalImage.material = null; + stateLocalImage.color = Color.white; + stateLocalImage.enabled = true; rectTrans = (RectTransform)stateLocal.transform; rectTrans.sizeDelta = new Vector2(16f, 16f); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -418,7 +429,10 @@ internal static class RealtimeLogisticsInfoPanel rectTrans.anchoredPosition3D = new Vector3(102f, y, 0); var stateRemote = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); stateRemote.name = "iconRemote" + index; - stateRemote.GetComponent().material = null; + var stateRemoteImage = stateRemote.GetComponent(); + stateRemoteImage.material = null; + stateRemoteImage.color = Color.white; + stateRemoteImage.enabled = true; rectTrans = (RectTransform)stateRemote.transform; rectTrans.sizeDelta = new Vector2(20f, 20f); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -428,6 +442,9 @@ internal static class RealtimeLogisticsInfoPanel } var iconPrefab = Object.Instantiate(GameObject.Find("UI Root/Overlay Canvas/In Game/Top Tips/Entity Briefs/brief-info-top/brief-info/content/icons/icon"), _tipPrefab.transform); + var iconPrefabImage = iconPrefab.GetComponent(); + iconPrefabImage.color = Color.white; + iconPrefabImage.enabled = true; Object.Destroy(iconPrefab.transform.Find("count-text").gameObject); Object.Destroy(iconPrefab.transform.Find("bg").gameObject); Object.Destroy(iconPrefab.transform.Find("inc").gameObject); @@ -456,6 +473,9 @@ internal static class RealtimeLogisticsInfoPanel text.text = "100"; text.alignment = TextAnchor.MiddleRight; text.color = Color.white; + text.fontStyle = FontStyle.Normal; + text.horizontalOverflow = HorizontalWrapMode.Overflow; + text.verticalOverflow = VerticalWrapMode.Overflow; rectTrans = (RectTransform)countText.transform; rectTrans.sizeDelta = new Vector2(40f, 30f); rectTrans.anchorMax = new Vector2(0f, 1f); @@ -474,6 +494,9 @@ internal static class RealtimeLogisticsInfoPanel text.text = "100"; text.alignment = TextAnchor.MiddleRight; text.color = Color.white; + text.fontStyle = FontStyle.Normal; + text.horizontalOverflow = HorizontalWrapMode.Overflow; + text.verticalOverflow = VerticalWrapMode.Overflow; rectTrans = (RectTransform)countText.transform; rectTrans.sizeDelta = new Vector2(40f, 30f); rectTrans.anchorMax = new Vector2(0f, 1f); diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index 38834e4..462ad11 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -730,6 +730,8 @@ public class PlayerPatch : PatchImpl UiTipText = Object.Instantiate(originText, originText.transform.parent); UiTipText.gameObject.SetActive(false); UiTipText.rectTransform.anchoredPosition = new Vector2(0f, 160f); + UiTipText.color = Color.white; + UiTipText.fontStyle = FontStyle.Normal; UiTipText.text = I18NKeys.AutoNavigationActive.Translate(); } diff --git a/UXAssist/Patches/UIPatch.cs b/UXAssist/Patches/UIPatch.cs index 46e3e73..9dafafb 100644 --- a/UXAssist/Patches/UIPatch.cs +++ b/UXAssist/Patches/UIPatch.cs @@ -160,6 +160,12 @@ public class UIPatch : PatchImpl var parent = uiresAmountEntry.labelText.transform.parent; vt.textCtrl = Object.Instantiate(uiresAmountEntry.valueText, parent); vt.textCtrl.font = uiresAmountEntry.labelText.font; + vt.textCtrl.text = ""; + vt.textCtrl.color = uiresAmountEntry.normalColor; + vt.textCtrl.alignment = TextAnchor.MiddleRight; + vt.textCtrl.fontStyle = FontStyle.Normal; + vt.textCtrl.horizontalOverflow = HorizontalWrapMode.Overflow; + vt.textCtrl.verticalOverflow = VerticalWrapMode.Overflow; RectTransform trans = vt.textCtrl.rectTransform; var pos = uiresAmountEntry.rectTrans.localPosition; pos.x = pos.x + uiresAmountEntry.iconImage.rectTransform.localPosition.x - 25f; diff --git a/UXAssist/UI/LayoutHelper.cs b/UXAssist/UI/LayoutHelper.cs index 146663e..b354c17 100644 --- a/UXAssist/UI/LayoutHelper.cs +++ b/UXAssist/UI/LayoutHelper.cs @@ -25,7 +25,10 @@ public static class LayoutHelper txt.color = new Color(1f, 1f, 1f, 0.4f); txt.alignment = TextAnchor.MiddleLeft; txt.fontSize = fontSize; - txt.rectTransform.sizeDelta = new Vector2(txt.preferredWidth + 8f, txt.preferredHeight + 8f); + txt.fontStyle = FontStyle.Normal; + txt.horizontalOverflow = HorizontalWrapMode.Overflow; + txt.verticalOverflow = VerticalWrapMode.Overflow; + txt.rectTransform.sizeDelta = new Vector2(Util.GetPreferredWidth(txt) + 8f, txt.preferredHeight + 8f); AddElement(x, y, txt.rectTransform, parent); return txt; } @@ -36,6 +39,7 @@ public static class LayoutHelper var dst = UnityEngine.Object.Instantiate(src); dst.gameObject.name = objName; var btn = dst.GetComponent(); + Util.ResetButton(btn); Util.NormalizeRectWithTopLeft(btn, x, y, parent); btn.tips.topLevel = true; btn.tips.tipTitle = label; @@ -54,6 +58,7 @@ public static class LayoutHelper var panel = UIRoot.instance.uiGame.statWindow.performancePanelUI; var btn = UnityEngine.Object.Instantiate(panel.cpuActiveButton); btn.gameObject.name = objName; + Util.ResetButton(btn); var rect = Util.NormalizeRectWithTopLeft(btn, x, y, parent); rect.sizeDelta = new Vector2(width, rect.sizeDelta.y); var l = btn.gameObject.transform.Find("button-text").GetComponent(); @@ -67,6 +72,10 @@ public static class LayoutHelper if (t != null) { t.text = text.Translate(); + t.color = Color.white; + t.fontStyle = FontStyle.Normal; + t.horizontalOverflow = HorizontalWrapMode.Overflow; + t.verticalOverflow = VerticalWrapMode.Overflow; } t.fontSize = fontSize; diff --git a/UXAssist/UI/MyCheckButton.cs b/UXAssist/UI/MyCheckButton.cs index 09686b9..ee9a29d 100644 --- a/UXAssist/UI/MyCheckButton.cs +++ b/UXAssist/UI/MyCheckButton.cs @@ -38,6 +38,7 @@ public class MyCheckButton : MonoBehaviour var go = Instantiate(UIRoot.instance.uiGame.beltWindow.reverseButton.gameObject); go.name = "my-checkbutton"; go.SetActive(false); + Util.ResetButton(go.GetComponent()); var comp = go.transform.Find("text"); if (comp) { @@ -46,6 +47,8 @@ public class MyCheckButton : MonoBehaviour { txt.text = ""; txt.alignment = TextAnchor.MiddleCenter; + txt.color = Color.white; + txt.fontStyle = FontStyle.Normal; txt.rectTransform.anchorMax = new Vector2(0f, 1f); txt.rectTransform.anchorMin = new Vector2(0f, 1f); txt.rectTransform.pivot = new Vector2(0f, 1f); @@ -82,6 +85,7 @@ public class MyCheckButton : MonoBehaviour cb.rectTrans = rect; cb.uiButton = go.GetComponent(); + Util.ResetButton(cb.uiButton); var child = go.transform.Find("text"); if (child != null) @@ -91,6 +95,8 @@ public class MyCheckButton : MonoBehaviour { cb.labelText.text = ""; cb.labelText.fontSize = fontSize; + cb.labelText.color = Color.white; + cb.labelText.fontStyle = FontStyle.Normal; } } diff --git a/UXAssist/UI/MyCheckbox.cs b/UXAssist/UI/MyCheckbox.cs index 045c61d..1792089 100644 --- a/UXAssist/UI/MyCheckbox.cs +++ b/UXAssist/UI/MyCheckbox.cs @@ -28,11 +28,30 @@ public class MyCheckBox : MonoBehaviour var go = Instantiate(UIRoot.instance.uiGame.buildMenu.uxFacilityCheck.gameObject); go.name = "my-checkbox"; go.SetActive(false); + Util.ResetButton(go.GetComponent()); + var boxImage = go.GetComponent(); + if (boxImage) + { + boxImage.color = BoxColor; + boxImage.enabled = true; + } + var checkImage = go.transform.Find("checked")?.GetComponent(); + if (checkImage) + { + checkImage.color = CheckColor; + checkImage.enabled = false; + } var comp = go.transform.Find("text"); if (comp) { var txt = comp.GetComponent(); - if (txt) txt.text = ""; + if (txt) + { + txt.text = ""; + txt.color = TextColor; + txt.alignment = TextAnchor.MiddleLeft; + txt.fontStyle = FontStyle.Normal; + } var localizer = comp.GetComponent(); if (localizer) DestroyImmediate(localizer); } @@ -66,6 +85,11 @@ public class MyCheckBox : MonoBehaviour cb.uiButton = go.GetComponent(); cb.boxImage = go.transform.GetComponent(); cb.checkImage = go.transform.Find("checked")?.GetComponent(); + Util.ResetButton(cb.uiButton); + cb.boxImage.color = BoxColor; + cb.boxImage.enabled = true; + cb.checkImage.color = CheckColor; + cb.checkImage.enabled = false; Util.NormalizeRectWithTopLeft(cb.checkImage, 0f, 0f); var child = go.transform.Find("text"); @@ -76,17 +100,21 @@ public class MyCheckBox : MonoBehaviour { cb.labelText.text = ""; cb.labelText.fontSize = fontSize; + cb.labelText.color = TextColor; + cb.labelText.alignment = TextAnchor.MiddleLeft; + cb.labelText.fontStyle = FontStyle.Normal; cb.UpdateLabelTextWidth(); } } + cb.SetEnable(true); cb.uiButton.onClick += cb.OnClick; return cb; } private void UpdateLabelTextWidth() { - if (labelText) labelText.rectTransform.sizeDelta = new Vector2(labelText.preferredWidth, labelText.rectTransform.sizeDelta.y); + if (labelText) labelText.rectTransform.sizeDelta = new Vector2(Util.GetPreferredWidth(labelText), labelText.rectTransform.sizeDelta.y); } public bool Checked diff --git a/UXAssist/UI/MyComboBox.cs b/UXAssist/UI/MyComboBox.cs index fd4e914..63916a2 100644 --- a/UXAssist/UI/MyComboBox.cs +++ b/UXAssist/UI/MyComboBox.cs @@ -21,6 +21,10 @@ public class MyComboBox : MonoBehaviour var go = Instantiate(UIRoot.instance.optionWindow.resolutionComp.gameObject); go.name = "my-combobox"; go.SetActive(false); + foreach (var button in go.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } var rect = (RectTransform)go.transform; var cbctrl = rect.GetComponent(); @@ -38,6 +42,7 @@ public class MyComboBox : MonoBehaviour txtComp.font = fontSource.font; txtComp.fontSize = fontSource.fontSize; txtComp.fontStyle = fontSource.fontStyle; + txtComp.color = Color.white; } txtComp = rect.Find("Main Button/Text")?.GetComponent(); if (txtComp) @@ -45,10 +50,22 @@ public class MyComboBox : MonoBehaviour txtComp.font = fontSource.font; txtComp.fontSize = fontSource.fontSize; txtComp.fontStyle = fontSource.fontStyle; + txtComp.color = Color.white; } } cbctrl.onSubmit.RemoveAllListeners(); cbctrl.onItemIndexChange.RemoveAllListeners(); + cbctrl.itemIndex = -1; + cbctrl.isDroppedDown = false; + cbctrl.m_Input.text = ""; + cbctrl.m_Text.text = ""; + cbctrl.m_Input.textComponent.color = Color.white; + cbctrl.m_Text.color = Color.white; + cbctrl.m_DropDownContent.anchoredPosition = Vector2.zero; + cbctrl.m_DropDownList.gameObject.SetActive(false); + cbctrl.m_EmptyItemRes.gameObject.SetActive(false); + cbctrl.m_SelectionBG.gameObject.SetActive(false); + cbctrl.m_Scrollbar.gameObject.SetActive(false); _baseObject = go; } @@ -58,6 +75,10 @@ public class MyComboBox : MonoBehaviour gameObject.name = "my-combobox"; gameObject.SetActive(true); var cb = gameObject.AddComponent(); + foreach (var button in gameObject.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent); cb._rectTrans = rtrans; var box = rtrans.GetComponent(); @@ -161,4 +182,4 @@ public class MyComboBox : MonoBehaviour public float Width => _rectTrans.sizeDelta.x; public float Height => _rectTrans.sizeDelta.y; -} \ No newline at end of file +} diff --git a/UXAssist/UI/MyCornerComboBox.cs b/UXAssist/UI/MyCornerComboBox.cs index cf5fd0d..59f1e27 100644 --- a/UXAssist/UI/MyCornerComboBox.cs +++ b/UXAssist/UI/MyCornerComboBox.cs @@ -21,16 +21,32 @@ public class MyCornerComboBox : MonoBehaviour var go = Instantiate(UIRoot.instance.uiGame.starDetail.displayCombo.gameObject); go.name = "my-small-combobox"; go.SetActive(false); + foreach (var button in go.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } var cbctrl = go.transform.GetComponent(); cbctrl.onSubmit.RemoveAllListeners(); cbctrl.onItemIndexChange.RemoveAllListeners(); + cbctrl.itemIndex = -1; + cbctrl.isDroppedDown = false; + cbctrl.m_Input.text = ""; + cbctrl.m_Text.text = ""; + cbctrl.m_Input.textComponent.color = Color.white; + cbctrl.m_Text.color = Color.white; + cbctrl.m_DropDownContent.anchoredPosition = Vector2.zero; + cbctrl.m_DropDownList.gameObject.SetActive(false); + cbctrl.m_EmptyItemRes.gameObject.SetActive(false); + cbctrl.m_SelectionBG.gameObject.SetActive(false); + cbctrl.m_Scrollbar.gameObject.SetActive(false); foreach (var button in cbctrl.ItemButtons) { Destroy(button.gameObject); } cbctrl.Items.Clear(); cbctrl.ItemButtons.Clear(); + cbctrl.m_ListItemRes.GetComponentInChildren().color = Color.white; _baseObject = go; } @@ -40,6 +56,10 @@ public class MyCornerComboBox : MonoBehaviour gameObject.name = "my-combobox"; gameObject.SetActive(true); var cb = gameObject.AddComponent(); + foreach (var button in gameObject.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } RectTransform rtrans; if (topRight) { diff --git a/UXAssist/UI/MyFlatButton.cs b/UXAssist/UI/MyFlatButton.cs index b477352..96676b1 100644 --- a/UXAssist/UI/MyFlatButton.cs +++ b/UXAssist/UI/MyFlatButton.cs @@ -20,18 +20,30 @@ public class MyFlatButton : MonoBehaviour var btn = go.GetComponent(); go.GetComponent().sprite = panel.buttonDefaultSprite; btn.gameObject.name = "my-flatbutton"; + go.SetActive(false); + Util.ResetButton(btn); btn.highlighted = false; var img = btn.GetComponent(); if (img != null) { img.sprite = panel.buttonDefaultSprite; - img.color = new Color(img.color.r, img.color.g, img.color.b, 13f / 255f); + img.color = new Color(1f, 1f, 1f, 13f / 255f); + img.enabled = true; } img = btn.gameObject.transform.Find("frame")?.GetComponent(); if (img != null) { - img.color = new Color(img.color.r, img.color.g, img.color.b, 0f); + img.color = new Color(1f, 1f, 1f, 0f); + img.enabled = true; + } + + var text = btn.gameObject.transform.Find("Text")?.GetComponent(); + if (text) + { + text.text = ""; + text.color = Color.white; + text.fontStyle = FontStyle.Normal; } btn.button.onClick.RemoveAllListeners(); @@ -53,6 +65,7 @@ public class MyFlatButton : MonoBehaviour cb.rectTrans = rect; cb.uiButton = go.GetComponent(); + Util.ResetButton(cb.uiButton); cb.labelText = go.transform.Find("Text")?.GetComponent(); cb.uiButton.onClick += onClick; diff --git a/UXAssist/UI/MyKeyBinder.cs b/UXAssist/UI/MyKeyBinder.cs index ee06c2c..1b6101e 100644 --- a/UXAssist/UI/MyKeyBinder.cs +++ b/UXAssist/UI/MyKeyBinder.cs @@ -60,6 +60,21 @@ public class MyKeyBinder : MonoBehaviour kb.setDefaultUIButton = uikeyEntry.setDefaultUIButton; kb.setNoneKeyUIButton = uikeyEntry.setNoneKeyUIButton; + Util.ResetButton(kb.inputUIButton); + Util.ResetButton(kb.setDefaultUIButton); + Util.ResetButton(kb.setNoneKeyUIButton); + kb.functionText.text = ""; + kb.functionText.color = Color.white; + kb.functionText.fontStyle = FontStyle.Normal; + kb.keyText.text = ""; + kb.keyText.color = uikeyEntry.builtinColor; + kb.keyText.fontStyle = FontStyle.Normal; + kb.conflictText.text = ""; + kb.waitingText.text = ""; + kb.conflictText.gameObject.SetActive(false); + kb.waitingText.gameObject.SetActive(false); + kb.setTheKeyToggle.isOn = false; + kb.setTheKeyInput.text = ""; kb.functionText.text = label.Translate(); kb.functionText.fontSize = 17; @@ -232,4 +247,4 @@ public class MyKeyBinder : MonoBehaviour { keyText.text = _config.Value.Serialize(); } -} \ No newline at end of file +} diff --git a/UXAssist/UI/MySideSlider.cs b/UXAssist/UI/MySideSlider.cs index 8942bfc..f8314e6 100644 --- a/UXAssist/UI/MySideSlider.cs +++ b/UXAssist/UI/MySideSlider.cs @@ -24,6 +24,10 @@ public class MySideSlider : MonoBehaviour var go = Instantiate(UIRoot.instance.uiGame.stationWindow.maxMiningSpeedGroup.gameObject); //sizeDelta = 240, 20 go.name = "my-side-slider"; + foreach (var button in go.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } Destroy(go.transform.Find("label").gameObject); Destroy(go.GetComponent()); go.SetActive(true); @@ -34,6 +38,7 @@ public class MySideSlider : MonoBehaviour sl.slider = go.transform.Find("slider").GetComponent(); sl.slider.minValue = 0f; sl.slider.maxValue = 100f; + sl.slider.interactable = true; sl.slider.onValueChanged.RemoveAllListeners(); sl.slider.onValueChanged.AddListener(sl.SliderChanged); if (width == 0) width = 160f; @@ -45,6 +50,9 @@ public class MySideSlider : MonoBehaviour sl.Value = 0f; sl.labelText = go.transform.Find("value").GetComponent(); + sl.labelText.text = ""; + sl.labelText.color = Color.white; + sl.labelText.fontStyle = FontStyle.Normal; sl.labelText.alignment = textWidth <= 0f ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight; if (sl.labelText.transform is RectTransform rectTrans2) { diff --git a/UXAssist/UI/MySlider.cs b/UXAssist/UI/MySlider.cs index 6a47468..03c1156 100644 --- a/UXAssist/UI/MySlider.cs +++ b/UXAssist/UI/MySlider.cs @@ -29,6 +29,10 @@ public class MySlider : MonoBehaviour //sizeDelta = 240, 20 go.name = "my-slider"; go.SetActive(true); + foreach (var button in go.GetComponentsInChildren(true)) + { + Util.ResetButton(button); + } var sl = go.AddComponent(); var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent); sl.rectTrans = rect; @@ -40,12 +44,17 @@ public class MySlider : MonoBehaviour sl.slider = go.GetComponent(); sl.slider.minValue = 0f; sl.slider.maxValue = 100f; + sl.slider.interactable = true; sl.slider.onValueChanged.RemoveAllListeners(); sl.slider.onValueChanged.AddListener(sl.SliderChanged); sl.Value = 0f; sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent(); if (sl.labelText) { + sl.labelText.text = ""; + sl.labelText.color = Color.white; + sl.labelText.alignment = TextAnchor.MiddleCenter; + sl.labelText.fontStyle = FontStyle.Normal; sl.labelText.fontSize = 14; if (sl.labelText.transform is RectTransform rectTrans) { @@ -60,11 +69,13 @@ public class MySlider : MonoBehaviour if (bg != null) { bg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); + bg.enabled = true; } var fill = sl.slider.fillRect.GetComponent(); if (fill != null) { fill.color = new Color(1f, 1f, 1f, 0.28f); + fill.enabled = true; } sl.UpdateLabel(); diff --git a/UXAssist/UI/MyWindow.cs b/UXAssist/UI/MyWindow.cs index b821c5b..2a01cf1 100644 --- a/UXAssist/UI/MyWindow.cs +++ b/UXAssist/UI/MyWindow.cs @@ -48,6 +48,7 @@ public class MyWindow : ManualBehaviour var go = Instantiate(_baseObject, UIRoot.instance.uiGame.transform.parent); go.name = name; go.SetActive(false); + Util.ResetButton(go.transform.Find("panel-bg")?.GetComponentInChildren()); MyWindow win = go.AddComponent(); if (!win) return null; @@ -385,9 +386,13 @@ public class MyWindow : ManualBehaviour inputField.gameObject.name = objName; Destroy(inputField.GetComponent()); inputField.GetComponent().color = new Color(1f, 1f, 1f, 0.05f); + inputField.GetComponent().enabled = true; + inputField.interactable = true; var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent); rect.sizeDelta = new Vector2(210, rect.sizeDelta.y); inputField.text = text; + inputField.textComponent.color = Color.white; + inputField.textComponent.fontStyle = FontStyle.Normal; inputField.textComponent.fontSize = fontSize; inputField.onValueChanged.RemoveAllListeners(); @@ -408,9 +413,13 @@ public class MyWindow : ManualBehaviour inputField.gameObject.name = objName; Destroy(inputField.GetComponent()); inputField.GetComponent().color = new Color(1f, 1f, 1f, 0.05f); + inputField.GetComponent().enabled = true; + inputField.interactable = true; var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent); rect.sizeDelta = new Vector2(width, rect.sizeDelta.y); inputField.text = config.Value; + inputField.textComponent.color = Color.white; + inputField.textComponent.fontStyle = FontStyle.Normal; inputField.textComponent.fontSize = fontSize; inputField.onValueChanged.RemoveAllListeners(); @@ -447,7 +456,10 @@ public class MyWindowWithTabs : MyWindow var swarmPanel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel; var src = swarmPanel.orbitButtons[0]; var btn = Instantiate(src); + Util.ResetButton(btn); btn.gameObject.GetComponent().sprite = swarmPanel.buttonDefaultSprite; + btn.gameObject.GetComponent().color = Color.white; + btn.gameObject.GetComponent().enabled = true; btn.name = "tab-btn-" + index; btn.highlighted = false; @@ -468,7 +480,9 @@ public class MyWindowWithTabs : MyWindow shadow.effectColor = new Color(0f, 0f, 0f, 0.4f); shadow.effectDistance = new Vector2(1f, -1f); btnText.text = label.Translate(); + btnText.color = Color.white; btnText.fontSize = 16; + btnText.fontStyle = FontStyle.Normal; btn.data = index; _tabGroup.AddTab(tabRect, btn); @@ -488,6 +502,12 @@ public class MyWindowWithTabs : MyWindow public void AddSplitter(RectTransform parent, float spacing) { var img = Instantiate(UIRoot.instance.optionWindow.transform.Find("tab-line").Find("bar")); + var image = img.GetComponent(); + if (image) + { + image.color = Color.white; + image.enabled = true; + } Destroy(img.Find("tri").gameObject); _tabY += spacing; var rect = Util.NormalizeRectWithTopLeft(img, 28, _tabY, parent); @@ -633,4 +653,4 @@ public abstract class MyWindowManager } } } -} \ No newline at end of file +} diff --git a/UXAssist/UI/Util.cs b/UXAssist/UI/Util.cs index 87a8a4d..380cc40 100644 --- a/UXAssist/UI/Util.cs +++ b/UXAssist/UI/Util.cs @@ -1,10 +1,34 @@ using UnityEngine; +using UnityEngine.UI; namespace UXAssist.UI; public static class Util { + public static float GetPreferredWidth(Text text) + { + // DSP caches preferred sizes in its custom text generator, separately from Unity's layout queue. + text.SetLayoutDirty(); + return text.preferredWidth; + } + + public static void ResetButton(UIButton button) + { + if (!button) return; + button.enabled = true; + button.highlighted = false; + button.updating = true; + button.data = 0; + button.tips = default; + if (button.button) + { + button.button.enabled = true; + button.button.interactable = true; + } + button.MReset(); + } + public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null) { if (cmp.transform is not RectTransform rect) return null; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index bedc68d..7881d7d 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -232,7 +232,7 @@ public static class UIConfigWindow { y += 36f; txt = wnd.AddText2(x + 2f, y, tab1, I18NKeys.LogicalFrameRate, 15, "game-frame-rate"); - x += txt.preferredWidth + 7f; + x += UI.Util.GetPreferredWidth(txt) + 7f; wnd.AddSlider(x, y + 6f, tab1, GamePatch.GameUpsFactor, new UpsMapper(), "0.0x", 100f).WithSmallerHandle(); var btn = wnd.AddFlatButton(x + 104f, y + 6f, tab1, I18NKeys.Reset, 13, "reset-game-frame-rate", () => GamePatch.GameUpsFactor.Value = 1.0f); ((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f); @@ -240,7 +240,7 @@ public static class UIConfigWindow } y += 36f; txt = wnd.AddText2(x + 2f, y, tab1, I18NKeys.ProcessPriority, 15, "process-priority"); - wnd.AddComboBox(x + 7f + txt.preferredWidth, y, tab1).WithItems(I18NKeys.High, I18NKeys.AboveNormal, I18NKeys.Normal, I18NKeys.BelowNormal, I18NKeys.Idle).WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority); + wnd.AddComboBox(x + 7f + UI.Util.GetPreferredWidth(txt), y, tab1).WithItems(I18NKeys.High, I18NKeys.AboveNormal, I18NKeys.Normal, I18NKeys.BelowNormal, I18NKeys.Idle).WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority); var tab2 = wnd.AddTab(trans, I18NKeys.Factory); x = 0f; @@ -252,11 +252,11 @@ public static class UIConfigWindow checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.NightLightEnabled, I18NKeys.NightLight); x += checkBoxForMeasureTextWidth.Width + 5f + 10f; txt = wnd.AddText2(x, y + 2f, tab2, I18NKeys.AngleX, 13, "text-nightlight-angle-x"); - x += txt.preferredWidth + 5f; + x += UI.Util.GetPreferredWidth(txt) + 5f; wnd.AddSlider(x, y + 7f, tab2, FactoryConfigProvider.NightLightAngleX, new AngleMapper(), "0", 60f).WithSmallerHandle(); x += 70f; txt = wnd.AddText2(x, y + 2f, tab2, "Y:", 13, "text-nightlight-angle-y"); - wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryConfigProvider.NightLightAngleY, new AngleMapper(), "0", 60f).WithSmallerHandle(); + wnd.AddSlider(x + UI.Util.GetPreferredWidth(txt) + 5f, y + 7f, tab2, FactoryConfigProvider.NightLightAngleY, new AngleMapper(), "0", 60f).WithSmallerHandle(); x = 0; y += 36f; wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.LargerAreaForUpgradeAndDismantleEnabled, I18NKeys.LargerAreaForUpgradeAndDismantle); @@ -276,7 +276,7 @@ public static class UIConfigWindow var cb = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.TankFastFillInAndTakeOutEnabled, I18NKeys.FastFillInToAndTakeOutFromTanks); x += cb.Width + 5f; txt = wnd.AddText2(x, y + 2f, tab2, I18NKeys.SpeedRatio, 13, "text-tank-fast-fill-speed-ratio"); - var tankSlider = wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryConfigProvider.TankFastFillInAndTakeOutMultiplier, [2, 5, 10, 20, 50, 100, 500, 1000], "G", 100f).WithSmallerHandle(); + var tankSlider = wnd.AddSlider(x + UI.Util.GetPreferredWidth(txt) + 5f, y + 7f, tab2, FactoryConfigProvider.TankFastFillInAndTakeOutMultiplier, [2, 5, 10, 20, 50, 100, 500, 1000], "G", 100f).WithSmallerHandle(); FactoryConfigProvider.TankFastFillInAndTakeOutEnabled.SettingChanged += TankSettingChanged; wnd.OnFree += () => { FactoryConfigProvider.TankFastFillInAndTakeOutEnabled.SettingChanged -= TankSettingChanged; }; TankSettingChanged(null, null); @@ -369,7 +369,7 @@ public static class UIConfigWindow wnd.AddButton(x, y, 200, tab2, I18NKeys.QuickBuildOrbitalCollectors, 16, "button-init-planet", PlanetFunctions.BuildOrbitalCollectors); y += 30f; txt = wnd.AddText2(x + 10f, y, tab2, I18NKeys.MaximumCountToBuild, 15, "text-oc-build-count"); - wnd.AddSlider(x + 10f + txt.preferredWidth + 5f, y + 6f, tab2, PlanetFunctions.OrbitalCollectorMaxBuildCount, new OcMapper(), "G", 160f); + wnd.AddSlider(x + 10f + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab2, PlanetFunctions.OrbitalCollectorMaxBuildCount, new OcMapper(), "G", 160f); y += 18f; @@ -380,28 +380,28 @@ public static class UIConfigWindow I18NKeys.TweakBuildingBuffersTips, "tweak-building-buffers-tips"); y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferTimeMultiplierInSeconds, 13); - var nx1 = txt.preferredWidth + 5f; + var nx1 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferMinimumMultiplier, 13); - var nx2 = txt.preferredWidth + 5f; + var nx2 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForAssemblingInLabs, 13); - var nx3 = txt.preferredWidth + 5f; + var nx3 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.ExtraBufferCountForSelfEvolutionLabs, 13); - var nx4 = txt.preferredWidth + 5f; + var nx4 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForResearchingInLabs, 13); - var nx5 = txt.preferredWidth + 5f; + var nx5 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.RayReceiverGravitonLensBufferCount, 13); - var nx6 = txt.preferredWidth + 5f; + var nx6 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.EjectorSolarSailsBufferCount, 13); - var nx7 = txt.preferredWidth + 5f; + var nx7 = UI.Util.GetPreferredWidth(txt) + 5f; y += 27f; txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.SiloRocketsBufferCount, 13); - var nx8 = txt.preferredWidth + 5f; + var nx8 = UI.Util.GetPreferredWidth(txt) + 5f; y -= 189f; var mx = Mathf.Max(nx1, nx2, nx3, nx4, nx5, nx6, nx7, nx8) + 20f; var assemblerBufferTimeMultiplierSlider = wnd.AddSlider(x + mx, y + 5f, tab2, FactoryConfigProvider.AssemblerBufferTimeMultiplier, new MyWindow.RangeValueMapper(2, 10), "0", 120f).WithSmallerHandle(); @@ -484,13 +484,14 @@ public static class UIConfigWindow { txt = wnd.AddText2(x, y + 4f, tab3, I18NKeys.OrbitalCollectorProductLimit, 15, "text-orbital-collector-product-limit"); var productLimitConfig = LogisticsConfigProvider.OrbitalCollectorProductLimit; - var productLimitInput = wnd.AddInputField(x + txt.preferredWidth + 10f, y, tab3, productLimitConfig.Value.ToString(), 15, + var productLimitLabelWidth = UI.Util.GetPreferredWidth(txt); + var productLimitInput = wnd.AddInputField(x + productLimitLabelWidth + 10f, y, tab3, productLimitConfig.Value.ToString(), 15, "input-orbital-collector-product-limit"); productLimitInput.onEndEdit.AddListener(SetProductLimit); productLimitInput.contentType = UnityEngine.UI.InputField.ContentType.IntegerNumber; productLimitInput.characterValidation = UnityEngine.UI.InputField.CharacterValidation.Integer; (productLimitInput.transform as RectTransform).sizeDelta = new Vector2(100f, (productLimitInput.transform as RectTransform).sizeDelta.y); - wnd.AddButton(x + txt.preferredWidth + 120f, y, 130f, tab3, I18NKeys.ApplyToUniverse, 14, + wnd.AddButton(x + productLimitLabelWidth + 120f, y, 130f, tab3, I18NKeys.ApplyToUniverse, 14, "button-apply-orbital-collector-product-limit", () => { SetProductLimit(productLimitInput.text); @@ -521,73 +522,73 @@ public static class UIConfigWindow var oy = y; x = 20f; var textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-dispenser-max-charging-power"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfBotsFilled, 13, "text-dispenser-count-of-bots-filled"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; wnd.AddText2(10f, y, tab3, I18NKeys.BattlefieldAnalysisBase, 14, "text-battlefield-analysis-base"); var battleBaseCatY = y; y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-battlefield-analysis-base-max-charging-power"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; wnd.AddText2(10f, y, tab3, I18NKeys.PLS, 14, "text-pls"); var plsCatY = y; y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-pls-max-charging-power"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.DroneTransportRange, 13, "text-pls-drone-transport-range"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfDrones, 13, "text-pls-min-load-of-drones"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.OutgoingIntegrationCount, 13, "text-pls-outgoing-integration-count"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfDronesFilled, 13, "text-pls-count-of-drones-filled"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; wnd.AddText2(10f, y, tab3, I18NKeys.ILS, 14, "text-ils"); var ilsCatY = y; y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-ils-max-charging-power"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.DroneTransportRange, 13, "text-ils-drone-transport-range"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.VesselTransportRange, 13, "text-ils-vessel-transport-range"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.WarpDistance, 13, "text-ils-warp-distance"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfDrones, 13, "text-ils-min-load-of-drones"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfVessels, 13, "text-ils-min-load-of-vessels"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.OutgoingIntegrationCount, 13, "text-ils-outgoing-integration-count"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfDronesFilled, 13, "text-ils-count-of-drones-filled"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfVesselsFilled, 13, "text-ils-count-of-vessels-filled"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; wnd.AddText2(10f, y, tab3, I18NKeys.AdvancedMiningMachine, 14, "text-amm"); var ammCatY = y; y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CollectingSpeed, 13, "text-amm-collecting-speed"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y += 18f; textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinPilerValue, 13, "text-amm-min-piler-value"); - maxWidth = Mathf.Max(maxWidth, textForMeasureTextWidth.preferredWidth); + maxWidth = Mathf.Max(maxWidth, UI.Util.GetPreferredWidth(textForMeasureTextWidth)); y = oy + 1; var nx = x + maxWidth + 5f + 10f; const float applyBtnWidth = 44f; @@ -704,7 +705,7 @@ public static class UIConfigWindow var autoBoostCheckBox = wnd.AddCheckBox(x + 20f, y, tab4, PlayerPatch.AutoBoostEnabled, I18NKeys.AutoBoost, 13); y += 27f; txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.DistanceToUseWarp, 15, "text-distance-to-warp"); - var navDistanceSlider = wnd.AddSlider(x + 20f + txt.preferredWidth + 5f, y + 6f, tab4, PlayerPatch.DistanceToWarp, new DistanceMapper(), "0.0", 100f); + var navDistanceSlider = wnd.AddSlider(x + 20f + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.DistanceToWarp, new DistanceMapper(), "0.0", 100f); y += 36f; MyCheckBox newAlgorithmCheckBox = wnd.AddCheckBox( @@ -725,7 +726,7 @@ public static class UIConfigWindow y += 27f; txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.UseWarpMinimalEnergy, 15, "use-warp-minimal-energy"); var warpEnergySlider = wnd.AddSideSlider( - x + 20f + txt.preferredWidth + 5f, + x + 20f + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.UseWarperMinimalEnergy, @@ -736,7 +737,7 @@ public static class UIConfigWindow y += 27f; txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.DistanceToUseWarp, 15, "text-new-navigation-distance-to-warp"); var newNavDistanceSlider = wnd.AddSlider( - x + 20f + txt.preferredWidth + 5f, + x + 20f + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.UseWarperDistance, @@ -748,7 +749,7 @@ public static class UIConfigWindow y += 27f; txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.AutoBoostMinimalEnergy, 15, "auto-boost-minimal-energy"); var speedUpEnergySlider = wnd.AddSideSlider( - x + 20f + txt.preferredWidth + 5f, + x + 20f + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.UseSpeedUpMinimalEnergy, @@ -759,7 +760,7 @@ public static class UIConfigWindow y += 27f; txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogHiveFollowDistance, 15, "dark-fog-hive-follow-distance"); var dfHiveSlider = wnd.AddSideSlider( - x + txt.preferredWidth + 5f, + x + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.DFHiveFollowDistance, @@ -770,7 +771,7 @@ public static class UIConfigWindow y += 27f; txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogCarrierFollowDistance, 15, "dark-fog-carrier-follow-distance"); var dfCarrierSlider = wnd.AddSideSlider( - x + txt.preferredWidth + 5f, + x + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab4, PlayerPatch.DFCarrierFollowDistance, @@ -848,7 +849,7 @@ public static class UIConfigWindow x = 400f; y += 36f; txt = wnd.AddText2(x, y, tab5, I18NKeys.AutoFastBuildSpeedMultiplier, 15, "text-auto-fast-build-multiplier"); - wnd.AddSlider(x + txt.preferredWidth + 5f, y + 6f, tab5, DysonSpherePatch.AutoConstructMultiplier, [1, 2, 5, 10, 20, 50, 100], "0", 100f); + wnd.AddSlider(x + UI.Util.GetPreferredWidth(txt) + 5f, y + 6f, tab5, DysonSpherePatch.AutoConstructMultiplier, [1, 2, 5, 10, 20, 50, 100], "0", 100f); _dysonTab = tab5; var tab6 = wnd.AddTab(trans, I18NKeys.TechCombatUI); diff --git a/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs b/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs index 3ffe269..edf2df8 100644 --- a/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs +++ b/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs @@ -67,9 +67,13 @@ public static class GalaxySelectUIPatch CreateSliderWithText(__instance.starCountSlider, out _maxStepTitle, out _maxStepSlider, out _maxStepText, out var maxStepLocalizer); CreateSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText, out var flattenLocalizer); minDistLocalizer.stringKey = Localization.StarDistanceMin; + _minDistTitle.text = Localization.StarDistanceMin.Translate(); minStepLocalizer.stringKey = Localization.StepDistanceMin; + _minStepTitle.text = Localization.StepDistanceMin.Translate(); maxStepLocalizer.stringKey = Localization.StepDistanceMax; + _maxStepTitle.text = Localization.StepDistanceMax.Translate(); flattenLocalizer.stringKey = Localization.Flatness; + _flattenTitle.text = Localization.Flatness.Translate(); _minDistTitle.name = "min-dist"; _minStepTitle.name = "min-step"; @@ -120,8 +124,31 @@ public static class GalaxySelectUIPatch { var origText = orig.transform.parent.GetComponent(); title = Object.Instantiate(origText, origText.transform.parent); + title.text = ""; + title.color = Color.white; + title.fontStyle = FontStyle.Normal; + title.horizontalOverflow = HorizontalWrapMode.Overflow; + title.verticalOverflow = VerticalWrapMode.Overflow; + title.enabled = true; + foreach (var button in title.GetComponentsInChildren(true)) + { + UXAssist.UI.Util.ResetButton(button); + } + foreach (var image in title.GetComponentsInChildren(true)) + { + image.enabled = true; + } slider = title.transform.FindChildRecur("Slider").GetComponent(); + slider.enabled = true; + slider.interactable = true; + slider.onValueChanged.RemoveAllListeners(); text = slider.transform.FindChildRecur("Text").GetComponent(); + text.text = ""; + text.color = Color.white; + text.fontStyle = FontStyle.Normal; + text.horizontalOverflow = HorizontalWrapMode.Overflow; + text.verticalOverflow = VerticalWrapMode.Overflow; + text.enabled = true; loc = title.GetComponent(); }