MatchingCompetitionRankView.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.MatchingCompetition;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. class MatchingCompetitionRankView : BaseWindow
  10. {
  11. private UI_MatchingCompetitionRankUI _ui;
  12. private int _currentIndex = 0;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. }
  19. _ui = null;
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_MatchingCompetitionRankUI.PACKAGE_NAME;
  26. _ui = UI_MatchingCompetitionRankUI.Create();
  27. this.viewCom = _ui.target;
  28. isReturnView = true;
  29. isfullScreen = true;
  30. _ui.m_RankList.itemRenderer = RenderRankList;
  31. _ui.m_BtnBack.onClick.Add(OnClickBtnBack);
  32. _ui.m_btnBefore.onClick.Add(OnClickBtnBefore);
  33. _ui.m_btnLook.onClick.Add(OnClickBtnLook);
  34. _ui.m_ruleBtn.onClick.Add(MatchingCompetitionDataManager.Instance.OnClickBtnRule);
  35. }
  36. protected override void OnShown()
  37. {
  38. base.OnShown();
  39. _ui.m_bg.url = ResPathUtil.GetBgImgPath("pxs_bj");
  40. _ui.m_outBg.url = ResPathUtil.GetBgImgPath("pxs_pmdb");
  41. _ui.m_titleText.text = JudgingRoundOpenCfgArray.Instance.dataArray[MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason - 1].Name;
  42. UpdateView();
  43. UpdateHead();
  44. }
  45. protected override void OnHide()
  46. {
  47. base.OnHide();
  48. }
  49. protected override void AddEventListener()
  50. {
  51. base.AddEventListener();
  52. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
  53. EventAgent.AddEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
  54. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
  55. }
  56. protected override void RemoveEventListener()
  57. {
  58. base.RemoveEventListener();
  59. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
  60. EventAgent.RemoveEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
  61. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
  62. }
  63. private void ViewUseCoroutine()
  64. {
  65. MatchingCompetitionSproxy.UseCoroutine();
  66. }
  67. private void UpdateView()
  68. {
  69. //排序
  70. MatchingCompetitionDataManager.Instance._currentRankList.Sort((a, b) =>
  71. {
  72. // 假设列表项具有一个名为 'score' 的属性,你想要按照分数进行排序
  73. if (a.JudgingInfo.Score > b.JudgingInfo.Score)
  74. {
  75. return -1; // a在b之前
  76. }
  77. else if (a.JudgingInfo.Score < b.JudgingInfo.Score)
  78. {
  79. return 1; // b在a之前
  80. }
  81. else
  82. {
  83. return 0; // a和b相同
  84. }
  85. });
  86. if(MatchingCompetitionDataManager.Instance._currentRankList.Count > 0)
  87. {
  88. CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
  89. _ui.m_playerImage.texture = otherInfo.Ntexture;
  90. }
  91. else
  92. {
  93. _ui.m_playerImage.texture = null;
  94. }
  95. _currentIndex = 0;
  96. _ui.m_RankList.numItems = MatchingCompetitionDataManager.Instance._currentRankList.Count;
  97. }
  98. private void UpdateHead()
  99. {
  100. RoleInfoManager.Instance.UpdateHead(_ui.m_playerHead.m_head, RoleDataManager.headId, RoleDataManager.headBorderId);
  101. _ui.m_playerHead.m_nameText.text = RoleDataManager.roleName.ToString();
  102. _ui.m_playerHead.m_countText.text = MatchingCompetitionDataManager.Instance.myWorks.Score.ToString();
  103. MatchingCompetitionDataManager.Instance.SetNumToRank(MatchingCompetitionDataManager.Instance.myWorks.Rank,_ui.m_playerHead.m_RankIndex);
  104. }
  105. private void RenderRankList(int index, GObject obj)
  106. {
  107. UI_Component3 item = UI_Component3.Proxy(obj);
  108. CurRanMatchingPhotoWorksData otherdata = MatchingCompetitionDataManager.Instance._currentRankList[index];
  109. JudgingRoundRoleInfo otherInfo = otherdata.JudgingInfo;
  110. otherInfo.Rank = index + 1;
  111. RoleInfoManager.Instance.UpdateHead(item.m_head, otherInfo.HeadItemId, otherInfo.HeadBorderItemId);
  112. item.m_nameText.text = otherInfo.RoleName.ToString();
  113. item.m_countText.text = otherInfo.Score.ToString();
  114. MatchingCompetitionDataManager.Instance.SetNumToRank(otherInfo.Rank, item.m_RankIndex);
  115. if(item.target.data == null)
  116. {
  117. item.target.onClick.Add(OnClickBtnItem);
  118. }
  119. item.target.data = index;
  120. UI_Component3.ProxyEnd();
  121. }
  122. private void OnClickBtnItem(EventContext context)
  123. {
  124. GObject item = context.sender as GObject;
  125. int index = (int)item.data;
  126. _currentIndex = index;
  127. CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
  128. _ui.m_playerImage.texture = otherInfo.Ntexture;
  129. }
  130. private void OnClickBtnBack()
  131. {
  132. ViewManager.GoBackFrom(typeof(MatchingCompetitionRankView).FullName);
  133. }
  134. private async void OnClickBtnBefore()
  135. {
  136. bool result = await MatchingCompetitionSproxy.ReqBeforeWorks();
  137. if(result)
  138. {
  139. ViewManager.Show<MatchingCompetitionWorksView>();
  140. }
  141. else
  142. {
  143. PromptController.Instance.ShowFloatTextPrompt("暂无往期数据!");
  144. }
  145. }
  146. private void OnClickBtnLook()
  147. {
  148. List<int> AllIdList = new List<int>();
  149. foreach (var info in MatchingCompetitionDataManager.Instance._currentRankList[_currentIndex].JudgingInfo.CollocationInfoList)
  150. {
  151. AllIdList.Add(MatchingCompetitionDataManager.Instance.GetIDByString(info.ItemId));
  152. }
  153. MatchingCompetitionDataManager.Instance.DetailNtexture = MatchingCompetitionDataManager.Instance._currentRankList[_currentIndex].Ntexture;
  154. ViewManager.Show<MatchingCompetitionDetailView>(AllIdList);
  155. }
  156. }
  157. }