mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Merge branch 'free-name-patch' into bepinex-upgrade
This commit is contained in:
2 files changed
+43
-32
No files matched your search
@@ -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, LoadSceneMode>) ((scene, _) =>
|
||||
{
|
||||
if (!__instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!scene.name.Equals("MMOnline")) return;
|
||||
if (!TryMoveObjects()) return;
|
||||
|
||||
var editName = DestroyableSingleton<AccountManager>.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<TextBoxTMP>();
|
||||
textBox.Background = nameText.GetComponentInChildren<SpriteRenderer>();
|
||||
textBox.OnChange = textBox.OnEnter = textBox.OnFocusLost = new Button.ButtonClickedEvent();
|
||||
textBox.characterLimit = 10;
|
||||
|
||||
var textMeshPro = nameText.GetComponentInChildren<TextMeshPro>();
|
||||
textBox.outputText = textMeshPro;
|
||||
textBox.SetText(SaveManager.PlayerName);
|
||||
|
||||
textBox.OnChange.AddListener((Action) (() =>
|
||||
{
|
||||
var textBox = nameText.GetComponent<TextBoxTMP>();
|
||||
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<TextMeshPro>().fontSize = 4f;
|
||||
}));
|
||||
}
|
||||
|
||||
var pipeGameObject = GameObject.Find("Pipe");
|
||||
if (!pipeGameObject)
|
||||
{
|
||||
return;
|
||||
}
|
||||
private static bool TryMoveObjects()
|
||||
{
|
||||
var toMove = new List<string>
|
||||
{
|
||||
"HostGameButton",
|
||||
"FindGameButton",
|
||||
"JoinGameButton"
|
||||
};
|
||||
|
||||
var pipe = UnityEngine.Object.Instantiate(pipeGameObject, textMeshPro.transform);
|
||||
pipe.GetComponent<TextMeshPro>().fontSize = 4f;
|
||||
textBox.Pipe = pipe.GetComponent<MeshRenderer>();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ namespace Reactor
|
||||
this.AddComponent<Coroutines.Component>();
|
||||
|
||||
ReactorVersionShower.Initialize();
|
||||
FreeNamePatch.Initialize();
|
||||
SplashSkip.Initialize();
|
||||
DefaultBundle.Load();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user