| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using UnityEngine; |
| | |
| | | public class HeroFatesWin : UIBase |
| | | { |
| | | [SerializeField] ScrollerController scroller; |
| | | [SerializeField] List<TextEx> attrs; |
| | | [SerializeField] ScrollerController attrScroller; |
| | | HeroFatesManager manager { get { return HeroFatesManager.Instance; } } |
| | | protected override void InitComponent() |
| | | { |
| | |
| | | protected override void OnPreOpen() |
| | | { |
| | | scroller.OnRefreshCell += OnRefreshCell; |
| | | attrScroller.OnRefreshCell += OnRefreshAttrCell; |
| | | manager.OnUpdateHeroFatesInfoEvent += OnUpdateHeroFatesInfo; |
| | | CreateScoller(); |
| | | |
| | |
| | | manager.HasShowRedDotFates(out firstIndex); |
| | | scroller.JumpIndex(firstIndex); |
| | | |
| | | DisplayAttrs(); |
| | | CreateAttrScoller(); |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | scroller.OnRefreshCell -= OnRefreshCell; |
| | | attrScroller.OnRefreshCell -= OnRefreshAttrCell; |
| | | manager.OnUpdateHeroFatesInfoEvent -= OnUpdateHeroFatesInfo; |
| | | } |
| | | |
| | | private void OnRefreshAttrCell(ScrollerDataType type, CellView cell) |
| | | { |
| | | var _cell = cell.GetComponent<HeroFatesAttrCell>(); |
| | | _cell?.Display(cell.index, totalAttrIdList, totalAttrDict); |
| | | } |
| | | |
| | | private void OnUpdateHeroFatesInfo() |
| | | { |
| | | RefeshScoller(); |
| | | DisplayAttrs(); |
| | | CreateAttrScoller(); |
| | | } |
| | | List<int> fatesIDList = new List<int>(); |
| | | private void OnRefreshCell(ScrollerDataType type, CellView cell) |
| | |
| | | scroller.m_Scorller.RefreshActiveCellViews(); |
| | | } |
| | | |
| | | void DisplayAttrs() |
| | | List<int> totalAttrIdList = new List<int>(); |
| | | Dictionary<int, long> totalAttrDict = new Dictionary<int, long>(); |
| | | void CreateAttrScoller() |
| | | { |
| | | Dictionary<int, long> totalAttrDict = manager.GetTotalAttr(); |
| | | if (attrs.IsNullOrEmpty() || totalAttrDict.IsNullOrEmpty()) |
| | | totalAttrDict = manager.GetTotalAttr(); |
| | | if (totalAttrDict.IsNullOrEmpty()) |
| | | return; |
| | | List<int> totalAttrIdList = totalAttrDict.Keys |
| | | .OrderByDescending(attrID => totalAttrDict[attrID] > 0) // 属性值>0的排前面 |
| | | .ThenBy(attrID => attrID) // 然后按attrID升序 |
| | | .ToList(); |
| | | for (int i = 0; i < attrs.Count; i++) |
| | | totalAttrIdList = totalAttrDict.Keys |
| | | .OrderByDescending(attrID => totalAttrDict[attrID] > 0) // 属性值>0的排前面 |
| | | .ThenBy(attrID => attrID) // 然后按attrID升序 |
| | | .ToList(); |
| | | |
| | | attrScroller.Refresh(); |
| | | if (!totalAttrIdList.IsNullOrEmpty()) |
| | | { |
| | | if (i < totalAttrDict.Count) |
| | | int rowCount = Mathf.CeilToInt((float)totalAttrIdList.Count / manager.attrRowCountMax); |
| | | for (int i = 0; i < rowCount; i++) |
| | | { |
| | | int attrID = totalAttrIdList[i]; |
| | | long attrValue = totalAttrDict[attrID]; |
| | | attrs[i].text = PlayerPropertyConfig.GetFullDescription(attrID, attrValue); |
| | | attrs[i].SetActive(true); |
| | | } |
| | | else |
| | | { |
| | | attrs[i].SetActive(false); |
| | | attrScroller.AddCell(ScrollerDataType.Header, i); |
| | | } |
| | | } |
| | | attrScroller.Restart(); |
| | | } |
| | | |
| | | } |