using vnxbqy.UI;
using System.Collections.Generic;
using System.Linq;
///
/// 天星塔
///
public class CelestialStarTowerWin : ILWindow
{
ScrollerController scroller;
TextEx txtBuy;
TextEx txtProfitRatio;
ButtonEx btnClose;
ButtonEx btnBuy;
ImageEx imgBuy;
TextEx orgPrice;
VipModel vipModel { get { return ModelCenter.Instance.GetModelEx(); } }
protected override void BindController()
{
scroller = proxy.GetWidgtEx("scroller");
txtBuy = proxy.GetWidgtEx("txtBuy");
txtProfitRatio = proxy.GetWidgtEx("txtProfitRatio");
btnClose = proxy.GetWidgtEx("btnClose");
btnBuy = proxy.GetWidgtEx("btnBuy");
imgBuy = proxy.GetWidgtEx("imgBuy");
var obj = btnBuy.FindComponent("TextEx", "Txt_orgPrice");
if (obj != null)
orgPrice = obj as TextEx;
}
protected override void AddListeners()
{
btnClose.SetListener(() =>
{
CloseWin();
});
btnBuy.SetListener(() =>
{
vipModel.CTG(CelestialStarTowerModel.Instance.ctgIdDict[3]);
});
}
protected override void OnPreOpen()
{
CelestialStarTowerModel.Instance.UpdateGiftStateEvent += UpdateGiftStateEvent;
ModelCenter.Instance.GetModel().OnChallengeState += OnFloorChangeEvent;
scroller.OnRefreshCell += OnScrollerRefreshCell;
bool isBuyZhanLing = CelestialStarTowerModel.Instance.zhanLingInfoDict[3].isActivite > 0;
btnBuy.SetActiveIL(isBuyZhanLing ? false : true);
imgBuy.SetActiveIL(isBuyZhanLing);
OrderInfoConfig orderCfg;
vipModel.TryGetOrderInfo(CelestialStarTowerModel.Instance.ctgIdDict[3], out orderCfg);
txtBuy.text = Language.Get("PayMoneyNum", orderCfg.PayRMBNum);
if (orgPrice != null)
{
orgPrice.SetActiveIL(PlayerDatas.Instance.baseData.IsActive90Off);
orgPrice.text = Language.Get("PayMoneyNum", UIHelper.GetMoneyFormat((int)orderCfg.m_PayRMBNum));
}
txtProfitRatio.text = Language.Get("BlessedLand039", CTGConfig.Get(CelestialStarTowerModel.Instance.ctgIdDict[3]).Percentage);
}
protected override void OnAfterOpen()
{
Initialize();
}
protected override void OnPreClose()
{
CelestialStarTowerModel.Instance.UpdateGiftStateEvent -= UpdateGiftStateEvent;
ModelCenter.Instance.GetModel().OnChallengeState -= OnFloorChangeEvent;
scroller.OnRefreshCell -= OnScrollerRefreshCell;
}
private void OnFloorChangeEvent()
{
if (CelestialStarTowerModel.Instance.zhanLingInfoDict == null ||!CelestialStarTowerModel.Instance.zhanLingInfoDict.ContainsKey(3))
return;
scroller.m_Scorller.RefreshActiveCellViews();
CelestialStarTowerModel.Instance.IsPlayAnimation = true;
}
private void UpdateGiftStateEvent()
{
scroller.m_Scorller.RefreshActiveCellViews();
bool isBuyZhanLing = CelestialStarTowerModel.Instance.zhanLingInfoDict[3].isActivite > 0;
btnBuy.SetActiveIL(!isBuyZhanLing);
imgBuy.SetActiveIL(isBuyZhanLing);
CelestialStarTowerModel.Instance.IsPlayAnimation = true;
}
private void OnScrollerRefreshCell(ScrollerDataType type, CellView cell)
{
var _cell = cell.GetILBehaviour();
_cell.Display(cell.index);
CelestialStarTowerModel.Instance.IsPlayAnimation = true;
}
void Initialize()
{
List cellList = ILZhanlingConfig.GetTypeToIDDict(3).Keys.ToList();
scroller.Refresh();
for (int i = 0; i < cellList.Count; i++)
{
scroller.AddCell(ScrollerDataType.Header, cellList[i]);
}
scroller.Restart();
scroller.JumpIndex(CelestialStarTowerModel.Instance.GetJumpStartIndex(3));
CelestialStarTowerModel.Instance.IsPlayAnimation = true;
}
}