yyl
9 天以前 bb5909bcd36b48b919366c95b4248a3754452698
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
 
/// <summary>
/// 武将图鉴界面
/// </summary>
public class HeroCollectionWin : UIBase
{
    [SerializeField] Button heroPackBtn;
    [SerializeField] Text heroPackText;
    [SerializeField] ScrollerController heroListScroller;
    [SerializeField] List<Text> totalAttrList;
    [SerializeField] Button attrBtn;
    [SerializeField] HeroSelectBehaviour fiterManager;  //武将筛选
 
    SinglePack singlePack;
 
    protected override void InitComponent()
    {
        attrBtn.AddListener(() =>
        {
            SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition);
            SmallTipWin.showText = Language.Get("herocard6");
            UIManager.Instance.OpenWindow<SmallTipWin>();
        });
 
        heroPackBtn.AddListener(() =>
        {
            HeroUIManager.Instance.QueryUnLockHeroPack();
        });
    }
 
    protected override void OnPreOpen()
    {
        singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
        PackManager.Instance.gridRefreshEvent += GridRefreshEvent;
        PackManager.Instance.RefreshItemEvent += RefreshItemEvent;
        HeroUIManager.Instance.OnHeroCollectEvent += OnHeroCollectEvent;
        heroListScroller.OnRefreshCell += OnRefreshCell;
        HeroUIManager.Instance.selectHeroCollectListJob = 0;
        HeroUIManager.Instance.selectHeroCollectListCountry = 0;
        HeroUIManager.Instance.SortHeroCollectList();
        Display();
    }
 
    protected override void OnPreClose()
    {
 
        PackManager.Instance.gridRefreshEvent -= GridRefreshEvent;
        PackManager.Instance.RefreshItemEvent -= RefreshItemEvent;
        HeroUIManager.Instance.OnHeroCollectEvent -= OnHeroCollectEvent;
        heroListScroller.OnRefreshCell -= OnRefreshCell;
    }
 
 
    void Display()
    {
        fiterManager.Display(0, HeroUIManager.Instance.selectHeroCollectListJob, HeroUIManager.Instance.selectHeroCollectListCountry, SelectJobCountry);
        
        CreateScroller();
        RefreshTotalAttr();
        RefreshPackCount();
    }
 
 
    void RefreshItemEvent(PackType type, int index, int itemID)
    {
        if (type != PackType.Hero)
            return;
 
 
        RefreshPackCount();
 
    }
 
    void RefreshPackCount()
    {
        int count = singlePack.GetAllItems().Count;
        heroPackText.text = UIHelper.AppendColor(count >= singlePack.unlockedGridCount ? TextColType.Red : TextColType.NavyBrown,
                            string.Format("{0}/{1}", count, singlePack.unlockedGridCount));
 
    }
 
    void GridRefreshEvent(PackType type)
    {
        if (type != PackType.Hero)
            return;
 
        RefreshPackCount();
    }
 
 
    void RefreshTotalAttr()
    {
        for (int i = 0; i < totalAttrList.Count; i++)
        {
            totalAttrList[i].text = PlayerPropertyConfig.GetFullDescription(PlayerPropertyConfig.basePerAttrs[i],
            HeroUIManager.Instance.allHeroBookPer);
        }
    }
 
 
    void SelectJobCountry(int job, int country)
    {
        HeroUIManager.Instance.selectHeroCollectListJob = job;
        HeroUIManager.Instance.selectHeroCollectListCountry = country;
        HeroUIManager.Instance.SortHeroCollectList();
        CreateScroller();
    }
 
 
    void CreateScroller()
    {
        heroListScroller.Refresh();
        var _List = HeroUIManager.Instance.heroCollectDict.Keys.ToList();
        _List.Reverse();
        for (int i = 0; i < _List.Count; i++)
        {
            var ids = HeroUIManager.Instance.heroCollectDict[_List[i]];
            if (ids.Count == 0)
                continue;
            //品质
            heroListScroller.AddCell(ScrollerDataType.Header, _List[i]);
            //武将
            for (int j = 0; j < ids.Count; j++)
            {
                if (j % 4 == 0)
                { 
                    CellInfo cellInfo = new CellInfo();
                    cellInfo.infoInt1 = _List[i];
                    heroListScroller.AddCell(ScrollerDataType.Normal, j, cellInfo);
                }
            }
        }
        heroListScroller.Restart();
    }
 
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        if (type == ScrollerDataType.Header)
        {
            var _cell = cell.GetComponent<Image>();
            _cell.SetSprite("herocoltitle" + cell.index);
        }
        else if (type == ScrollerDataType.Normal)
        {
            var _cell = cell as HeroCollectionLineCell;
            _cell?.Display(cell.index, cell.info.Value.infoInt1);
 
        }
    }
 
    void OnHeroCollectEvent()
    {
        RefreshTotalAttr();
        heroListScroller.m_Scorller.RefreshActiveCellViews();
    }
 
}