using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class HeroReturnZhanLingPreviewWin : UIBase
|
{
|
[SerializeField] ScrollerController allScroller; //所有等级奖励
|
[SerializeField] Button btnClose;
|
[SerializeField] Button btnBuy;
|
[SerializeField] Text txtBuy;
|
[SerializeField] Text txtPercentage;
|
[SerializeField] Image imgMoney;
|
[SerializeField] Text txtMoney;
|
HeroReturnManager model => HeroReturnManager.Instance;
|
int ctgID;
|
int showCnt = 10;
|
|
protected override void OnPreOpen()
|
{
|
allScroller.OnRefreshCell += OnScrollerRefreshAllCell;
|
btnClose.AddListener(CloseWindow);
|
btnBuy.AddListener(OnBuyClick);
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
allScroller.OnRefreshCell -= OnScrollerRefreshAllCell;
|
|
}
|
|
void OnBuyClick()
|
{
|
if (ctgID == 0)
|
{
|
CloseWindow();
|
return;
|
}
|
RechargeManager.Instance.CTG(ctgID);
|
CloseWindow();
|
}
|
|
protected override void NextFrameAfterOpen()
|
{
|
CreateAllScroller();
|
}
|
|
private void OnScrollerRefreshAllCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as HeroReturnZhanLingPreviewCell;
|
_cell.Display(_cell.index, model.GetPreviewGiftAllItem(showCnt));
|
}
|
|
void Display()
|
{
|
ctgID = model.GetPreviewCtgID();
|
var config = CTGConfig.Get(ctgID);
|
if (config == null)
|
{
|
CloseWindow();
|
return;
|
}
|
OrderInfoConfig orderCfg;
|
RechargeManager.Instance.TryGetOrderInfo(ctgID, out orderCfg);
|
|
txtPercentage.text = Language.Get("TimingGift02", config.Percentage);
|
txtBuy.text = Language.Get("PayMoneyNum", UIHelper.GetMoneyFormat(orderCfg.PayRMBNumOnSale));
|
imgMoney.SetIconWithMoneyType(config.MoneyType);
|
txtMoney.text = config.GainGold.ToString();
|
}
|
|
private void CreateAllScroller()
|
{
|
var items = model.GetPreviewGiftAllItem(showCnt);
|
if (items == null || items.Count == 0)
|
return;
|
int rowCount = (int)Math.Ceiling((double)items.Count / HeroReturnZhanLingPreviewCell.itemCountPerRow);
|
allScroller.Refresh();
|
for (int i = 0; i < rowCount; i++)
|
{
|
allScroller.AddCell(ScrollerDataType.Header, i);
|
}
|
allScroller.Restart();
|
}
|
|
|
}
|