ManaNickName.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. public class ManaNickName : Regist
  9. {
  10. #region Config
  11. public static Action OnSetNickNameSucceed;
  12. public static string NickName;
  13. public static InputField inputField;
  14. private static List<string> LastNames = new List<string>();
  15. private static List<string> FirstNames = new List<string>();
  16. #endregion
  17. public override void RegistValueA()
  18. {
  19. SetNickName (ManaData.GetPlayerString ("NickName"));
  20. inputField = ManaReso.Get<InputField> ("T_InputField");
  21. string defaultNames = ManaReso.Load<TextAsset>("DefaultNickName", Folder.Config).text;
  22. string[] names = defaultNames.Split('\n');
  23. FirstNames = names[0].Split('|')[1].Split(',').ToList();
  24. LastNames = names[1].Split('|')[1].Split(',').ToList();
  25. //Debug.Log(FirstNames.Count);
  26. //Debug.Log(LastNames.Count);
  27. //foreach (var VARIABLE in FirstNames)
  28. //{
  29. // Debug.Log(VARIABLE);
  30. //}
  31. //foreach (var VARIABLE in LastNames)
  32. //{
  33. // Debug.LogWarning(VARIABLE);
  34. //}
  35. }
  36. public static void SetRandomName()
  37. {
  38. inputField.text = FirstNames.Random()[0].Trim('\'') + LastNames.Random()[0].Trim('\'');
  39. }
  40. public static bool ShowNickNameSettingPanelFirstTime()
  41. {
  42. if (!string.IsNullOrEmpty (NickName))
  43. return false;
  44. ShowNickNameSettingPanel();
  45. return true;
  46. }
  47. public static void ShowNickNameSettingPanel()
  48. {
  49. if (string.IsNullOrEmpty(NickName))
  50. {
  51. ManaReso.SetActive("T_Close", false);
  52. }
  53. else
  54. {
  55. ManaReso.SetActive("T_Close", true);
  56. inputField.text = NickName;
  57. }
  58. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  59. if (!ManaTutorial.TutorialPlazaRoom && !ManaTutorial.TutorialC && !ManaTutorial.TutorialD)
  60. {
  61. ManaReso.Get("C_Main").TweenBacCG();
  62. }
  63. ManaReso.Get ("T_NickNameBK").TweenForCG ();
  64. }
  65. public static void CloseNickNameSettingPanel()
  66. {
  67. ManaReso.Get ("C_Main").TweenForCG ();
  68. ManaReso.Get ("T_NickNameBK").TweenBacCG ();
  69. }
  70. public static void ResetNickName()
  71. {
  72. if (inputField.text == NickName)
  73. {
  74. ResetSucceed();
  75. return;
  76. }
  77. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Checking"));
  78. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = false;
  79. if (InputFieldValidate ())
  80. {
  81. ManaServer.SetNickName
  82. (
  83. inputField.text,
  84. ResetSucceed,
  85. ResetFailed
  86. );
  87. }
  88. else
  89. {
  90. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  91. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  92. }
  93. }
  94. public static void ResetFailed(string str)
  95. {
  96. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  97. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  98. Bubble.Show(null, str);
  99. }
  100. public static void ResetSucceed()
  101. {
  102. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  103. SetNickName(inputField.text);
  104. ManaAudio.PlayClip(Clip.CloseClip);
  105. CloseNickNameSettingPanel();
  106. OnSetNickNameSucceed.SafeInvoke();
  107. }
  108. public static void SetNickName(string nickName)
  109. {
  110. NickName = nickName;
  111. ManaData.SavePlayerString ("NickName", nickName);
  112. ManaReso.SetText ("C_NickNameLab", nickName);
  113. }
  114. public static bool InputFieldValidate()
  115. {
  116. inputField.text = inputField.text.Trim();
  117. int charCnt = 0;
  118. for (int i = 0; i < inputField.text.Length; i++)
  119. {
  120. if (inputField.text[i] <= 127)
  121. {
  122. charCnt++;
  123. }
  124. else if (inputField.text[i] > 127)
  125. {
  126. charCnt += 2;
  127. }
  128. }
  129. if (charCnt == 0)
  130. {
  131. Bubble.Show(null, Language.GetStr("UI", "T_AllWhiteSpace"));
  132. return false;
  133. }
  134. else if (charCnt > 12)
  135. {
  136. Bubble.Show(null, Language.GetStr("UI", "T_TooLong"));
  137. inputField.text = inputField.text.Substring(0, 12);
  138. return false;
  139. }
  140. else
  141. {
  142. if (StringFilter.ContainSensitiveWord(inputField.text))
  143. {
  144. Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
  145. return false;
  146. }
  147. else
  148. {
  149. return true;
  150. }
  151. }
  152. }
  153. }