少年修仙传客户端代码仓库
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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, May 23, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class TreasureSoulWin : Window
    {
        [SerializeField] FunctionButton m_TreasureSoulBtn;
        [SerializeField] Button m_CloseBtn;
 
        [SerializeField] Image m_SelectSoulImg;
 
        [SerializeField] Text m_SoulName;
        [SerializeField] Text m_SoulDescription;
        [SerializeField] Image m_SoulTarget;
        [SerializeField] UIEffect m_SoulEffect;
        [SerializeField] Button m_Active;
        [SerializeField] Text m_ActiveText;
 
        [SerializeField] List<TreasureSoulPattern> m_TreasureSouls;
 
        [SerializeField] ScrollerController m_ScollerControl;
 
        [SerializeField] RectTransform m_ContainerPreview;
        [SerializeField] Text m_PreviewTitle;
        [SerializeField] List<PropertyBehaviour> m_PreviewPropretys;
 
        TreasureSoulModel m_Model;
        TreasureSoulModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureSoulModel>());
            }
        }
        PlayerSuitModel suitModel { get { return ModelCenter.Instance.GetModel<PlayerSuitModel>(); } }
        PlayerPackModel pack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
 
        public PlayerStrengthengDatas strengthengmodel
        {
            get
            {
                return ModelCenter.Instance.GetModel<PlayerStrengthengDatas>();
            }
        }
 
        TreasureModel treasureModel
        {
            get { return ModelCenter.Instance.GetModel<TreasureModel>(); }
        }
 
 
        int m_SelectSoul = 0;
 
        List<int> sortSouls = new List<int>();
 
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Active.onClick.AddListener(Active);
            m_CloseBtn.onClick.AddListener(CloseClick);
            m_ScollerControl.OnRefreshCell += OnRefreshCell;
        }
 
        protected override void OnPreOpen()
        {
            model.treasureSelectSoulChangeEvent += TreasureSelectSoulChangeEvent;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
            model.treasureSoulEvent += TreasureSoulEvent;
            m_TreasureSoulBtn.state = TitleBtnState.Click;
            Display();
            model.SetViewTreasureNewGot();
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            DisplaySelect();
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataRefresh refreshType)
        {
            if (refreshType == PlayerDataRefresh.LV)
            {
                m_ScollerControl.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            model.treasureSelectSoulChangeEvent -= TreasureSelectSoulChangeEvent;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
            model.treasureSoulEvent -= TreasureSoulEvent;
            for (int i = 0; i < m_TreasureSouls.Count; i++)
            {
                m_TreasureSouls[i].Dispose();
            }
            m_SelectSoul = model.selectSoul;
            model.newGotSoul = 0;
        }
 
        protected override void OnAfterClose()
        {
            if (!WindowJumpMgr.Instance.IsJumpState)
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
        }
        #endregion
 
        private void Display()
        {
            sortSouls.Clear();
            var _list = model.GetTreasureSouls();
            for (int i = 0; i < _list.Count; i++)
            {
                if (model.IsOpenTreasureSoul(_list[i]))
                {
                    sortSouls.Add(_list[i]);
                }
            }
            if (m_ScollerControl.GetNumberOfCells(m_ScollerControl.m_Scorller) != sortSouls.Count)
            {
                m_ScollerControl.Refresh();
                for (int i = 0; i < sortSouls.Count; i++)
                {
                    m_ScollerControl.AddCell(ScrollerDataType.Header, i);
                }
                m_ScollerControl.Restart();
            }
            sortSouls.Sort(Compare);
            model.selectSoul = CheckOpenSelect();
            var index = sortSouls.FindIndex((x) =>
             {
                 return x == model.selectSoul;
             });
            m_ScollerControl.m_Scorller.RefreshActiveCellViews();
            m_ScollerControl.JumpIndex(index);
        }
 
        int CheckOpenSelect()
        {
            if (WindowJumpMgr.Instance.IsJumpState && model.gotoSoul != 0)
            {
                var _soul = model.gotoSoul;
                model.gotoSoul = 0;
                return _soul;
            }
            model.gotoSoul = 0;
            var _select = 0;
            for (int i = 0; i < sortSouls.Count; i++)
            {
                TreasureSpecialData special;
                if (model.TryGetTreasureSoul(sortSouls[i], out special))
                {
                    if (special.redpoint.state == RedPointState.Simple)
                    {
                        return sortSouls[i];
                    }
                }
                if (!model.IsGetTreasureSoul(sortSouls[i]) && _select == 0)
                {
                    _select = sortSouls[i];
                }
            }
            if (model.newGotSoul != 0 && sortSouls.Contains(model.newGotSoul))
            {
                _select = model.newGotSoul;
                model.newGotSoul = 0;
            }
            _select = _select == 0 ? sortSouls[0] : _select;
            return _select;
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            TreasureSoulCell treasureSoulCell = cell as TreasureSoulCell;
            if (cell.index < sortSouls.Count)
            {
                treasureSoulCell.Display(sortSouls[cell.index]);
            }
        }
 
        private void TreasureSelectSoulChangeEvent(int _id)
        {
            DisplaySelect();
        }
 
        private void TreasureSoulEvent(int _id)
        {
            if (_id == model.selectSoul)
            {
                TreasureSpecialData special;
                if (model.TryGetTreasureSoul(_id, out special))
                {
                    DisplaySelect();
                }
            }
        }
 
        private void Active()
        {
            var config = TreasurePrivilegeConfig.Get(model.selectSoul);
            treasureModel.selectedTreasure = config.treasureId;
            treasureModel.currentCategory = TreasureCategory.Human;
            WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.TreasureCollectSoul);
        }
 
        private void DisplaySelect()
        {
            TreasureSpecialData special;
            model.TryGetTreasureSoul(model.selectSoul, out special);
            if (special != null)
            {
                var config = TreasurePrivilegeConfig.Get((int)special.type);
                if (config != null)
                {
                    m_SoulName.text = config.Name;
                    m_SoulDescription.text = UIHelper.ReplaceNewLine(config.Description);
                    m_SoulTarget.SetSprite(config.targetDescription);
                    m_SoulTarget.SetNativeSize();
                    DisplayPrivilege(special);
 
                    m_SelectSoulImg.SetSprite(config.Icon);
                    m_SelectSoulImg.material = special.active ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
                    m_SelectSoulImg.SetNativeSize();
 
                    m_Active.gameObject.SetActive(!special.active);
 
                    m_ContainerPreview.gameObject.SetActive(!special.active);
                    m_SoulEffect.StopImediatly();
                    if (!special.active)
                    {
                        DisplayPreview(model.selectSoul);
                    }
                    else
                    {
                        m_SoulEffect.effect = config.effectId;
                        m_SoulEffect.Play();
                    }
                }
            }
        }
 
        private void DisplayPrivilege(TreasureSpecialData special)
        {
            int _pattern = -1;
            switch (special.type)
            {
                case TreasurePrivilege.Property:
                case TreasurePrivilege.Suit:
                case TreasurePrivilege.Wing:
                    _pattern = 3;
                    break;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Sp:
                    _pattern = 0;
                    break;
                case TreasurePrivilege.StrengthenAdd:
                    _pattern = 1;
                    break;
                case TreasurePrivilege.Wash:
                    _pattern = 2;
                    break;
            }
            for (int i = 0; i < m_TreasureSouls.Count; i++)
            {
                m_TreasureSouls[i].Dispose();
                m_TreasureSouls[i].gameObject.SetActive(_pattern == i && model.IsGetTreasureSoul(model.selectSoul));
                if (m_TreasureSouls[i].bottom != null)
                {
                    m_TreasureSouls[i].bottom.gameObject.SetActive(_pattern == i && model.IsGetTreasureSoul(model.selectSoul));
                }
                if (_pattern == i)
                {
                    m_TreasureSouls[i].Display((int)special.type);
                }
            }
        }
 
        private void DisplayPreview(int _id)
        {
            m_ContainerPreview.gameObject.SetActive(false);
            TreasureSpecialData special;
            model.TryGetTreasureSoul(_id, out special);
            switch (special.type)
            {
                case TreasurePrivilege.Wing:
                case TreasurePrivilege.Suit:
                case TreasurePrivilege.Property:
                    m_PreviewTitle.text = Language.Get("TreasureSoulAddPropertyTitle");
                    break;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.StrengthenAdd:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Sp:
                    m_PreviewTitle.text = Language.Get("TreasureSoulGetPropertyTitle");
                    break;
            }
            for (int i = 0; i < m_PreviewPropretys.Count; i++)
            {
                m_PreviewPropretys[i].gameObject.SetActive(false);
            }
            switch (special.type)
            {
                case TreasurePrivilege.Property:
                    var _index = 0;
                    m_ContainerPreview.gameObject.SetActive(true);
                    foreach (var _key in special.propertyDict.Keys)
                    {
                        var _value = special.propertyDict[_key];
                        m_PreviewPropretys[_index].gameObject.SetActive(true);
                        m_PreviewPropretys[_index].DisplayUpper(_key, _value);
                        _index++;
                    }
                    break;
                case TreasurePrivilege.Suit:
                    var percentSuit = (float)special.propertyDict[87] / 10000;
                    var dict = suitModel.GetActiveSuitAttr();
                    var _suitIndex = 0;
                    foreach (var _key in dict.Keys)
                    {
                        var propertyConfig = PlayerPropertyConfig.Get(_key);
                        if (propertyConfig == null || propertyConfig.type != 1)
                        {
                            continue;
                        }
                        m_PreviewPropretys[_suitIndex].gameObject.SetActive(true);
                        m_PreviewPropretys[_suitIndex].DisplayUpper(_key, (int)(percentSuit * dict[_key]));
                        _suitIndex++;
                    }
                    m_ContainerPreview.gameObject.SetActive(_suitIndex > 0);
                    break;
                case TreasurePrivilege.Wing:
                    var percentWing = (float)special.propertyDict[86] / 10000;
                    var itemModel = pack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing);
                    m_ContainerPreview.gameObject.SetActive(itemModel != null);
                    if (itemModel != null)
                    {
                        var itemConfig = ItemConfig.Get(itemModel.itemId);
                        float value = 0;
                        if (ContainsProperty(itemConfig, 6, out value))
                        {
                            if (itemModel.GetUseDataModel(42) != null)
                            {
                                value += strengthengmodel.BackpackWings(itemModel.itemId, itemModel.GetUseDataModel(42)[0])[1];
                            }
                        }
                        m_PreviewPropretys[0].gameObject.SetActive(true);
                        m_PreviewPropretys[0].DisplayUpper(6, (int)(value * percentWing));
                    }
                    break;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.Sp:
                    var index = 0;
                    m_ContainerPreview.gameObject.SetActive(true);
                    foreach (var _key in special.propertyDict.Keys)
                    {
                        var _value = special.propertyDict[_key] * (special.presentGetCount / special.progress);
                        if (_value <= 0)
                        {
                            m_ContainerPreview.gameObject.SetActive(false);
                            break;
                        }
                        m_PreviewPropretys[index].gameObject.SetActive(true);
                        m_PreviewPropretys[index].DisplayUpper(_key, _value);
                        index++;
                    }
                    break;
                case TreasurePrivilege.StrengthenAdd:
                    var configs = Config.Instance.GetAllValues<ItemPlusSumAttrConfig>();
                    var present = -1;
                    var next = 0;
                    var presentGetCount = 0;
                    foreach (var value in strengthengmodel._EqInfo.Values)
                    {
                        ItemModel equip = pack.GetItemModelByIndex(PackType.rptEquip, value.EquipIndex);
                        if (equip != null)
                        {
                            presentGetCount += value.EquipPartStarLV;
                        }
                    }
                    for (int i = 0; i < configs.Count; i++)
                    {
                        if (presentGetCount >= configs[i].countNeed)
                        {
                            present = i;
                        }
                    }
                    next = present + 1;
                    m_ContainerPreview.gameObject.SetActive(present >= 0);
                    if (present >= 0)
                    {
                        var config = configs[present];
                        for (int i = 0; i < m_PreviewPropretys.Count; i++)
                        {
                            m_PreviewPropretys[i].gameObject.SetActive(i < config.attType.Length);
                            if (i < config.attType.Length)
                            {
                                m_PreviewPropretys[i].DisplayUpper(config.attType[i], config.attValue[i]);
                            }
                        }
                    }
                    break;
            }
        }
 
        int Compare(int x, int y)
        {
            var leftConfig = TreasurePrivilegeConfig.Get(x);
            var rightConfig = TreasurePrivilegeConfig.Get(y);
            if (leftConfig != null && rightConfig != null)
            {
                return leftConfig.sort.CompareTo(rightConfig.sort);
            }
            return x.CompareTo(y);
        }
 
        bool ContainsProperty(ItemConfig config, int _property, out float value)
        {
            value = 0;
            if (config.Effect1 == _property && config.EffectValueA1 > 0)
            {
                value = config.EffectValueA1;
                return true;
            }
            if (config.Effect2 == _property && config.EffectValueA2 > 0)
            {
                value = config.EffectValueA2;
                return true;
            }
            if (config.Effect3 == _property && config.EffectValueA3 > 0)
            {
                value = config.EffectValueA3;
                return true;
            }
            if (config.Effect4 == _property && config.EffectValueA4 > 0)
            {
                value = config.EffectValueA4;
                return true;
            }
            if (config.Effect5 == _property && config.EffectValueA5 > 0)
            {
                value = config.EffectValueA5;
                return true;
            }
            return false;
        }
    }
 
}