//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 18, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
//自选充值 + 商店
|
public class RechargeGiftAct31Win : Window
|
{
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] Text actTime;
|
RechargeGiftAct31Model model { get { return ModelCenter.Instance.GetModel<RechargeGiftAct31Model>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
#region Built-in
|
protected override void BindController()
|
{
|
|
|
}
|
|
protected override void AddListeners()
|
{
|
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
DisplayScroll();
|
secondEvent();
|
}
|
|
private void VipModel_rechargeCountEvent(int obj)
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
m_Controller.OnRefreshCell -= OnRefreshCell;
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
|
void DisplayScroll()
|
{
|
m_Controller.Refresh();
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(RechargeGiftAct31Model.operaType, out act);
|
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
|
|
int totaleCnt = (_list == null ? 0 : _list.Count) + act.ctgIDs.Count;
|
|
for (int i = 0; i < totaleCnt; i++)
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, i);
|
}
|
m_Controller.Restart();
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
m_Controller.JumpIndex(GetDefaultSelect());
|
|
|
}
|
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type != ScrollerDataType.Header) return;
|
|
var _cell = cell as RechargeGiftAct31Cell;
|
|
_cell.Display(_cell.index);
|
|
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
int GetDefaultSelect()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(RechargeGiftAct31Model.operaType, out act);
|
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.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 < act.ctgIDs.Count; i++)
|
{
|
int ctgID = act.ctgIDs[i];
|
var countInfo = model.GetBuyCntInfo(ctgID);
|
|
if (countInfo.x < countInfo.y)
|
return i + storeCnt;
|
}
|
return 0;
|
|
}
|
|
void secondEvent()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(RechargeGiftAct31Model.operaType, out act);
|
actTime.text = Language.Get("BossFHLanguage2", TimeUtility.SecondsToHMS(act.GetResetSurplusTime()));
|
}
|
|
}
|
}
|