少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-13 43828dce1bfb99809bc46d206fe7aadf79319efa
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class GuardTip : MonoBehaviour
    {
        #region TopUI
        [SerializeField]
        Button closeBtn;
        [SerializeField]
        GameObject putOnIcon;
        [SerializeField]
        Text titleText;
        [SerializeField]
        Text equipScoreDes;
        [SerializeField]
        Text equipScoreValue;
        [SerializeField]
        Text needLvDes;
        [SerializeField]
        Text needLvValue;
        [SerializeField]
        List<Text> needPointTextlist = new List<Text>();
        [SerializeField]
        List<Text> needPointNumlist = new List<Text>();
        [SerializeField]
        Text dateText;
        [SerializeField]
        ItemCell itemCell;
        #endregion
 
        #region MidUI
        [SerializeField]
        RectTransform attrContent;
        [SerializeField]
        ScrollRect scrollRect;
        [SerializeField]
        LayoutElement scrollLayout;
 
        [SerializeField]
        GameObject basicAttr;
        [SerializeField]
        Text basicTitleText;
        [SerializeField]
        Text basicAttrDes;
        #endregion
 
        #region BottomUI
        [SerializeField]
        GameObject bottomPart;
        [SerializeField]
        EquipSource equipSource;
        #endregion
 
        [SerializeField]
        RectTransform btnGroup;
 
        [SerializeField]
        GameObject operateBtn;
 
        [SerializeField]
        CanvasGroup tipAlpha;
 
        Dictionary<PropertyType, int> needPointDict = new Dictionary<PropertyType, int>();
 
        ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        ItemAttrData itemAttrData;
        Color32 conditionColor = new Color32(255, 244, 205, 255);
 
        public void InitModel(ItemAttrData attrData)
        {
            KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct += RefreshRemainTime;
            itemAttrData = attrData;
            InitUI();
            closeBtn.AddListener(OnClickCloseBtn);
        }
 
        private void OnEnable()
        {
            bottomPart.gameObject.SetActive(false);
            StartCoroutine(SetScrollSize());
        }
 
        IEnumerator SetScrollSize()
        {
            yield return null;
            yield return null;
            attrContent.anchoredPosition3D = new Vector3(attrContent.anchoredPosition3D.x, 0, 0);
            SetMidUIHeight(attrContent.rect.height);
            StartCoroutine(ShowBottomPart());
        }
 
        IEnumerator ShowBottomPart()
        {
            yield return null;
            bottomPart.gameObject.SetActive(true);
            SetBottomUI();
            StartCoroutine(SetPanelScale());
        }
 
        IEnumerator SetPanelScale()
        {
            yield return null;
            if (itemAttrData.isCompare)
            {
                if (itemAttrData.packType != PackType.Equip)
                {
                    itemTipsModel.SetCurTips(this.GetComponent<RectTransform>());
                }
                else
                {
                    itemTipsModel.SetCompareTips(this.GetComponent<RectTransform>());
                }
            }
            else
            {
                itemTipsModel.SetCurTips(this.GetComponent<RectTransform>());
            }
 
            tipAlpha.alpha = 1;
        }
 
        private void InitUI()
        {
            #region 设置TopUI
            titleText.text = itemTipsModel.GetItemTipsTitle(itemAttrData);
            titleText.color = UIHelper.GetUIColor(itemAttrData.itemConfig.ItemColor);
            ItemCellModel cellModel = new ItemCellModel(itemAttrData.itemId, itemAttrData.isPreview, (ulong)itemAttrData.count,
                itemAttrData.guid, itemAttrData.packType, itemAttrData.isCompare, itemAttrData.useDataDict);
            itemCell.Init(cellModel);
            if (itemAttrData.packType == PackType.Equip)
            {
                putOnIcon.SetActive(true);
            }
            else
            {
                putOnIcon.SetActive(false);
            }
 
            equipScoreDes.text = Language.Get("EquipWin_EquipPointText_1");
            equipScoreValue.text = itemAttrData.score.ToString();
            RefreshNeedPointUI();
            needLvDes.text = Language.Get("KnapS110");
 
            if (itemAttrData.itemConfig.UseLV > 1)
            {
                needLvDes.gameObject.SetActive(true);
                needLvValue.gameObject.SetActive(true);
            }
            else
            {
                needLvDes.gameObject.SetActive(false);
                needLvValue.gameObject.SetActive(false);
            }
 
            if (itemAttrData.isHavePutLimit)
            {
                needLvValue.text = itemAttrData.itemConfig.UseLV.ToString();
                if (PlayerDatas.Instance.baseData.LV >= itemAttrData.itemConfig.UseLV)
                {
                    needLvDes.color = conditionColor;
                    needLvValue.color = conditionColor;
                }
                else
                {
                    needLvDes.color = UIHelper.GetUIColor(TextColType.Red);
                    needLvValue.color = UIHelper.GetUIColor(TextColType.Red);
                }
            }
            else
            {
                needLvValue.text = 1.ToString();
                needLvDes.color = conditionColor;
                needLvValue.color = conditionColor;
            }
 
            RefreshRemainTime(itemAttrData.guid);
            #endregion
 
            #region 设置MidUI
            SetBasicAttrUI();
            #endregion
 
            #region 设置功能按钮
            operateBtn.SetActive(false);
            if (itemAttrData.isCompare)
            {
                if (itemAttrData.packType != PackType.Equip)
                {
                    CreateFuncBtn();
                }
            }
            else
            {
                CreateFuncBtn();
            }
            #endregion
        }
 
        private void OnDisable()
        {
            KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct -= RefreshRemainTime;
        }
 
        private void RefreshRemainTime(string guid)
        {
            if (guid != itemAttrData.guid)
            {
                return;
            }
 
            var isOverdue = ItemLogicUtility.Instance.IsOverdue(guid);
            dateText.gameObject.SetActive(!isOverdue);
            if (!isOverdue)
            {
                var item = packModel.GetItemByGuid(guid);
                SetDateLimitUI(item != null ? item.overdueSurplusTime : 0);
            }
        }
 
        private void SetDateLimitUI(double time)
        {
            dateText.gameObject.SetActive(true);
            TimeSpan t = TimeSpan.FromSeconds(time);
            if (t.TotalDays > 1)
            {
                dateText.text = Language.Get("EquipInfo_OverdueDay", (int)t.TotalDays);
            }
            else if (t.TotalHours > 1)
            {
                dateText.text = Language.Get("EquipInfo_OverdueHour", (int)t.TotalHours);
            }
            else if (t.TotalMinutes > 1)
            {
                dateText.text = Language.Get("EquipInfo_OverdueMin", (int)t.TotalMinutes);
            }
            else if (t.TotalMinutes > 0)
            {
                dateText.text = Language.Get("EquipInfo_OverdueMin", 1);
            }
            else if (t.TotalSeconds <= 0)
            {
                dateText.text = Language.Get("EquipInfo_Overdued");
            }
        }
 
        private void RefreshNeedPointUI()
        {
            needPointDict.Clear();
            if (itemAttrData.itemConfig.LimitSTR > 0)
            {
                needPointDict.Add(PropertyType.POWER, itemAttrData.itemConfig.LimitSTR);
            }
 
            if (itemAttrData.itemConfig.LimitPHY > 0)
            {
                needPointDict.Add(PropertyType.AGILITY, itemAttrData.itemConfig.LimitPHY);
            }
 
            if (itemAttrData.itemConfig.LimitPNE > 0)
            {
                needPointDict.Add(PropertyType.MENTALITY, itemAttrData.itemConfig.LimitPNE);
            }
 
            List<PropertyType> needlist = needPointDict.Keys.ToList();
 
            int i = 0;
            float offset = 0;
            for (i = 0; i < needPointTextlist.Count; i++)
            {
                if (i < needlist.Count)
                {
                    needPointTextlist[i].gameObject.SetActive(true);
                    needPointNumlist[i].gameObject.SetActive(true);
                    offset = needPointDict[needlist[i]] - UIHelper.GetPropertyValue(needlist[i]);
                    switch (needlist[i])
                    {
                        case PropertyType.POWER:
                            if (itemAttrData.isHavePutLimit)
                            {
                                SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113"));
                            }
                            else
                            {
                                SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113"));
                            }
                            break;
                        case PropertyType.AGILITY:
                            if (itemAttrData.isHavePutLimit)
                            {
                                SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112"));
                            }
                            else
                            {
                                SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112"));
                            }
 
                            break;
                        case PropertyType.MENTALITY:
                            if (itemAttrData.isHavePutLimit)
                            {
                                SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111"));
                            }
                            else
                            {
                                SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111"));
                            }
                            break;
                    }
 
                }
                else
                {
                    needPointTextlist[i].gameObject.SetActive(false);
                    needPointNumlist[i].gameObject.SetActive(false);
                }
            }
 
        }
 
        private void SetNeedPointUI(float needPoint, float offset, Text needPoinText, Text needPoinNum, string msg)
        {
            if (offset > 0)
            {
                needPoinNum.text = UIHelper.AppendColor(TextColType.Red, StringUtility.Contact(needPoint, Language.Get("KnapS118", offset)));
                needPoinText.text = UIHelper.AppendColor(TextColType.Red, msg);
            }
            else
            {
                needPoinNum.color = conditionColor;
                needPoinText.color = conditionColor;
                needPoinNum.text = needPoint.ToString();
                needPoinText.text = msg;
            }
        }
 
        #region 设置属性UI
        private void SetBasicAttrUI()
        {
            basicAttr.SetActive(true);
            basicTitleText.text = Language.Get("RolePanel_BaseAttrText_1");
            basicAttrDes.text = itemTipsModel.GetBasicAttr(itemAttrData);
        }
 
        private void SetMidUIHeight(float midHeight)
        {
            scrollRect.enabled = false;
 
            if (midHeight < itemTipsModel.equipMidHeights[0])
            {
                scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[0];
            }
            else if (midHeight > itemTipsModel.equipMidHeights[1])
            {
                scrollRect.enabled = true;
                scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[1];
            }
            else
            {
                scrollLayout.preferredHeight = midHeight;
            }
        }
        #endregion
 
        private void SetBottomUI()
        {
            SetBottomText(equipSource);
        }
 
        private void SetBottomText(EquipSource source)
        {
            source.jobTitleText.text = Language.Get("EquipWin_JobTitleText_1");
            source.jobText.text = itemTipsModel.GetEquipJobName(itemAttrData);
            source.partTitleText.text = Language.Get("EquipWin_PartTitleText_1");
            source.partText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][0];
            source.itemDesText.text = itemAttrData.itemConfig.Description;
            source.sourceText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][1];
        }
 
        private void CreateFuncBtn()
        {
            btnGroup.anchoredPosition3D = Vector3.zero;
            if (itemAttrData.tipsFuncBtnDic.Count > 0)
            {
                foreach (ItemOperateType key in itemAttrData.tipsFuncBtnDic.Keys)
                {
                    Button btn = OnGUIButton(btnGroup.gameObject, operateBtn, key.ToString(), Language.Get(StringUtility.Contact("ItemHandle_", key.ToString())));
                    btn.RemoveAllListeners();
                    btn.onClick.AddListener(() =>
                    {
                        OnClickCloseBtn();
                        itemAttrData.tipsFuncBtnDic[key](key, "");
 
                    });
                }
            }
        }
 
        private Button OnGUIButton(GameObject parent, GameObject sourceBtn, string btnName, string textName)
        {
            GameObject go = Instantiate(sourceBtn);
            go.name = btnName;
            go.transform.SetParent(parent.transform);
            go.transform.Find("BtnText").GetComponent<Text>().text = textName;
            go.transform.localPosition = Vector3.zero;
            go.transform.localScale = Vector3.one;
            Button btn = go.GetComponent<Button>();
            go.SetActive(true);
            KnapSackEventMgr.Instance.SetGuardWinTempObj(go);
            return btn;
        }
 
        private void OnClickCloseBtn()
        {
            closeBtn.onClick.RemoveAllListeners();
            KnapSackEventMgr.Instance.HideItemPopWin();
        }
 
    }
}