hch
8 天以前 ee3196b5a04c15d025d1a9eab825d5d14987758d
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class StoreWin : UIBase
{
    [SerializeField] OwnMoneyCell ownMoneyCellWithShop;
    //有刷新功能的商店
    [SerializeField] GameObject refreshGo;
    [SerializeField] Image refreshMoneyIcon;
    [SerializeField] Text refreshMoneyText;
    [SerializeField] Button refreshButton;
 
    [SerializeField] GroupButtonEx normalShopBtn;
    [SerializeField] GroupButtonEx guildShopBtn;
    [SerializeField] GroupButtonEx heroShopBtn;
 
    [SerializeField] ScrollerController scroller;
 
 
    protected override void InitComponent()
    {
        refreshButton.AddListener(RefreshStore);
        normalShopBtn.AddListener(() => { OnSelectStoreFuncType(1); });
        guildShopBtn.AddListener(() => { OnSelectStoreFuncType(2); });
        heroShopBtn.AddListener(() => { OnSelectStoreFuncType(3); });
    }
 
 
    protected override void OnPreOpen()
    {
        scroller.OnRefreshCell += OnRefreshCell;
        StoreModel.Instance.RefreshShopEvent += Display;
        StoreModel.Instance.RefreshBuyShopLimitEvent += Display;
        GuildManager.Instance.EnterOrQuitGuildEvent += EnterOrQuitGuildEvent;
        
        Display();
    }
 
    protected override void OnPreClose()
    {
        scroller.OnRefreshCell -= OnRefreshCell;
        StoreModel.Instance.RefreshShopEvent -= Display;
        StoreModel.Instance.RefreshBuyShopLimitEvent -= Display;
        GuildManager.Instance.EnterOrQuitGuildEvent -= EnterOrQuitGuildEvent;
        StoreModel.Instance.selectStoreFuncType = StoreFunc.Normal;
    }
 
    void Display()
    {
        if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Normal)
        {
            normalShopBtn.SelectBtn();
        }
        else if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Guild)
        {
            guildShopBtn.SelectBtn();
        }
        else if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Hero)
        {
            heroShopBtn.SelectBtn();
        }
 
        guildShopBtn.SetColorful(null, PlayerDatas.Instance.fairyData.HasFairy);
 
        ShowMoney();
        CreateScroller();
    }
 
    void EnterOrQuitGuildEvent(bool isEnter)
    {
        if (!isEnter && StoreModel.Instance.selectStoreFuncType == StoreFunc.Guild)
        {
            StoreModel.Instance.selectStoreFuncType = StoreFunc.Normal;
        }
        Display();
    }
 
    void CreateScroller()
    {
        if (!StoreModel.Instance.storeTypeDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType))
        {
            return;
        }
 
        scroller.Refresh();
        var list = StoreModel.Instance.storeTypeDict[(int)StoreModel.Instance.selectStoreFuncType];
        for (int i = 0; i < list.Count; i++)
        {
            if (i % 3 == 0)
            {
                scroller.AddCell(ScrollerDataType.Header, i);
            }
        }
        scroller.Restart();
    }
 
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as StoreLineCell;
        _cell.Display(cell.index);
    }
 
 
    void ShowMoney()
    {
        if (!StoreModel.Instance.shopMoneyTypeDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType))
        {
            return;
        }
        var moneyType = StoreModel.Instance.shopMoneyTypeDict[(int)StoreModel.Instance.selectStoreFuncType];
        ownMoneyCellWithShop.moneyType = moneyType;
        ownMoneyCellWithShop.Display(true);
 
        if (StoreModel.Instance.selectStoreFuncType == StoreFunc.Hero)
        {
            refreshGo.SetActive(true);
            refreshMoneyIcon.SetIconWithMoneyType(StoreModel.Instance.heroSoulRefreshMoneyType);
 
            if (StoreModel.Instance.shopRefreshCntDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType))
            {
                if (StoreModel.Instance.shopRefreshCntDict[(int)StoreModel.Instance.selectStoreFuncType] >=
                StoreModel.Instance.heroSoulRefreshFreeCount)
                {
                    refreshMoneyText.text = StoreModel.Instance.heroSoulRefreshMoney.ToString();
                }
                else
                {
                    refreshMoneyText.text = Language.Get("L1127");
                }
            }
            else
            {
                refreshMoneyText.text = Language.Get("L1127");
            }
        }
        else
        {
            refreshGo.SetActive(false);
        }
    }
 
    void RefreshStore()
    {
        if (StoreModel.Instance.selectStoreFuncType != StoreFunc.Hero)
        {
            return;
        }
        var useCnt = 0;
        if (StoreModel.Instance.shopRefreshCntDict.ContainsKey((int)StoreModel.Instance.selectStoreFuncType))
        {
            if (StoreModel.Instance.shopRefreshCntDict[(int)StoreModel.Instance.selectStoreFuncType] >=
            StoreModel.Instance.heroSoulRefreshFreeCount)
            {
                useCnt = StoreModel.Instance.heroSoulRefreshMoney;
            }
        }
 
        if (UIHelper.CheckMoneyCount(StoreModel.Instance.heroSoulRefreshMoneyType, useCnt, 2))
        {
            StoreModel.Instance.RefreshStore((int)StoreFunc.Hero);
        }
    }
 
    void OnSelectStoreFuncType(int index)
    {
        if (index == 2)
        {
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                SysNotifyMgr.Instance.ShowTip("NoGuild");
                return;
            }
        }
        StoreModel.Instance.selectStoreFuncType = (StoreFunc)index;
        Display();
    }
}