LeagueTeaPartyView.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. }
  66. protected override void OnShown()
  67. {
  68. base.OnShown();
  69. var openCfg = TeapartyOpenCfgArray.Instance.GetCfg(LeagueDataManager.Instance.TeaPartyId);
  70. _ui.m_txtTeaName.text = openCfg.name;
  71. _ui.m_teaPartyItemTips.target.visible = false;
  72. int myPos = LeagueDataManager.Instance.GetMyPos();
  73. bool isLeader = myPos == LeaguePos.Owner || myPos == LeaguePos.SubOwner;
  74. _ui.m_btnChallenge.visible = isLeader;
  75. GetTeapartyMatchingInfos();
  76. GetRoleContainerInfos();
  77. }
  78. private void UpDataTime(object param = null)
  79. {
  80. UpDataOverTime();
  81. if (TimeInfo.Instance.ServerNow() >= LeagueDataManager.Instance.TeaPartyCloseTime)
  82. Timers.inst.Remove(UpDataTime);
  83. }
  84. private void UpDataOverTime()
  85. {
  86. _ui.m_txtOverTime.text = "挑战剩余时间:" + TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), LeagueDataManager.Instance.TeaPartyCloseTime);
  87. }
  88. private async void GetTeapartyMatchingInfos()
  89. {
  90. bool result = await LeagueSproxy.GetTeapartyMatchingInfos(RoleDataManager.roleId);
  91. if (result)
  92. {
  93. _ui.m_ListTeaParty.numItems = 6;
  94. }
  95. }
  96. private async void GetRoleContainerInfos()
  97. {
  98. bool result = await LeagueSproxy.GetRoleContainerInfos(RoleDataManager.roleId);
  99. if (result)
  100. {
  101. UpDataOverTime();
  102. Timers.inst.Add(1f, 0, UpDataTime);
  103. _ui.m_ListTeaParty.numItems = 6;
  104. }
  105. }
  106. protected override void OnHide()
  107. {
  108. base.OnHide();
  109. Timers.inst.Remove(UpDataTime);
  110. }
  111. protected override void RemoveEventListener()
  112. {
  113. base.RemoveEventListener();
  114. }
  115. private void OnBtnChatClick()
  116. {
  117. ViewManager.Show<LeagueChatView>();
  118. }
  119. private void OnBtnChallengeClick()
  120. {
  121. if (LeagueDataManager.Instance.TeaPartyStatus != 1)
  122. return;
  123. TeapartyStartChallenge();
  124. }
  125. private async void TeapartyStartChallenge()
  126. {
  127. bool result = await LeagueSproxy.TeapartyStartChallenge(RoleDataManager.roleId);
  128. if (result)
  129. {
  130. ViewManager.Show<LeagueTeaPartyShowView>();
  131. }
  132. }
  133. private void OnBtnRewardClick()
  134. {
  135. ViewManager.Show<LeagueTeaPartyRewardView>();
  136. }
  137. private void OnBtnBackClick()
  138. {
  139. ViewManager.GoBackFrom(typeof(LeagueView).FullName);
  140. }
  141. private void OnBtnDetailClick(EventContext context)
  142. {
  143. GObject obj = context.sender as GObject;
  144. int index = (int)obj.data;
  145. Vector2 pos = new Vector2();
  146. if (index % 2 == 0) {
  147. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  148. pos.x = pos.x + TeaPartyItemObj[index].width;
  149. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  150. }
  151. else {
  152. pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position);
  153. pos.x = pos.x - TeaPartyItemObj[index].width;
  154. pos.y = pos.y + TeaPartyItemObj[index].height / 2;
  155. }
  156. _ui.m_teaPartyItemTips.m_window.position = pos;
  157. _ui.m_teaPartyItemTips.target.visible = true;
  158. _ui.m_teaPartyItemTips.m_txtName.text = teapartyRoleCfg[index].name;
  159. _ui.m_teaPartyItemTips.m_txtDesc.text = teapartyRoleCfg[index].hint;
  160. }
  161. private void OnTeaPartyItemTipsClick()
  162. {
  163. _ui.m_teaPartyItemTips.target.visible = false;
  164. }
  165. private void OnBtnIconRoleClick(EventContext context)
  166. {
  167. if (LeagueDataManager.Instance.TeaPartyStatus != 1)
  168. return;
  169. GObject obj = context.sender as GObject;
  170. LeagueDataManager.Instance.ChooseTeaPartId = (int)obj.data + 1;
  171. DressUpFightType dressUpFightType = new DressUpFightType();
  172. dressUpFightType.levelID = 0;
  173. dressUpFightType.teaPartID = LeagueDataManager.Instance.ChooseTeaPartId;
  174. ViewManager.Show<DressUpFightView>(dressUpFightType, new object[] { typeof(LeagueTeaPartyView).FullName, null }, true);
  175. }
  176. }
  177. }