lcy
4 天以前 2dd1841d03a730d3d369092c2a3ad656cee4bf64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using UnityEngine;
using UnityEngine.UI;
 
public class HeroReturnZhanLingPreviewHWin : 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 = 50;
    protected override void InitComponent()
    {
        btnClose.AddListener(CloseWindow);
        btnBuy.AddListener(OnBuyClick);
    }
 
    protected override void OnPreOpen()
    {
        allScroller.OnRefreshCell += OnScrollerRefreshAllCell;
        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 HeroReturnZhanLingPreviewHCell;
        _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();
    }
 
}