少年修仙传客户端代码仓库
client_Zxw
2018-08-30 61b5058b990da2fe7f4b76e1e61b817d4f511432
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
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class FairyGrabBossBehaviour : ScrollItem
    {
        [SerializeField] AutoSelectCyclicScroll m_Scroll;
        [SerializeField] SmoothMask m_SmoothMask;
        [SerializeField] RectTransform m_CenterSign;
        [SerializeField] RectTransform m_ContainerSelect;
        [SerializeField] RectTransform m_ContainerKilling;
        [SerializeField] RectTransform m_ContainerKilled;
        [SerializeField] Image m_BossPortrait;
        [SerializeField] Text m_MapName;
        [SerializeField] Text m_BossName;
        [SerializeField] Text m_Progress;
        [SerializeField] Button m_Select;
        public int bossId { get; private set; }
 
        FairyGrabBossModel model { get { return ModelCenter.Instance.GetModel<FairyGrabBossModel>(); } }
 
        private void Awake()
        {
            m_Select.AddListener(SelectBoss);
        }
 
        private void SelectBoss()
        {
            m_Scroll.TrySelectData(bossId);
        }
 
        public override void Display(object _data)
        {
            base.Display(_data);
            bossId = (int)_data;
 
            DrawBossBaseInfo();
            DisplayProgress();
            OnSelected(model.selectBoss);
 
            model.bossSelectedEvent -= OnSelected;
            model.bossSelectedEvent += OnSelected;
            model.bossProgressUpdate -= BossProgressUpdate;
            model.bossProgressUpdate += BossProgressUpdate;
            model.stateUpdate -= StateUpdate;
            model.stateUpdate += StateUpdate;
        }
 
        public override void Dispose()
        {
            base.Dispose();
            model.bossSelectedEvent -= OnSelected;
            model.bossProgressUpdate -= BossProgressUpdate;
            model.stateUpdate -= StateUpdate;
        }
 
        private void OnSelected(int _bossId)
        {
            m_ContainerSelect.gameObject.SetActive(model.selectBoss == bossId);
        }
 
        void DrawBossBaseInfo()
        {
            var config = Config.Instance.Get<FairyGrabBossConfig>(bossId);
            var bossInfoConfig = Config.Instance.Get<BossInfoConfig>(bossId);
            var mapConfig = Config.Instance.Get<MapConfig>(bossInfoConfig.MapID);
            var npcConfig = Config.Instance.Get<NPCConfig>(bossId);
            m_BossPortrait.SetSprite(config.PortraitID);
            m_MapName.text = mapConfig.Name;
            m_BossName.text = npcConfig.charName;
        }
 
        private void BossProgressUpdate(int _bossId)
        {
            if (_bossId == bossId)
            {
                DisplayProgress();
            }
        }
 
        private void StateUpdate()
        {
            DisplayProgress();
        }
 
        void DisplayProgress()
        {
            FairyGrabBossModel.BossProgressInfo bossProgress;
            bool killed = false;
            bool opened = model.InActivityTime;
            if (model.TryGetBossProgress(bossId, out bossProgress))
            {
                var progress = 1 - (float)bossProgress.currentHp / bossProgress.totalHp;
                m_Progress.text = StringUtility.Contact((int)(progress * 100), "%");
                killed = progress >= 1;
            }
            else
            {
                m_Progress.text = StringUtility.Contact(0, "%");
            }
            m_ContainerKilled.gameObject.SetActive(killed && opened);
            m_ContainerKilling.gameObject.SetActive(!killed && opened);
            m_BossPortrait.material = opened ? m_SmoothMask.imageMaterials[0] : m_SmoothMask.imageMaterials[1];
        }
 
 
 
        protected virtual void LateUpdate()
        {
            if (m_Scroll.autoSelectable && model.selectBoss != bossId && bossId > 0)
            {
                if (Mathf.Abs(m_CenterSign.position.y - rectTransform.position.y) * 100f < rectTransform.rect.height * 0.45f)
                {
                    model.selectBoss = bossId;
                }
            }
        }
    }
}