LeagueTeaPartyView.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using ET;
  2. using FairyGUI;
  3. using Hutool;
  4. using System.Collections.Generic;
  5. using UI.League;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class LeagueTeaPartyView : BaseWindow
  10. {
  11. private UI_LeagueTeaPartyUI _ui;
  12. private List<TeapartyRoleCfg> teapartyRoleCfg;
  13. private List<GObject> TeaPartyItemObj = new List<GObject>();
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_LeagueTeaPartyUI.PACKAGE_NAME;
  27. _ui = UI_LeagueTeaPartyUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_loaBg.url = ResPathUtil.GetDressUpPath("chahuibg");
  31. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  32. _ui.m_btnChat.onClick.Add(OnBtnChatClick);
  33. _ui.m_btnChallenge.onClick.Add(OnBtnChallengeClick);
  34. _ui.m_btnReward.onClick.Add(OnBtnRewardClick);
  35. _ui.m_teaPartyItemTips.target.onClick.Add(OnTeaPartyItemTipsClick);
  36. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  37. _ui.m_btnRule.data = 300022;
  38. _ui.m_ListTeaParty.itemRenderer = ListTeaPartyItemRender;
  39. teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId);
  40. }
  41. private void ListTeaPartyItemRender(int index, GObject obj)
  42. {
  43. TeaPartyItemObj.Add(obj);
  44. UI_comTeaPartyItem itemObj = UI_comTeaPartyItem.Proxy(obj);
  45. itemObj.m_btnDetail.data = index;
  46. itemObj.m_btnDetail.onClick.Add(OnBtnDetailClick);
  47. itemObj.m_iconRole.data = index;
  48. itemObj.m_iconRole.onClick.Add(OnBtnIconRoleClick);
  49. itemObj.m_txtRoleName.text = teapartyRoleCfg[index].name;
  50. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  51. if (roleContainerList != null && roleContainerList.Count > 0)
  52. {
  53. itemObj.m_txtMaxValue.text = roleContainerList[index].MaxScore.ToString();
  54. itemObj.m_txtNumber.text = roleContainerList[index].PerNum.ToString();
  55. itemObj.m_txtMaxName.text = roleContainerList[index].MaxScoreRoleName;
  56. }
  57. var roleTeapartyInfo = LeagueDataManager.Instance.RoleTeapartyInfo;
  58. if (roleTeapartyInfo != null)
  59. itemObj.m_imgChoose.visible = index == (roleTeapartyInfo.TeapartyRoleId - 1);
  60. UI_comTeaPartyItem.ProxyEnd();
  61. }
  62. protected override void AddEventListener()
  63. {
  64. base.AddEventListener();
  65. EventAgent.AddEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty);
  66. EventAgent.AddEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange);
  67. }
  68. protected override void OnShown()
  69. {
  70. base.OnShown();
  71. var openCfg = TeapartyOpenCfgArray.Instance.GetCfg(LeagueDataManager.Instance.TeaPartyId);
  72. _ui.m_txtTeaName.text = openCfg.name;
  73. _ui.m_teaPartyItemTips.target.visible = false;
  74. int myPos = LeagueDataManager.Instance.GetMyPos();
  75. bool isLeader = myPos == LeaguePos.Owner || myPos == LeaguePos.SubOwner;
  76. _ui.m_btnChallenge.visible = isLeader;
  77. GetTeapartyMatchingInfos();
  78. GetRoleContainerInfos();
  79. }
  80. protected override void OnHide()
  81. {
  82. base.OnHide();
  83. QuitTeapparty();
  84. Timers.inst.Remove(UpDataTime);
  85. }
  86. protected override void RemoveEventListener()
  87. {
  88. base.RemoveEventListener();
  89. EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty);
  90. EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange);
  91. }
  92. private async void QuitTeapparty()
  93. {
  94. bool result = await LeagueSproxy.QuitTeapparty(RoleDataManager.roleId);
  95. if (result)
  96. {
  97. }
  98. }
  99. private void OnBtnChatClick()
  100. {
  101. ViewManager.Show<LeagueChatView>();
  102. }
  103. private void OnBtnChallengeClick()
  104. {
  105. if (LeagueDataManager.Instance.TeaPartyStatus != 1)
  106. return;
  107. TeapartyStartChallenge();
  108. }
  109. private async void TeapartyStartChallenge()
  110. {
  111. bool result = await LeagueSproxy.TeapartyStartChallenge(RoleDataManager.roleId);
  112. if (result)
  113. {
  114. ViewManager.Show<LeagueTeaPartyShowView>();
  115. }
  116. }
  117. private void OnBtnRewardClick()
  118. {
  119. ViewManager.Show<LeagueTeaPartyRewardView>();
  120. }
  121. private void OnBtnBackClick()
  122. {
  123. ViewManager.GoBackFrom(typeof(LeagueView).FullName);
  124. }
  125. private void OnBtnDetailClick(EventContext context)
  126. {
  127. GObject obj = context.sender as GObject;
  128. int index = (int)obj.data;
  129. Vector2 pos = new Vector2();
  130. if (index % 2 == 0) {
  131. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  132. pos.x = pos.x + TeaPartyItemObj[index].width;
  133. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  134. }
  135. else {
  136. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  137. pos.x = pos.x - TeaPartyItemObj[index].width;
  138. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  139. }
  140. _ui.m_teaPartyItemTips.m_window.position = pos;
  141. _ui.m_teaPartyItemTips.target.visible = true;
  142. _ui.m_teaPartyItemTips.m_txtName.text = teapartyRoleCfg[index].name;
  143. _ui.m_teaPartyItemTips.m_txtDesc.text = teapartyRoleCfg[index].desc;
  144. }
  145. private void OnTeaPartyItemTipsClick()
  146. {
  147. _ui.m_teaPartyItemTips.target.visible = false;
  148. }
  149. private void OnBtnIconRoleClick(EventContext context)
  150. {
  151. if (LeagueDataManager.Instance.TeaPartyStatus != 1)
  152. return;
  153. GObject obj = context.sender as GObject;
  154. LeagueDataManager.Instance.ChooseTeaPartId = (int)obj.data + 1;
  155. DressUpFightType dressUpFightType = new DressUpFightType();
  156. dressUpFightType.levelID = 0;
  157. dressUpFightType.teaPartID = LeagueDataManager.Instance.ChooseTeaPartId;
  158. ViewManager.Show<DressUpFightView>(dressUpFightType, new object[] { typeof(LeagueTeaPartyView).FullName, null }, true);
  159. }
  160. private void UpDataTime(object param = null)
  161. {
  162. UpDataOverTime();
  163. if (TimeInfo.Instance.ServerNow() >= LeagueDataManager.Instance.TeaPartyCloseTime)
  164. Timers.inst.Remove(UpDataTime);
  165. }
  166. private void UpDataOverTime()
  167. {
  168. _ui.m_txtOverTime.text = "挑战剩余时间:" + TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), LeagueDataManager.Instance.TeaPartyCloseTime);
  169. }
  170. private async void GetTeapartyMatchingInfos()
  171. {
  172. bool result = await LeagueSproxy.GetTeapartyMatchingInfos(RoleDataManager.roleId);
  173. if (result)
  174. {
  175. RefreshListTeaParty();
  176. }
  177. }
  178. private async void GetRoleContainerInfos()
  179. {
  180. bool result = await LeagueSproxy.GetRoleContainerInfos(RoleDataManager.roleId);
  181. if (result)
  182. {
  183. UpDataOverTime();
  184. Timers.inst.Add(1f, 0, UpDataTime);
  185. RefreshListTeaParty();
  186. }
  187. }
  188. private void RefreshListTeaParty()
  189. {
  190. _ui.m_ListTeaParty.numItems = teapartyRoleCfg.Count;
  191. }
  192. private void TeaPartyStatuChange()
  193. {
  194. if (LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo) {
  195. if (LeagueDataManager.Instance.RoleTeapartyInfo.Status)
  196. ViewManager.Show<LeagueTeaPartyShowView>();
  197. else
  198. OnBtnRewardClick();
  199. }
  200. }
  201. }
  202. }