ProfilePanel.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ProfilePanel : PopUpPanel
  5. {
  6. public Text titleTxt;
  7. public Text nickTxt;
  8. public Text btnTxt;
  9. public Text rankTxt;
  10. public Text winLabel;
  11. public Text winTxt;
  12. private CallBackUtil.SimpleCallBack clickHandler;
  13. private int id;
  14. void Awake()
  15. {
  16. titleTxt.text = Language.GetStr ("UserPanel", "profile");
  17. winLabel.text = Language.GetStr ("UserPanel", "win")+":";
  18. }
  19. public void SetUserId(int id)
  20. {
  21. this.id = id;
  22. nickTxt.text = UserCache.GetNick (id);
  23. UserCache.UserDataGot.RemoveListener (OnGetUserData);
  24. UserCache.UserDataGot.AddListener (OnGetUserData);
  25. UserCache.GetUser (id);
  26. if(id == Session.myUserId)
  27. {
  28. btnTxt.text = Language.GetStr ("UserPanel", "changeName");
  29. clickHandler = MyClickHandler;
  30. }
  31. else
  32. {
  33. if (FollowManager.GetInstance ().IsFollow (id)) {
  34. clickHandler = UnfollowClickHandler;
  35. btnTxt.text = Language.GetStr ("UserPanel", "unfollow");
  36. } else {
  37. clickHandler = FollowClickHandler;
  38. btnTxt.text = Language.GetStr ("UserPanel", "follow");
  39. }
  40. }
  41. }
  42. private void OnGetUserData(UserData userData)
  43. {
  44. if (id != userData.id)
  45. return;
  46. nickTxt.text = userData.nick;
  47. rankTxt.text = userData.rank.ToString ();
  48. winTxt.text = userData.win.ToString ();
  49. }
  50. public void OnClick()
  51. {
  52. if (id <= 0)
  53. return;
  54. clickHandler ();
  55. }
  56. private void MyClickHandler()
  57. {
  58. NickPanel.Show ();
  59. }
  60. private void FollowClickHandler()
  61. {
  62. FollowManager.GetInstance ().Follow (id, (bool success)=>{
  63. if(success)
  64. SetUserId(id);
  65. });
  66. }
  67. private void UnfollowClickHandler()
  68. {
  69. FollowManager.GetInstance ().Unfollow (id, (bool success)=>{
  70. if(success)
  71. SetUserId(id);
  72. });
  73. }
  74. private static ProfilePanel currentPanel;
  75. public static ProfilePanel Show(int userId)
  76. {
  77. if (currentPanel != null) {
  78. currentPanel.gameObject.SetActive (true);
  79. PopUpManager.AddToMainCanvas (currentPanel.gameObject);
  80. }
  81. else
  82. currentPanel = PopUpManager.AddPopUp<ProfilePanel> (Resources.Load<GameObject> ("Prefabs/UI/UserPanel/ProfilePanel"), null, true);
  83. currentPanel.Open ();
  84. currentPanel.SetUserId (userId);
  85. return currentPanel;
  86. }
  87. }