少年修仙传客户端代码仓库
client_Wu Xijin
2018-11-15 d5bf165ef28b530ed531aed097ad301278c5fcae
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, November 13, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class DemonTreasureWin : Window
    {
        [SerializeField] TreasureDemonBehaviour m_TreasureDemonBehaviour;
        [SerializeField] Text m_PropertyTitle;
        [SerializeField] PropertyBehaviour[] m_Propertys;
        [SerializeField] Text m_SkillTitle;
        [SerializeField] Image m_SkillIcon;
        [SerializeField] Text m_SkillState;
        [SerializeField] Text m_SkillName;
        [SerializeField] Text m_SkillDescription;
        [SerializeField] RectTransform m_DungeonsContent;
        [SerializeField] Transform m_ContainerDungeons;
        [SerializeField] DemonDungeonBehaviour[] m_DungeonBehaviours;
 
        [SerializeField] Transform m_ContainerChallenge;
        [SerializeField] Button m_Challenge;
        [SerializeField] Text m_RecommondPower;
        [SerializeField] Button m_ViewProperty;
 
        [SerializeField] float m_Expand = 1.05f;
 
        [SerializeField] PositionTween m_TreasureGainTween;
        [SerializeField] PositionTween m_DescriptionTween;
        [SerializeField] PositionTween m_SkillTween;
        [SerializeField] PositionTween m_NameTween;
        [SerializeField] UIAlphaTween m_DungeonAlphaTween;
 
        TreasureModel model
        {
            get { return ModelCenter.Instance.GetModel<TreasureModel>(); }
        }
 
        DungeonModel dungeonModel
        {
            get { return ModelCenter.Instance.GetModel<DungeonModel>(); }
        }
 
        static Dictionary<int, int> currentPropertyDict = new Dictionary<int, int>();
        static List<int> displayPropertys = new List<int>();
        static Dictionary<int, int> addPropertyDict = new Dictionary<int, int>();
 
        public static float expand = 1.05f;
 
        AnimationStep m_Step = AnimationStep.None;
        AnimationStep step
        {
            get { return m_Step; }
            set
            {
                if (m_Step != value)
                {
                    m_Step = value;
                    DisplayAnimation();
                }
            }
        }
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_ViewProperty.onClick.AddListener(ViewProperty);
            m_Challenge.onClick.AddListener(Challenge);
        }
 
        protected override void OnPreOpen()
        {
            expand = m_Expand;
            m_Step = AnimationStep.None;
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            model.treasureSelectedEvent += TreasureSelectedEvent;
            model.treasureStateChangeEvent += TreasureStateChangeEvent;
            model.demonTreasureDungeonUpdate += DemonTreasureDungeonUpdate;
            Display();
 
            Treasure treasure;
            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
            {
                switch (treasure.state)
                {
                    case TreasureState.Collecting:
                    case TreasureState.Collected:
                        step = AnimationStep.None2Collect;
                        break;
                    case TreasureState.Locked:
                        step = AnimationStep.None2Lock;
                        break;
                }
            }
        }
 
        protected override void OnAfterOpen()
        {
            
        }
 
        protected override void OnPreClose()
        {
            model.treasureSelectedEvent -= TreasureSelectedEvent;
            model.treasureStateChangeEvent -= TreasureStateChangeEvent;
            model.demonTreasureDungeonUpdate -= DemonTreasureDungeonUpdate;
            model.SetTreasureUnlockShow(TreasureCategory.Demon, 0);
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void ViewProperty()
        {
            WindowCenter.Instance.Open<DemonTreasurePropertyWin>();
        }
 
        private void Challenge()
        {
            Treasure treasure;
            if (!model.TryGetTreasure(model.selectedTreasure, out treasure))
            {
                return;
            }
            var fightPower = PlayerDatas.Instance.baseData.FightPoint;
            var recommandPower = 0;
            TreasureDungeon treasureDungeon;
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                var dungeonInfo = treasureDungeon.Get(treasureDungeon.currentLevel + 1);
                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
                {
                    recommandPower = dungeonInfo.fightPower;
                }
            }
 
            var config = Config.Instance.Get<TreasureConfig>(model.selectedTreasure);
            if (fightPower < recommandPower)
            {
                ConfirmCancel.ShowPopConfirm(Language.Get("DemonLackPowerTitle"), Language.Get("DemonLackFightPower", recommandPower)
                    , (bool isOk) =>
                     {
                         if (isOk)
                         {
                             model.collectingDemon = model.selectedTreasure;
                             dungeonModel.SingleChallenge(TreasureModel.TREASURE_DATAMAPID, config.LineId);
                         }
                     });
            }
            else
            {
                model.collectingDemon = model.selectedTreasure;
                dungeonModel.SingleChallenge(TreasureModel.TREASURE_DATAMAPID, config.LineId);
            }
        }
 
        private void Display()
        {
            m_TreasureDemonBehaviour.Display(model.selectedTreasure);
            DisplayProperty();
            DisplaySkill();
            DisplayDungeons();
            DisplayChallenge();
            DisplayDungeonPosition();
        }
 
        private void DisplayAnimation()
        {
            switch (step)
            {
                case AnimationStep.None2Lock:
                    m_DescriptionTween.Play();
                    m_NameTween.Play();
                    m_SkillTween.Play();
                    m_TreasureGainTween.SetStartState();
                    UI3DTreasureSelectStage.Instance.SetStartState();
                    m_ContainerDungeons.gameObject.SetActive(false);
                    break;
                case AnimationStep.None2Collect:
                    m_ContainerDungeons.gameObject.SetActive(true);
                    m_DungeonAlphaTween.Play();
                    UI3DTreasureSelectStage.Instance.Tween(null);
                    m_DescriptionTween.SetStartState();
                    m_NameTween.SetStartState();
                    m_SkillTween.SetStartState();
                    m_TreasureGainTween.Play();
                    break;
                case AnimationStep.Lock2Collect:
                    m_ContainerDungeons.gameObject.SetActive(true);
                    m_DungeonAlphaTween.Play();
                    UI3DTreasureSelectStage.Instance.Tween(null);
                    m_DescriptionTween.Play(true);
                    m_NameTween.Play(true);
                    m_SkillTween.Play(true);
                    m_TreasureGainTween.Play();
                    break;
                case AnimationStep.Collect2Lock:
                    m_ContainerDungeons.gameObject.SetActive(false);
                    UI3DTreasureSelectStage.Instance.SetStartState();
                    m_DescriptionTween.Play();
                    m_NameTween.Play();
                    m_SkillTween.Play();
                    m_TreasureGainTween.Play(true);
                    break;
            }
        }
 
        private void DisplayProperty()
        {
            TreasureDungeon treasureDungeon;
            currentPropertyDict.Clear();
            addPropertyDict.Clear();
            displayPropertys.Clear();
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                for (int i = 0; i < treasureDungeon.dungeonInfos.Count; i++)
                {
                    var info = treasureDungeon.dungeonInfos[i];
                    if (treasureDungeon.currentLevel >= info.level)
                    {
                        foreach (var key in info.propertyDict.Keys)
                        {
                            if (!currentPropertyDict.ContainsKey(key))
                            {
                                currentPropertyDict.Add(key, 0);
                            }
                            currentPropertyDict[key] += info.propertyDict[key];
                            if (!displayPropertys.Contains(key))
                            {
                                displayPropertys.Add(key);
                            }
                        }
                    }
                    else
                    {
                        foreach (var key in info.propertyDict.Keys)
                        {
                            if (!addPropertyDict.ContainsKey(key))
                            {
                                addPropertyDict.Add(key, info.propertyDict[key]);
                            }
                            if (!displayPropertys.Contains(key))
                            {
                                displayPropertys.Add(key);
                            }
                        }
                        break;
                    }
                }
                if (treasureDungeon.currentLevel == treasureDungeon.maxLevel)
                {
                    m_PropertyTitle.text = Language.Get("GetTreasurePropertyTitle");
                }
                else
                {
                    m_PropertyTitle.text = Language.Get("PassTreasureDungeonPropertyTitle");
                }
            }
            for (int i = 0; i < m_Propertys.Length; i++)
            {
                if (i < displayPropertys.Count)
                {
                    m_Propertys[i].gameObject.SetActive(true);
                    var currentValue = 0;
                    if (currentPropertyDict.ContainsKey(displayPropertys[i]))
                    {
                        currentValue = currentPropertyDict[displayPropertys[i]];
                    }
                    var addValue = 0;
                    if (addPropertyDict.ContainsKey(displayPropertys[i]))
                    {
                        addValue = addPropertyDict[displayPropertys[i]];
                    }
                    m_Propertys[i].DisplayAdd(displayPropertys[i], currentValue, addValue);
                }
                else
                {
                    m_Propertys[i].gameObject.SetActive(false);
                }
            }
        }
 
        private void DisplaySkill()
        {
            Treasure treasure;
            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
            {
                var skillConfig = Config.Instance.Get<SkillConfig>(treasure.unlockSkill);
                if (skillConfig != null)
                {
                    m_SkillIcon.SetSprite(skillConfig.IconName);
                    m_SkillName.text = skillConfig.SkillName;
                    m_SkillDescription.text = skillConfig.Description;
                    if (treasure.state == TreasureState.Collected)
                    {
                        m_SkillState.text = Language.Get("DemonTreasureSkillGot");
                        m_SkillState.color = UIHelper.GetUIColor(TextColType.Green, true);
                    }
                    else
                    {
                        m_SkillState.text = Language.Get("DemonTreasureSkillGetting");
                        m_SkillState.color = UIHelper.GetUIColor(TextColType.Red, true);
                    }
                }
            }
            TreasureDungeon treasureDungeon;
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                var dungeonInfo = treasureDungeon.Get(treasureDungeon.maxLevel);
                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
                {
                    var config = Config.Instance.Get<TreasureDungeonConfig>(dungeonInfo.key);
                    m_SkillTitle.text = Language.Get("PassTreasureDungeonSkillTitle", config.bossName);
                }
            }
        }
 
        private void DisplayChallenge()
        {
            Treasure treasure;
            if (!model.TryGetTreasure(model.selectedTreasure, out treasure))
            {
                return;
            }
            m_ContainerChallenge.gameObject.SetActive(treasure.state == TreasureState.Collecting);
            var fightPower = PlayerDatas.Instance.baseData.FightPoint;
            var recommandPower = 0;
            TreasureDungeon treasureDungeon;
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                var dungeonInfo = treasureDungeon.Get(treasureDungeon.currentLevel + 1);
                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
                {
                    recommandPower = dungeonInfo.fightPower;
                }
            }
            m_RecommondPower.text = Language.Get("TreasureRecommendAttr", StringUtility.Contact(fightPower, "/", recommandPower));
            m_RecommondPower.color = UIHelper.GetUIColor(fightPower >= recommandPower ? TextColType.Green : TextColType.Red);
        }
 
        private void DisplayDungeons()
        {
            TreasureDungeon treasureDungeon;
            DemonDungeonScriptable config = ScriptableObjectLoader.LoadSoDemonDungeon(model.selectedTreasure);
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                for (int i = 0; i < m_DungeonBehaviours.Length; i++)
                {
                    if (i < treasureDungeon.dungeonInfos.Count)
                    {
                        m_DungeonBehaviours[i].gameObject.SetActive(true);
                        m_DungeonBehaviours[i].Display(model.selectedTreasure, treasureDungeon.dungeonInfos[i].level);
                        if (config != null)
                        {
                            m_DungeonBehaviours[i].transform.localPosition = config.GetPosition(i);
                        }
                    }
                    else
                    {
                        m_DungeonBehaviours[i].gameObject.SetActive(false);
                    }
                }
            }
        }
 
        private void TreasureStateChangeEvent(int id)
        {
            if (id == model.selectedTreasure)
            {
                DisplaySkill();
                DisplayProperty();
                DisplayChallenge();
 
                UpdateAnimationStep();
            }
        }
 
        private void TreasureSelectedEvent(int id)
        {
            Display();
            UpdateAnimationStep();
        }
 
        private void DemonTreasureDungeonUpdate(int id)
        {
            if (id == model.selectedTreasure)
            {
                DisplayDungeons();
                DisplayChallenge();
            }
        }
 
        private void UpdateAnimationStep()
        {
            Treasure treasure;
            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
            {
                switch (treasure.state)
                {
                    case TreasureState.Collecting:
                    case TreasureState.Collected:
                        switch (step)
                        {
                            case AnimationStep.Collect2Lock:
                            case AnimationStep.None2Lock:
                                step = AnimationStep.Lock2Collect;
                                break;
                        }
                        break;
                    case TreasureState.Locked:
                        switch (step)
                        {
                            case AnimationStep.None2Collect:
                            case AnimationStep.Lock2Collect:
                                step = AnimationStep.Collect2Lock;
                                break;
                        }
                        break;
                }
            }
        }
 
        private void DisplayDungeonPosition()
        {
            TreasureDungeon treasureDungeon;
            var scriptable = ScriptableObjectLoader.LoadSoDemonDungeon(model.selectedTreasure);
            if (scriptable == null)
            {
                return;
            }
            var height = (m_DungeonBehaviours[0].transform as RectTransform).sizeDelta.y;
            var viewAreaHeight = (m_ContainerDungeons as RectTransform).sizeDelta.y;
            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
            {
                var selectLevel = treasureDungeon.currentLevel == treasureDungeon.maxLevel ?
                    treasureDungeon.maxLevel : (treasureDungeon.currentLevel + 1);
                var selectPosition = scriptable.GetPosition(selectLevel - 1);
                if (selectPosition.y + (height / 2) * expand <= viewAreaHeight)
                {
                    m_DungeonsContent.anchoredPosition = Vector3.zero;
                    return;
                }
                else
                {
                    var delta = selectPosition.y + (height / 2) * expand - viewAreaHeight;
                    m_DungeonsContent.anchoredPosition = m_DungeonsContent.localPosition.SetY(-delta);
                }
            }
        }
 
        enum AnimationStep
        {
            None,
            None2Lock,
            None2Collect,
            Lock2Collect,
            Collect2Lock,
        }
 
#if UNITY_EDITOR
        [SerializeField] DemonDungeonScriptable m_EditorScriptable;
 
        [ContextMenu("应用位置信息")]
        void ApplyPositions()
        {
            if (m_EditorScriptable == null)
            {
                return;
            }
            var index = 0;
            for (int i = 0; i < m_DungeonBehaviours.Length; i++)
            {
                if (m_DungeonBehaviours[i].gameObject.activeSelf)
                {
                    m_EditorScriptable.ApplyPosition(index, m_DungeonBehaviours[i].transform.localPosition);
                    index++;
                }
            }
        }
#endif
    }
 
}