using System.Collections.Generic; using System.Dynamic; using System.Linq; using UnityEngine; namespace vnxbqy.UI { //福地-寻觅 public class BlessedLandSeekWin : Window { [SerializeField] ScrollerController itemScroller; [SerializeField] TextEx txtTime; [SerializeField] ButtonEx btnClose; [SerializeField] ButtonEx btnRefresh; [SerializeField] ImageEx imgRefresh; BlessedLandModel blessedLandModel { get { return ModelCenter.Instance.GetModel(); } } protected override void BindController() { } protected override void AddListeners() { btnClose.SetListener(() => { WindowCenter.Instance.Close(); }); btnRefresh.SetListener(() => { bool isLimit = blessedLandModel.TryGetRefreshTypeDailyLimitValue(2, out int maxLimit); if (isLimit) { if (blessedLandModel.RefreshCountRob >= maxLimit) { SysNotifyMgr.Instance.ShowTip("XBTodayMax"); return; } } //在冷却时间中 if (blessedLandModel.GetCoolDownEndTime(0) > 0) return; blessedLandModel.SendCB031Pack(2); blessedLandModel.lastSurroundRefreshTime = TimeUtility.AllSeconds; blessedLandModel.SetTime(0); blessedLandModel.SaveAllTime(); }); } protected override void OnPreOpen() { itemScroller.OnRefreshCell += OnItemCellScrollerRefreshCell; GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; blessedLandModel.UpdateFellowAndSurroundAreaData += OnUpdateFellowAndSurroundAreaData; blessedLandModel.UpdateFindAreaData += OnUpdateFindAreaData; DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; Display(); } protected override void OnAfterClose() { } protected override void OnAfterOpen() { CreateItemScroller(); } protected override void OnPreClose() { itemScroller.OnRefreshCell -= OnItemCellScrollerRefreshCell; blessedLandModel.UpdateFellowAndSurroundAreaData -= OnUpdateFellowAndSurroundAreaData; GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; blessedLandModel.UpdateFindAreaData -= OnUpdateFindAreaData; DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; } private void OnSecondEvent() { Display(); if (blessedLandModel.GetCoolDownEndTime(0) > 0) { txtTime.text = TimeUtility.SecondsToDHMS(blessedLandModel.GetCoolDownEndTime(0)); } } void Display() { txtTime.SetActive(blessedLandModel.GetCoolDownEndTime(0) > 0); imgRefresh.sprite = blessedLandModel.GetCoolDownEndTime(0) == 0 ? UILoader.LoadSprite("BlessedLand03") : UILoader.LoadSprite("BlessedLand04"); } private void OnUpdateFindAreaData() { WindowJumpMgr.Instance.WindowJumpToEx("BlessedLandOtherWin"); } private void OnUpdateFellowAndSurroundAreaData() { CreateItemScroller(); } private void OnItemCellScrollerRefreshCell(ScrollerDataType type, CellView cell) { if (type == ScrollerDataType.Header) { var _cell = cell as BlessedLandSeekHeadCell; _cell.Display(_cell.index); } else { var _cell = cell as BlessedLandSeekNormalCell; _cell.Display(_cell.index, cell); } } void CreateItemScroller() { itemScroller.Refresh(); int combinedValue = 0; itemScroller.AddCell(ScrollerDataType.Header, combinedValue); if (blessedLandModel.typeToPlayerIDs.ContainsKey(3)) { List keyList = blessedLandModel.typeToPlayerIDs[3]; int minIndex = blessedLandModel.surroundCount; Dictionary dict = blessedLandModel.realmUnlockPlayerCountDict; var list = dict.Keys.ToList(); list.Sort(); int maxNum = list[list.Count - 1]; for (int i = 0; i < maxNum; i++) { CellInfo cellInfo = new CellInfo(); if (i< keyList.Count) { combinedValue = (int)keyList[i] * 10 + 3; if (i < minIndex) { cellInfo.infoInt1 = -1; } else { cellInfo.infoInt1 = i - minIndex; } } else { cellInfo.infoInt1 = i - minIndex; } itemScroller.AddCell(ScrollerDataType.Normal, combinedValue, cellInfo); } } combinedValue = 1; itemScroller.AddCell(ScrollerDataType.Header, combinedValue); if (blessedLandModel.typeToPlayerIDs.ContainsKey(2)) { List keyList = blessedLandModel.typeToPlayerIDs[2]; for (int i = 0; i < keyList.Count; i++) { combinedValue = (int)keyList[i] * 10 + 2; CellInfo cellInfo = new CellInfo(); cellInfo.infoInt1 = -1; itemScroller.AddCell(ScrollerDataType.Normal, combinedValue, cellInfo); } } itemScroller.Restart(); } public void OnBeforePlayerDataInitialize() { if (WindowCenter.Instance.IsOpen()) { WindowJumpMgr.Instance.ClearJumpData(); WindowCenter.Instance.CloseAll(); } } } }