From 15c5bbdd72d89b0c963554a1924c1d16be4b1601 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sat, 11 Jul 2026 01:02:12 +0800 Subject: [PATCH] feat(cheatenabler): add bounded shell-count input --- AGENTS.md | 2 +- CheatEnabler/CheatEnabler.cs | 5 +- .../Functions/DysonSphereFunctions.cs | 3 + CheatEnabler/UIConfigWindow.cs | 55 ++++++++++--------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1f6cddc..566e29e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,7 +52,7 @@ DSP_Mods/ | Mod | GUID | Description | |-----|------|-------------| | **UXAssist** | `org.soardev.uxassist` | Core QoL mod and shared library. Window resize, profile-based saves, FPS control, factory/logistics/navigation/Dyson Sphere tweaks, UI improvements, config panel UI, and `Common/` + `UI/` widget library shared by other mods. The Logistics tab can also push auto-config values to all existing facilities of a type on the current planet (per-setting `Apply` and per-category `Apply All` buttons; logic in `LogisticsPatch.Apply*`/`ForEach*`, wired in `UIConfigWindow`). | -| **CheatEnabler** | `org.soardev.cheatenabler` | Cheat pack (depends on UXAssist). Instant build, architect mode, infinite resources, power boosts, Dyson Sphere cheats, mecha invincibility, and more. | +| **CheatEnabler** | `org.soardev.cheatenabler` | Cheat pack (depends on UXAssist). Instant build, architect mode, infinite resources, power boosts, Dyson Sphere cheats with a bounded shell-count input (1–99,999), mecha invincibility, and more. | | **LogisticMiner** | — | Makes logistic stations automatically mine ores and water from the current planet. | | **HideTips** | — | Suppresses all tutorial popups, random tips, achievement/milestone cards, and skips the prologue cutscene. | | **MechaDronesTweaks** | — | Configurable drone speed multiplier, skip stage-1 animation, reduce energy consumption. Successor to FastDrones. | diff --git a/CheatEnabler/CheatEnabler.cs b/CheatEnabler/CheatEnabler.cs index 457c6c5..9bc4261 100644 --- a/CheatEnabler/CheatEnabler.cs +++ b/CheatEnabler/CheatEnabler.cs @@ -1,5 +1,6 @@ using System.Reflection; using BepInEx; +using BepInEx.Configuration; using CheatEnabler.Patches; using CheatEnabler.Patches.Factory; using UXAssist.Common; @@ -92,7 +93,9 @@ public class CheatEnabler : BaseUnityPlugin Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled = Config.Bind("DysonSphere", "IllegalDysonShellFunctions", false, "Enable illegal dyson shell functions"); Functions.DysonSphereFunctions.ShellsCountForFunctions = Config.Bind("DysonSphere", "ShellsCountForFunctions", 2048, - "Shells count for various functions"); + new ConfigDescription("Shells count for various functions", new AcceptableValueRange( + Functions.DysonSphereFunctions.MinShellsCountForFunctions, + Functions.DysonSphereFunctions.MaxShellsCountForFunctions))); CombatPatch.MechaInvincibleEnabled = Config.Bind("Battle", "MechaInvincible", false, "Mecha and Drones/Fleets invincible"); CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false, diff --git a/CheatEnabler/Functions/DysonSphereFunctions.cs b/CheatEnabler/Functions/DysonSphereFunctions.cs index 6f19d23..467a24a 100644 --- a/CheatEnabler/Functions/DysonSphereFunctions.cs +++ b/CheatEnabler/Functions/DysonSphereFunctions.cs @@ -8,6 +8,9 @@ namespace CheatEnabler.Functions; [ModFeature("CheatDysonSphere", Order = 20)] public static class DysonSphereFunctions { + public const int MinShellsCountForFunctions = 1; + public const int MaxShellsCountForFunctions = 99_999; + public static ConfigEntry IllegalDysonShellFunctionsEnabled; public static ConfigEntry ShellsCountForFunctions; diff --git a/CheatEnabler/UIConfigWindow.cs b/CheatEnabler/UIConfigWindow.cs index 1817fbe..4ac3ede 100644 --- a/CheatEnabler/UIConfigWindow.cs +++ b/CheatEnabler/UIConfigWindow.cs @@ -2,6 +2,7 @@ using CheatEnabler.Patches; using CheatEnabler.Patches.Factory; using UnityEngine; +using UnityEngine.UI; using UXAssist.UI; using UXAssist.Common; using System; @@ -41,34 +42,34 @@ public static class UIConfigWindow } } - class ShellsCountMapper : MyWindow.RangeValueMapper + private static InputField AddShellsCountInput(MyConfigWindow wnd, float x, float y, RectTransform parent, string objName) { - public ShellsCountMapper() : base(1, 139) - { - } + var config = DysonSphereFunctions.ShellsCountForFunctions; + var count = Mathf.Clamp(config.Value, DysonSphereFunctions.MinShellsCountForFunctions, DysonSphereFunctions.MaxShellsCountForFunctions); + if (config.Value != count) config.Value = count; - public override int ValueToIndex(int value) + InputField input = null; + input = wnd.AddInputField(x, y, parent, count.ToString(), 15, objName, onEditEnd: value => { - return value switch - { - < 4 => value, - < 64 => value / 4 + 3, - < 256 => value / 16 + 15, - < 4096 => value / 64 + 27, - _ => value / 256 + 75, - }; - } + if (!int.TryParse(value, out var parsed)) parsed = config.Value; + parsed = Mathf.Clamp(parsed, DysonSphereFunctions.MinShellsCountForFunctions, DysonSphereFunctions.MaxShellsCountForFunctions); + config.Value = parsed; + input.text = parsed.ToString(); + }); + input.contentType = InputField.ContentType.IntegerNumber; + input.characterLimit = 5; - public override int IndexToValue(int index) + config.SettingChanged += OnShellsCountChanged; + wnd.OnFree += () => config.SettingChanged -= OnShellsCountChanged; + return input; + + void OnShellsCountChanged(object o, EventArgs e) { - return index switch - { - < 4 => index, - < 19 => (index - 3) * 4, - < 31 => (index - 15) * 16, - < 91 => (index - 27) * 64, - _ => (index - 75) * 256, - }; + var normalized = Mathf.Clamp(config.Value, DysonSphereFunctions.MinShellsCountForFunctions, DysonSphereFunctions.MaxShellsCountForFunctions); + if (config.Value != normalized) config.Value = normalized; + + var value = normalized.ToString(); + if (input.text != value) input.text = value; } } @@ -266,7 +267,7 @@ public static class UIConfigWindow () => { DysonSphereFunctions.DuplicateShellsWithHighestProduction(); }); }); y += 30f; - var slider1 = wnd.AddSlider(x + 20f, y, tab4, DysonSphereFunctions.ShellsCountForFunctions, new ShellsCountMapper()); + var input1 = AddShellsCountInput(wnd, x + 20f, y, tab4, "input-shells-count-illegal"); y = originalY; var btn4 = wnd.AddButton(x, y, 300f, tab4, "Generate illegal dyson shell quickly", 16, "button-generate-illegal-dyson-shells-quickly", () => @@ -276,7 +277,7 @@ public static class UIConfigWindow }); y += 30f; var txt2 = wnd.AddText2(x, y, tab4, "Shells count", 15, "text-shells-count"); - var slider2 = wnd.AddSlider(x + txt2.preferredWidth + 5f, y + 6f, tab4, DysonSphereFunctions.ShellsCountForFunctions, new ShellsCountMapper()); + var input2 = AddShellsCountInput(wnd, x + txt2.preferredWidth + 5f, y, tab4, "input-shells-count-quick"); Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged += onIllegalDysonShellFunctionsChanged; wnd.OnFree += () => { Functions.DysonSphereFunctions.IllegalDysonShellFunctionsEnabled.SettingChanged -= onIllegalDysonShellFunctionsChanged; }; @@ -288,11 +289,11 @@ public static class UIConfigWindow btn1.gameObject.SetActive(enabled); btn2.gameObject.SetActive(enabled); btn3.gameObject.SetActive(enabled); - slider1.gameObject.SetActive(enabled); + input1.gameObject.SetActive(enabled); btn4.gameObject.SetActive(!enabled); txt2.gameObject.SetActive(!enabled); - slider2.gameObject.SetActive(!enabled); + input2.gameObject.SetActive(!enabled); } }