fix(UXAssist): reset cloned UI state

This commit is contained in:
soarqin committed 2026-09-02 18:47:37 +08:00
1 parent f611f2f9b3
commit 574919f1f0
21 files changed
+308 -58

No files matched your search

+1
View File
@@ -153,6 +153,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod`
- **Fail-soft patch application:** `PatchImpl<T>.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. - **Fail-soft patch application:** `PatchImpl<T>.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. - **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.
- **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. - **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. - **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. - **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.
+2 -2
View File
@@ -278,7 +278,7 @@ public static class UIConfigWindow
}); });
y += 30f; y += 30f;
var txt2 = wnd.AddText2(x, y, tab4, "Shells count", 15, "text-shells-count"); 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; Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged += onIllegalDysonShellFunctionsChanged;
wnd.OnFree += () => { Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged -= onIllegalDysonShellFunctionsChanged; }; wnd.OnFree += () => { Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged -= onIllegalDysonShellFunctionsChanged; };
@@ -337,4 +337,4 @@ public static class UIConfigWindow
_clearBanBtn.gameObject.SetActive(banEnabled); _clearBanBtn.gameObject.SetActive(banEnabled);
} }
} }
} }
+3
View File
@@ -78,6 +78,9 @@ internal static class AutoConstructUI
ConstructCountText.color = new Color(1f, 1f, 1f, 0.4f); ConstructCountText.color = new Color(1f, 1f, 1f, 0.4f);
ConstructCountText.alignment = TextAnchor.MiddleLeft; ConstructCountText.alignment = TextAnchor.MiddleLeft;
ConstructCountText.fontSize = 16; ConstructCountText.fontSize = 16;
ConstructCountText.fontStyle = FontStyle.Normal;
ConstructCountText.horizontalOverflow = HorizontalWrapMode.Overflow;
ConstructCountText.verticalOverflow = VerticalWrapMode.Overflow;
rectTrans = ConstructCountText.rectTransform; rectTrans = ConstructCountText.rectTransform;
rectTrans.SetParent(ConstructCountPanel.transform); rectTrans.SetParent(ConstructCountPanel.transform);
rectTrans.sizeDelta = new Vector2(150f, 20f); rectTrans.sizeDelta = new Vector2(150f, 20f);
+9
View File
@@ -77,6 +77,12 @@ internal static class MenuButtonUI
var parent = src.transform.parent; var parent = src.transform.parent;
var btn = GameObject.Instantiate(src, parent); var btn = GameObject.Instantiate(src, parent);
btn.name = "button-uxassist-config"; 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<Localizer>(); var l = btn.text.GetComponent<Localizer>();
if (l != null) if (l != null)
{ {
@@ -103,10 +109,13 @@ internal static class MenuButtonUI
_buttonOnPlanetGlobe = b.gameObject; _buttonOnPlanetGlobe = b.gameObject;
var rect = (RectTransform)_buttonOnPlanetGlobe.transform; var rect = (RectTransform)_buttonOnPlanetGlobe.transform;
var btn = _buttonOnPlanetGlobe.GetComponent<UIButton>(); var btn = _buttonOnPlanetGlobe.GetComponent<UIButton>();
global::UXAssist.UI.Util.ResetButton(btn);
var img = _buttonOnPlanetGlobe.transform.Find("button-2/icon")?.GetComponent<Image>(); var img = _buttonOnPlanetGlobe.transform.Find("button-2/icon")?.GetComponent<Image>();
if (img != null) if (img != null)
{ {
img.sprite = icon; img.sprite = icon;
img.color = Color.white;
img.enabled = icon != null;
} }
if (_buttonOnPlanetGlobe != null && btn != null) if (_buttonOnPlanetGlobe != null && btn != null)
+7 -4
View File
@@ -187,6 +187,9 @@ internal static class MilkyWayUI
txt.color = new Color(1f, 1f, 1f, 0.4f); txt.color = new Color(1f, 1f, 1f, 0.4f);
txt.alignment = TextAnchor.MiddleLeft; txt.alignment = TextAnchor.MiddleLeft;
txt.fontSize = 15; txt.fontSize = 15;
txt.fontStyle = FontStyle.Normal;
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
txt.verticalOverflow = VerticalWrapMode.Overflow;
txt.rectTransform.sizeDelta = new Vector2(0, 18); txt.rectTransform.sizeDelta = new Vector2(0, 18);
return txt; return txt;
} }
@@ -266,10 +269,10 @@ internal static class MilkyWayUI
textFields[i * 4 + 1].text = _topTenPlayerData[i].name; textFields[i * 4 + 1].text = _topTenPlayerData[i].name;
textFields[i * 4 + 2].text = SeedToString(_topTenPlayerData[i].seedKey); textFields[i * 4 + 2].text = SeedToString(_topTenPlayerData[i].seedKey);
textFields[i * 4 + 3].text = String.Format("{0}W", ToKMG(_topTenPlayerData[i].genCap * 60L)); textFields[i * 4 + 3].text = String.Format("{0}W", ToKMG(_topTenPlayerData[i].genCap * 60L));
maxWidth0 = Math.Max(maxWidth0, textFields[i * 4].preferredWidth); maxWidth0 = Math.Max(maxWidth0, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4]));
maxWidth1 = Math.Max(maxWidth1, textFields[i * 4 + 1].preferredWidth); maxWidth1 = Math.Max(maxWidth1, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 1]));
maxWidth2 = Math.Max(maxWidth2, textFields[i * 4 + 2].preferredWidth); maxWidth2 = Math.Max(maxWidth2, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 2]));
maxWidth3 = Math.Max(maxWidth3, textFields[i * 4 + 3].preferredWidth); maxWidth3 = Math.Max(maxWidth3, global::UXAssist.UI.Util.GetPreferredWidth(textFields[i * 4 + 3]));
button.gameObject.SetActive(true); button.gameObject.SetActive(true);
textFields[i * 4].gameObject.SetActive(true); textFields[i * 4].gameObject.SetActive(true);
textFields[i * 4 + 1].gameObject.SetActive(true); textFields[i * 4 + 1].gameObject.SetActive(true);
@@ -353,6 +353,9 @@ internal static class RealtimeLogisticsInfoPanel
var y = -5f - 35f * index; var y = -5f - 35f * index;
var itemIcon = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); var itemIcon = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform);
itemIcon.name = "icon" + index; itemIcon.name = "icon" + index;
var itemIconImage = itemIcon.GetComponent<Image>();
itemIconImage.color = Color.white;
itemIconImage.enabled = true;
rectTrans = (RectTransform)itemIcon.transform; rectTrans = (RectTransform)itemIcon.transform;
rectTrans.sizeDelta = new Vector2(30f, 30f); rectTrans.sizeDelta = new Vector2(30f, 30f);
rectTrans.anchorMax = new Vector2(0f, 1f); 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); var sliderBg = Object.Instantiate(sliderBgPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform);
sliderBg.name = "sliderBg" + index; sliderBg.name = "sliderBg" + index;
sliderBg.GetComponent<Image>().enabled = true;
rectTrans = (RectTransform)sliderBg.transform; rectTrans = (RectTransform)sliderBg.transform;
rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight); rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
@@ -398,7 +402,11 @@ internal static class RealtimeLogisticsInfoPanel
var text = countText.GetComponent<Text>(); var text = countText.GetComponent<Text>();
text.fontSize = 18; text.fontSize = 18;
text.text = ""; text.text = "";
text.color = Color.white;
text.alignment = TextAnchor.UpperRight; text.alignment = TextAnchor.UpperRight;
text.fontStyle = FontStyle.Normal;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
text.verticalOverflow = VerticalWrapMode.Overflow;
rectTrans = (RectTransform)countText.transform; rectTrans = (RectTransform)countText.transform;
rectTrans.sizeDelta = new Vector2(70f, 20f); rectTrans.sizeDelta = new Vector2(70f, 20f);
rectTrans.anchorMax = new Vector2(0f, 1f); 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); var stateLocal = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform);
stateLocal.name = "iconLocal" + index; stateLocal.name = "iconLocal" + index;
stateLocal.GetComponent<Image>().material = null; var stateLocalImage = stateLocal.GetComponent<Image>();
stateLocalImage.material = null;
stateLocalImage.color = Color.white;
stateLocalImage.enabled = true;
rectTrans = (RectTransform)stateLocal.transform; rectTrans = (RectTransform)stateLocal.transform;
rectTrans.sizeDelta = new Vector2(16f, 16f); rectTrans.sizeDelta = new Vector2(16f, 16f);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
@@ -418,7 +429,10 @@ internal static class RealtimeLogisticsInfoPanel
rectTrans.anchoredPosition3D = new Vector3(102f, y, 0); rectTrans.anchoredPosition3D = new Vector3(102f, y, 0);
var stateRemote = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); var stateRemote = Object.Instantiate(tipIconPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform);
stateRemote.name = "iconRemote" + index; stateRemote.name = "iconRemote" + index;
stateRemote.GetComponent<Image>().material = null; var stateRemoteImage = stateRemote.GetComponent<Image>();
stateRemoteImage.material = null;
stateRemoteImage.color = Color.white;
stateRemoteImage.enabled = true;
rectTrans = (RectTransform)stateRemote.transform; rectTrans = (RectTransform)stateRemote.transform;
rectTrans.sizeDelta = new Vector2(20f, 20f); rectTrans.sizeDelta = new Vector2(20f, 20f);
rectTrans.anchorMax = new Vector2(0f, 1f); 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 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<Image>();
iconPrefabImage.color = Color.white;
iconPrefabImage.enabled = true;
Object.Destroy(iconPrefab.transform.Find("count-text").gameObject); Object.Destroy(iconPrefab.transform.Find("count-text").gameObject);
Object.Destroy(iconPrefab.transform.Find("bg").gameObject); Object.Destroy(iconPrefab.transform.Find("bg").gameObject);
Object.Destroy(iconPrefab.transform.Find("inc").gameObject); Object.Destroy(iconPrefab.transform.Find("inc").gameObject);
@@ -456,6 +473,9 @@ internal static class RealtimeLogisticsInfoPanel
text.text = "100"; text.text = "100";
text.alignment = TextAnchor.MiddleRight; text.alignment = TextAnchor.MiddleRight;
text.color = Color.white; text.color = Color.white;
text.fontStyle = FontStyle.Normal;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
text.verticalOverflow = VerticalWrapMode.Overflow;
rectTrans = (RectTransform)countText.transform; rectTrans = (RectTransform)countText.transform;
rectTrans.sizeDelta = new Vector2(40f, 30f); rectTrans.sizeDelta = new Vector2(40f, 30f);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
@@ -474,6 +494,9 @@ internal static class RealtimeLogisticsInfoPanel
text.text = "100"; text.text = "100";
text.alignment = TextAnchor.MiddleRight; text.alignment = TextAnchor.MiddleRight;
text.color = Color.white; text.color = Color.white;
text.fontStyle = FontStyle.Normal;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
text.verticalOverflow = VerticalWrapMode.Overflow;
rectTrans = (RectTransform)countText.transform; rectTrans = (RectTransform)countText.transform;
rectTrans.sizeDelta = new Vector2(40f, 30f); rectTrans.sizeDelta = new Vector2(40f, 30f);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
+2
View File
@@ -730,6 +730,8 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
UiTipText = Object.Instantiate(originText, originText.transform.parent); UiTipText = Object.Instantiate(originText, originText.transform.parent);
UiTipText.gameObject.SetActive(false); UiTipText.gameObject.SetActive(false);
UiTipText.rectTransform.anchoredPosition = new Vector2(0f, 160f); UiTipText.rectTransform.anchoredPosition = new Vector2(0f, 160f);
UiTipText.color = Color.white;
UiTipText.fontStyle = FontStyle.Normal;
UiTipText.text = I18NKeys.AutoNavigationActive.Translate(); UiTipText.text = I18NKeys.AutoNavigationActive.Translate();
} }
+6
View File
@@ -160,6 +160,12 @@ public class UIPatch : PatchImpl<UIPatch>
var parent = uiresAmountEntry.labelText.transform.parent; var parent = uiresAmountEntry.labelText.transform.parent;
vt.textCtrl = Object.Instantiate(uiresAmountEntry.valueText, parent); vt.textCtrl = Object.Instantiate(uiresAmountEntry.valueText, parent);
vt.textCtrl.font = uiresAmountEntry.labelText.font; 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; RectTransform trans = vt.textCtrl.rectTransform;
var pos = uiresAmountEntry.rectTrans.localPosition; var pos = uiresAmountEntry.rectTrans.localPosition;
pos.x = pos.x + uiresAmountEntry.iconImage.rectTransform.localPosition.x - 25f; pos.x = pos.x + uiresAmountEntry.iconImage.rectTransform.localPosition.x - 25f;
+10 -1
View File
@@ -25,7 +25,10 @@ public static class LayoutHelper
txt.color = new Color(1f, 1f, 1f, 0.4f); txt.color = new Color(1f, 1f, 1f, 0.4f);
txt.alignment = TextAnchor.MiddleLeft; txt.alignment = TextAnchor.MiddleLeft;
txt.fontSize = fontSize; 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); AddElement(x, y, txt.rectTransform, parent);
return txt; return txt;
} }
@@ -36,6 +39,7 @@ public static class LayoutHelper
var dst = UnityEngine.Object.Instantiate(src); var dst = UnityEngine.Object.Instantiate(src);
dst.gameObject.name = objName; dst.gameObject.name = objName;
var btn = dst.GetComponent<UIButton>(); var btn = dst.GetComponent<UIButton>();
Util.ResetButton(btn);
Util.NormalizeRectWithTopLeft(btn, x, y, parent); Util.NormalizeRectWithTopLeft(btn, x, y, parent);
btn.tips.topLevel = true; btn.tips.topLevel = true;
btn.tips.tipTitle = label; btn.tips.tipTitle = label;
@@ -54,6 +58,7 @@ public static class LayoutHelper
var panel = UIRoot.instance.uiGame.statWindow.performancePanelUI; var panel = UIRoot.instance.uiGame.statWindow.performancePanelUI;
var btn = UnityEngine.Object.Instantiate(panel.cpuActiveButton); var btn = UnityEngine.Object.Instantiate(panel.cpuActiveButton);
btn.gameObject.name = objName; btn.gameObject.name = objName;
Util.ResetButton(btn);
var rect = Util.NormalizeRectWithTopLeft(btn, x, y, parent); var rect = Util.NormalizeRectWithTopLeft(btn, x, y, parent);
rect.sizeDelta = new Vector2(width, rect.sizeDelta.y); rect.sizeDelta = new Vector2(width, rect.sizeDelta.y);
var l = btn.gameObject.transform.Find("button-text").GetComponent<Localizer>(); var l = btn.gameObject.transform.Find("button-text").GetComponent<Localizer>();
@@ -67,6 +72,10 @@ public static class LayoutHelper
if (t != null) if (t != null)
{ {
t.text = text.Translate(); t.text = text.Translate();
t.color = Color.white;
t.fontStyle = FontStyle.Normal;
t.horizontalOverflow = HorizontalWrapMode.Overflow;
t.verticalOverflow = VerticalWrapMode.Overflow;
} }
t.fontSize = fontSize; t.fontSize = fontSize;
+6
View File
@@ -38,6 +38,7 @@ public class MyCheckButton : MonoBehaviour
var go = Instantiate(UIRoot.instance.uiGame.beltWindow.reverseButton.gameObject); var go = Instantiate(UIRoot.instance.uiGame.beltWindow.reverseButton.gameObject);
go.name = "my-checkbutton"; go.name = "my-checkbutton";
go.SetActive(false); go.SetActive(false);
Util.ResetButton(go.GetComponent<UIButton>());
var comp = go.transform.Find("text"); var comp = go.transform.Find("text");
if (comp) if (comp)
{ {
@@ -46,6 +47,8 @@ public class MyCheckButton : MonoBehaviour
{ {
txt.text = ""; txt.text = "";
txt.alignment = TextAnchor.MiddleCenter; txt.alignment = TextAnchor.MiddleCenter;
txt.color = Color.white;
txt.fontStyle = FontStyle.Normal;
txt.rectTransform.anchorMax = new Vector2(0f, 1f); txt.rectTransform.anchorMax = new Vector2(0f, 1f);
txt.rectTransform.anchorMin = new Vector2(0f, 1f); txt.rectTransform.anchorMin = new Vector2(0f, 1f);
txt.rectTransform.pivot = new Vector2(0f, 1f); txt.rectTransform.pivot = new Vector2(0f, 1f);
@@ -82,6 +85,7 @@ public class MyCheckButton : MonoBehaviour
cb.rectTrans = rect; cb.rectTrans = rect;
cb.uiButton = go.GetComponent<UIButton>(); cb.uiButton = go.GetComponent<UIButton>();
Util.ResetButton(cb.uiButton);
var child = go.transform.Find("text"); var child = go.transform.Find("text");
if (child != null) if (child != null)
@@ -91,6 +95,8 @@ public class MyCheckButton : MonoBehaviour
{ {
cb.labelText.text = ""; cb.labelText.text = "";
cb.labelText.fontSize = fontSize; cb.labelText.fontSize = fontSize;
cb.labelText.color = Color.white;
cb.labelText.fontStyle = FontStyle.Normal;
} }
} }
+30 -2
View File
@@ -28,11 +28,30 @@ public class MyCheckBox : MonoBehaviour
var go = Instantiate(UIRoot.instance.uiGame.buildMenu.uxFacilityCheck.gameObject); var go = Instantiate(UIRoot.instance.uiGame.buildMenu.uxFacilityCheck.gameObject);
go.name = "my-checkbox"; go.name = "my-checkbox";
go.SetActive(false); go.SetActive(false);
Util.ResetButton(go.GetComponent<UIButton>());
var boxImage = go.GetComponent<Image>();
if (boxImage)
{
boxImage.color = BoxColor;
boxImage.enabled = true;
}
var checkImage = go.transform.Find("checked")?.GetComponent<Image>();
if (checkImage)
{
checkImage.color = CheckColor;
checkImage.enabled = false;
}
var comp = go.transform.Find("text"); var comp = go.transform.Find("text");
if (comp) if (comp)
{ {
var txt = comp.GetComponent<Text>(); var txt = comp.GetComponent<Text>();
if (txt) txt.text = ""; if (txt)
{
txt.text = "";
txt.color = TextColor;
txt.alignment = TextAnchor.MiddleLeft;
txt.fontStyle = FontStyle.Normal;
}
var localizer = comp.GetComponent<Localizer>(); var localizer = comp.GetComponent<Localizer>();
if (localizer) DestroyImmediate(localizer); if (localizer) DestroyImmediate(localizer);
} }
@@ -66,6 +85,11 @@ public class MyCheckBox : MonoBehaviour
cb.uiButton = go.GetComponent<UIButton>(); cb.uiButton = go.GetComponent<UIButton>();
cb.boxImage = go.transform.GetComponent<Image>(); cb.boxImage = go.transform.GetComponent<Image>();
cb.checkImage = go.transform.Find("checked")?.GetComponent<Image>(); cb.checkImage = go.transform.Find("checked")?.GetComponent<Image>();
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); Util.NormalizeRectWithTopLeft(cb.checkImage, 0f, 0f);
var child = go.transform.Find("text"); var child = go.transform.Find("text");
@@ -76,17 +100,21 @@ public class MyCheckBox : MonoBehaviour
{ {
cb.labelText.text = ""; cb.labelText.text = "";
cb.labelText.fontSize = fontSize; cb.labelText.fontSize = fontSize;
cb.labelText.color = TextColor;
cb.labelText.alignment = TextAnchor.MiddleLeft;
cb.labelText.fontStyle = FontStyle.Normal;
cb.UpdateLabelTextWidth(); cb.UpdateLabelTextWidth();
} }
} }
cb.SetEnable(true);
cb.uiButton.onClick += cb.OnClick; cb.uiButton.onClick += cb.OnClick;
return cb; return cb;
} }
private void UpdateLabelTextWidth() 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 public bool Checked
+22 -1
View File
@@ -21,6 +21,10 @@ public class MyComboBox : MonoBehaviour
var go = Instantiate(UIRoot.instance.optionWindow.resolutionComp.gameObject); var go = Instantiate(UIRoot.instance.optionWindow.resolutionComp.gameObject);
go.name = "my-combobox"; go.name = "my-combobox";
go.SetActive(false); go.SetActive(false);
foreach (var button in go.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
var rect = (RectTransform)go.transform; var rect = (RectTransform)go.transform;
var cbctrl = rect.GetComponent<UIComboBox>(); var cbctrl = rect.GetComponent<UIComboBox>();
@@ -38,6 +42,7 @@ public class MyComboBox : MonoBehaviour
txtComp.font = fontSource.font; txtComp.font = fontSource.font;
txtComp.fontSize = fontSource.fontSize; txtComp.fontSize = fontSource.fontSize;
txtComp.fontStyle = fontSource.fontStyle; txtComp.fontStyle = fontSource.fontStyle;
txtComp.color = Color.white;
} }
txtComp = rect.Find("Main Button/Text")?.GetComponent<Text>(); txtComp = rect.Find("Main Button/Text")?.GetComponent<Text>();
if (txtComp) if (txtComp)
@@ -45,10 +50,22 @@ public class MyComboBox : MonoBehaviour
txtComp.font = fontSource.font; txtComp.font = fontSource.font;
txtComp.fontSize = fontSource.fontSize; txtComp.fontSize = fontSource.fontSize;
txtComp.fontStyle = fontSource.fontStyle; txtComp.fontStyle = fontSource.fontStyle;
txtComp.color = Color.white;
} }
} }
cbctrl.onSubmit.RemoveAllListeners(); cbctrl.onSubmit.RemoveAllListeners();
cbctrl.onItemIndexChange.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; _baseObject = go;
} }
@@ -58,6 +75,10 @@ public class MyComboBox : MonoBehaviour
gameObject.name = "my-combobox"; gameObject.name = "my-combobox";
gameObject.SetActive(true); gameObject.SetActive(true);
var cb = gameObject.AddComponent<MyComboBox>(); var cb = gameObject.AddComponent<MyComboBox>();
foreach (var button in gameObject.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent); var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
cb._rectTrans = rtrans; cb._rectTrans = rtrans;
var box = rtrans.GetComponent<UIComboBox>(); var box = rtrans.GetComponent<UIComboBox>();
@@ -161,4 +182,4 @@ public class MyComboBox : MonoBehaviour
public float Width => _rectTrans.sizeDelta.x; public float Width => _rectTrans.sizeDelta.x;
public float Height => _rectTrans.sizeDelta.y; public float Height => _rectTrans.sizeDelta.y;
} }
+20
View File
@@ -21,16 +21,32 @@ public class MyCornerComboBox : MonoBehaviour
var go = Instantiate(UIRoot.instance.uiGame.starDetail.displayCombo.gameObject); var go = Instantiate(UIRoot.instance.uiGame.starDetail.displayCombo.gameObject);
go.name = "my-small-combobox"; go.name = "my-small-combobox";
go.SetActive(false); go.SetActive(false);
foreach (var button in go.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
var cbctrl = go.transform.GetComponent<UIComboBox>(); var cbctrl = go.transform.GetComponent<UIComboBox>();
cbctrl.onSubmit.RemoveAllListeners(); cbctrl.onSubmit.RemoveAllListeners();
cbctrl.onItemIndexChange.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) foreach (var button in cbctrl.ItemButtons)
{ {
Destroy(button.gameObject); Destroy(button.gameObject);
} }
cbctrl.Items.Clear(); cbctrl.Items.Clear();
cbctrl.ItemButtons.Clear(); cbctrl.ItemButtons.Clear();
cbctrl.m_ListItemRes.GetComponentInChildren<Text>().color = Color.white;
_baseObject = go; _baseObject = go;
} }
@@ -40,6 +56,10 @@ public class MyCornerComboBox : MonoBehaviour
gameObject.name = "my-combobox"; gameObject.name = "my-combobox";
gameObject.SetActive(true); gameObject.SetActive(true);
var cb = gameObject.AddComponent<MyCornerComboBox>(); var cb = gameObject.AddComponent<MyCornerComboBox>();
foreach (var button in gameObject.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
RectTransform rtrans; RectTransform rtrans;
if (topRight) if (topRight)
{ {
+15 -2
View File
@@ -20,18 +20,30 @@ public class MyFlatButton : MonoBehaviour
var btn = go.GetComponent<UIButton>(); var btn = go.GetComponent<UIButton>();
go.GetComponent<Image>().sprite = panel.buttonDefaultSprite; go.GetComponent<Image>().sprite = panel.buttonDefaultSprite;
btn.gameObject.name = "my-flatbutton"; btn.gameObject.name = "my-flatbutton";
go.SetActive(false);
Util.ResetButton(btn);
btn.highlighted = false; btn.highlighted = false;
var img = btn.GetComponent<Image>(); var img = btn.GetComponent<Image>();
if (img != null) if (img != null)
{ {
img.sprite = panel.buttonDefaultSprite; 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<Image>(); img = btn.gameObject.transform.Find("frame")?.GetComponent<Image>();
if (img != null) 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<Text>();
if (text)
{
text.text = "";
text.color = Color.white;
text.fontStyle = FontStyle.Normal;
} }
btn.button.onClick.RemoveAllListeners(); btn.button.onClick.RemoveAllListeners();
@@ -53,6 +65,7 @@ public class MyFlatButton : MonoBehaviour
cb.rectTrans = rect; cb.rectTrans = rect;
cb.uiButton = go.GetComponent<UIButton>(); cb.uiButton = go.GetComponent<UIButton>();
Util.ResetButton(cb.uiButton);
cb.labelText = go.transform.Find("Text")?.GetComponent<Text>(); cb.labelText = go.transform.Find("Text")?.GetComponent<Text>();
cb.uiButton.onClick += onClick; cb.uiButton.onClick += onClick;
+16 -1
View File
@@ -60,6 +60,21 @@ public class MyKeyBinder : MonoBehaviour
kb.setDefaultUIButton = uikeyEntry.setDefaultUIButton; kb.setDefaultUIButton = uikeyEntry.setDefaultUIButton;
kb.setNoneKeyUIButton = uikeyEntry.setNoneKeyUIButton; 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.text = label.Translate();
kb.functionText.fontSize = 17; kb.functionText.fontSize = 17;
@@ -232,4 +247,4 @@ public class MyKeyBinder : MonoBehaviour
{ {
keyText.text = _config.Value.Serialize(); keyText.text = _config.Value.Serialize();
} }
} }
+8
View File
@@ -24,6 +24,10 @@ public class MySideSlider : MonoBehaviour
var go = Instantiate(UIRoot.instance.uiGame.stationWindow.maxMiningSpeedGroup.gameObject); var go = Instantiate(UIRoot.instance.uiGame.stationWindow.maxMiningSpeedGroup.gameObject);
//sizeDelta = 240, 20 //sizeDelta = 240, 20
go.name = "my-side-slider"; go.name = "my-side-slider";
foreach (var button in go.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
Destroy(go.transform.Find("label").gameObject); Destroy(go.transform.Find("label").gameObject);
Destroy(go.GetComponent<UIButton>()); Destroy(go.GetComponent<UIButton>());
go.SetActive(true); go.SetActive(true);
@@ -34,6 +38,7 @@ public class MySideSlider : MonoBehaviour
sl.slider = go.transform.Find("slider").GetComponent<Slider>(); sl.slider = go.transform.Find("slider").GetComponent<Slider>();
sl.slider.minValue = 0f; sl.slider.minValue = 0f;
sl.slider.maxValue = 100f; sl.slider.maxValue = 100f;
sl.slider.interactable = true;
sl.slider.onValueChanged.RemoveAllListeners(); sl.slider.onValueChanged.RemoveAllListeners();
sl.slider.onValueChanged.AddListener(sl.SliderChanged); sl.slider.onValueChanged.AddListener(sl.SliderChanged);
if (width == 0) width = 160f; if (width == 0) width = 160f;
@@ -45,6 +50,9 @@ public class MySideSlider : MonoBehaviour
sl.Value = 0f; sl.Value = 0f;
sl.labelText = go.transform.Find("value").GetComponent<Text>(); sl.labelText = go.transform.Find("value").GetComponent<Text>();
sl.labelText.text = "";
sl.labelText.color = Color.white;
sl.labelText.fontStyle = FontStyle.Normal;
sl.labelText.alignment = textWidth <= 0f ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight; sl.labelText.alignment = textWidth <= 0f ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight;
if (sl.labelText.transform is RectTransform rectTrans2) if (sl.labelText.transform is RectTransform rectTrans2)
{ {
+11
View File
@@ -29,6 +29,10 @@ public class MySlider : MonoBehaviour
//sizeDelta = 240, 20 //sizeDelta = 240, 20
go.name = "my-slider"; go.name = "my-slider";
go.SetActive(true); go.SetActive(true);
foreach (var button in go.GetComponentsInChildren<UIButton>(true))
{
Util.ResetButton(button);
}
var sl = go.AddComponent<MySlider>(); var sl = go.AddComponent<MySlider>();
var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent); var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent);
sl.rectTrans = rect; sl.rectTrans = rect;
@@ -40,12 +44,17 @@ public class MySlider : MonoBehaviour
sl.slider = go.GetComponent<Slider>(); sl.slider = go.GetComponent<Slider>();
sl.slider.minValue = 0f; sl.slider.minValue = 0f;
sl.slider.maxValue = 100f; sl.slider.maxValue = 100f;
sl.slider.interactable = true;
sl.slider.onValueChanged.RemoveAllListeners(); sl.slider.onValueChanged.RemoveAllListeners();
sl.slider.onValueChanged.AddListener(sl.SliderChanged); sl.slider.onValueChanged.AddListener(sl.SliderChanged);
sl.Value = 0f; sl.Value = 0f;
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>(); sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
if (sl.labelText) 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; sl.labelText.fontSize = 14;
if (sl.labelText.transform is RectTransform rectTrans) if (sl.labelText.transform is RectTransform rectTrans)
{ {
@@ -60,11 +69,13 @@ public class MySlider : MonoBehaviour
if (bg != null) if (bg != null)
{ {
bg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); bg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
bg.enabled = true;
} }
var fill = sl.slider.fillRect.GetComponent<Image>(); var fill = sl.slider.fillRect.GetComponent<Image>();
if (fill != null) if (fill != null)
{ {
fill.color = new Color(1f, 1f, 1f, 0.28f); fill.color = new Color(1f, 1f, 1f, 0.28f);
fill.enabled = true;
} }
sl.UpdateLabel(); sl.UpdateLabel();
+21 -1
View File
@@ -48,6 +48,7 @@ public class MyWindow : ManualBehaviour
var go = Instantiate(_baseObject, UIRoot.instance.uiGame.transform.parent); var go = Instantiate(_baseObject, UIRoot.instance.uiGame.transform.parent);
go.name = name; go.name = name;
go.SetActive(false); go.SetActive(false);
Util.ResetButton(go.transform.Find("panel-bg")?.GetComponentInChildren<UIButton>());
MyWindow win = go.AddComponent<T>(); MyWindow win = go.AddComponent<T>();
if (!win) return null; if (!win) return null;
@@ -385,9 +386,13 @@ public class MyWindow : ManualBehaviour
inputField.gameObject.name = objName; inputField.gameObject.name = objName;
Destroy(inputField.GetComponent<UIButton>()); Destroy(inputField.GetComponent<UIButton>());
inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f); inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f);
inputField.GetComponent<Image>().enabled = true;
inputField.interactable = true;
var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent); var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent);
rect.sizeDelta = new Vector2(210, rect.sizeDelta.y); rect.sizeDelta = new Vector2(210, rect.sizeDelta.y);
inputField.text = text; inputField.text = text;
inputField.textComponent.color = Color.white;
inputField.textComponent.fontStyle = FontStyle.Normal;
inputField.textComponent.fontSize = fontSize; inputField.textComponent.fontSize = fontSize;
inputField.onValueChanged.RemoveAllListeners(); inputField.onValueChanged.RemoveAllListeners();
@@ -408,9 +413,13 @@ public class MyWindow : ManualBehaviour
inputField.gameObject.name = objName; inputField.gameObject.name = objName;
Destroy(inputField.GetComponent<UIButton>()); Destroy(inputField.GetComponent<UIButton>());
inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f); inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f);
inputField.GetComponent<Image>().enabled = true;
inputField.interactable = true;
var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent); var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent);
rect.sizeDelta = new Vector2(width, rect.sizeDelta.y); rect.sizeDelta = new Vector2(width, rect.sizeDelta.y);
inputField.text = config.Value; inputField.text = config.Value;
inputField.textComponent.color = Color.white;
inputField.textComponent.fontStyle = FontStyle.Normal;
inputField.textComponent.fontSize = fontSize; inputField.textComponent.fontSize = fontSize;
inputField.onValueChanged.RemoveAllListeners(); inputField.onValueChanged.RemoveAllListeners();
@@ -447,7 +456,10 @@ public class MyWindowWithTabs : MyWindow
var swarmPanel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel; var swarmPanel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel;
var src = swarmPanel.orbitButtons[0]; var src = swarmPanel.orbitButtons[0];
var btn = Instantiate(src); var btn = Instantiate(src);
Util.ResetButton(btn);
btn.gameObject.GetComponent<Image>().sprite = swarmPanel.buttonDefaultSprite; btn.gameObject.GetComponent<Image>().sprite = swarmPanel.buttonDefaultSprite;
btn.gameObject.GetComponent<Image>().color = Color.white;
btn.gameObject.GetComponent<Image>().enabled = true;
btn.name = "tab-btn-" + index; btn.name = "tab-btn-" + index;
btn.highlighted = false; btn.highlighted = false;
@@ -468,7 +480,9 @@ public class MyWindowWithTabs : MyWindow
shadow.effectColor = new Color(0f, 0f, 0f, 0.4f); shadow.effectColor = new Color(0f, 0f, 0f, 0.4f);
shadow.effectDistance = new Vector2(1f, -1f); shadow.effectDistance = new Vector2(1f, -1f);
btnText.text = label.Translate(); btnText.text = label.Translate();
btnText.color = Color.white;
btnText.fontSize = 16; btnText.fontSize = 16;
btnText.fontStyle = FontStyle.Normal;
btn.data = index; btn.data = index;
_tabGroup.AddTab(tabRect, btn); _tabGroup.AddTab(tabRect, btn);
@@ -488,6 +502,12 @@ public class MyWindowWithTabs : MyWindow
public void AddSplitter(RectTransform parent, float spacing) public void AddSplitter(RectTransform parent, float spacing)
{ {
var img = Instantiate(UIRoot.instance.optionWindow.transform.Find("tab-line").Find("bar")); var img = Instantiate(UIRoot.instance.optionWindow.transform.Find("tab-line").Find("bar"));
var image = img.GetComponent<Image>();
if (image)
{
image.color = Color.white;
image.enabled = true;
}
Destroy(img.Find("tri").gameObject); Destroy(img.Find("tri").gameObject);
_tabY += spacing; _tabY += spacing;
var rect = Util.NormalizeRectWithTopLeft(img, 28, _tabY, parent); var rect = Util.NormalizeRectWithTopLeft(img, 28, _tabY, parent);
@@ -633,4 +653,4 @@ public abstract class MyWindowManager
} }
} }
} }
} }
+24
View File
@@ -1,10 +1,34 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
namespace UXAssist.UI; namespace UXAssist.UI;
public static class Util 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) public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null)
{ {
if (cmp.transform is not RectTransform rect) return null; if (cmp.transform is not RectTransform rect) return null;
+43 -42
View File
@@ -232,7 +232,7 @@ public static class UIConfigWindow
{ {
y += 36f; y += 36f;
txt = wnd.AddText2(x + 2f, y, tab1, I18NKeys.LogicalFrameRate, 15, "game-frame-rate"); 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(); 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); 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); ((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
@@ -240,7 +240,7 @@ public static class UIConfigWindow
} }
y += 36f; y += 36f;
txt = wnd.AddText2(x + 2f, y, tab1, I18NKeys.ProcessPriority, 15, "process-priority"); 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); var tab2 = wnd.AddTab(trans, I18NKeys.Factory);
x = 0f; x = 0f;
@@ -252,11 +252,11 @@ public static class UIConfigWindow
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.NightLightEnabled, I18NKeys.NightLight); checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.NightLightEnabled, I18NKeys.NightLight);
x += checkBoxForMeasureTextWidth.Width + 5f + 10f; x += checkBoxForMeasureTextWidth.Width + 5f + 10f;
txt = wnd.AddText2(x, y + 2f, tab2, I18NKeys.AngleX, 13, "text-nightlight-angle-x"); 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(); wnd.AddSlider(x, y + 7f, tab2, FactoryConfigProvider.NightLightAngleX, new AngleMapper(), "0", 60f).WithSmallerHandle();
x += 70f; x += 70f;
txt = wnd.AddText2(x, y + 2f, tab2, "Y:", 13, "text-nightlight-angle-y"); 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; x = 0;
y += 36f; y += 36f;
wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.LargerAreaForUpgradeAndDismantleEnabled, I18NKeys.LargerAreaForUpgradeAndDismantle); 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); var cb = wnd.AddCheckBox(x, y, tab2, FactoryConfigProvider.TankFastFillInAndTakeOutEnabled, I18NKeys.FastFillInToAndTakeOutFromTanks);
x += cb.Width + 5f; x += cb.Width + 5f;
txt = wnd.AddText2(x, y + 2f, tab2, I18NKeys.SpeedRatio, 13, "text-tank-fast-fill-speed-ratio"); 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; FactoryConfigProvider.TankFastFillInAndTakeOutEnabled.SettingChanged += TankSettingChanged;
wnd.OnFree += () => { FactoryConfigProvider.TankFastFillInAndTakeOutEnabled.SettingChanged -= TankSettingChanged; }; wnd.OnFree += () => { FactoryConfigProvider.TankFastFillInAndTakeOutEnabled.SettingChanged -= TankSettingChanged; };
TankSettingChanged(null, null); 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); wnd.AddButton(x, y, 200, tab2, I18NKeys.QuickBuildOrbitalCollectors, 16, "button-init-planet", PlanetFunctions.BuildOrbitalCollectors);
y += 30f; y += 30f;
txt = wnd.AddText2(x + 10f, y, tab2, I18NKeys.MaximumCountToBuild, 15, "text-oc-build-count"); 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; y += 18f;
@@ -380,28 +380,28 @@ public static class UIConfigWindow
I18NKeys.TweakBuildingBuffersTips, "tweak-building-buffers-tips"); I18NKeys.TweakBuildingBuffersTips, "tweak-building-buffers-tips");
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferTimeMultiplierInSeconds, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferTimeMultiplierInSeconds, 13);
var nx1 = txt.preferredWidth + 5f; var nx1 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferMinimumMultiplier, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.AssemblerBufferMinimumMultiplier, 13);
var nx2 = txt.preferredWidth + 5f; var nx2 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForAssemblingInLabs, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForAssemblingInLabs, 13);
var nx3 = txt.preferredWidth + 5f; var nx3 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.ExtraBufferCountForSelfEvolutionLabs, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.ExtraBufferCountForSelfEvolutionLabs, 13);
var nx4 = txt.preferredWidth + 5f; var nx4 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForResearchingInLabs, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.BufferCountForResearchingInLabs, 13);
var nx5 = txt.preferredWidth + 5f; var nx5 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.RayReceiverGravitonLensBufferCount, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.RayReceiverGravitonLensBufferCount, 13);
var nx6 = txt.preferredWidth + 5f; var nx6 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.EjectorSolarSailsBufferCount, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.EjectorSolarSailsBufferCount, 13);
var nx7 = txt.preferredWidth + 5f; var nx7 = UI.Util.GetPreferredWidth(txt) + 5f;
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.SiloRocketsBufferCount, 13); txt = wnd.AddText2(x + 20f, y, tab2, I18NKeys.SiloRocketsBufferCount, 13);
var nx8 = txt.preferredWidth + 5f; var nx8 = UI.Util.GetPreferredWidth(txt) + 5f;
y -= 189f; y -= 189f;
var mx = Mathf.Max(nx1, nx2, nx3, nx4, nx5, nx6, nx7, nx8) + 20f; 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<int>(2, 10), "0", 120f).WithSmallerHandle(); var assemblerBufferTimeMultiplierSlider = wnd.AddSlider(x + mx, y + 5f, tab2, FactoryConfigProvider.AssemblerBufferTimeMultiplier, new MyWindow.RangeValueMapper<int>(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"); txt = wnd.AddText2(x, y + 4f, tab3, I18NKeys.OrbitalCollectorProductLimit, 15, "text-orbital-collector-product-limit");
var productLimitConfig = LogisticsConfigProvider.OrbitalCollectorProductLimit; 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"); "input-orbital-collector-product-limit");
productLimitInput.onEndEdit.AddListener(SetProductLimit); productLimitInput.onEndEdit.AddListener(SetProductLimit);
productLimitInput.contentType = UnityEngine.UI.InputField.ContentType.IntegerNumber; productLimitInput.contentType = UnityEngine.UI.InputField.ContentType.IntegerNumber;
productLimitInput.characterValidation = UnityEngine.UI.InputField.CharacterValidation.Integer; productLimitInput.characterValidation = UnityEngine.UI.InputField.CharacterValidation.Integer;
(productLimitInput.transform as RectTransform).sizeDelta = new Vector2(100f, (productLimitInput.transform as RectTransform).sizeDelta.y); (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", () => "button-apply-orbital-collector-product-limit", () =>
{ {
SetProductLimit(productLimitInput.text); SetProductLimit(productLimitInput.text);
@@ -521,73 +522,73 @@ public static class UIConfigWindow
var oy = y; var oy = y;
x = 20f; x = 20f;
var textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-dispenser-max-charging-power"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfBotsFilled, 13, "text-dispenser-count-of-bots-filled"); 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; y += 18f;
wnd.AddText2(10f, y, tab3, I18NKeys.BattlefieldAnalysisBase, 14, "text-battlefield-analysis-base"); wnd.AddText2(10f, y, tab3, I18NKeys.BattlefieldAnalysisBase, 14, "text-battlefield-analysis-base");
var battleBaseCatY = y; var battleBaseCatY = y;
y += 18f; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-battlefield-analysis-base-max-charging-power"); 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; y += 18f;
wnd.AddText2(10f, y, tab3, I18NKeys.PLS, 14, "text-pls"); wnd.AddText2(10f, y, tab3, I18NKeys.PLS, 14, "text-pls");
var plsCatY = y; var plsCatY = y;
y += 18f; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-pls-max-charging-power"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.DroneTransportRange, 13, "text-pls-drone-transport-range"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfDrones, 13, "text-pls-min-load-of-drones"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.OutgoingIntegrationCount, 13, "text-pls-outgoing-integration-count"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfDronesFilled, 13, "text-pls-count-of-drones-filled"); 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; y += 18f;
wnd.AddText2(10f, y, tab3, I18NKeys.ILS, 14, "text-ils"); wnd.AddText2(10f, y, tab3, I18NKeys.ILS, 14, "text-ils");
var ilsCatY = y; var ilsCatY = y;
y += 18f; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MaxChargingPower, 13, "text-ils-max-charging-power"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.DroneTransportRange, 13, "text-ils-drone-transport-range"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.VesselTransportRange, 13, "text-ils-vessel-transport-range"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.WarpDistance, 13, "text-ils-warp-distance"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfDrones, 13, "text-ils-min-load-of-drones"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinLoadOfVessels, 13, "text-ils-min-load-of-vessels"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.OutgoingIntegrationCount, 13, "text-ils-outgoing-integration-count"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfDronesFilled, 13, "text-ils-count-of-drones-filled"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CountOfVesselsFilled, 13, "text-ils-count-of-vessels-filled"); 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; y += 18f;
wnd.AddText2(10f, y, tab3, I18NKeys.AdvancedMiningMachine, 14, "text-amm"); wnd.AddText2(10f, y, tab3, I18NKeys.AdvancedMiningMachine, 14, "text-amm");
var ammCatY = y; var ammCatY = y;
y += 18f; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.CollectingSpeed, 13, "text-amm-collecting-speed"); 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; y += 18f;
textForMeasureTextWidth = wnd.AddText2(x, y, tab3, I18NKeys.MinPilerValue, 13, "text-amm-min-piler-value"); 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; y = oy + 1;
var nx = x + maxWidth + 5f + 10f; var nx = x + maxWidth + 5f + 10f;
const float applyBtnWidth = 44f; 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); var autoBoostCheckBox = wnd.AddCheckBox(x + 20f, y, tab4, PlayerPatch.AutoBoostEnabled, I18NKeys.AutoBoost, 13);
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.DistanceToUseWarp, 15, "text-distance-to-warp"); 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; y += 36f;
MyCheckBox newAlgorithmCheckBox = wnd.AddCheckBox( MyCheckBox newAlgorithmCheckBox = wnd.AddCheckBox(
@@ -725,7 +726,7 @@ public static class UIConfigWindow
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.UseWarpMinimalEnergy, 15, "use-warp-minimal-energy"); txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.UseWarpMinimalEnergy, 15, "use-warp-minimal-energy");
var warpEnergySlider = wnd.AddSideSlider( var warpEnergySlider = wnd.AddSideSlider(
x + 20f + txt.preferredWidth + 5f, x + 20f + UI.Util.GetPreferredWidth(txt) + 5f,
y + 6f, y + 6f,
tab4, tab4,
PlayerPatch.UseWarperMinimalEnergy, PlayerPatch.UseWarperMinimalEnergy,
@@ -736,7 +737,7 @@ public static class UIConfigWindow
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.DistanceToUseWarp, 15, "text-new-navigation-distance-to-warp"); txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.DistanceToUseWarp, 15, "text-new-navigation-distance-to-warp");
var newNavDistanceSlider = wnd.AddSlider( var newNavDistanceSlider = wnd.AddSlider(
x + 20f + txt.preferredWidth + 5f, x + 20f + UI.Util.GetPreferredWidth(txt) + 5f,
y + 6f, y + 6f,
tab4, tab4,
PlayerPatch.UseWarperDistance, PlayerPatch.UseWarperDistance,
@@ -748,7 +749,7 @@ public static class UIConfigWindow
y += 27f; y += 27f;
txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.AutoBoostMinimalEnergy, 15, "auto-boost-minimal-energy"); txt = wnd.AddText2(x + 20f, y, tab4, I18NKeys.AutoBoostMinimalEnergy, 15, "auto-boost-minimal-energy");
var speedUpEnergySlider = wnd.AddSideSlider( var speedUpEnergySlider = wnd.AddSideSlider(
x + 20f + txt.preferredWidth + 5f, x + 20f + UI.Util.GetPreferredWidth(txt) + 5f,
y + 6f, y + 6f,
tab4, tab4,
PlayerPatch.UseSpeedUpMinimalEnergy, PlayerPatch.UseSpeedUpMinimalEnergy,
@@ -759,7 +760,7 @@ public static class UIConfigWindow
y += 27f; y += 27f;
txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogHiveFollowDistance, 15, "dark-fog-hive-follow-distance"); txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogHiveFollowDistance, 15, "dark-fog-hive-follow-distance");
var dfHiveSlider = wnd.AddSideSlider( var dfHiveSlider = wnd.AddSideSlider(
x + txt.preferredWidth + 5f, x + UI.Util.GetPreferredWidth(txt) + 5f,
y + 6f, y + 6f,
tab4, tab4,
PlayerPatch.DFHiveFollowDistance, PlayerPatch.DFHiveFollowDistance,
@@ -770,7 +771,7 @@ public static class UIConfigWindow
y += 27f; y += 27f;
txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogCarrierFollowDistance, 15, "dark-fog-carrier-follow-distance"); txt = wnd.AddText2(x, y, tab4, I18NKeys.DarkFogCarrierFollowDistance, 15, "dark-fog-carrier-follow-distance");
var dfCarrierSlider = wnd.AddSideSlider( var dfCarrierSlider = wnd.AddSideSlider(
x + txt.preferredWidth + 5f, x + UI.Util.GetPreferredWidth(txt) + 5f,
y + 6f, y + 6f,
tab4, tab4,
PlayerPatch.DFCarrierFollowDistance, PlayerPatch.DFCarrierFollowDistance,
@@ -848,7 +849,7 @@ public static class UIConfigWindow
x = 400f; x = 400f;
y += 36f; y += 36f;
txt = wnd.AddText2(x, y, tab5, I18NKeys.AutoFastBuildSpeedMultiplier, 15, "text-auto-fast-build-multiplier"); 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; _dysonTab = tab5;
var tab6 = wnd.AddTab(trans, I18NKeys.TechCombatUI); var tab6 = wnd.AddTab(trans, I18NKeys.TechCombatUI);
@@ -67,9 +67,13 @@ public static class GalaxySelectUIPatch
CreateSliderWithText(__instance.starCountSlider, out _maxStepTitle, out _maxStepSlider, out _maxStepText, out var maxStepLocalizer); CreateSliderWithText(__instance.starCountSlider, out _maxStepTitle, out _maxStepSlider, out _maxStepText, out var maxStepLocalizer);
CreateSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText, out var flattenLocalizer); CreateSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText, out var flattenLocalizer);
minDistLocalizer.stringKey = Localization.StarDistanceMin; minDistLocalizer.stringKey = Localization.StarDistanceMin;
_minDistTitle.text = Localization.StarDistanceMin.Translate();
minStepLocalizer.stringKey = Localization.StepDistanceMin; minStepLocalizer.stringKey = Localization.StepDistanceMin;
_minStepTitle.text = Localization.StepDistanceMin.Translate();
maxStepLocalizer.stringKey = Localization.StepDistanceMax; maxStepLocalizer.stringKey = Localization.StepDistanceMax;
_maxStepTitle.text = Localization.StepDistanceMax.Translate();
flattenLocalizer.stringKey = Localization.Flatness; flattenLocalizer.stringKey = Localization.Flatness;
_flattenTitle.text = Localization.Flatness.Translate();
_minDistTitle.name = "min-dist"; _minDistTitle.name = "min-dist";
_minStepTitle.name = "min-step"; _minStepTitle.name = "min-step";
@@ -120,8 +124,31 @@ public static class GalaxySelectUIPatch
{ {
var origText = orig.transform.parent.GetComponent<Text>(); var origText = orig.transform.parent.GetComponent<Text>();
title = Object.Instantiate(origText, origText.transform.parent); 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<UIButton>(true))
{
UXAssist.UI.Util.ResetButton(button);
}
foreach (var image in title.GetComponentsInChildren<Image>(true))
{
image.enabled = true;
}
slider = title.transform.FindChildRecur("Slider").GetComponent<Slider>(); slider = title.transform.FindChildRecur("Slider").GetComponent<Slider>();
slider.enabled = true;
slider.interactable = true;
slider.onValueChanged.RemoveAllListeners();
text = slider.transform.FindChildRecur("Text").GetComponent<Text>(); text = slider.transform.FindChildRecur("Text").GetComponent<Text>();
text.text = "";
text.color = Color.white;
text.fontStyle = FontStyle.Normal;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
text.verticalOverflow = VerticalWrapMode.Overflow;
text.enabled = true;
loc = title.GetComponent<Localizer>(); loc = title.GetComponent<Localizer>();
} }