少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-13 c7f64d977c4e2884d5411a5a2d0f37b6afa52963
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
using System;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class DanDrugRecycleTip : MonoBehaviour
    {
        [SerializeField] ScrollerController shopCtrl;
        [SerializeField] Text sumMoneyText;
        [SerializeField] ScrollerController danDrugCtrl;
        [SerializeField] Text getMoneyText;
        [SerializeField] Text _resetRefreshTimeText;
        [SerializeField] Button recycleBtn;
        [SerializeField] UIEffect uieffect;
        [Header("回收丹药格子数")]
        [SerializeField] int sumGridCnt = 45;
 
        List<StoreModel.StoreData> shoplist;
        int SingleLineCnt = 2;
        StoreModel _storeModel;
        StoreModel m_storeModel
        {
            get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
        }
        PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
        PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
        BlastFurnaceModel blastFurnace { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
        Dictionary<string, List<ItemModel>> recycleDict;
        List<string> recycleKeylist;
        private void OnEnable()
        {
            GlobalTimeEvent.Instance.secondEvent += RefreshResetTime;
            blastFurnace.RefreshSelectRecycleAct += RefreshRecycleGetMoney;
            danDrugCtrl.OnRefreshCell += RefreshRecycleDan;
            shopCtrl.OnRefreshCell += RefreshShopCell;
            m_storeModel.RefreshBuyShopLimitEvent += CreateShopCell;
            m_storeModel.RefreshTCBPlayerDataEvent += RefreshRecycleScore;
            blastFurnace.RefreshMakeItemAnswerAct += OnGetRecycleResult;
            m_storeModel.storeFuncType = StoreFunc.DanDrugStore;
            recycleBtn.AddListener(ClickRecycle);
            playerPack.RefreshItemCountAct += RefreshItemCnt;
            Init();
        }
        private void OnDisable()
        {
            shopCtrl.OnRefreshCell -= RefreshShopCell;
            danDrugCtrl.OnRefreshCell -= RefreshRecycleDan;
            m_storeModel.RefreshTCBPlayerDataEvent -= RefreshRecycleScore;
            blastFurnace.RefreshSelectRecycleAct -= RefreshRecycleGetMoney;
            blastFurnace.RefreshMakeItemAnswerAct -= OnGetRecycleResult;
            playerPack.RefreshItemCountAct -= RefreshItemCnt;
            m_storeModel.RefreshBuyShopLimitEvent -= CreateShopCell;
            recycleBtn.RemoveAllListeners();
            GlobalTimeEvent.Instance.secondEvent -= RefreshResetTime;
        }
 
        private void RefreshItemCnt(PackType type, int index, int id)
        {
            if (type != PackType.rptItem || !playerPack.CheckIsDrugById(id)) return;
            CreateRecycleDan();
            RefreshRecycleGetMoney();
        }
 
        private void Init()
        {
            CreateShopCell();
            CreateRecycleDan();
            RefreshRecycleScore(PlayerDataRefresh.CDBPlayerRefresh_Danjing);
            RefreshRecycleGetMoney();
            RefreshResetTime();
        }
 
        private void RefreshResetTime()
        {
            if (shoplist != null && shoplist.Count > 0)
            {
                if (shoplist[0].storeConfig.RefreshType == 0)
                {
                    _resetRefreshTimeText.gameObject.SetActive(false);
                }
                else
                {
                    _resetRefreshTimeText.gameObject.SetActive(true);
                    _resetRefreshTimeText.text = m_storeModel.GetStoreRefreshTimeByType(shoplist[0].storeConfig.RefreshType);
                }
            }
            else
            {
                _resetRefreshTimeText.gameObject.SetActive(false);
            }
        }
 
 
        private void OnGetRecycleResult(MakeType type, int result)
        {
            if (type != MakeType.Def_DanRecycle || result != 1) return;
 
            uieffect.Play();
        }
 
        private void RefreshRecycleScore(PlayerDataRefresh refreshType)
        {
            if (refreshType != PlayerDataRefresh.CDBPlayerRefresh_Danjing) return;
 
            sumMoneyText.text = UIHelper.GetMoneyCnt(27).ToString();
        }
 
        private void RefreshRecycleGetMoney()
        {
            getMoneyText.text = blastFurnace.GetRecycleMoney().ToString();
        }
 
        private void CreateShopCell()
        {
            shopCtrl.Refresh();
            shoplist = m_storeModel.TryGetStoreDatas((int)m_storeModel.storeFuncType);
            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);
                DanDrugShopCell shopCell = cell.transform.GetChild(i).GetComponent<DanDrugShopCell>();
                if (shoplist.Count >= cellCount)
                {
                    shopCell.gameObject.SetActive(true);
                    shopCell.SetModel(shoplist[cellCount - 1].storeConfig);
                }
                else
                {
                    shopCell.gameObject.SetActive(false);
                }
            }
        }
 
        private void CreateRecycleDan()
        {
            recycleDict = blastFurnace.GetLookRecycleDanlist();
            recycleKeylist = recycleDict.Keys.ToList();
            danDrugCtrl.Refresh();
            int i = 0;
            int line = (int)sumGridCnt / 3;
            for (i = 0; i < line; i++)
            {
                danDrugCtrl.AddCell(ScrollerDataType.Header, i);
            }
            danDrugCtrl.Restart();
        }
 
        private void RefreshRecycleDan(ScrollerDataType type, CellView cell)
        {
        
            for(int i = 0; i < cell.transform.childCount; i++)
            {
                RecycleDrugCell drugCell = cell.transform.GetChild(i).GetComponent<RecycleDrugCell>();
                int index = (cell.transform.childCount) * cell.index + i;
                if(index <= recycleKeylist.Count - 1)
                {
                    drugCell.SetDisplayModel(recycleDict[recycleKeylist[index]]);
                }
                else
                {
                    drugCell.SetDisplayModel(null);
                }
            }
        }
 
        private void ClickRecycle()
        {
            blastFurnace.SetSelectRecycleDan();
        }
 
    }
 
}