少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-04 49d14c36c7a6ec949fc18c118896550b45bcbfba
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, February 28, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class EquipStarWin : Window
    {
        [SerializeField] CyclicScroll m_CandidateScroll;
        [SerializeField] ImageCouple[] m_Stars;
        [SerializeField] ItemCell m_TargetEquip;
        [SerializeField] Materials m_Materials;
        [SerializeField] Text m_SuccessRate;
        [SerializeField] BaseProperty[] m_BasePropertys;
        [SerializeField] Text[] m_LevelUpPropertys;
        [SerializeField] Button m_StarUpgrade;
        [SerializeField] EquipStarMaterialCandidateWidget m_MaterialCandidateWidget;
 
        EquipStarModel model { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        #region Built-in
        protected override void BindController()
        {
            m_StarUpgrade.SetListener(StarUpgrade);
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            DisplayBaseInfo();
            DisplayDynamicInfo(true);
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
            DisplayDynamicInfo(false);
        }
 
        #endregion
 
        private void DisplayBaseInfo()
        {
            var equip = packModel.GetItemByGuid(model.selectedEquip.Fetch());
            var currentStarLevel = model.GetEquipStarLevel(equip.config.LV, equip.config.EquipPlace);
            var starConfig = EquipStarConfig.Get(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
            for (var i = 1; i <= 5; i++)
            {
                m_Materials[i].Display(i >= starConfig.CostEquipCnt);
            }
 
            m_Materials[6].Display(starConfig.CostItemDict.x == 0);
        }
 
        private void DisplayDynamicInfo(bool force)
        {
            if (force || model.selectedEquip.dirty)
            {
                var equip = packModel.GetItemByGuid(model.selectedEquip.Fetch());
                m_TargetEquip.Init(equip);
 
                var currentStarLevel = model.GetEquipStarLevel(equip.config.LV, equip.config.EquipPlace);
                DisplayStars(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
                DisplayBaseProperty(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
                DisplayLevelUpProperty(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
            }
 
            if (force || model.starUpgradeProbability.dirty)
            {
                m_SuccessRate.text = string.Format("成功率 {0}", model.starUpgradeProbability.Fetch());
            }
 
            if (force || equipModel.selectedLevel.dirty)
            {
                var level = equipModel.selectedLevel.Fetch();
                var candidates = model.GetCandidateEquips();
                m_CandidateScroll.Init(candidates);
            }
 
            if (force || model.operateMaterialIndex.dirty)
            {
                var index = model.operateMaterialIndex.Fetch();
                DisplayMaterialCandidates(index);
            }
        }
 
        private void DisplayStars(int level, int equipPlace, int currentStarLevel)
        {
            var maxStarLevel = model.GetMaxStarLevel(level);
            for (var i = 0; i < m_Stars.Length; i++)
            {
                if (i < maxStarLevel)
                {
                    m_Stars[i].Display(i < currentStarLevel);
                }
                else
                {
                    m_Stars[i].Hide();
                }
            }
        }
 
        private void DisplayBaseProperty(int level, int equipPlace, int currentStarLevel)
        {
            var nowConfig = EquipStarConfig.Get(level, equipPlace, currentStarLevel);
            var nextConfig = EquipStarConfig.Get(level, equipPlace, currentStarLevel + 1);
            var count = nextConfig.BaseAttrInfo.Length;
            for (var i = 0; i < m_BasePropertys.Length; i++)
            {
                var behaviour = m_BasePropertys[i];
                if (i < count)
                {
                    var current = nowConfig == null ? 0 : nowConfig.BaseAttrInfo[i].y;
                    var next = nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].y;
                    behaviour.Display(nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].x, current, next);
                }
                else
                {
                    behaviour.Hide();
                }
            }
        }
 
        private void DisplayLevelUpProperty(int level, int equipPlace, int currentStarLevel)
        {
            var configs = EquipStarConfig.GetConfigs(level, equipPlace);
            var levelUpProperties = new Dictionary<int, Int2>();
            var prePropertiesCount = 0;
            foreach (var config in configs)
            {
                if (config.StarAttrInfo.Length > prePropertiesCount)
                {
                    var length = config.StarAttrInfo.Length;
                    levelUpProperties[config.Star] = config.StarAttrInfo[length - 1];
                    prePropertiesCount = config.StarAttrInfo.Length;
                }
            }
 
            var keys = new List<int>(levelUpProperties.Keys);
            for (var i = 0; i < m_LevelUpPropertys.Length; i++)
            {
                var behaviour = m_LevelUpPropertys[i];
                if (i < keys.Count)
                {
                    var property = levelUpProperties[keys[i]];
                    var config = PlayerPropertyConfig.Get(property.x);
                    behaviour.gameObject.SetActive(true);
                    behaviour.text = string.Format("【{0}星】{1}+{2}", config.Name, PlayerPropertyConfig.GetPropertyDescription(property.x, property.y));
                    behaviour.color = UIHelper.GetUIColor(keys[i] == currentStarLevel + 1 ? TextColType.Green : TextColType.Gray);
                }
                else
                {
                    behaviour.gameObject.SetActive(false);
                }
            }
        }
 
        private void DisplayMaterialCandidates(int materialIndex)
        {
            if (materialIndex == 0)
            {
                m_MaterialCandidateWidget.gameObject.SetActive(false);
            }
            else
            {
                m_MaterialCandidateWidget.gameObject.SetActive(true);
 
                var targetEquip = model.selectedEquip.value;
                var item = packModel.GetItemByGuid(targetEquip);
                var starLevel = model.GetEquipStarLevel(item.config.lv, item.config.EquipPlace);
                m_MaterialCandidateWidget.Display(item.config.LV, item.config.EquipPlace, starLevel);
 
                var position = Vector3.zero;
                m_MaterialCandidateWidget.transform.localPosition = position;
            }
        }
 
        private void StarUpgrade()
        {
            var equip = packModel.GetItemByGuid(model.selectedEquip.value);
            var level = equip.config.LV;
            var place = equip.config.EquipPlace;
            var currentStarLevel = model.GetEquipStarLevel(level, place);
            model.DoStarUpgrade(level, place, currentStarLevel);
        }
 
        [System.Serializable]
        public class ImageCouple
        {
            public RectTransform container;
            public Image imageBase;
            public Image imageStar;
 
            public void Display(bool active)
            {
                container.gameObject.SetActive(true);
                imageStar.gameObject.SetActive(active);
            }
 
            public void Hide()
            {
                container.gameObject.SetActive(false);
            }
        }
 
        [System.Serializable]
        public class Materials
        {
            public EquipStarUpgradeMaterialBehaviour m_Material1;
            public EquipStarUpgradeMaterialBehaviour m_Material2;
            public EquipStarUpgradeMaterialBehaviour m_Material3;
            public EquipStarUpgradeMaterialBehaviour m_Material4;
            public EquipStarUpgradeMaterialBehaviour m_Material5;
            public EquipStarUpgradeMaterialBehaviour m_MaterialSpecial;
 
            public EquipStarUpgradeMaterialBehaviour this[int index]
            {
                get
                {
                    switch (index)
                    {
                        case 1:
                            return m_Material1;
                        case 2:
                            return m_Material2;
                        case 3:
                            return m_Material3;
                        case 4:
                            return m_Material4;
                        case 5:
                            return m_Material5;
                        case 6:
                            return m_MaterialSpecial;
                        default:
                            return null;
                    }
                }
            }
 
        }
 
        [System.Serializable]
        public class BaseProperty
        {
            public RectTransform container;
            public Text current;
            public Text next;
 
            public void Display(int propertyId, int currentValue, int nextValue)
            {
                container.gameObject.SetActive(true);
                var config = PlayerPropertyConfig.Get(propertyId);
                if (config != null)
                {
                    this.current.text = StringUtility.Contact(config.Name, ":", PlayerPropertyConfig.GetPropertyDescription(propertyId, currentValue));
                    this.next.text = PlayerPropertyConfig.GetPropertyDescription(propertyId, nextValue);
                }
            }
 
            public void Hide()
            {
                container.gameObject.SetActive(false);
            }
        }
 
 
    }
 
}