LeagueTeaPartyView.cs 6.5 KB

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