123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class ProfilePanel : PopUpPanel
- {
- public Text titleTxt;
- public Text nickTxt;
- public Text btnTxt;
- public Text rankTxt;
- public Text winLabel;
- public Text winTxt;
- private CallBackUtil.SimpleCallBack clickHandler;
- private int id;
- void Awake()
- {
- titleTxt.text = Language.GetStr ("UserPanel", "profile");
- winLabel.text = Language.GetStr ("UserPanel", "win")+":";
- }
- public void SetUserId(int id)
- {
- this.id = id;
- nickTxt.text = UserCache.GetNick (id);
- UserCache.UserDataGot.RemoveListener (OnGetUserData);
- UserCache.UserDataGot.AddListener (OnGetUserData);
- UserCache.GetUser (id);
- if(id == Session.myUserId)
- {
- btnTxt.text = Language.GetStr ("UserPanel", "changeName");
- clickHandler = MyClickHandler;
- }
- else
- {
- if (FollowManager.GetInstance ().IsFollow (id)) {
- clickHandler = UnfollowClickHandler;
- btnTxt.text = Language.GetStr ("UserPanel", "unfollow");
- } else {
- clickHandler = FollowClickHandler;
- btnTxt.text = Language.GetStr ("UserPanel", "follow");
- }
- }
- }
- private void OnGetUserData(UserData userData)
- {
- if (id != userData.id)
- return;
- nickTxt.text = userData.nick;
- rankTxt.text = userData.rank.ToString ();
- winTxt.text = userData.win.ToString ();
- }
- public void OnClick()
- {
- if (id <= 0)
- return;
- clickHandler ();
- }
- private void MyClickHandler()
- {
- NickPanel.Show ();
- }
- private void FollowClickHandler()
- {
- FollowManager.GetInstance ().Follow (id, (bool success)=>{
- if(success)
- SetUserId(id);
- });
- }
- private void UnfollowClickHandler()
- {
- FollowManager.GetInstance ().Unfollow (id, (bool success)=>{
- if(success)
- SetUserId(id);
- });
- }
- private static ProfilePanel currentPanel;
- public static ProfilePanel Show(int userId)
- {
- if (currentPanel != null) {
- currentPanel.gameObject.SetActive (true);
- PopUpManager.AddToMainCanvas (currentPanel.gameObject);
- }
- else
- currentPanel = PopUpManager.AddPopUp<ProfilePanel> (Resources.Load<GameObject> ("Prefabs/UI/UserPanel/ProfilePanel"), null, true);
- currentPanel.Open ();
- currentPanel.SetUserId (userId);
- return currentPanel;
- }
- }
|