Merge pull request #33 from DaemonBeast/free-name-patch

This commit is contained in:
js6pak authored and GitHub committed 2021-06-07 22:01:57 +00:00
commit 7affc2a9f3
3 files changed
+74 -20

No files matched your search

-20
View File
@@ -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);
}
}
}
}
+25
View File
@@ -0,0 +1,25 @@
using System.Linq;
using HarmonyLib;
using TMPro;
using UnityEngine;
namespace Reactor.Patches
{
/// <summary>
/// "Fixes" an issue where empty TextBoxes have wrong cursor positions
/// </summary>
[HarmonyPatch(typeof(TextMeshProExtensions), nameof(TextMeshProExtensions.CursorPos))]
internal static class CursorPosPatch
{
public static bool Prefix(TextMeshPro self, ref Vector2 __result)
{
if (self.textInfo == null || self.textInfo.lineCount == 0 || self.textInfo.lineInfo[0].characterCount <= 0)
{
__result = self.GetTextInfo(" ").lineInfo.First().lineExtents.max;
return false;
}
return true;
}
}
}
+49
View File
@@ -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>();
}
}
}
}