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 (Resources.Load ("Prefabs/UI/UserPanel/ProfilePanel"), null, true); currentPanel.Open (); currentPanel.SetUserId (userId); return currentPanel; } }