123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.MatchingCompetition;
- using UnityEngine;
- namespace GFGGame
- {
- class MatchingCompetitionRankView : BaseWindow
- {
- private UI_MatchingCompetitionRankUI _ui;
- private int _currentIndex = 0;
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- }
- _ui = null;
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_MatchingCompetitionRankUI.PACKAGE_NAME;
- _ui = UI_MatchingCompetitionRankUI.Create();
- this.viewCom = _ui.target;
- isReturnView = true;
- isfullScreen = true;
- _ui.m_RankList.itemRenderer = RenderRankList;
- _ui.m_BtnBack.onClick.Add(OnClickBtnBack);
- _ui.m_btnBefore.onClick.Add(OnClickBtnBefore);
- _ui.m_btnLook.onClick.Add(OnClickBtnLook);
- _ui.m_ruleBtn.onClick.Add(MatchingCompetitionDataManager.Instance.OnClickBtnRule);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _ui.m_bg.url = ResPathUtil.GetBgImgPath("pxs_bj");
- _ui.m_outBg.url = ResPathUtil.GetBgImgPath("pxs_pmdb");
- _ui.m_titleText.text = JudgingRoundOpenCfgArray.Instance.dataArray[MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason - 1].Name;
- UpdateView();
- UpdateHead();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
- EventAgent.AddEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
- EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
- EventAgent.RemoveEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
- EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
- }
- private void ViewUseCoroutine()
- {
- MatchingCompetitionSproxy.UseCoroutine();
- }
- private void UpdateView()
- {
- //排序
- MatchingCompetitionDataManager.Instance._currentRankList.Sort((a, b) =>
- {
- // 假设列表项具有一个名为 'score' 的属性,你想要按照分数进行排序
- if (a.JudgingInfo.Score > b.JudgingInfo.Score)
- {
- return -1; // a在b之前
- }
- else if (a.JudgingInfo.Score < b.JudgingInfo.Score)
- {
- return 1; // b在a之前
- }
- else
- {
- return 0; // a和b相同
- }
- });
-
- if(MatchingCompetitionDataManager.Instance._currentRankList.Count > 0)
- {
- CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
- _ui.m_playerImage.texture = otherInfo.Ntexture;
- }
- else
- {
- _ui.m_playerImage.texture = null;
- }
- _currentIndex = 0;
- _ui.m_RankList.numItems = MatchingCompetitionDataManager.Instance._currentRankList.Count;
- }
- private void UpdateHead()
- {
- RoleInfoManager.Instance.UpdateHead(_ui.m_playerHead.m_head, RoleDataManager.headId, RoleDataManager.headBorderId);
- _ui.m_playerHead.m_nameText.text = RoleDataManager.roleName.ToString();
- _ui.m_playerHead.m_countText.text = MatchingCompetitionDataManager.Instance.myWorks.Score.ToString();
- MatchingCompetitionDataManager.Instance.SetNumToRank(MatchingCompetitionDataManager.Instance.myWorks.Rank,_ui.m_playerHead.m_RankIndex);
- }
- private void RenderRankList(int index, GObject obj)
- {
- UI_Component3 item = UI_Component3.Proxy(obj);
- CurRanMatchingPhotoWorksData otherdata = MatchingCompetitionDataManager.Instance._currentRankList[index];
- JudgingRoundRoleInfo otherInfo = otherdata.JudgingInfo;
- otherInfo.Rank = index + 1;
- RoleInfoManager.Instance.UpdateHead(item.m_head, otherInfo.HeadItemId, otherInfo.HeadBorderItemId);
- item.m_nameText.text = otherInfo.RoleName.ToString();
- item.m_countText.text = otherInfo.Score.ToString();
- MatchingCompetitionDataManager.Instance.SetNumToRank(otherInfo.Rank, item.m_RankIndex);
- if(item.target.data == null)
- {
- item.target.onClick.Add(OnClickBtnItem);
- }
- item.target.data = index;
- UI_Component3.ProxyEnd();
- }
- private void OnClickBtnItem(EventContext context)
- {
- GObject item = context.sender as GObject;
- int index = (int)item.data;
- _currentIndex = index;
- CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
- _ui.m_playerImage.texture = otherInfo.Ntexture;
- }
- private void OnClickBtnBack()
- {
- ViewManager.GoBackFrom(typeof(MatchingCompetitionRankView).FullName);
- }
- private async void OnClickBtnBefore()
- {
- bool result = await MatchingCompetitionSproxy.ReqBeforeWorks();
- if(result)
- {
- ViewManager.Show<MatchingCompetitionWorksView>();
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("暂无往期数据!");
- }
- }
- private void OnClickBtnLook()
- {
- List<int> AllIdList = new List<int>();
- foreach (var info in MatchingCompetitionDataManager.Instance._currentRankList[_currentIndex].JudgingInfo.CollocationInfoList)
- {
- AllIdList.Add(MatchingCompetitionDataManager.Instance.GetIDByString(info.ItemId));
- }
- MatchingCompetitionDataManager.Instance.DetailNtexture = MatchingCompetitionDataManager.Instance._currentRankList[_currentIndex].Ntexture;
- ViewManager.Show<MatchingCompetitionDetailView>(AllIdList);
- }
- }
- }
|