ManaNickName.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. ManaAudio.PlayClip(Clip.CloseClip);
  33. ManaReso.Get ("C_Main").TweenForCG ();
  34. ManaReso.Get ("T_NickNameBK").TweenBacCG ();
  35. }
  36. public static void ResetNickName()
  37. {
  38. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Checking"));
  39. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = false;
  40. if (InputFieldValidate ())
  41. {
  42. ManaServer.SetNickName
  43. (
  44. inputField.text,
  45. SetNickNameAction,
  46. ResetSucceed,
  47. ResetFailed
  48. );
  49. }
  50. else
  51. {
  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. CloseNickNameSettingPanel();
  69. }
  70. public static void SetNickName(string nickName)
  71. {
  72. NickName = nickName;
  73. ManaData.SavePlayerString ("NickName", nickName);
  74. ManaReso.SetText ("C_NickNameLab", nickName);
  75. }
  76. public static bool InputFieldValidate()
  77. {
  78. inputField.text = inputField.text.Trim();
  79. int charCnt = 0;
  80. for (int i = 0; i < inputField.text.Length; i++)
  81. {
  82. if (inputField.text[i] <= 127)
  83. {
  84. charCnt++;
  85. }
  86. else if (inputField.text[i] > 127)
  87. {
  88. charCnt += 2;
  89. }
  90. }
  91. if (charCnt == 0)
  92. {
  93. Bubble.Show(null, Language.GetStr("UI", "T_AllWhiteSpace"));
  94. return false;
  95. }
  96. else if (charCnt > 12)
  97. {
  98. Bubble.Show(null, Language.GetStr("UI", "T_TooLong"));
  99. inputField.text = inputField.text.Substring(0, 12);
  100. return false;
  101. }
  102. else
  103. {
  104. if (StringFilter.ContainSensitiveWord(inputField.text))
  105. {
  106. Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
  107. return false;
  108. }
  109. else
  110. {
  111. ManaAudio.PlayClip(Clip.CloseClip);
  112. return true;
  113. }
  114. }
  115. }
  116. }