summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/NameTextBehaviour.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/NameTextBehaviour.cs')
-rw-r--r--Client/Assembly-CSharp/NameTextBehaviour.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/NameTextBehaviour.cs b/Client/Assembly-CSharp/NameTextBehaviour.cs
new file mode 100644
index 0000000..83a3ad7
--- /dev/null
+++ b/Client/Assembly-CSharp/NameTextBehaviour.cs
@@ -0,0 +1,61 @@
+using System;
+using UnityEngine;
+using UnityEngine.Events;
+
+public class NameTextBehaviour : MonoBehaviour
+{
+ public static NameTextBehaviour Instance;
+
+ public TextBox nameSource;
+
+ public void Start()
+ {
+ NameTextBehaviour.Instance = this;
+ this.nameSource.SetText(SaveManager.PlayerName, "");
+ this.nameSource.OnFocusLost.AddListener(new UnityAction(this.UpdateName));
+ }
+
+ public void UpdateName()
+ {
+ if (this.ShakeIfInvalid())
+ {
+ return;
+ }
+ SaveManager.PlayerName = this.nameSource.text;
+ }
+
+ public static bool IsValidName(string text)
+ {
+ if (text == null || text.Length == 0)
+ {
+ return false;
+ }
+ if (text.Equals("Enter Name", StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+ if (BlockedWords.ContainsWord(text))
+ {
+ return false;
+ }
+ bool result = false;
+ for (int i = 0; i < text.Length; i++)
+ {
+ if (text[i] != ' ')
+ {
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ public bool ShakeIfInvalid()
+ {
+ if (!NameTextBehaviour.IsValidName(this.nameSource.text))
+ {
+ base.StartCoroutine(Effects.Shake(this.nameSource.transform, 0.75f, 0.25f));
+ return true;
+ }
+ return false;
+ }
+}