mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
text input WIP
This commit is contained in:
1 parent
2f56c95b39
commit
9e8c05f21d
2 files changed
+53
No files matched your search
@@ -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<string>? OnTextChanged;
|
||||
|
||||
public delegate bool ValidateInput(string input);
|
||||
public ValidateInput? Validate;
|
||||
|
||||
public static void Create(Action<string>? onTextChanged = null, ValidateInput? validate = null)
|
||||
{
|
||||
var source = FindObjectOfType<NameTextBehaviour>(true);
|
||||
var input = Instantiate(source);
|
||||
var inputBox = input.gameObject.AddComponent<TextInput>();
|
||||
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);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -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<TextTranslatorTMP>(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);
|
||||
|
||||
Reference in new issue
Block a user