using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
// Âֻصî
|
public class CycleHallWin : Window
|
{
|
[SerializeField] ScrollerController tabScroller;
|
[SerializeField] ScrollerController missionScroller;
|
[SerializeField] ScrollerController giftScroller;
|
|
[SerializeField] ImageEx imgTitle;
|
[SerializeField] ImageEx imgInfo;
|
[SerializeField] ImageEx imgLH;
|
[SerializeField] TextEx actTime;
|
[SerializeField] TextEx txtRewardRound;
|
[SerializeField] ButtonEx btnGo;
|
[SerializeField] ButtonEx btnClose;
|
|
RechargeGiftActModel rechargeGiftActModel { get { return ModelCenter.Instance.GetModel<RechargeGiftActModel>(); } }
|
CycleHallActModel model { get { return ModelCenter.Instance.GetModel<CycleHallActModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
protected override void AddListeners()
|
{
|
btnGo.SetListener(OnClickGo);
|
btnClose.SetListener(CloseClick);
|
}
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
GlobalTimeEvent.Instance.secondEvent += SecondEvent;
|
tabScroller.OnRefreshCell += OnScrollerRefreshTabCell;
|
missionScroller.OnRefreshCell += OnScrollerRefreshMissionCell;
|
giftScroller.OnRefreshCell += OnScrollerRefreshGiftCell;
|
model.onNowTabIdUpdate += OnNowTabIdUpdate;
|
vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
model.UpdatePlayerInfoAction += OnUpdatePlayerInfoAction;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += OperationTimeUpdateEvent;
|
var list = model.GetTabIDList();
|
if (!list.IsNullOrEmpty())
|
{
|
model.nowTabId = list.First();
|
}
|
else
|
{
|
WindowCenter.Instance.Close<CycleHallWin>();
|
}
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
|
tabScroller.OnRefreshCell -= OnScrollerRefreshTabCell;
|
missionScroller.OnRefreshCell -= OnScrollerRefreshMissionCell;
|
giftScroller.OnRefreshCell -= OnScrollerRefreshGiftCell;
|
model.onNowTabIdUpdate -= OnNowTabIdUpdate;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
model.UpdatePlayerInfoAction -= OnUpdatePlayerInfoAction;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationTimeUpdateEvent;
|
}
|
|
private void OperationTimeUpdateEvent(Operation operation)
|
{
|
if (operation == Operation.default47)
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
missionScroller.m_Scorller.RefreshActiveCellViews();
|
giftScroller.m_Scorller.RefreshActiveCellViews();
|
Display();
|
}
|
}
|
|
private void OnUpdatePlayerInfoAction()
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
missionScroller.m_Scorller.RefreshActiveCellViews();
|
giftScroller.m_Scorller.RefreshActiveCellViews();
|
Display();
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
giftScroller.m_Scorller.RefreshActiveCellViews();
|
model.IsPlayAnimation = true;
|
}
|
|
private void VipModel_rechargeCountEvent(int obj)
|
{
|
giftScroller.m_Scorller.RefreshActiveCellViews();
|
model.IsPlayAnimation = true;
|
}
|
|
private void OnNowTabIdUpdate()
|
{
|
tabScroller.m_Scorller.RefreshActiveCellViews();
|
CreateScroller();
|
missionScroller.JumpIndex(JumpMissionIndex());
|
giftScroller.JumpIndex(JumpGiftIndex());
|
Display();
|
}
|
|
private void OnScrollerRefreshTabCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as CycleHallTabCell;
|
_cell.Display(_cell.index);
|
}
|
|
private void OnScrollerRefreshMissionCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as CycleHallMissionCell;
|
_cell.Display(_cell.index, cell);
|
model.IsPlayAnimation = true;
|
}
|
|
private void OnScrollerRefreshGiftCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as CycleHallGiftCell;
|
_cell.Display(_cell.index, cell);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CreateTabScroller();
|
tabScroller.JumpIndex(JumpTabIndex());
|
CreateScroller();
|
missionScroller.JumpIndex(JumpMissionIndex());
|
giftScroller.JumpIndex(JumpGiftIndex());
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
private void SecondEvent()
|
{
|
GetActTime(functionOrder);
|
}
|
|
private void Display()
|
{
|
int id = model.nowTabId;
|
if (!CycleHallConfig.Has(id))
|
return;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
int roundType = config.RoundType;
|
int tabType = config.TabType;
|
|
var act = model.GetOperationInfo();
|
if (act == null || !act.TryGetRound(roundType, out var round) || !model.playerInfoDict.TryGetValue(roundType, out var playerInfo))
|
return;
|
imgLH.SetSprite(config.StandImage);
|
imgLH.SetNativeSize();
|
imgTitle.SetSprite(config.TitleImage);
|
imgTitle.SetNativeSize();
|
imgInfo.SetSprite(config.InfoImage);
|
imgInfo.SetNativeSize();
|
txtRewardRound.text = Language.Get("CycleHall01", playerInfo.CurRound, round.RoundMax);
|
GetActTime(functionOrder);
|
}
|
|
private void GetActTime(int functionOrder)
|
{
|
var act = model.GetOperationInfo();
|
actTime.text = act == null ? string.Empty : Language.Get("CycleHall07", TimeUtility.SecondsToDHMSCHS(act.GetResetSurplusTime()));
|
}
|
|
private void CreateTabScroller()
|
{
|
tabScroller.Refresh();
|
var list = model.GetTabIDList();
|
if (!list.IsNullOrEmpty())
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
tabScroller.AddCell(ScrollerDataType.Header, list[i]);
|
}
|
}
|
tabScroller.Restart();
|
}
|
|
private void CreateScroller()
|
{
|
missionScroller.SetActive(false);
|
giftScroller.SetActive(false);
|
int id = model.nowTabId;
|
if (!CycleHallConfig.Has(id))
|
return;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
CellInfo cellInfo = new CellInfo();
|
cellInfo.infoInt1 = config.RoundType;
|
cellInfo.infoInt2 = config.TabType;
|
|
if (config.TabType == 1)
|
{
|
missionScroller.SetActive(true);
|
missionScroller.Refresh();
|
var act = model.GetOperationInfo();
|
if (act != null && act.TryGetRound(config.RoundType, out var round) && round.AwardList != null)
|
{
|
for (int i = 0; i < round.AwardList.Length; i++)
|
{
|
missionScroller.AddCell(ScrollerDataType.Header, round.AwardList[i].AwardIndex, cellInfo);
|
}
|
}
|
missionScroller.Restart();
|
}
|
else if (config.TabType == 2)
|
{
|
giftScroller.SetActive(true);
|
giftScroller.Refresh();
|
var act = model.GetOperationInfo();
|
if (act != null && act.TryGetRound(config.RoundType, out var round) && round.CTGIDList != null)
|
{
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(round.ShopType, out _list);
|
int totaleCnt = (_list == null ? 0 : _list.Count) + round.CTGIDList.Length;
|
for (int i = 0; i < totaleCnt; i++)
|
{
|
giftScroller.AddCell(ScrollerDataType.Header, i, cellInfo);
|
}
|
}
|
giftScroller.Restart();
|
}
|
}
|
|
private int JumpTabIndex()
|
{
|
var act = model.GetOperationInfo();
|
if (act == null || act.roundInfoDict == null)
|
return 0;
|
var roundTypeList = act.roundInfoDict.Keys.ToList();
|
for (int i = 0; i < roundTypeList.Count; i++)
|
{
|
int roundType = roundTypeList[i];
|
if (!act.roundInfoDict.ContainsKey(roundType))
|
continue;
|
int id = CycleHallConfig.GetIndex(roundType, 1);
|
if (id <= 0)
|
continue;
|
var tabIDList = model.GetTabIDList();
|
if (tabIDList == null)
|
return 0;
|
//ÓпÉÁìÈ¡µÄÈÎÎñ½±Àø
|
if (!act.TryGetRound(roundType, out var round) || round.AwardList == null)
|
return 0;
|
for (int j = 0; j < round.AwardList.Length; j++)
|
{
|
var award = round.AwardList[j];
|
int index = award.AwardIndex;
|
int state = model.GetAwardState(roundType, index);//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
if (state == 1)
|
{
|
int num = tabIDList.IndexOf(id);
|
model.nowTabId = id;
|
return num >= 0 ? num : 0;
|
}
|
}
|
}
|
for (int i = 0; i < roundTypeList.Count; i++)
|
{
|
//É̵êÃâ·Ñ
|
int roundType = roundTypeList[i];
|
if (!act.roundInfoDict.ContainsKey(roundType))
|
continue;
|
int id = CycleHallConfig.GetIndex(roundType, 2);
|
if (id <= 0)
|
continue;
|
var tabIDList = model.GetTabIDList();
|
if (tabIDList == null)
|
return 0;
|
//ÓпÉÁìÈ¡µÄÈÎÎñ½±Àø
|
if (!act.TryGetRound(roundType, out var round) || round.AwardList == null)
|
return 0;
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(round.ShopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int k = 0; k < storeCnt; k++)
|
{
|
if (_list[k].MoneyNumber == 0)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[k], out remainNum);
|
if (remainNum > 0)
|
{
|
int num = tabIDList.IndexOf(id);
|
model.nowTabId = id;
|
return num >= 0 ? num : 0;
|
}
|
}
|
}
|
}
|
return 0;
|
}
|
|
private int JumpMissionIndex()
|
{
|
int id = model.nowTabId;
|
if (!CycleHallConfig.Has(id))
|
return 0;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
var act = model.GetOperationInfo();
|
if (act == null || !act.TryGetRound(config.RoundType, out var round) || round.AwardList == null)
|
return 0;
|
for (int i = 0; i < round.AwardList.Length; i++)
|
{
|
var award = round.AwardList[i];
|
int state = model.GetAwardState(config.RoundType, award.AwardIndex);
|
if (state == 1)
|
return i;
|
}
|
return 0;
|
}
|
|
private int JumpGiftIndex()
|
{
|
int id = model.nowTabId;
|
if (!CycleHallConfig.Has(id))
|
return 0;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
var act = model.GetOperationInfo();
|
if (act == null || !act.TryGetRound(config.RoundType, out var round) || round.CTGIDList == null)
|
return 0;
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(round.ShopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int i = 0; i < storeCnt; i++)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[i], out remainNum);
|
if (remainNum > 0)
|
return i;
|
}
|
|
//Ìø¹ýÒѹºÂò
|
for (int i = 0; i < round.CTGIDList.Length; i++)
|
{
|
int ctgID = round.CTGIDList[i];
|
var countInfo = rechargeGiftActModel.GetBuyCntInfo(ctgID);
|
|
if (countInfo.x < countInfo.y)
|
return i + storeCnt;
|
}
|
return 0;
|
}
|
|
public void OnClickGo()
|
{
|
int id = model.nowTabId;
|
if (!CycleHallConfig.Has(id))
|
return;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
int winID;
|
if (model.windowIDDict == null || !model.windowIDDict.TryGetValue(config.RoundType, out winID))
|
return;
|
WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)winID);
|
}
|
}
|
}
|