123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class ManaNickName : Regist
- {
- #region Config
- public static Action OnSetNickNameSucceed;
- public static string NickName;
- public static InputField inputField;
- private static List<string> LastNames = new List<string>();
- private static List<string> FirstNames = new List<string>();
- #endregion
- public override void RegistValueA()
- {
- SetNickName (ManaData.GetPlayerString ("NickName"));
- inputField = ManaReso.Get<InputField> ("T_InputField");
- string defaultNames = ManaReso.Load<TextAsset>("DefaultNickName", Folder.Config).text;
- string[] names = defaultNames.Split('\n');
- FirstNames = names[0].Split('|')[1].Split(',').ToList();
- LastNames = names[1].Split('|')[1].Split(',').ToList();
- //Debug.Log(FirstNames.Count);
- //Debug.Log(LastNames.Count);
- //foreach (var VARIABLE in FirstNames)
- //{
- // Debug.Log(VARIABLE);
- //}
- //foreach (var VARIABLE in LastNames)
- //{
- // Debug.LogWarning(VARIABLE);
- //}
- }
- public static void SetRandomName()
- {
- inputField.text = FirstNames.Random()[0].Trim('\'') + LastNames.Random()[0].Trim('\'');
- }
- public static bool ShowNickNameSettingPanelFirstTime()
- {
- if (!string.IsNullOrEmpty (NickName))
- return false;
- ShowNickNameSettingPanel();
- return true;
- }
- public static void ShowNickNameSettingPanel()
- {
- if (string.IsNullOrEmpty(NickName))
- {
- ManaReso.SetActive("T_Close", false);
- }
- else
- {
- ManaReso.SetActive("T_Close", true);
- inputField.text = NickName;
- }
- ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
- if (!ManaTutorial.TutorialPlazaRoom && !ManaTutorial.TutorialC && !ManaTutorial.TutorialD)
- {
- ManaReso.Get("C_Main").TweenBacCG();
- }
- ManaReso.Get ("T_NickNameBK").TweenForCG ();
- }
- public static void CloseNickNameSettingPanel()
- {
- ManaReso.Get ("C_Main").TweenForCG ();
- ManaReso.Get ("T_NickNameBK").TweenBacCG ();
- }
- public static void ResetNickName()
- {
- if (inputField.text == NickName)
- {
- ResetSucceed();
- return;
- }
- ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Checking"));
- ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = false;
- if (InputFieldValidate ())
- {
- ManaServer.SetNickName
- (
- inputField.text,
- ResetSucceed,
- ResetFailed
- );
- }
- else
- {
- ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
- ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
- }
- }
- public static void ResetFailed(string str)
- {
- ManaReso.SetText("T_Tit", Language.GetStr("UI", "T_Tit"));
- ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
- Bubble.Show(null, str);
- }
- public static void ResetSucceed()
- {
- ManaReso.Get<CanvasGroup>("T_NickNameBK").interactable = true;
- SetNickName(inputField.text);
- ManaAudio.PlayClip(Clip.CloseClip);
- CloseNickNameSettingPanel();
- OnSetNickNameSucceed.SafeInvoke();
- }
- public static void SetNickName(string nickName)
- {
- NickName = nickName;
- ManaData.SavePlayerString ("NickName", nickName);
- ManaReso.SetText ("C_NickNameLab", nickName);
- }
- public static bool InputFieldValidate()
- {
- inputField.text = inputField.text.Trim();
- int charCnt = 0;
- for (int i = 0; i < inputField.text.Length; i++)
- {
- if (inputField.text[i] <= 127)
- {
- charCnt++;
- }
- else if (inputField.text[i] > 127)
- {
- charCnt += 2;
- }
- }
- if (charCnt == 0)
- {
- Bubble.Show(null, Language.GetStr("UI", "T_AllWhiteSpace"));
- return false;
- }
- else if (charCnt > 12)
- {
- Bubble.Show(null, Language.GetStr("UI", "T_TooLong"));
- inputField.text = inputField.text.Substring(0, 12);
- return false;
- }
- else
- {
- if (StringFilter.ContainSensitiveWord(inputField.text))
- {
- Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- }
|