少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
 
using DG.Tweening;
 
namespace vnxbqy.UI
{
    public class TreasureProperty : MonoBehaviour
    {
        [SerializeField] Text m_FightPower;
        [SerializeField] Image m_Bottom;
        [SerializeField] RectTransform[] m_PropertyComs;
        [SerializeField] Property[] m_Properties;
        [SerializeField] RectTransform m_ContainerProperty;
        [SerializeField] RectTransform m_ContainerName;
        [SerializeField] Image m_TreasureName;
        [SerializeField] PositionTween m_TreasureNameTween;
 
        Treasure treasure;
        TreasureStage m_TreasureStage;
 
        TreasureModel m_Model;
        TreasureModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureModel>());
            }
        }
 
        public RectTransform containerName
        {
            get
            {
                return m_ContainerName;
            }
        }
 
        public RectTransform containerProperty
        {
            get
            {
                return m_ContainerProperty;
            }
        }
 
        public PositionTween treasureNameTween
        {
            get
            {
                return m_TreasureNameTween;
            }
        }
 
        Dictionary<int, int> m_PropertyDict = new Dictionary<int, int>();
 
        Dictionary<int, int> m_BeforeProperty = new Dictionary<int, int>();
 
        public void Display(int _treasure, bool _stageUp = false)
        {
            if (!model.TryGetTreasure(_treasure, out treasure))
            {
                return;
            }
            var config = TreasureConfig.Get(treasure.id);
            if (treasure.level < treasure.treasureStages.Count)
            {
                m_TreasureStage = treasure.treasureStages[treasure.level];
            }
            m_PropertyDict.Clear();
            if (config.Category == (int)TreasureCategory.Human)
            {
                for (int i = 0; i < treasure.treasureStages.Count; i++)
                {
                    TreasureStage _treasureStage = treasure.treasureStages[i];
                    if (treasure.level >= _treasureStage.stage
                        && _treasureStage.unlockType == TreasureStageUnlock.Property)
                    {
                        foreach (var _key in _treasureStage.propertyDict.Keys)
                        {
                            if (m_PropertyDict.ContainsKey(_key))
                            {
                                m_PropertyDict[_key] += _treasureStage.propertyDict[_key];
                            }
                            else
                            {
                                m_PropertyDict[_key] = _treasureStage.propertyDict[_key];
                            }
                        }
                    }
                }
            }
 
 
            int _index = 0;
            foreach (var _key in m_PropertyDict.Keys)
            {
                if (_index < m_PropertyComs.Length && _index < m_Properties.Length)
                {
                    m_PropertyComs[_index].SetActive(true);
                    m_Properties[_index].Display(_key, m_PropertyDict[_key]);
                    if (_stageUp && !m_BeforeProperty.ContainsKey(_key))
                    {
                        m_Properties[_index].StartAlphaTween(0, 1);
                    }
                    else if (_stageUp && m_BeforeProperty.ContainsKey(_key)
                        && m_BeforeProperty[_key] < m_PropertyDict[_key])
                    {
                        StartCoroutine(Co_NumberClock(m_Properties[_index], m_BeforeProperty[_key], m_PropertyDict[_key]));
                    }
                }
                _index++;
            }
            m_Bottom.SetActive(_index > 0);
            for (int i = _index; i < m_PropertyComs.Length; i++)
            {
                m_PropertyComs[i].SetActive(false);
            }
 
            m_BeforeProperty.Clear();
            foreach (var _key in m_PropertyDict.Keys)
            {
                m_BeforeProperty.Add(_key, m_PropertyDict[_key]);
            }
 
            if (treasure.state != TreasureState.Collected)
            {
                m_FightPower.text = treasure.treasureStages.Count > 0 ? treasure.treasureStages[0].GetFightPower().ToString() : string.Empty;
            }
            else
            {
                m_FightPower.text = model.GetTreasureFightPower(_treasure).ToString();
            }
            m_ContainerProperty.SetActive(config.Category == 1);
            m_TreasureName.SetSprite(config.TreasureNameIcon);
        }
 
        public void SetActive(bool _active)
        {
            if (!_active)
            {
                m_Bottom.SetActive(_active);
            }
            m_ContainerProperty.SetActive(_active);
            m_ContainerName.SetActive(_active);
        }
 
        IEnumerator Co_NumberClock(Property _property, int _before, int _target)
        {
            float _timer = 0f;
            int _value = _before;
            while (_timer < 0.5f)
            {
                _timer += Time.deltaTime;
                _property.propertyValue.text = StringUtility.Contact("+", _value);
                yield return null;
                _value = (int)((_target - _before) * _timer / 0.5f) + _before;
            }
            _property.propertyValue.text = StringUtility.Contact("+", _target);
        }
    }
 
    [Serializable]
    public class Property
    {
        [SerializeField] Text m_Property;
        [SerializeField] Text m_Value;
 
        public Text propertyValue
        {
            get
            {
                return m_Value;
            }
        }
 
        public void Display(int _property, float _value)
        {
            var _cfg = PlayerPropertyConfig.Get(_property);
            m_Property.text = _cfg.Name;
            m_Value.text = StringUtility.Contact("+", _value);
        }
 
        public void StartAlphaTween(float _from, float _to)
        {
            m_Property.color = m_Property.color.SetA(_from);
            m_Property.DOColor(m_Property.color.SetA(_to), 1.0f);
        }
    }
}