diff --git a/Reactor/Patches/FreeNamePatch.cs b/Reactor/Patches/FreeNamePatch.cs index 06aeef7..529f22b 100644 --- a/Reactor/Patches/FreeNamePatch.cs +++ b/Reactor/Patches/FreeNamePatch.cs @@ -1,50 +1,60 @@ using System; -using HarmonyLib; +using System.Collections.Generic; +using System.Linq; using TMPro; using UnityEngine; -using UnityEngine.UI; +using UnityEngine.SceneManagement; +using Object = UnityEngine.Object; namespace Reactor.Patches { - // TODO this needs some changes as text box was entirely removed in 2021.6.15 - internal static class FreeNamePatch + public static class FreeNamePatch { - [HarmonyPatch(typeof(SetNameText), nameof(SetNameText.Start))] - public static class NameInputPatch + public static void Initialize() { - public static void Postfix(SetNameText __instance) + SceneManager.add_sceneLoaded((Action) ((scene, _) => { - if (!__instance) - { - return; - } + if (!scene.name.Equals("MMOnline")) return; + if (!TryMoveObjects()) return; + + var editName = DestroyableSingleton.Instance.accountTab.editNameScreen; + var nameText = Object.Instantiate(editName.nameText.gameObject); - var nameText = __instance.gameObject; + nameText.transform.localPosition += Vector3.up * 2.2f; - var textBox = nameText.AddComponent(); - textBox.Background = nameText.GetComponentInChildren(); - textBox.OnChange = textBox.OnEnter = textBox.OnFocusLost = new Button.ButtonClickedEvent(); - textBox.characterLimit = 10; - - var textMeshPro = nameText.GetComponentInChildren(); - textBox.outputText = textMeshPro; - textBox.SetText(SaveManager.PlayerName); - - textBox.OnChange.AddListener((Action) (() => - { + var textBox = nameText.GetComponent(); + textBox.outputText.alignment = TextAlignmentOptions.CenterGeoAligned; + textBox.outputText.transform.position = nameText.transform.position; + textBox.outputText.fontSize = 4f; + + textBox.OnChange.AddListener((Action) (() => { SaveManager.PlayerName = textBox.text; })); + textBox.OnEnter = textBox.OnFocusLost = textBox.OnChange; + + textBox.Pipe.GetComponent().fontSize = 4f; + })); + } - var pipeGameObject = GameObject.Find("Pipe"); - if (!pipeGameObject) - { - return; - } + private static bool TryMoveObjects() + { + var toMove = new List + { + "HostGameButton", + "FindGameButton", + "JoinGameButton" + }; - var pipe = UnityEngine.Object.Instantiate(pipeGameObject, textMeshPro.transform); - pipe.GetComponent().fontSize = 4f; - textBox.Pipe = pipe.GetComponent(); - } + var offset = Vector3.up; + var gameObjects = toMove.Select(x => GameObject.Find("NormalMenu/" + x)).ToList(); + if (gameObjects.Contains(null)) return false; + + gameObjects.ForEach(x => { + x.transform.position = offset; + offset += Vector3.down * 1.5f; + }); + + return true; } } } diff --git a/Reactor/ReactorPlugin.cs b/Reactor/ReactorPlugin.cs index 91f58c9..9bb170f 100644 --- a/Reactor/ReactorPlugin.cs +++ b/Reactor/ReactorPlugin.cs @@ -46,6 +46,7 @@ namespace Reactor this.AddComponent(); ReactorVersionShower.Initialize(); + FreeNamePatch.Initialize(); SplashSkip.Initialize(); DefaultBundle.Load(); }