using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
//成长必买
|
public class CZBMWin : Window
|
{
|
[SerializeField] ScrollerController m_GroupCtrl;
|
[SerializeField] ScrollerController m_BuyInfoCtrl;
|
[SerializeField] Button m_BtnClose;
|
[SerializeField] RichText m_ShowTip;
|
[SerializeField] Text m_Time;
|
|
|
CZBMModel model { get { return ModelCenter.Instance.GetModel<CZBMModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
m_BtnClose.onClick.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_GroupCtrl.OnRefreshCell += OnGroupRefresh;
|
m_BuyInfoCtrl.OnRefreshCell += OnBuyInfoRefresh;
|
vipModel.rechargeCountEvent += RechargeCountEvent;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += RefreshUI;
|
model.selectUpdate += OnSelectGroup;
|
model.selectIndex = GetDefaultSelect();
|
Display();
|
}
|
|
protected override void OnActived()
|
{
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.CZBM_REDPOINT, true);
|
model.CloseRedpoint();
|
}
|
|
protected override void OnPreClose()
|
{
|
m_GroupCtrl.OnRefreshCell -= OnGroupRefresh;
|
m_BuyInfoCtrl.OnRefreshCell -= OnBuyInfoRefresh;
|
vipModel.rechargeCountEvent -= RechargeCountEvent;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= RefreshUI;
|
model.selectUpdate -= OnSelectGroup;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void RechargeCountEvent(int id)
|
{
|
Display();
|
}
|
|
//过滤已购买的
|
int GetDefaultSelect()
|
{
|
int i = 0;
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.CZBMGift, out operationBase))
|
{
|
OperationCZBM operation = operationBase as OperationCZBM;
|
foreach(var buyInfo in operation.CZBMGiftInfo)
|
{
|
if (buyInfo.PlayerBuyIndex == buyInfo.BuyCTGIDList.Length - 1)
|
{
|
//最后一档是否已购买
|
int ctgID = (int)buyInfo.BuyCTGIDList[buyInfo.PlayerBuyIndex].CTGID;
|
|
VipModel.RechargeCount _rechargeCount;
|
if (vipModel.TryGetRechargeCount(ctgID, out _rechargeCount))
|
{
|
if (_rechargeCount.todayCount > 0)
|
{
|
i++;
|
if (i >= operation.CZBMGiftInfo.Count)
|
{
|
//全部购买完毕显示最后一个
|
i = operation.CZBMGiftInfo.Count - 1;
|
}
|
}
|
|
}
|
else
|
{
|
break;
|
}
|
}
|
else
|
{
|
break;
|
}
|
}
|
}
|
return i;
|
}
|
|
|
|
private void OnGroupRefresh(ScrollerDataType type, CellView cell)
|
{
|
var resolveCell = cell as CZBMGroupCell;
|
resolveCell.Display(cell.index);
|
}
|
|
private void OnBuyInfoRefresh(ScrollerDataType type, CellView cell)
|
{
|
var resolveCell = cell as CZBMCell;
|
resolveCell.Display(cell.index);
|
}
|
|
// 选中刷新购买物品
|
private void OnSelectGroup()
|
{
|
m_GroupCtrl.m_Scorller.RefreshActiveCellViews();
|
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.CZBMGift, out operationBase))
|
{
|
OperationCZBM operation = operationBase as OperationCZBM;
|
if(model.selectIndex >= operation.CZBMGiftInfo.Count)
|
{
|
CloseClick();
|
return;
|
}
|
m_BuyInfoCtrl.Refresh();
|
for(var i = 0; i < operation.CZBMGiftInfo[model.selectIndex].BuyCTGIDList.Length; i++)
|
{
|
m_BuyInfoCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
|
m_BuyInfoCtrl.Restart();
|
m_BuyInfoCtrl.m_Scorller.RefreshActiveCellViews();
|
|
ShowTip(operation);
|
}
|
}
|
|
|
private void ShowTip(OperationCZBM operation)
|
{
|
if (operation.CZBMGiftInfo[model.selectIndex].PlayerBuyIndex >= operation.CZBMGiftInfo[model.selectIndex].BuyCTGIDList.Length)
|
{
|
m_ShowTip.text = string.Empty;
|
return;
|
}
|
int ctgID = (int)operation.CZBMGiftInfo[model.selectIndex].BuyCTGIDList[operation.CZBMGiftInfo[model.selectIndex].PlayerBuyIndex].CTGID;
|
var ctgInfo = CTGConfig.Get(ctgID);
|
|
int ctgID1 = (int)operation.CZBMGiftInfo[model.selectIndex].BuyCTGIDList[0].CTGID;
|
var ctgInfo1 = CTGConfig.Get(ctgID1);
|
|
m_ShowTip.text = Language.Get("CZBMBuyTip", ctgInfo.Title, ctgInfo1.Title, ctgInfo.Title);
|
}
|
private void RefreshUI(Operation _type)
|
{
|
if (_type != Operation.CZBMGift)
|
{
|
return;
|
}
|
|
|
Display();
|
}
|
|
private void Display()
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.CZBMGift, out operationBase))
|
{
|
OperationCZBM operation = operationBase as OperationCZBM;
|
if(operation.CZBMGiftInfo.Count == 0)
|
{
|
CloseClick();
|
return;
|
}
|
RefreshGroup(operation);
|
|
ShowTip(operation);
|
m_Time.text = Language.Get("ActivityTime") + operationBase.startDate.ToDisplay() + "-" + operationBase.endDate.ToDisplay();
|
}
|
|
|
}
|
|
private void RefreshGroup(OperationCZBM operation)
|
{
|
m_GroupCtrl.Refresh();
|
for(var i = 0; i < operation.CZBMGiftInfo.Count; i++)
|
{
|
m_GroupCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
|
m_GroupCtrl.Restart();
|
m_GroupCtrl.m_Scorller.RefreshActiveCellViews();
|
|
m_BuyInfoCtrl.Refresh();
|
for(var i = 0; i < operation.CZBMGiftInfo[model.selectIndex].BuyCTGIDList.Length; i++)
|
{
|
m_BuyInfoCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
|
m_BuyInfoCtrl.Restart();
|
m_BuyInfoCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
}
|
}
|