ClanInfoView.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ClanInfoView : View {
  5. public Text nameText;
  6. public Text descText;
  7. public Button actionBtn;
  8. public Text actionBtnLabel;
  9. public Button editBtn;
  10. public Text editBtnLabel;
  11. public Text rankLabel;
  12. public Text rankText;
  13. public Text idLabe;
  14. public Text idText;
  15. public Text menberLabel;
  16. public Text menberText;
  17. public Text requireLabel;
  18. public Text requireText;
  19. public Text typeLabel;
  20. public Text typeText;
  21. public Transform menberContainer;
  22. public ClanMenberItem menberItemPrefab;
  23. private ClanData clanData;
  24. void Awake()
  25. {
  26. nameText.text = "";
  27. descText.text = "";
  28. rankLabel.text = Language.GetStr ("ClanPanel", "rankLabel");
  29. idLabe.text = Language.GetStr ("ClanPanel", "idLabel");
  30. menberLabel.text = Language.GetStr ("ClanPanel", "menberLabel");
  31. requireLabel.text = Language.GetStr ("ClanPanel", "requireLabel");
  32. typeLabel.text = Language.GetStr ("ClanPanel", "typeLabel");
  33. editBtnLabel.text = Language.GetStr ("ClanPanel", "edit");
  34. rankText.text = idText.text = menberText.text = requireText.text = typeText.text = "";
  35. menberItemPrefab.gameObject.SetActive (false);
  36. actionBtn.gameObject.SetActive (false);
  37. menberItemPrefab.clanInfoView = this;
  38. }
  39. protected override void OnInitCompleted ()
  40. {
  41. this.data = data;
  42. }
  43. public override object data {
  44. get {
  45. return base.data;
  46. }
  47. set {
  48. base.data = value;
  49. if (value != null && value is int) {
  50. SetClanId ((int)value);
  51. }
  52. }
  53. }
  54. private void SetClanId(int clanId)
  55. {
  56. if (initialized && clanId > 0) {
  57. actionBtn.gameObject.SetActive (false);
  58. editBtn.gameObject.SetActive (false);
  59. ProgressPanel.Show ();
  60. ClanManager.GetInstance ().GetClan (clanId, OnGetClan);
  61. }
  62. }
  63. private void OnGetClan(ClanData data)
  64. {
  65. ProgressPanel.Hide ();
  66. this.clanData = data;
  67. int myClanId = Session.GetInstance ().myUserData.clanId;
  68. if (myClanId == 0) {
  69. actionBtnLabel.text = Language.GetStr ("ClanPanel", "join");
  70. actionBtn.gameObject.SetActive (true);
  71. } else if (data.id == myClanId) {
  72. actionBtnLabel.text = Language.GetStr ("ClanPanel", "leave");
  73. actionBtn.gameObject.SetActive (true);
  74. } else {
  75. actionBtn.gameObject.SetActive (false);
  76. }
  77. editBtn.gameObject.SetActive (clanData.founder == Session.myUserId);
  78. nameText.text = data.name;
  79. descText.text = data.description;
  80. rankText.text = data.rank.ToString ();
  81. idText.text = data.id.ToString ();
  82. menberText.text = "" + data.amount + "/" + data.maxAmount;
  83. //requireText.text = data.
  84. typeText.text = data.GetLimitStr();
  85. int index = 0;
  86. if(data.userList != null)
  87. {
  88. for(int i=0; i<data.userList.Count; i++)
  89. {
  90. ClanMenberItem item = null;
  91. if (i >= menberContainer.childCount) {
  92. item = Instantiate<GameObject> (menberItemPrefab.gameObject).GetComponent<ClanMenberItem> ();
  93. PopUpManager.AddToMainCanvas (item.gameObject, menberContainer);
  94. } else {
  95. item = menberContainer.GetChild (i).GetComponent<ClanMenberItem> ();
  96. }
  97. item.gameObject.SetActive (true);
  98. item.SetUserData (data.userList [i]);
  99. index++;
  100. }
  101. }
  102. while(index < menberContainer.childCount)
  103. {
  104. menberContainer.GetChild (index).gameObject.SetActive (false);
  105. index++;
  106. }
  107. }
  108. public void ClanEdit()
  109. {
  110. if(clanData != null && clanData.founder == Session.myUserId)
  111. ClanPanel.ShowEdit();
  112. }
  113. public void ClanAction()
  114. {
  115. int myClanId = Session.GetInstance ().myUserData.clanId;
  116. if (myClanId == 0) {
  117. ClanRequest.Join (clanData.id).ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
  118. if(success)
  119. {
  120. int clanId = JsonUtil.ToInt(data);
  121. ClanManager.GetInstance().RemoveClan(clanId);
  122. Session.GetInstance().myUserData.clanId = clanId;
  123. ClanPanel.ShowClanInfo(clanId);
  124. Session.GetInstance().GetBattleSession().GetMessageManager().ClanJoin();
  125. }
  126. });
  127. } else if (clanData.id == myClanId) {
  128. ClanRequest.Leave ().ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
  129. if(success)
  130. {
  131. int clanId = JsonUtil.ToInt(data);
  132. ClanManager.GetInstance().RemoveClan(clanId);
  133. Session.GetInstance().myUserData.clanId = 0;
  134. ClanPanel.ShowClanInfo(0);
  135. Session.GetInstance().GetBattleSession().GetMessageManager().ClanLeft();
  136. }
  137. });
  138. }
  139. }
  140. public bool IsFounder()
  141. {
  142. if (clanData != null && clanData.founder == Session.myUserId)
  143. return true;
  144. return false;
  145. }
  146. public void Kick(int id, ClanMenberItem item)
  147. {
  148. if (!IsFounder ())
  149. return;
  150. string info = Language.GetStr ("ClanPanel", "kick").Replace ("%NICK%", UserCache.GetNick(id));
  151. AlertPanel.Show (info, AlertPanel.YES|AlertPanel.NO, (AlertCloseEvent evt) => {
  152. if(evt.detail == AlertPanel.YES)
  153. {
  154. ClanRequest.Kick (id, clanData.id).ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
  155. if(success)
  156. {
  157. item.transform.SetAsLastSibling();
  158. item.gameObject.SetActive(false);
  159. }
  160. });
  161. }
  162. });
  163. }
  164. }