12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class NickPanel : PopUpPanel
- {
- public Text titleTxt;
- public InputField input;
- public Text btnLabel;
- private string oldNick;
- void Awake()
- {
- titleTxt.text = Language.GetStr ("UserPanel", "changeNick");
- btnLabel.text = Language.GetStr ("Public", "ok");
- input.onValidateInput += StringUtil.InputValidateHandler;
- }
- void Start()
- {
- input.text = oldNick = Session.GetInstance ().myUserData.nick;
- }
- public void OnNameChanged()
- {
- input.text = StringUtil.LimitInput (input.text, Config.MAX_USER_NAME_LENGTH);
- }
- public void OnClick()
- {
- if(oldNick == input.text)
- {
- Close ();
- return;
- }
- if (StringUtil.Empty (input.text))
- return;
- UserRequest.Nick (Session.myUserId, input.text).ResultEvent.AddListener ((bool success, LitJson.JsonData data) => {
- if(success)
- {
- UserData userData = Session.GetInstance().myUserData;
- userData.nick = input.text;
- Close();
- ProfilePanel.Show(Session.myUserId);
- }
- });
- }
- protected override void Remove ()
- {
- base.Remove ();
- input.onValidateInput -= StringUtil.InputValidateHandler;
- }
- private static NickPanel currentPanel;
- public static NickPanel Show()
- {
- if (currentPanel != null) {
- currentPanel.gameObject.SetActive (true);
- PopUpManager.AddToMainCanvas (currentPanel.gameObject);
- }
- else
- currentPanel = PopUpManager.AddPopUp<NickPanel> (Resources.Load<GameObject> ("Prefabs/UI/UserPanel/NickPanel"), null, true);
- currentPanel.Open ();
- return currentPanel;
- }
- }
|