少年修仙传客户端代码仓库
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Collections.Generic;
using System.Text;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class PlayerStarNumWin : Window
    {
        [SerializeField] Text curSumStarText;
        [SerializeField] GameObject nowActObj;
        [SerializeField] GameObject nowNoActObj;
        [SerializeField] Text nowStarNumText;
        [SerializeField] Text nowAttrText;
        [SerializeField] GameObject nextActObj;
        [SerializeField] GameObject nextNoActObj;
        [SerializeField] Text nextEffectText;
        [SerializeField] Text nextStarNumText;
        [SerializeField] Text nextAttrText;
        [SerializeField] Button closeBtn;
        [SerializeField] Button activityBtn;
        [SerializeField] Text activeBtnText;
        [SerializeField] UIEffect successEffect;
        [SerializeField] Text addAttrText;
 
        private int _curStarsCount;
        private PlayerPropertyConfig _playerProModel;
        private Dictionary<int, ItemModel> _itemDict;
        private RoleEquipStarsConfig activeStarsConfig = null;
        private RoleEquipStarsConfig nextActiveStarsConfig = null;
        private int nextActiveCnt = 0;
 
        PackModel _playerPack;
        PackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
        }
 
        protected override void AddListeners()
        {
            closeBtn.AddListener(CloseClick);
        }
 
        protected override void BindController()
        {
            
        }
 
        protected override void OnPreOpen()
        {
            playerPack.RefreshActiveAttrAct += RefreshUI;
            SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
            if (singlePack != null)
            {
                _itemDict = singlePack.GetAllItems();
            }
            RefreshUI();
        }
 
        protected override void OnAfterOpen()
        {
            
        }
 
        protected override void OnPreClose()
        {
            playerPack.RefreshActiveAttrAct -= RefreshUI;
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void RefreshUI()
        {
            _curStarsCount = 0;
            if (_itemDict != null)
            {
                foreach (var model in _itemDict.Values)
                {
                    _curStarsCount += model.config.StarLevel;
                }
            }
 
            curSumStarText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString());
            int realActiveStars = GetActiveStarsAttr();
            int serverActiveCnt = playerPack.GetActiveCntByType(1);
            StringBuilder attrStr = new StringBuilder();
            if (activeStarsConfig != null)
            {
                attrStr.Length = 0;
                nowNoActObj.SetActive(false);
                nowActObj.SetActive(true);
                nowStarNumText.text = Language.Get("KnapS123").Replace("{0}",activeStarsConfig.countNeed.ToString());
                int i = 0;
                for (i = 0; i < activeStarsConfig.attType.Length; i++)
                {
                    _playerProModel = PlayerPropertyConfig.Get(activeStarsConfig.attType[i]);
                    if (_playerProModel != null)
                    {
                        attrStr.Append(SetIsPercentShow(_playerProModel, activeStarsConfig.attValue[i]) + "\n");
                    }
 
                }
                nowAttrText.text = attrStr.ToString();
            }
            else
            {
                nowNoActObj.SetActive(true);
                nowActObj.SetActive(false);
            }
 
            if(nextActiveStarsConfig != null)
            {
                nextActObj.SetActive(true);
                nextNoActObj.SetActive(false);
                attrStr.Length = 0;
                nextStarNumText.text = Language.Get("KnapS123").Replace("{0}", nextActiveStarsConfig.countNeed.ToString());
                int i = 0;
                for (i = 0; i < nextActiveStarsConfig.attType.Length; i++)
                {
                    _playerProModel = PlayerPropertyConfig.Get(nextActiveStarsConfig.attType[i]);
                    if (_playerProModel != null)
                    {
                        attrStr.Append(SetIsPercentShow(_playerProModel, nextActiveStarsConfig.attValue[i]) + "\n");
                    }
 
                }
                nextAttrText.text = attrStr.ToString();
                if(nextActiveStarsConfig.countNeed <= serverActiveCnt)
                {
                    RefreshActiveBtnUI(false);
                    nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS143"));
                }
                else
                {
                    nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS144"));
                    if (_curStarsCount >= nextActiveStarsConfig.countNeed)
                    {
                        nextActiveCnt = nextActiveStarsConfig.countNeed;
                        RefreshActiveBtnUI(true);
                    }
                    else
                    {
                        RefreshActiveBtnUI(false);
                    }
                }
            }
            else
            {
                nextActObj.SetActive(false);
                nextNoActObj.SetActive(true);
                RefreshActiveBtnUI(false);
            }
 
            int addAttrStarsNum = 0;
            List<int> addIdlist = playerPack.GetAddAttrIdByStars(_curStarsCount,out addAttrStarsNum);
            if(addIdlist.Count > 0)
            {
                addAttrText.gameObject.SetActive(true);
                string addAttr = "";
                for(int i = 0; i < addIdlist.Count; i++)
                {
                    PlayerPropertyConfig propertyConfig = PlayerPropertyConfig.Get(addIdlist[i]);
                    if(propertyConfig != null)
                    {
                        addAttr = StringUtility.Contact(addAttr, propertyConfig.Name);
                    }
                }
                addAttrText.text = Language.Get("KnapS148",addAttrStarsNum,addAttr);
            }
            else
            {
                addAttrText.gameObject.SetActive(false);
            }
        }
 
        private void RefreshActiveBtnUI(bool isActive)
        {
            activityBtn.RemoveAllListeners();
            if (isActive)
            {
                activeBtnText.text = Language.Get("MountPanel_UnlockBtn_1");
                activityBtn.AddListener(ClickActivityBtn);
            }
            else
            {
                activeBtnText.text = Language.Get("MountPanel_ConfirmTxt_1");
                activityBtn.AddListener(CloseClick);
            }
        }
 
        private void ClickActivityBtn()
        {
            playerPack.SendActiveAttrQuest(1,nextActiveCnt);
            successEffect.Play();
        }
 
        private int GetActiveStarsAttr()
        {
            activeStarsConfig = null;
            nextActiveStarsConfig = null;
            int serverActiveCnt = playerPack.GetActiveCntByType(1);
            List<int> starslist = RoleEquipStarsConfig.GetEquipStarsCntlist();
            if (starslist == null || starslist.Count < 1) return serverActiveCnt;
 
            int realActiveStars = _curStarsCount > serverActiveCnt ? serverActiveCnt : _curStarsCount;
            for (int i = starslist.Count - 1; i > -1 ; i--)
            {
                if (i == 0 && starslist[i] > realActiveStars)
                {
                    realActiveStars = 0;
                    break;
                }
                if (starslist[i] <= realActiveStars)
                {
                    realActiveStars = starslist[i];
                    break;
                }
            }
 
 
            if (realActiveStars < starslist[0])
            {
                activeStarsConfig = null;
                nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(starslist[0]);
            }
           else
            {
                int nextActiveStars = 0;
                for (int i = 0; i < starslist.Count; i++)
                {
                    if(starslist[i] > realActiveStars)
                    {
                        nextActiveStars = starslist[i];
                        break;
                    }
                }
 
                activeStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(realActiveStars);
                if (nextActiveStars != 0)
                {
                    nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(nextActiveStars);
                }
                else
                {
                    nextActiveStarsConfig = null;
                }
            }
 
            return realActiveStars;
        }
 
        //判断属性是否百分比显示
        public string SetIsPercentShow(PlayerPropertyConfig _playerProModel, int proValue)
        {
            string strPro = "";
            if (!_playerProModel.Name.Contains("%s"))
            {
                if (_playerProModel.ISPercentage == 0)
                {
                    strPro = _playerProModel.Name + "<color=#109D06FF>" + " +" + proValue + "</color>";
                }
                else if (_playerProModel.ISPercentage == 1)
                {
                    strPro = _playerProModel.Name + "<color=#109D06FF>" + " +" + (float)Math.Round(proValue / 100f, 1) + "%" + "</color>";
                }
            }
            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;
        }
    }
}