少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 cdb0198fb8e85811ec1e06b15f36df9cbe0fdb9a
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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
using System.Text;
using Snxxz.UI;
using System.Collections;
 
public class RoleEquipStarTips : MonoBehaviour
{
    #region 成员变量
    [SerializeField]
    CanvasGroup tipAlpha;
    private GameObject _curStars;
    private Text _curStarsText;
    private Text _curAttrValueText;
    private Text _haveStarsText;
    private GameObject _nextStars;
    private Text _nextStarsText;
    private Text _nextAttrValueText;
    private Text _noOpenText;
    #endregion
 
    private int p_preIndex = -1;
    private int p_nextIndex = -1;
    private int _curStarsCount;
    private int[] attrTypes;
    private int[] attrValues;
    private PlayerPropertyConfig _playerProModel;
    private ItemConfig _tagChinModel;
    private Dictionary<int, ItemModel> _itemDict;
    private RoleEquipStarsConfig _tagEquipStarsModel;
    private List<RoleEquipStarsConfig> _tagEquipStarsModellist;
 
    PackModel _playerPack;
    PackModel playerPack
    {
        get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
    }
 
    private void Awake()
    {
        _curStars = transform.Find("CurrentStars").gameObject;
        _curStarsText = transform.Find("CurrentStars/TargetNowText").GetComponent<Text>();
        _curAttrValueText = transform.Find("CurrentStars/AttrValueText").GetComponent<Text>();
        _haveStarsText = transform.Find("CurrentStars/CountNowText").GetComponent<Text>();
 
        _nextStars = transform.Find("NextStars").gameObject;
        _nextStarsText = transform.Find("NextStars/TargetNextText").GetComponent<Text>();
        _nextAttrValueText = transform.Find("NextStars/AttrValueText").GetComponent<Text>();
        _noOpenText = transform.Find("CurrentStars/NoOpenText").GetComponent<Text>();
 
    }
 
    private void OnEnable()
    {
        SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
        if (singlePack != null)
        {
            _itemDict = singlePack.GetAllItems();
        }
        _tagEquipStarsModellist = RoleEquipStarsConfig.GetEquipStarslist();
        tipAlpha.alpha = 0;
        _nextStars.SetActive(false);
        _curStars.SetActive(false);
        RefreshUI();
 
        StartCoroutine(SetScrollSize());
    }
 
    private void RefreshUI()
    {
        _curStarsCount = 0;
        p_preIndex = -1;
        p_nextIndex = -1;
        RectTransform size = _haveStarsText.GetComponent<RectTransform>();
        if (_itemDict != null)
        {
            foreach (var model in _itemDict.Values)
            {
                _tagChinModel = ItemConfig.Get((int)model.itemId);
                if (_tagChinModel == null)
                    return;
                _curStarsCount += _tagChinModel.StarLevel;
            }
        }
 
        GetTwoAdjacentNumber(0, _tagEquipStarsModellist.Count - 1, _curStarsCount);
        StringBuilder attrStr = new StringBuilder();
        if (p_preIndex != -1)
        {
            _tagEquipStarsModel = _tagEquipStarsModellist[p_preIndex];
            _noOpenText.gameObject.SetActive(false);
            _curStarsText.gameObject.SetActive(true);
            _curAttrValueText.gameObject.SetActive(true);
            _curStarsText.text = Language.Get("KnapS123").Replace("{0}", _tagEquipStarsModel.countNeed.ToString());
            _haveStarsText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString());
            int i = 0;
            for (i = 0; i < _tagEquipStarsModel.attType.Length; i++)
            {
                _playerProModel = PlayerPropertyConfig.Get(_tagEquipStarsModel.attType[i]);
                if (_playerProModel != null)
                {
                    attrStr.Append(SetIsPercentShow(_playerProModel, _tagEquipStarsModel.attValue[i]) + "\n");
                }
 
            }
            _curAttrValueText.text = attrStr.ToString();
        }
        else
        {
            _noOpenText.gameObject.SetActive(true);
            _curStarsText.gameObject.SetActive(false);
            _curAttrValueText.gameObject.SetActive(false);
            _haveStarsText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString());
        }
 
        if (p_nextIndex != -1)
        {
            _nextStars.SetActive(true);
            attrStr.Length = 0;
            _tagEquipStarsModel = _tagEquipStarsModellist[p_nextIndex];
            _nextStarsText.text = Language.Get("KnapS123").Replace("{0}", _tagEquipStarsModel.countNeed.ToString());
            int i = 0;
            for (i = 0; i < _tagEquipStarsModel.attType.Length; i++)
            {
                _playerProModel = PlayerPropertyConfig.Get(_tagEquipStarsModel.attType[i]);
                if (_playerProModel != null)
                {
                    attrStr.Append(SetIsPercentShow(_playerProModel, _tagEquipStarsModel.attValue[i]) + "\n");
                }
 
            }
            _nextAttrValueText.text = attrStr.ToString();
        }
        else
        {
            _nextStars.SetActive(false);
        }
 
    }
 
    IEnumerator SetScrollSize()
    {
        yield return null;
        yield return null;
        _curStars.SetActive(true);
        StartCoroutine(ShowBottomPart());
    }
 
    IEnumerator ShowBottomPart()
    {
        yield return null;
        _nextStars.SetActive(true);
        StartCoroutine(SetPanelScale());
    }
 
    IEnumerator SetPanelScale()
    {
        yield return null;
        tipAlpha.alpha = 1;
    }
 
    //得到相邻的两个数
    private void GetTwoAdjacentNumber(int minIndex, int maxIndex, int currentLevel)
    {
        p_preIndex = -1;
        p_nextIndex = -1;
        int minCount = _tagEquipStarsModellist[minIndex].countNeed;
        int maxCount = _tagEquipStarsModellist[maxIndex].countNeed;
        int sum = minCount + maxCount;
        int adjacentIndex = 0;
        if (sum != 0)
        {
            adjacentIndex = (int)((float)currentLevel / (minCount + maxCount) * _tagEquipStarsModellist.Count);
        }
 
        if (adjacentIndex < _tagEquipStarsModellist.Count)
        {
            for (int i = adjacentIndex; i > -1; i--)
            {
                if (_tagEquipStarsModellist[i].countNeed <= currentLevel)
                {
                    p_preIndex = i;
                    break;
                }
                else
                {
                    p_nextIndex = i;
                }
            }
 
            if (p_nextIndex == -1)
            {
                for (int i = adjacentIndex; i < _tagEquipStarsModellist.Count; i++)
                {
                    if (_tagEquipStarsModellist[i].countNeed >= currentLevel)
                    {
                        if (adjacentIndex != _tagEquipStarsModellist.Count - 1)
                        {
                            p_nextIndex = i;
                        }
                        break;
                    }
                    else
                    {
                        p_preIndex = i;
                    }
                }
            }
 
            if (p_preIndex != -1 && p_nextIndex != -1)
            {
                if (p_preIndex == p_nextIndex)
                {
                    p_nextIndex += 1;
                }
            }
        }
        else
        {
            p_preIndex = _tagEquipStarsModellist.Count - 1;
            p_nextIndex = -1;
        }
 
 
    }
 
 
    //判断属性是否百分比显示
    public string SetIsPercentShow(PlayerPropertyConfig _playerProModel, int proValue)
    {
 
        string strPro = "";
        if (!_playerProModel.Name.Contains("%s"))
        {
            if (_playerProModel.ISPercentage == 0)
            {
                strPro = _playerProModel.Name + "+" + proValue;
            }
            else if (_playerProModel.ISPercentage == 1)
            {
                strPro = _playerProModel.Name + "+" + (float)Math.Round(proValue / 100f, 1) + "%";
            }
        }
        else
        {
            if (_playerProModel.ISPercentage == 0)
            {
                strPro = _playerProModel.Name.Replace("%s", proValue.ToString());
            }
            else if (_playerProModel.ISPercentage == 1)
            {
                strPro = _playerProModel.Name.Replace("%s", (float)Math.Round(proValue / 100f, 1) + "%");
            }
        }
 
        return strPro;
    }
 
}