ManaNickName.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. }
  50. public static void ResetFailed()
  51. {
  52. ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
  53. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  54. if (!ManaTutorial.TutorialA)
  55. {
  56. Bubble.Show(null, Language.GetStr("UI", "T_RepeatName"));
  57. }
  58. }
  59. public static void ResetSucceed()
  60. {
  61. ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
  62. SetNickName(inputField.text);
  63. CloseNickNameSettingPanel();
  64. }
  65. public static void SetNickName(string nickName)
  66. {
  67. NickName = nickName;
  68. ManaData.SavePlayerString ("NickName", nickName);
  69. ManaReso.SetText ("C_NickNameLab", nickName);
  70. }
  71. public static bool InputFieldValidate()
  72. {
  73. inputField.text = inputField.text.Trim ();
  74. int charCnt = 0;
  75. for (int i = 0; i < inputField.text.Length; i++) {
  76. if (inputField.text [i] <= 127) {
  77. charCnt++;
  78. } else if (inputField.text [i] > 127) {
  79. charCnt += 2;
  80. }
  81. }
  82. if (charCnt == 0) {
  83. Bubble.Show (null, Language.GetStr("UI", "T_AllWhiteSpace"));
  84. return false;
  85. } else if (charCnt > 12) {
  86. Bubble.Show (null, Language.GetStr("UI", "T_TooLong"));
  87. inputField.text = inputField.text.Substring (0, 12);
  88. return false;
  89. } else {
  90. if (StringFilter.ContainSensitiveWord(inputField.text))
  91. {
  92. Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
  93. return false;
  94. }
  95. else
  96. {
  97. ManaAudio.PlayClip(Clip.CloseClip);
  98. return true;
  99. }
  100. }
  101. }
  102. }