LeagueTeaPartyView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. _ui.m_btnChallenge.grayed = LeagueDataManager.Instance.TeaPartyStatus != LeagueTeaPartyStatus.YesOpen;
  78. GetTeapartyMatchingInfos();
  79. GetRoleContainerInfos();
  80. }
  81. protected override void OnHide()
  82. {
  83. base.OnHide();
  84. Timers.inst.Remove(UpDataTime);
  85. QuitTeapparty();
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty);
  91. EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange);
  92. }
  93. private async void QuitTeapparty()
  94. {
  95. bool result = await LeagueSproxy.QuitTeapparty(RoleDataManager.roleId);
  96. if (result)
  97. {
  98. }
  99. }
  100. private void OnBtnChatClick()
  101. {
  102. ViewManager.Show<LeagueChatView>();
  103. }
  104. private void OnBtnChallengeClick()
  105. {
  106. if (LeagueDataManager.Instance.TeaPartyStatus != LeagueTeaPartyStatus.YesOpen)
  107. return;
  108. TeapartyStartChallenge();
  109. }
  110. private async void TeapartyStartChallenge()
  111. {
  112. bool result = await LeagueSproxy.TeapartyStartChallenge(RoleDataManager.roleId);
  113. if (result)
  114. {
  115. ViewManager.Show<LeagueTeaPartyShowView>();
  116. }
  117. }
  118. private void OnBtnRewardClick()
  119. {
  120. ViewManager.Show<LeagueTeaPartyRewardView>();
  121. }
  122. private void OnBtnBackClick()
  123. {
  124. ViewManager.GoBackFrom(typeof(LeagueView).FullName);
  125. }
  126. private void OnBtnDetailClick(EventContext context)
  127. {
  128. GObject obj = context.sender as GObject;
  129. int index = (int)obj.data;
  130. Vector2 pos = new Vector2();
  131. if (index % 2 == 0) {
  132. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  133. pos.x = pos.x + TeaPartyItemObj[index].width;
  134. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  135. }
  136. else {
  137. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  138. pos.x = pos.x - TeaPartyItemObj[index].width;
  139. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  140. }
  141. _ui.m_teaPartyItemTips.m_window.position = pos;
  142. _ui.m_teaPartyItemTips.target.visible = true;
  143. _ui.m_teaPartyItemTips.m_txtName.text = teapartyRoleCfg[index].name;
  144. _ui.m_teaPartyItemTips.m_txtDesc.text = teapartyRoleCfg[index].desc;
  145. }
  146. private void OnTeaPartyItemTipsClick()
  147. {
  148. _ui.m_teaPartyItemTips.target.visible = false;
  149. }
  150. private void OnBtnIconRoleClick(EventContext context)
  151. {
  152. if (LeagueDataManager.Instance.TeaPartyStatus != 1)
  153. return;
  154. GObject obj = context.sender as GObject;
  155. LeagueDataManager.Instance.ChooseTeaPartId = (int)obj.data + 1;
  156. DressUpFightType dressUpFightType = new DressUpFightType();
  157. dressUpFightType.levelID = 0;
  158. dressUpFightType.teaPartID = LeagueDataManager.Instance.ChooseTeaPartId;
  159. ViewManager.Show<DressUpFightView>(dressUpFightType, new object[] { typeof(LeagueTeaPartyView).FullName, null }, true);
  160. }
  161. private void UpDataTime(object param = null)
  162. {
  163. UpDataOverTime();
  164. if (TimeInfo.Instance.ServerNow() >= LeagueDataManager.Instance.TeaPartyCloseTime)
  165. Timers.inst.Remove(UpDataTime);
  166. }
  167. private void UpDataOverTime()
  168. {
  169. string strTimeText = "挑战剩余时间:";
  170. if(LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo)
  171. strTimeText = "公开剩余时间:";
  172. _ui.m_txtOverTime.text = "挑战剩余时间:" + TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), LeagueDataManager.Instance.TeaPartyCloseTime);
  173. }
  174. private async void GetTeapartyMatchingInfos()
  175. {
  176. bool result = await LeagueSproxy.GetTeapartyMatchingInfos(RoleDataManager.roleId);
  177. if (result)
  178. {
  179. RefreshListTeaParty();
  180. }
  181. }
  182. private async void GetRoleContainerInfos()
  183. {
  184. bool result = await LeagueSproxy.GetRoleContainerInfos(RoleDataManager.roleId);
  185. if (result)
  186. {
  187. UpDataOverTime();
  188. Timers.inst.Add(1f, 0, UpDataTime);
  189. RefreshListTeaParty();
  190. }
  191. }
  192. private void RefreshListTeaParty()
  193. {
  194. _ui.m_ListTeaParty.numItems = teapartyRoleCfg.Count;
  195. }
  196. private void TeaPartyStatuChange()
  197. {
  198. if (LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo) {
  199. if (LeagueDataManager.Instance.RoleTeapartyInfo.Status)
  200. ViewManager.Show<LeagueTeaPartyShowView>();
  201. else
  202. OnBtnRewardClick();
  203. }
  204. }
  205. }
  206. }