少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, October 09, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
using DG.Tweening;
 
namespace Snxxz.UI
{
 
    public class TreasurePotentialBriefInfo : MonoBehaviour
    {
        [SerializeField] PositionTween m_DeadPotentailTween;
        [SerializeField] Text m_PotentialName;
        [SerializeField] Text m_Level;
        [SerializeField] Button m_Button;
        [SerializeField] UIEffect m_PotentialSfx;
        [SerializeField] Image m_Select;
        [SerializeField] Image m_Icon;
        //[SerializeField] ScaleTween m_SelectScale;
 
        public TreasurePotential potential { get; private set; }
 
        int maxLevel = 10;
 
        TreasurePotentialPanel m_TreasurePotential;
        public TreasurePotentialPanel treasurePotential {
            get {
                return m_TreasurePotential;
            }
            set {
                if (m_TreasurePotential != null)
                {
                    m_TreasurePotential.potentialSelectEvent -= OnPotentialSelected;
                }
                m_TreasurePotential = value;
                m_TreasurePotential.potentialSelectEvent += OnPotentialSelected;
            }
        }
 
        public PositionTween potentialTween { get { return m_DeadPotentailTween; } }
 
        TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
 
        public void DisplayBaseInfo(TreasurePotential _potential, int _state = 0)
        {
            potential = _potential;
            var config = SkillConfig.Get(potential.id);
            maxLevel = config.SkillMaxLV;
            m_Select.gameObject.SetActive(false);
 
            if (treasurePotential.selectedPotential == potential.id && _state != 2)
            {
                OnPotentialSelected(potential.id);
            }
 
            bool _unlock = potential != null && model.IsPotentialUnlock(model.selectedTreasure, potential.id);
            if (_state == 2 || model.GetPotentialUnlockShow(model.selectedTreasure))
            {
                _unlock = false;
            }
            m_Level.text = _unlock ? StringUtility.Contact(_potential.level, "/", maxLevel) : string.Empty;
            m_Level.transform.localScale = Vector3.one;
 
            DisplayName(_unlock, config);
 
            model.potentialLevelChangeEvent -= OnPotentialLevelUp;
            model.potentialLevelChangeEvent += OnPotentialLevelUp;
 
            DisplayStateSfx(!_unlock);
        }
 
        public void Dispose()
        {
            model.potentialLevelChangeEvent -= OnPotentialLevelUp;
        }
 
        private void SelectPotential()
        {
            if (potential == null/* || !model.IsPotentialUnlock(model.selectedTreasure, potential.id)*/)
            {
                return;
            }
            treasurePotential.selectedPotential = potential.id;
        }
 
        public void SelectTotal()
        {
            m_Select.gameObject.SetActive(false);
        }
 
        public void DisplayUnlock()
        {
            DisplayStateSfx();
            var config = SkillConfig.Get(potential.id);
            bool _unlock = potential != null && model.IsPotentialUnlock(model.selectedTreasure, potential.id);
            m_Level.text = _unlock ? StringUtility.Contact(potential.level, "/", maxLevel) : string.Empty;
            m_Level.transform.localScale = Vector3.one;
            DisplayName(_unlock, config);
        }
 
        void DisplayName(bool unlock, SkillConfig config)
        {
            m_PotentialName.text = config.SkillName;
            m_PotentialName.color = UIHelper.GetUIColor(TextColType.LightYellow);
            if (!unlock)
            {
                var requirement = string.Empty;
                if (config.LearnSkillReq > 0 && config.LearnSkillLV > 0)
                {
                    var preskillConfig = SkillConfig.Get(config.LearnSkillReq);
                    requirement = Language.Get("Hallows_NeedSkillLVStart", preskillConfig.SkillName, config.LearnSkillLV, config.SkillName);
                    m_PotentialName.text = requirement;
                    m_PotentialName.color = UIHelper.GetUIColor(TextColType.Red);
                }
            }
        }
 
        public void OnPotentialSelected(int _potentialId)
        {
            m_Select.gameObject.SetActive(_potentialId == potential.id);
        }
 
        private void OnPotentialLevelUp(int _treasureId, int _potential)
        {
            if (potential.id != _potential)
            {
                return;
            }
 
            m_Level.text = StringUtility.Contact(potential.level, "/", maxLevel);
            //DisplayStateSfx();
        }
 
        public void DisplayStateSfx(int _state)
        {
            m_PotentialSfx.StopImediatly();
            m_PotentialSfx.loop = true;
            m_DeadPotentailTween.enabled = false;
            m_DeadPotentailTween.SetStartState();
            m_Icon.material = MaterialUtility.GetUIDefaultGraphicMaterial();
            switch (_state)
            {
                case 0:
                    m_DeadPotentailTween.enabled = true;
                    m_Icon.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
                    break;
                case 1:
                    m_PotentialSfx.effect = 5128;
                    m_PotentialSfx.Play();
                    break;
                case 2:
                    m_PotentialSfx.effect = 5129;
                    m_PotentialSfx.Play();
                    break;
                case 3:
                    m_PotentialSfx.effect = 5130;
                    m_PotentialSfx.Play();
                    break;
                case 4:
                    m_PotentialSfx.effect = 5131;
                    m_PotentialSfx.Play();
                    break;
            }
        }
 
        public void DisplayStateSfx(bool _animation = false)
        {
            if (potential == null || !model.IsPotentialUnlock(model.selectedTreasure, potential.id) || _animation)
            {
                DisplayStateSfx(0);
            }
            else if (potential.level == 0)
            {
                DisplayStateSfx(1);
            }
            else if (potential.level < 15)
            {
                DisplayStateSfx(2);
            }
            else if (potential.level < maxLevel)
            {
                DisplayStateSfx(3);
            }
            else
            {
                DisplayStateSfx(4);
            }
        }
 
        public void StartLevelTween()
        {
            var tweener = m_Level.transform.DOScale(Vector3.one * 3, 0.2f);
            tweener.OnStepComplete(() =>
            {
                m_Level.transform.DOScale(Vector3.one, 0.2f);
            });
        }
 
        private void Awake()
        {
            if (m_Button != null)
            {
                m_Button.AddListener(SelectPotential);
            }
        }
    }
}