ManaNickName.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class ManaNickName : Regist
  8. {
  9. public static Action SetNickNameAction;
  10. public static string NickName;
  11. public static InputField inputField;
  12. public override void RegistValueA()
  13. {
  14. SetNickName (ManaData.GetPlayerString ("NickName"));
  15. inputField = ManaReso.Get<InputField> ("T_InputField");
  16. }
  17. public static bool ShowNickNameSettingPanelFirstTime()
  18. {
  19. if (!string.IsNullOrEmpty (NickName))
  20. return false;
  21. ShowNickNameSettingPanel();
  22. return true;
  23. }
  24. public static void ShowNickNameSettingPanel()
  25. {
  26. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  27. ManaReso.Get ("C_Main").TweenBacCG ();
  28. ManaReso.Get ("T_NickNameBK").TweenForCG ();
  29. }
  30. public static void CloseNickNameSettingPanel()
  31. {
  32. ManaReso.Get ("C_Main").TweenForCG ();
  33. ManaReso.Get ("T_NickNameBK").TweenBacCG ();
  34. }
  35. public static void ResetNickName()
  36. {
  37. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Checking"));
  38. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = false;
  39. if (InputFieldValidate ())
  40. {
  41. ManaServer.SetNickName
  42. (
  43. inputField.text,
  44. SetNickNameAction,
  45. ResetSucceed,
  46. ResetFailed
  47. );
  48. }
  49. else
  50. {
  51. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  52. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  53. }
  54. }
  55. public static void ResetFailed()
  56. {
  57. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  58. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  59. if (!ManaTutorial.TutorialA)
  60. {
  61. Bubble.Show(null, Language.GetStr("UI", "T_RepeatName"));
  62. }
  63. }
  64. public static void ResetSucceed()
  65. {
  66. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  67. SetNickName(inputField.text);
  68. ManaAudio.PlayClip(Clip.CloseClip);
  69. CloseNickNameSettingPanel();
  70. }
  71. public static void SetNickName(string nickName)
  72. {
  73. NickName = nickName;
  74. ManaData.SavePlayerString ("NickName", nickName);
  75. ManaReso.SetText ("C_NickNameLab", nickName);
  76. }
  77. public static bool InputFieldValidate()
  78. {
  79. inputField.text = inputField.text.Trim();
  80. int charCnt = 0;
  81. for (int i = 0; i < inputField.text.Length; i++)
  82. {
  83. if (inputField.text[i] <= 127)
  84. {
  85. charCnt++;
  86. }
  87. else if (inputField.text[i] > 127)
  88. {
  89. charCnt += 2;
  90. }
  91. }
  92. if (charCnt == 0)
  93. {
  94. Bubble.Show(null, Language.GetStr("UI", "T_AllWhiteSpace"));
  95. return false;
  96. }
  97. else if (charCnt > 12)
  98. {
  99. Bubble.Show(null, Language.GetStr("UI", "T_TooLong"));
  100. inputField.text = inputField.text.Substring(0, 12);
  101. return false;
  102. }
  103. else
  104. {
  105. if (StringFilter.ContainSensitiveWord(inputField.text))
  106. {
  107. Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
  108. return false;
  109. }
  110. else
  111. {
  112. return true;
  113. }
  114. }
  115. }
  116. }