少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, September 18, 2017
//--------------------------------------------------------
 
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class UnionStoreWin : StoreUIBasic ,SecondWindowInterface
    {
 
        #region 成员变量
        [SerializeField]
        private ScrollerController _shopCtrl;
        [SerializeField]
        private Text _moneyNumText;
        [SerializeField]
        private Toggle _toolToggle;
 
        [SerializeField] Button getPathBtn;
 
        [SerializeField]
        private Toggle _mountStoneToggle;
        [SerializeField]
        private Toggle _mountSkillBookToggle;
 
        #endregion
 
        private int _unionLv;
 
        StoreModel _storeModel;
        StoreModel m_storeModel
        {
            get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
        }
 
        int shopId = 0;
        #region Built-in
 
        public Button close { get; set; }
 
        protected override void BindController()
        {
            if (this is SecondWindowInterface)
            {
                var frame = this.GetComponentInChildren<SecondFrameLoader>();
                frame.Create();
                close = frame.GetComponentInChildren<Button>();
            }
        }
   
        protected override void AddListeners()
        {
            _shopCtrl.OnRefreshCell += RefreshShopLineCell;
            _shopCtrl.lockType = EnhanceLockType.KeepVertical;
            _toolToggle.onValueChanged.AddListener((bool isOn)=> { OnClickToolToggle(isOn); });
            _mountStoneToggle.onValueChanged.AddListener((bool isOn) => { OnClickMountStoneToggle(isOn); });
            _mountSkillBookToggle.onValueChanged.AddListener((bool isOn) => { OnClickMountSkillBookToggle(isOn); });
            close.onClick.AddListener(CloseWin);
            getPathBtn.AddListener(ClickGetPathBtn);
        }
 
        protected override void OnPreOpen()
        {
            m_storeModel.storeFuncType = StoreFunc.ToolStore;
            m_storeModel.RefreshTCBPlayerDataEvent += OnRefreshPlayerInfo;
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += CreateCell;
            m_storeModel.RefreshBuyShopLimitEvent += CreateCell;
            CreateCell();
            RefreshUI();
        }
 
        protected override void OnAfterOpen()
        {
            switch (m_storeModel.storeFuncType)
            {
                case StoreFunc.ToolStore:
                    _toolToggle.isOn = true;
                    break;
                case StoreFunc.MountStoneStore:
                    _mountStoneToggle.isOn = true;
                    break;
                case StoreFunc.MountSkillBookStore:
                    _mountSkillBookToggle.isOn = true;
                    break;
            }
            _shopCtrl.JumpIndex(0);
            CheckJumpToModel();
        }
 
        protected override void OnPreClose()
        {
            m_storeModel.RefreshBuyShopLimitEvent -= CreateCell;
            m_storeModel.RefreshTCBPlayerDataEvent -= OnRefreshPlayerInfo;
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= CreateCell;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void CheckJumpToModel()
        {
            if (AchievementGoto.guideAchievementId != 0)
            {
                SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
                if (successConfig.Type == 97)
                {
                    p_shopItemlist = m_storeModel.TryGetStoreDatas(m_storeModel.storeFuncType);
                    List<StoreModel.StoreData> orderlist = new List<StoreModel.StoreData>();
                    orderlist.AddRange(p_shopItemlist);
                    orderlist.Sort(CompareByMoney);
                    for (int i = 0; i < p_shopItemlist.Count; i++)
                    {
                        if (p_shopItemlist[i].shopId == orderlist[0].shopId)
                        {
                            shopId = p_shopItemlist[i].shopId;
                            int index = i / 2;
                            _shopCtrl.JumpIndex(index);
                            _shopCtrl.m_Scorller.RefreshActiveCellViews();
                            break;
                        }
                    }
                    AchievementGoto.guideAchievementId = 0;
                }
            }
        }
 
        public int CompareByMoney(StoreModel.StoreData start, StoreModel.StoreData end)
        {
            int money1 = start.storeConfig.MoneyNumber;
            int money2 = end.storeConfig.MoneyNumber;
            if (money1.CompareTo(money2) != 0) return money1.CompareTo(money2);
            int index1 = p_shopItemlist.IndexOf(start);
            int index2 = p_shopItemlist.IndexOf(end);
            if (index1.CompareTo(index2) != 0) return index1.CompareTo(index2);
            return 0;
        }
 
        private void RefreshUI()
        {
            _moneyNumText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(UIHelper.GetMoneyCnt(15));
        }
 
        private void OnRefreshPlayerInfo(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.UnionLiven)
                RefreshUI();
        }
 
        private void CreateCell()
        {
            shopId = 0;
            _unionLv = 0;
            if(PlayerDatas.Instance.fairyData.HasFairy)
            {
                _unionLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
            }
            base.CreateShopItemCell(_shopCtrl,2);
        }
 
        private void RefreshShopLineCell(ScrollerDataType type, CellView cell)
        {
            int childCode = 0;
            for (childCode = 0; childCode < cell.transform.childCount; childCode++)
            {
                int cellCount = (cell.transform.childCount) * cell.index + (childCode + 1);
                UnionShopCell shopItemCell = cell.transform.GetChild(childCode).GetComponent<UnionShopCell>();
                if (shopItemCell == null)
                {
                    shopItemCell = cell.transform.GetChild(childCode).gameObject.AddComponent<UnionShopCell>();
                }
 
                if (p_shopItemlist.Count >= cellCount)
                {
                    StoreConfig shopInfo = p_shopItemlist[cellCount - 1].storeConfig;
                    cell.transform.GetChild(childCode).gameObject.SetActive(true);
                    if (shopInfo.SalesStatus.Trim() != "")
                    {
                        shopItemCell.stateImage.gameObject.SetActive(true);
                        shopItemCell.stateImage.SetSprite(shopInfo.SalesStatus);
                    }
                    else
                    {
                        shopItemCell.stateImage.gameObject.SetActive(false);
                    }
                    ItemConfig chinModel = ItemConfig.Get(m_storeModel.GetReplaceId(shopInfo.ID,shopInfo.ItemID));
                    if (chinModel != null)
                    {
                        ItemCellModel cellModel = new ItemCellModel(chinModel.ID,false, 0);
                        shopItemCell.itemCell.enabled = false;
                        shopItemCell.itemCell.Init(cellModel);
                        shopItemCell.itemCell.button.SetListener(() =>
                        {
                            ItemTipUtility.Show(chinModel.ID);
                        });
                        shopItemCell.itemNameText.text = chinModel.ItemName;
                        shopItemCell.itemNameText.color = UIHelper.GetUIColor(chinModel.ItemColor, true);
                        shopItemCell.coinsIcon.SetIconWithMoneyType(shopInfo.MoneyType);
                        ulong shopCost = (ulong)(shopInfo.MoneyNumber);
                        shopItemCell.coinNumText.text = UIHelper.ReplaceLargeNum(shopCost);
                        BuyItemController buyItem = BuyItemController.Instance;
                        int curVipIndex = -1;
                        int nextVipIndex = -1;
                        bool isVipBuy = buyItem.CheckIsVipBuy(shopInfo, out curVipIndex, out nextVipIndex);
                        int canBuyCnt = 0;
                        int addBuyCnt = 0;
                        bool isLimitBuy = buyItem.CheckIsLimitBuyCnt(shopInfo, out canBuyCnt, out addBuyCnt);
                        bool isShowBuyPrice = true;
                        shopItemCell.buyBtn.gameObject.SetActive(true);
                        if (isVipBuy)
                        {
                            if (curVipIndex == -1 && nextVipIndex != -1)
                            {
                                shopItemCell.coinsIcon.gameObject.SetActive(false);
                                shopItemCell.vipText.gameObject.SetActive(true);
                                shopItemCell.vipText.text = Language.Get("StoreWin101", shopInfo.VIPLV[nextVipIndex]);
                                shopItemCell.sellImage.gameObject.SetActive(false);
                                isShowBuyPrice = false;
                            }
                        }
                        if (isShowBuyPrice)
                        {
                            shopItemCell.coinsIcon.gameObject.SetActive(true);
                            shopItemCell.vipText.gameObject.SetActive(false);
                            shopItemCell.sellImage.gameObject.SetActive(false);
                            shopItemCell.itemCell.countText.gameObject.SetActive(false);
                            if (canBuyCnt > 0)
                            {
                                shopItemCell.itemCell.countText.gameObject.SetActive(true);
                                BuyShopItemLimit shopItemLimit = m_storeModel.GetBuyShopLimit((uint)shopInfo.ID);
                                int remainNum = canBuyCnt;
                                if (shopItemLimit != null)
                                {
                                    remainNum = canBuyCnt - shopItemLimit.BuyCnt;
                                }
 
                                if (remainNum > 0)
                                {
                                    shopItemCell.itemCell.countText.text = StringUtility.Contact(remainNum.ToString(),
                                        "/" + canBuyCnt.ToString());
                                    shopItemCell.sellImage.gameObject.SetActive(false);
                                   
                                }
                                else
                                {
                                    shopItemCell.itemCell.countText.text = StringUtility.Contact(UIHelper.AppendColor(TextColType.Red, remainNum.ToString()),
                                        "/" + canBuyCnt.ToString());
                                    shopItemCell.sellImage.gameObject.SetActive(true);
                                    shopItemCell.buyBtn.gameObject.SetActive(false);
                                    shopItemCell.stateImage.gameObject.SetActive(false);
                                }
                            }
                        }
 
                        if(_unionLv >= shopInfo.LimitValue)
                        {
                            shopItemCell.moneyObj.SetActive(true);
                            shopItemCell.buyNeedText.gameObject.SetActive(false);
                            //shopItemCell.buyBtnIcon.SetSprite("");
                            shopItemCell.buyBtn.interactable = true;
                            shopItemCell.LoadGuidEffectCtrl(shopInfo.ID, shopId);
                        }
                        else
                        {
                            shopItemCell.buyNeedText.gameObject.SetActive(true);
                            shopItemCell.buyNeedText.text = Language.Get("FairyStore101",shopInfo.LimitValue);
                            shopItemCell.buyBtn.interactable = false;
                            shopItemCell.moneyObj.SetActive(false);
                            //shopItemCell.buyBtnIcon.SetSprite("");
                        }
                    }
 
              
                    shopItemCell.buyBtn.RemoveAllListeners();
                    shopItemCell.buyBtn.AddListener(() => {
                        if(shopInfo.ID == shopId)
                        {
                            shopId = 0;
                            shopItemCell.LoadGuidEffectCtrl(shopInfo.ID, shopId);
                        }
                        m_storeModel.SendBuyShopItem(shopInfo, 1);
                    });
                    shopItemCell.ShopCellBtn.RemoveAllListeners();
                    shopItemCell.ShopCellBtn.AddListener(() => {
                        if (shopInfo.ID == shopId)
                        {
                            shopId = 0;
                            shopItemCell.LoadGuidEffectCtrl(shopInfo.ID, shopId);
                        }
                        m_storeModel.OnClickShopCell(shopInfo);
                    });
                 
                }
                else
                {
                    cell.transform.GetChild(childCode).gameObject.SetActive(false);
                }
            }
        }
 
        private void OnClickMountSkillBookToggle(bool isOn)
        {
            m_storeModel.storeFuncType = StoreFunc.MountSkillBookStore;
            CreateCell();
            _shopCtrl.JumpIndex(0);
        }
 
        private void OnClickToolToggle(bool isOn)
        {
            m_storeModel.storeFuncType = StoreFunc.ToolStore;
            CreateCell();
            _shopCtrl.JumpIndex(0);
        }
 
        private void OnClickMountStoneToggle(bool isOn)
        {
            m_storeModel.storeFuncType = StoreFunc.MountStoneStore;
            CreateCell();
            _shopCtrl.JumpIndex(0);
        }
        private void ClickGetPathBtn()
        {
            int itemId = GeneralDefine.moneyDisplayIds[15];
            ItemTipUtility.Show(itemId);
        }
        private void CloseWin()
        {
            Close();
        }
 
    }
 
}