mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-20 01:46:21 +00:00
Add ability to always change username
This commit is contained in:
1 parent
1509a94257
commit
0853801bda
2 files changed
+49
-20
No files matched your search
@@ -15,25 +15,5 @@ namespace Reactor.Patches
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(AccountTab), nameof(AccountTab.Open))]
|
||||
public static class EditNamePatch
|
||||
{
|
||||
public static void Prefix(AccountTab __instance)
|
||||
{
|
||||
Fix(__instance, __instance.guestMode);
|
||||
Fix(__instance, __instance.offlineMode);
|
||||
}
|
||||
|
||||
private static void Fix(AccountTab __instance, GameObject mode)
|
||||
{
|
||||
var randomizeName = mode.transform.Find("RandomizeName").gameObject;
|
||||
if (!randomizeName.active)
|
||||
return;
|
||||
|
||||
randomizeName.active = false;
|
||||
Object.Instantiate(__instance.loggedInMode.editNameButton, mode.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using HarmonyLib;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Reactor.Patches
|
||||
{
|
||||
internal static class FreeNamePatch
|
||||
{
|
||||
[HarmonyPatch(typeof(SetNameText), nameof(SetNameText.Start))]
|
||||
public static class NameInputPatch
|
||||
{
|
||||
public static void Postfix(SetNameText __instance)
|
||||
{
|
||||
if (!__instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var nameText = __instance.gameObject;
|
||||
|
||||
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) (() =>
|
||||
{
|
||||
SaveManager.PlayerName = textBox.text;
|
||||
}));
|
||||
|
||||
var pipeGameObject = GameObject.Find("Pipe");
|
||||
if (!pipeGameObject)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pipe = UnityEngine.Object.Instantiate(pipeGameObject, textMeshPro.transform);
|
||||
pipe.GetComponent<TextMeshPro>().fontSize = 4f;
|
||||
textBox.Pipe = pipe.GetComponent<MeshRenderer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user