From 9e8c05f21da0d8ec394cb09da0e37171724c170c Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 23 Mar 2025 15:01:31 -0400 Subject: [PATCH] text input WIP --- MiraAPI/Hud/Tools/TextInput.cs | 39 +++++++++++++++++++ .../Patches/Options/GamePresetsTabPatches.cs | 14 +++++++ 2 files changed, 53 insertions(+) create mode 100644 MiraAPI/Hud/Tools/TextInput.cs diff --git a/MiraAPI/Hud/Tools/TextInput.cs b/MiraAPI/Hud/Tools/TextInput.cs new file mode 100644 index 0000000..62a2051 --- /dev/null +++ b/MiraAPI/Hud/Tools/TextInput.cs @@ -0,0 +1,39 @@ +using System; +using Reactor.Utilities.Attributes; +using UnityEngine; +using UnityEngine.UI; + +namespace MiraAPI.Hud.Tools; + +[RegisterInIl2Cpp] +public class TextInput : MonoBehaviour +{ + public TextBoxTMP textBox; + + public Action? OnTextChanged; + + public delegate bool ValidateInput(string input); + public ValidateInput? Validate; + + public static void Create(Action? onTextChanged = null, ValidateInput? validate = null) + { + var source = FindObjectOfType(true); + var input = Instantiate(source); + var inputBox = input.gameObject.AddComponent(); + inputBox.textBox = source.nameSource; + inputBox.OnTextChanged = onTextChanged; + inputBox.Validate = validate; + + inputBox.textBox.OnChange = new Button.ButtonClickedEvent(); + inputBox.textBox.OnChange.AddListener((UnityEngine.Events.UnityAction)(() => + { + var text = inputBox.textBox.text; + if (inputBox.Validate != null && !inputBox.Validate(text)) + { + return; + } + + inputBox.OnTextChanged?.Invoke(text); + })); + } +} diff --git a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs index c068a52..07aca24 100644 --- a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs +++ b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs @@ -6,6 +6,7 @@ using Reactor.Utilities.Extensions; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; +using Object = UnityEngine.Object; namespace MiraAPI.Patches.Options; @@ -24,6 +25,19 @@ internal static class GamePresetsTabPatches return; } + var saveButton = Object.Instantiate(prefab, __instance.transform); + saveButton.buttonText.text = "Save Settings"; + if (saveButton.buttonText.TryGetComponent(out var textTranslator)) + { + textTranslator.DestroyImmediate(); + } + saveButton.OnClick = new Button.ButtonClickedEvent(); + saveButton.OnClick.AddListener( + (UnityAction)(() => + { + + })); + var holder = new GameObject("PresetHolder"); holder.transform.SetParent(__instance.transform, false); holder.transform.localPosition = new Vector3(-1.7f, 1.7f, 0);