少年修仙传客户端代码仓库
hch
2023-06-14 f23c81d21c9cc4c9f06e8bed3ebb7ddbe7e15ac3
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
namespace Snxxz.UI
{
    public class XBStoreWin : Window
    {
        [SerializeField] ScrollerController shopCtrl;
        [SerializeField] Toggle equipToggle;
        [SerializeField] Toggle runeToggle;
        [SerializeField] Toggle toolToggle;
        [SerializeField] Text soreValueText;
 
        List<StoreFunc> storeFuncEnables = new List<StoreFunc>();
 
        StoreModel _storeModel;
        StoreModel m_storeModel
        {
            get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
        }
 
        List<StoreModel.StoreData> shoplist;
        int SingleLineCnt = 2;
 
        protected override void BindController()
        {
            shopCtrl.OnRefreshCell += RefreshShopCell;
            shopCtrl.lockType = EnhanceLockType.KeepVertical;
        }
 
        protected override void AddListeners()
        {
            equipToggle.onValueChanged.AddListener((bool isOn) => { OnClickEquipToggle(isOn); });
            runeToggle.onValueChanged.AddListener((bool isOn) => { OnClickRuneToggle(isOn); });
            toolToggle.onValueChanged.AddListener((bool isOn) => { OnClickToolToggle(isOn); });
        }
 
        protected override void OnPreOpen()
        {
            m_storeModel.RefreshBuyShopLimitEvent += UpdateStore;
 
            storeFuncEnables.Clear();
            shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBEquipStore);
            if (shoplist.Count > 0)
            {
                storeFuncEnables.Add(StoreFunc.XBEquipStore);
            }
            shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBToolStore);
            if (shoplist.Count > 0)
            {
                storeFuncEnables.Add(StoreFunc.XBToolStore);
            }
            shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBRuneStore);
            if (shoplist.Count > 0)
            {
                storeFuncEnables.Add(StoreFunc.XBRuneStore);
            }
 
            equipToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBEquipStore));
            runeToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBRuneStore));
            toolToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBToolStore));
 
            PlayerDatas.Instance.playerDataRefreshEvent += RefreshXBScore;
            RefreshXBScore(PlayerDataType.CDBPlayerRefresh_TreasureScore);
            if (m_storeModel.jumpStoreFuncType != 0
                && storeFuncEnables.Contains((StoreFunc)m_storeModel.jumpStoreFuncType))
            {
                m_storeModel.storeFuncType = (StoreFunc)m_storeModel.jumpStoreFuncType;
                m_storeModel.jumpStoreFuncType = 0;
            }
            else
            {
                m_storeModel.storeFuncType = storeFuncEnables[0];
            }
        }
 
        protected override void OnAfterOpen()
        {
            switch (m_storeModel.storeFuncType)
            {
                case StoreFunc.XBEquipStore:
                    equipToggle.isOn = true;
                    OnClickEquipToggle(true);
                    break;
                case StoreFunc.XBRuneStore:
                    runeToggle.isOn = true;
                    OnClickRuneToggle(true);
                    break;
                case StoreFunc.XBToolStore:
                    toolToggle.isOn = true;
                    OnClickToolToggle(true);
                    break;
            }
 
        }
 
        protected override void OnPreClose()
        {
            m_storeModel.RefreshBuyShopLimitEvent -= UpdateStore;
            PlayerDatas.Instance.playerDataRefreshEvent -= RefreshXBScore;
        }
        protected override void OnAfterClose()
        {
 
        }
 
        private void RefreshXBScore(PlayerDataType refreshType)
        {
            if (refreshType != PlayerDataType.CDBPlayerRefresh_TreasureScore) return;
 
            soreValueText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(UIHelper.GetMoneyCnt(25));
            
        }
 
        private void UpdateStore()
        {
            CreateShopCell();
        }
 
        private void OnClickToolToggle(bool isOn)
        {
            if (isOn)
            {
                m_storeModel.storeFuncType = StoreFunc.XBToolStore;
                CreateShopCell();
            }
        }
 
        private void OnClickRuneToggle(bool isOn)
        {
            if (isOn)
            {
                m_storeModel.storeFuncType = StoreFunc.XBRuneStore;
                CreateShopCell();
            }
        }
 
        private void OnClickEquipToggle(bool isOn)
        {
            if(isOn)
            {
                m_storeModel.storeFuncType = StoreFunc.XBEquipStore;
                CreateShopCell();
            }
        }
 
        private void CreateShopCell()
        {
            shopCtrl.Refresh();
            List<StoreModel.StoreData> resultList = new List<StoreModel.StoreData>();
            shoplist.Clear();
            resultList = m_storeModel.TryGetStoreDatas(m_storeModel.storeFuncType);
 
            //隐藏已售罄物品
            int remainCnt = 0;
            foreach(var item in resultList)
            {
                if (!_storeModel.TryGetIsSellOut(item.storeConfig, out remainCnt))
                {
                    shoplist.Add(item);
                }
            }
            if (shoplist.Count > 0)
            {
                int i = 0;
                int remain = shoplist.Count % SingleLineCnt;
                int line = (int)shoplist.Count / SingleLineCnt;
                if (remain > 0)
                {
                    line += 1;
                }
 
                for (i = 0; i < line; i++)
                {
                    shopCtrl.AddCell(ScrollerDataType.Header, i);
                }
            }
            shopCtrl.Restart();
 
            shopCtrl.JumpIndex(0);
        }
 
        private void RefreshShopCell(ScrollerDataType type, CellView cell)
        {
            int length = cell.transform.childCount;
            for(int i = 0; i < length;i++)
            {
                int cellCount = length * cell.index + (i + 1);
                XBShopCell shopCell = cell.transform.GetChild(i).GetComponent<XBShopCell>();
                if(shoplist.Count >= cellCount)
                {
                    shopCell.SetActive(true);
                    shopCell.SetModel(shoplist[cellCount-1].storeConfig);
                }
                else
                {
                    shopCell.SetActive(false);
                }
            }
        }
 
    }
}