diff --git a/CheatEnabler/AbnormalDiabler.cs b/CheatEnabler/AbnormalDiabler.cs new file mode 100644 index 0000000..2ed428f --- /dev/null +++ b/CheatEnabler/AbnormalDiabler.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using BepInEx.Configuration; +using HarmonyLib; + +namespace CheatEnabler; +public static class AbnormalDisabler +{ + public static ConfigEntry Enabled; + private static Dictionary _savedDeterminators; + + [HarmonyPrefix] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")] + private static bool DisableAbnormalLogic() + { + return !Enabled.Value; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")] + private static void DisableAbnormalDeterminators(AbnormalityLogic __instance) + { + _savedDeterminators = __instance.determinators; + Enabled.SettingChanged += (_, _) => + { + if (Enabled.Value) + { + _savedDeterminators = __instance.determinators; + __instance.determinators = new Dictionary(); + foreach (var p in _savedDeterminators) + { + p.Value.OnUnregEvent(); + } + } + else + { + __instance.determinators = _savedDeterminators; + foreach (var p in _savedDeterminators) + { + p.Value.OnRegEvent(); + } + } + }; + + _savedDeterminators = __instance.determinators; + if (!Enabled.Value) return; + __instance.determinators = new Dictionary(); + foreach (var p in _savedDeterminators) + { + p.Value.OnUnregEvent(); + } + } +} diff --git a/CheatEnabler/CheatEnabler.cs b/CheatEnabler/CheatEnabler.cs index 6eeca7c..0e2fc3e 100644 --- a/CheatEnabler/CheatEnabler.cs +++ b/CheatEnabler/CheatEnabler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection.Emit; using BepInEx; +using BepInEx.Configuration; using HarmonyLib; namespace CheatEnabler; @@ -10,11 +11,12 @@ namespace CheatEnabler; [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class CheatEnabler : BaseUnityPlugin { - private new static readonly BepInEx.Logging.ManualLogSource Logger = + public new static readonly BepInEx.Logging.ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); - private bool _devShortcuts = true; - private bool _disableAbnormalChecks = true; + private static bool _initialized = false; + private static KeyboardShortcut _shortcut = KeyboardShortcut.Deserialize("H + LeftControl"); + private static UIConfigWindow _configWin; private bool _alwaysInfiniteResource = true; private bool _waterPumpAnywhere = true; private static bool _sitiVeinsOnBirthPlanet = true; @@ -33,9 +35,9 @@ public class CheatEnabler : BaseUnityPlugin private void Awake() { - _devShortcuts = Config.Bind("General", "DevShortcuts", _devShortcuts, "enable DevMode shortcuts").Value; - _disableAbnormalChecks = Config.Bind("General", "DisableAbnormalChecks", _disableAbnormalChecks, - "disable all abnormal checks").Value; + DevShortcuts.Enabled = Config.Bind("General", "DevShortcuts", true, "enable DevMode shortcuts"); + AbnormalDisabler.Enabled = Config.Bind("General", "DisableAbnormalChecks", false, + "disable all abnormal checks"); _alwaysInfiniteResource = Config.Bind("General", "AlwaysInfiniteResource", _alwaysInfiniteResource, "always infinite resource").Value; _unlockTechToMaximumLevel = Config.Bind("General", "UnlockTechToMaxLevel", _unlockTechToMaximumLevel, @@ -69,16 +71,10 @@ public class CheatEnabler : BaseUnityPlugin // UI Patch Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch)); + Harmony.CreateAndPatchAll(typeof(CheatEnabler)); - if (_devShortcuts) - { - Harmony.CreateAndPatchAll(typeof(DevShortcuts)); - } - - if (_disableAbnormalChecks) - { - Harmony.CreateAndPatchAll(typeof(AbnormalDisabler)); - } + Harmony.CreateAndPatchAll(typeof(DevShortcuts)); + Harmony.CreateAndPatchAll(typeof(AbnormalDisabler)); if (_alwaysInfiniteResource) { @@ -115,62 +111,39 @@ public class CheatEnabler : BaseUnityPlugin Harmony.CreateAndPatchAll(typeof(TerraformAnyway)); } } - - private class DevShortcuts + + private void Update() { - [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerController), "Init")] - private static void PlayerControllerInit(PlayerController __instance) + if (!GameMain.isRunning) { - var cnt = __instance.actions.Length; - var newActions = new PlayerAction[cnt + 1]; - for (var i = 0; i < cnt; i++) - { - newActions[i] = __instance.actions[i]; - } - - var test = new PlayerAction_Test(); - test.Init(__instance.player); - newActions[cnt] = test; - __instance.actions = newActions; + return; } - [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerAction_Test), "GameTick")] - private static void PlayerAction_TestGameTick(PlayerAction_Test __instance) + if (VFInput.inputing) { - var lastActive = __instance.active; - __instance.Update(); - if (lastActive != __instance.active) + return; + } + + if (_shortcut.IsDown()) + { + if (_configWin.active) { - UIRealtimeTip.PopupAhead( - (lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(), - false); + _configWin._Close(); + } + else + { + UIRoot.instance.uiGame.ShutPlayerInventory(); + _configWin.Open(); } } } - private class AbnormalDisabler + [HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnCreate")] + public static void UIGame__OnCreate_Postfix() { - [HarmonyPrefix] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")] - [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")] - private static bool DisableAbnormalLogic() - { - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")] - private static bool DisableAbnormalDeterminators(ref Dictionary ___determinators) - { - ___determinators = new Dictionary(); - return false; - } + if (_initialized) return; + _initialized = true; + _configWin = UIConfigWindow.CreateInstance(); } private class AlwaysInfiniteResource diff --git a/CheatEnabler/DevShortcuts.cs b/CheatEnabler/DevShortcuts.cs new file mode 100644 index 0000000..caed4ba --- /dev/null +++ b/CheatEnabler/DevShortcuts.cs @@ -0,0 +1,48 @@ +using BepInEx.Configuration; +using HarmonyLib; + +namespace CheatEnabler; +public class DevShortcuts +{ + public static ConfigEntry Enabled; + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerController), "Init")] + private static void PlayerController_Init_Postfix(PlayerController __instance) + { + var cnt = __instance.actions.Length; + var newActions = new PlayerAction[cnt + 1]; + for (var i = 0; i < cnt; i++) + { + newActions[i] = __instance.actions[i]; + } + + var test = new PlayerAction_Test(); + test.Init(__instance.player); + newActions[cnt] = test; + __instance.actions = newActions; + + Enabled.SettingChanged += (_, _) => + { + if (!Enabled.Value) + { + test.active = false; + } + }; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerAction_Test), "GameTick")] + private static void PlayerAction_Test_GameTick_Postfix(PlayerAction_Test __instance) + { + if (!Enabled.Value) return; + var lastActive = __instance.active; + __instance.Update(); + if (lastActive != __instance.active) + { + UIRealtimeTip.PopupAhead( + (lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(), + false); + } + } +} \ No newline at end of file diff --git a/CheatEnabler/UI/MyCheckbox.cs b/CheatEnabler/UI/MyCheckbox.cs index 2c7f55b..bfdb0d9 100644 --- a/CheatEnabler/UI/MyCheckbox.cs +++ b/CheatEnabler/UI/MyCheckbox.cs @@ -1,4 +1,5 @@ using System; +using BepInEx.Configuration; using UnityEngine; using UnityEngine.UI; @@ -11,8 +12,10 @@ public class MyCheckBox : MonoBehaviour public Image checkImage; public RectTransform rectTrans; public Text labelText; - public event Action OnChecked; + private bool _checked; + private ConfigEntry _configAssigned; + public bool Checked { get => _checked; @@ -23,30 +26,25 @@ public class MyCheckBox : MonoBehaviour } } - private bool _checked; + public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, ConfigEntry config, string label = "", int fontSize = 15) + { + var cb = CreateCheckBox(x, y, parent, config.Value, label, fontSize); + cb._configAssigned = config; + cb.OnChecked += () => config.Value = !config.Value; + config.SettingChanged += (_, _) => cb.Checked = config.Value; + return cb; + } - public static MyCheckBox CreateCheckBox(bool check, Transform parent = null, float x = 0f, float y = 0f, string label = "", int fontSize = 15) + public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, bool check, string label = "", int fontSize = 15) { var buildMenu = UIRoot.instance.uiGame.buildMenu; var src = buildMenu.uxFacilityCheck; var go = Instantiate(src.gameObject); - var rect = go.transform as RectTransform; - if (rect == null) - { - return null; - } go.name = "my-checkbox"; var cb = go.AddComponent(); cb._checked = check; - if (parent != null) - { - rect.SetParent(parent); - } - rect.anchorMax = new Vector2(0f, 1f); - rect.anchorMin = new Vector2(0f, 1f); - rect.pivot = new Vector2(0f, 1f); - rect.anchoredPosition3D = new Vector3(x, -y, 0f); + var rect = Util.NormalizeRectWithTopLeft(cb, x, y, parent); cb.rectTrans = rect; cb.uiButton = go.GetComponent(); diff --git a/CheatEnabler/UI/MySlider.cs b/CheatEnabler/UI/MySlider.cs new file mode 100644 index 0000000..7978f44 --- /dev/null +++ b/CheatEnabler/UI/MySlider.cs @@ -0,0 +1,123 @@ +using System; +using UnityEngine; +using UnityEngine.UI; + +namespace CheatEnabler.UI; + +// MySlider modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MySlider.cs + +public class MySlider : MonoBehaviour +{ + public Slider slider; + public RectTransform rectTrans; + public Text labelText; + public string labelFormat; + public event Action OnValueChanged; + private float _value; + public float Value + { + get => _value; + set + { + _value = value; + OnValueSet(); + } + } + + public static RectTransform CreateSlider(float x, float y, RectTransform parent, float value, float minValue, float maxValue, string format = "{0}", float width = 0f) + { + var optionWindow = UIRoot.instance.optionWindow; + var src = optionWindow.audioVolumeComp; + + var go = Instantiate(src.gameObject); + //sizeDelta = 240, 20 + go.name = "my-slider"; + go.SetActive(true); + var sl = go.AddComponent(); + sl._value = value; + var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent); + sl.rectTrans = rect; + if (width > 0) + { + rect.sizeDelta = new Vector2(width, rect.sizeDelta.y); + } + + sl.slider = go.GetComponent(); + sl.slider.minValue = minValue; + sl.slider.maxValue = maxValue; + sl.slider.onValueChanged.RemoveAllListeners(); + sl.slider.onValueChanged.AddListener(sl.SliderChanged); + sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent(); + if (sl.labelText != null) + { + sl.labelText.fontSize = 14; + if (sl.labelText.transform is RectTransform rectTrans) + { + rectTrans.sizeDelta = new Vector2(22f, 22f); + } + } + sl.labelFormat = format; + + var bg = sl.slider.transform.Find("Background")?.GetComponent(); + if (bg != null) + { + bg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); + } + var fill = sl.slider.fillRect.GetComponent(); + if (fill != null) + { + fill.color = new Color(1f, 1f, 1f, 0.28f); + } + sl.OnValueSet(); + sl.UpdateLabel(); + + return sl.rectTrans; + } + public void OnValueSet() + { + lock (this) + { + var sliderVal = _value; + if (_value.Equals(slider.value)) return; + if (sliderVal > slider.maxValue) + { + _value = sliderVal = slider.maxValue; + } + else if (sliderVal < slider.minValue) + { + _value = sliderVal = slider.minValue; + } + + slider.value = sliderVal; + UpdateLabel(); + } + } + public void UpdateLabel() + { + if (labelText != null) + { + labelText.text = _value.ToString(labelFormat); + } + } + + public void SetLabelText(string text) + { + if (labelText != null) + { + labelText.text = text; + } + } + + public void SliderChanged(float val) + { + lock (this) + { + var newVal = Mathf.Round(slider.value); + if (_value.Equals(newVal)) return; + _value = newVal; + UpdateLabel(); + OnValueChanged?.Invoke(); + } + } + +} \ No newline at end of file diff --git a/CheatEnabler/UI/MyWindow.cs b/CheatEnabler/UI/MyWindow.cs index 998f0ea..f3a2e0f 100644 --- a/CheatEnabler/UI/MyWindow.cs +++ b/CheatEnabler/UI/MyWindow.cs @@ -1,17 +1,221 @@ -using HarmonyLib; +using System; +using HarmonyLib; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Events; using UnityEngine.UI; +using Object = UnityEngine.Object; namespace CheatEnabler.UI; -// MyWindowManager modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyWindowCtl.cs +// MyWindow modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyWindowCtl.cs + +public class MyWindow: ManualBehaviour +{ + private readonly Dictionary, UnityAction>> _inputFields = new(); + protected bool EventRegistered { get; private set; } + + public virtual void TryClose() + { + _Close(); + } + + public virtual bool IsWindowFunctional() + { + return true; + } + + public void Open() + { + _Open(); + transform.SetAsLastSibling(); + } + + public void Close() => _Close(); + + public void SetTitle(string title) + { + var txt = gameObject.transform.Find("panel-bg/title-text")?.gameObject.GetComponent(); + if (txt) + { + txt.text = title; + } + } + + private static void AddElement(float x, float y, RectTransform rect, RectTransform parent = null) + { + if (rect != null) + { + Util.NormalizeRectWithTopLeft(rect, x, y, parent); + } + } + + protected static Text AddText(float x, float y, RectTransform parent, string label, int fontSize = 14, string objName = "label") + { + var src = UIRoot.instance.uiGame.assemblerWindow.stateText; + var txt = Instantiate(src); + txt.gameObject.name = objName; + txt.text = label; + txt.color = new Color(1f, 1f, 1f, 0.4f); + txt.alignment = TextAnchor.MiddleLeft; + txt.fontSize = fontSize; + if (txt.transform is RectTransform rect) + { + rect.sizeDelta = new Vector2(txt.preferredWidth + 40f, 30f); + } + AddElement(x, y, txt.rectTransform, parent); + return txt; + } + + protected InputField AddInputField(float x, float y, RectTransform parent, string text = "", int fontSize = 16, string objName = "input", UnityAction onChanged = null, UnityAction onEditEnd = null) + { + var stationWindow = UIRoot.instance.uiGame.stationWindow; + //public InputField nameInput; + var inputField = Instantiate(stationWindow.nameInput); + inputField.gameObject.name = "search-field"; + Destroy(inputField.GetComponent()); + inputField.GetComponent().color = new Color(1f, 1f, 1f, 0.05f); + var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent); + rect.sizeDelta = new Vector2(210, rect.sizeDelta.y); + inputField.textComponent.text = text; + inputField.textComponent.fontSize = fontSize; + _inputFields[inputField] = Tuple.Create(onChanged, onEditEnd); + if (EventRegistered) + { + if (onChanged != null) + inputField.onValueChanged.AddListener(onChanged); + if (onEditEnd != null) + inputField.onEndEdit.AddListener(onEditEnd); + } + return inputField; + } + + public override void _OnRegEvent() + { + base._OnRegEvent(); + if (EventRegistered) return; + foreach (var t in _inputFields) + { + var inputField = t.Key; + if (t.Value.Item1 != null) + inputField.onValueChanged.AddListener(t.Value.Item1); + if (t.Value.Item2 != null) + inputField.onEndEdit.AddListener(t.Value.Item2); + } + EventRegistered = true; + } + + public override void _OnUnregEvent() + { + base._OnUnregEvent(); + if (!EventRegistered) return; + EventRegistered = false; + foreach (var t in _inputFields) + { + var inputField = t.Key; + if (t.Value.Item1 != null) + inputField.onValueChanged.RemoveListener(t.Value.Item1); + if (t.Value.Item2 != null) + inputField.onEndEdit.RemoveListener(t.Value.Item2); + } + } +} + +public class MyWindowWithTabs : MyWindow +{ + private readonly List> _tabs = new(); + public override void TryClose() + { + _Close(); + } + + public override bool IsWindowFunctional() + { + return true; + } + + protected RectTransform AddTab(float x, int index, RectTransform parent, string label) + { + var tab = new GameObject(); + var tabRect = tab.AddComponent(); + Util.NormalizeRectWithMargin(tabRect, 54f + 28f, 36f, 0f, 0f, parent); + tab.name = "tab-" + index; + var swarmPanel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel; + var src = swarmPanel.orbitButtons[0]; + var btn = Instantiate(src); + var btnRect = Util.NormalizeRectWithTopLeft(btn, x, 54f, parent); + btnRect.sizeDelta = new Vector2(100f, 24f); + btn.transform.Find("frame").gameObject.SetActive(false); + if (btn.transitions.Length >= 3) + { + btn.transitions[0].normalColor = new Color(0.1f, 0.1f, 0.1f, 0.68f); + btn.transitions[0].highlightColorOverride = new Color(0.9906f, 0.5897f, 0.3691f, 0.4f); + btn.transitions[1].normalColor = new Color(1f, 1f, 1f, 0.6f); + btn.transitions[1].highlightColorOverride = new Color(0.2f, 0.1f, 0.1f, 0.9f); + } + + var btnText = btn.transform.Find("Text").GetComponent(); + btnText.text = label; + btnText.fontSize = 16; + btn.data = index; + + _tabs.Add(Tuple.Create(tabRect, btn)); + if (EventRegistered) + { + btn.onClick += OnTabButtonClick; + } + return tabRect; + } + + public override void _OnRegEvent() + { + if (!EventRegistered) + { + foreach (var t in _tabs) + { + t.Item2.onClick += OnTabButtonClick; + } + } + base._OnRegEvent(); + } + + public override void _OnUnregEvent() + { + if (EventRegistered) + { + foreach (var t in _tabs) + { + t.Item2.onClick -= OnTabButtonClick; + } + } + base._OnUnregEvent(); + } + + protected void SetCurrentTab(int index) => OnTabButtonClick(index); + + private void OnTabButtonClick(int index) + { + foreach (var t in _tabs) + { + var btn = t.Item2; + if (btn.data != index) + { + btn.highlighted = false; + t.Item1.gameObject.SetActive(false); + continue; + } + btn.highlighted = true; + t.Item1.gameObject.SetActive(true); + } + } +} + public static class MyWindowManager { private static readonly List Windows = new(4); - private static bool _inited = false; + private static bool _initialized = false; - public static T CreateWindow(string name, string title = "") where T : Component + public static T CreateWindow(string name, string title = "") where T : MyWindow { var srcWin = UIRoot.instance.uiGame.tankWindow; var src = srcWin.gameObject; @@ -19,10 +223,10 @@ public static class MyWindowManager go.name = name; go.SetActive(false); Object.Destroy(go.GetComponent()); - var win = go.AddComponent() as ManualBehaviour; + var win = go.AddComponent() as MyWindow; if (win == null) return null; - //shadow + for (var i = 0; i < go.transform.childCount; i++) { var child = go.transform.GetChild(i).gameObject; @@ -34,10 +238,6 @@ public static class MyWindowManager { btn.onClick.AddListener(win._Close); } - else - { - - } } else if (child.name != "shadow" && child.name != "panel-bg") { @@ -45,33 +245,14 @@ public static class MyWindowManager } } - SetTitle(win, title); + win.SetTitle(title); win._Create(); - if (_inited) + if (_initialized) { win._Init(win.data); } Windows.Add(win); - return win as T; - } - - public static void SetTitle(ManualBehaviour win, string title) - { - var txt = GetTitleText(win); - if (txt) - { - txt.text = title; - } - } - public static Text GetTitleText(ManualBehaviour win) - { - return win.gameObject.transform.Find("panel-bg/title-text")?.gameObject.GetComponent(); - } - - - public static RectTransform GetRectTransform(ManualBehaviour win) - { - return win.GetComponent(); + return (T)win; } /* @@ -83,17 +264,6 @@ public static class MyWindowManager } */ - public static void OpenWindow(ManualBehaviour win) - { - win._Open(); - win.transform.SetAsLastSibling(); - } - - public static void CloseWindow(ManualBehaviour win) - { - win._Close(); - } - public static class Patch { @@ -122,7 +292,7 @@ public static class MyWindowManager { win._Init(win.data); } - _inited = true; + _initialized = true; } [HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnFree")] @@ -152,7 +322,10 @@ public static class MyWindowManager { foreach (var win in Windows) { - win._Close(); + if (win is MyWindow theWin && theWin.IsWindowFunctional()) + { + theWin.TryClose(); + } } } } diff --git a/CheatEnabler/UI/Util.cs b/CheatEnabler/UI/Util.cs new file mode 100644 index 0000000..34d5e29 --- /dev/null +++ b/CheatEnabler/UI/Util.cs @@ -0,0 +1,66 @@ +using UnityEngine; + +namespace CheatEnabler.UI; + +public static class Util +{ + + public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null) + { + if (cmp.transform is not RectTransform rect) return null; + if (parent != null) + { + rect.SetParent(parent, false); + } + rect.anchorMax = new Vector2(0f, 1f); + rect.anchorMin = new Vector2(0f, 1f); + rect.pivot = new Vector2(0f, 1f); + rect.anchoredPosition3D = new Vector3(left, -top, 0f); + return rect; + } + + public static RectTransform NormalizeRectWithBottomLeft(Component cmp, float left, float bottom, Transform parent = null) + { + if (cmp.transform is not RectTransform rect) return null; + if (parent != null) + { + rect.SetParent(parent, false); + } + rect.anchorMax = new Vector2(0f, 0f); + rect.anchorMin = new Vector2(0f, 0f); + rect.pivot = new Vector2(0f, 0f); + rect.anchoredPosition3D = new Vector3(left, bottom, 0f); + return rect; + } + + public static RectTransform NormalizeRectWithMargin(Component cmp, float top, float left, float bottom, float right, Transform parent = null) + { + if (cmp.transform is not RectTransform rect) return null; + if (parent != null) + { + rect.SetParent(parent, false); + } + rect.anchoredPosition3D = Vector3.zero; + rect.localScale = Vector3.one; + rect.anchorMax = Vector2.one; + rect.anchorMin = Vector2.zero; + rect.pivot = new Vector2(0.5f, 0.5f); + rect.offsetMax = new Vector2(-right, -top); + rect.offsetMin = new Vector2(left, bottom); + return rect; + } + + public static RectTransform NormalizeRectCenter(GameObject go, float width = 0, float height = 0) + { + if (go.transform is not RectTransform rect) return null; + rect.anchorMax = new Vector2(0.5f, 0.5f); + rect.anchorMin = new Vector2(0.5f, 0.5f); + rect.pivot = new Vector2(0.5f, 0.5f); + if (width > 0 && height > 0) + { + rect.sizeDelta = new Vector2(width, height); + } + return rect; + } + +} diff --git a/CheatEnabler/UIConfigWindow.cs b/CheatEnabler/UIConfigWindow.cs new file mode 100644 index 0000000..25744b5 --- /dev/null +++ b/CheatEnabler/UIConfigWindow.cs @@ -0,0 +1,62 @@ +using UnityEngine; + +namespace CheatEnabler; + +public class UIConfigWindow : UI.MyWindowWithTabs +{ + private RectTransform _windowTrans; + + public static UIConfigWindow CreateInstance() + { + return UI.MyWindowManager.CreateWindow("CEConfigWindow", "CheatEnabler Config"); + } + + public override void _OnCreate() + { + _windowTrans = GetComponent(); + _windowTrans.sizeDelta = new Vector2(640f, 428f); + + CreateUI(); + } + + private void CreateUI() + { + //General tab + var tab1 = AddTab(36f, 0, _windowTrans, "General"); + var x = 0f; + var y = 0f; + UI.MyCheckBox.CreateCheckBox(x, y, tab1, DevShortcuts.Enabled, "Enable Dev Shortcuts"); + y += 26f; + UI.MyCheckBox.CreateCheckBox(x, y, tab1, AbnormalDisabler.Enabled, "Disable Abnormal Checks"); + SetCurrentTab(0); + } + + public override void _OnDestroy() + { + } + + public override bool _OnInit() + { + _windowTrans.anchoredPosition = new Vector2(0, 0); + return true; + } + + public override void _OnFree() + { + } + + public override void _OnOpen() + { + } + + public override void _OnClose() + { + } + + public override void _OnUpdate() + { + if (!VFInput.escape || VFInput.inputing) return; + VFInput.UseEscape(); + _Close(); + } +}