少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 aecb6a5a62d8a4cfc7b924ce957a9c7ea90c235d
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, August 01, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class TrialExchangeWin : Window
    {
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] Text m_SelectClass;
        [SerializeField] Button m_SelectClassUp;
        [SerializeField] TrialSelectClassBehaviour m_SelectClassBehaviour;
        //[SerializeField] ItemBehaviour[] m_Tokens;
        //[SerializeField] Text[] m_TokenCounts;
        [SerializeField] Button m_Close;
 
        TrialDungeonModel model { get { return ModelCenter.Instance.GetModel<TrialDungeonModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
        PlayerPackModel packModel { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
        #region Built-in
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_Close.onClick.AddListener(CloseClick);
            m_SelectClassUp.onClick.AddListener(SelectClassUp);
        }
 
        protected override void OnPreOpen()
        {
            model.selectEquipClass = 1;
            m_SelectClassBehaviour.gameObject.SetActive(false);
            m_SelectClassUp.transform.localEulerAngles = Vector3.zero.SetZ(180);
            foreach (var mapID in dungeonModel.GetDungeonIds(60010))
            {
                DungeonConfig _tagDungeonModel = Config.Instance.Get<DungeonConfig>(mapID);
                DungeonRecord dungeonRecord;
                if (dungeonModel.TryGetRecord(60010, out dungeonRecord))
                {
                    if (dungeonRecord.lineGrades != null && dungeonRecord.lineGrades.ContainsKey(_tagDungeonModel.LineID)
                        && dungeonRecord.lineGrades[_tagDungeonModel.LineID] > 0)
                    {
                        model.selectEquipClass = model.LineToTokenClass(_tagDungeonModel.LineID);
                    }
                }
            }
 
            var maxClass = 0;
            if (model.TryGetSatisfyExchange(out maxClass))
            {
                model.selectEquipClass = maxClass;
            }
 
            if (WindowJumpMgr.Instance.IsJumpState)
            {
                if (PackSendQuestMgr.Instance.useItemModel != null
                    && model.trialTokens.Contains(PackSendQuestMgr.Instance.useItemModel.itemId))
                {
                    var itemId = PackSendQuestMgr.Instance.useItemModel.itemId;
                    var config = Config.Instance.Get<ItemConfig>(itemId);
                    if (config != null)
                    {
                        model.selectEquipClass = config.LV;
                    }
                    PackSendQuestMgr.Instance.useItemModel = null;
                }
            }
 
            model.SelectEquipClassEvent += SelectEquipClassEvent;
            packModel.RefreshItemCountAct += RefreshItemCountAct;
            Display();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            model.SelectEquipClassEvent -= SelectEquipClassEvent;
            packModel.RefreshItemCountAct -= RefreshItemCountAct;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            switch (type)
            {
                case ScrollerDataType.Header:
                    var _class = cell.index / 100;
                    var _line = cell.index % 100;
                    TrialExchangeCell trialExchangeCell = cell as TrialExchangeCell;
                    trialExchangeCell.Display(_class, _line);
                    break;
                case ScrollerDataType.Normal:
                    TrialExchangeTitleCell trialExchangeTitleCell = cell as TrialExchangeTitleCell;
                    trialExchangeTitleCell.Display(cell.index);
                    break;
            }
        }
 
        private void SelectClassUp()
        {
            bool _up = m_SelectClassBehaviour.gameObject.activeSelf;
            m_SelectClassBehaviour.gameObject.SetActive(!_up);
            if (!_up)
            {
                m_SelectClassBehaviour.Display();
            }
            m_SelectClassUp.transform.localEulerAngles = Vector3.zero.SetZ(_up ? 180 : 0);
        }
 
        void Display()
        {
            DisplayTrialExchanges();
            DisplaySelectClass();
            DisplayTokens();
        }
 
        void DisplayTrialExchanges()
        {
            m_Controller.Refresh();
            if (model.selectEquipClass == 1)
            {
                var trialClasses = model.GetTotalClass();
                for (int i = 0; i < trialClasses.Count; i++)
                {
                    List<TrialExchangeConfig> list;
                    if (model.TryGetTrialExchanges(trialClasses[i], out list))
                    {
                        m_Controller.AddCell(ScrollerDataType.Normal, trialClasses[i]);
                        var line = Mathf.CeilToInt((float)list.Count / 3);
                        for (int k = 0; k < line; k++)
                        {
                            m_Controller.AddCell(ScrollerDataType.Header, trialClasses[i] * 100 + k);
                        }
                    }
                }
            }
            else
            {
                List<TrialExchangeConfig> list;
                if (model.TryGetTrialExchanges(model.selectEquipClass, out list))
                {
                    var line = Mathf.CeilToInt((float)list.Count / 3);
                    for (int i = 0; i < line; i++)
                    {
                        m_Controller.AddCell(ScrollerDataType.Header, model.selectEquipClass * 100 + i);
                    }
                }
            }
            m_Controller.Restart();
        }
 
        private void RefreshItemCountAct(PackType packtype, int arg2, int itemId)
        {
            if (packtype == PackType.rptItem && model.trialTokens.Contains(itemId))
            {
                m_Controller.m_Scorller.RefreshActiveCellViews();
                DisplayTokens();
            }
            else if (packtype == PackType.rptEquip)
            {
                m_Controller.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        void DisplaySelectClass()
        {
            m_SelectClass.text = model.selectEquipClass == 1 ? Language.Get("TrialClassSeleclAll") :
                Language.Get("EquipSuitLV", Language.Get(StringUtility.Contact("Num_CHS_", model.selectEquipClass)));
        }
 
        void DisplayTokens()
        {
            //var list = model.trialClassTokens.ContainsKey(model.selectEquipClass) ? model.trialClassTokens[model.selectEquipClass] : null;
            //for (int i = 0; i < m_Tokens.Length; i++)
            //{
            //    if (list != null && i < list.Count)
            //    {
            //        m_Tokens[i].gameObject.SetActive(model.selectEquipClass != 1);
            //        if (model.selectEquipClass != 1)
            //        {
            //            m_Tokens[i].SetItem(list[i], 0);
            //            m_TokenCounts[i].text = model.GetTrialTokenCount(list[i]).ToString();
            //        }
            //    }
            //    else
            //    {
            //        m_Tokens[i].gameObject.SetActive(false);
            //    }
            //}
        }
 
        private void SelectEquipClassEvent()
        {
            DisplayTrialExchanges();
            DisplaySelectClass();
            DisplayTokens();
            bool _up = m_SelectClassBehaviour.gameObject.activeSelf;
            m_SelectClassUp.transform.localEulerAngles = Vector3.zero.SetZ(_up ? 0 : 180);
        }
    }
 
}