少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, June 19, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
namespace Snxxz.UI {
 
    public class TitleTotalGetWin : Window
    {
        [SerializeField] Text m_TitleTotal;
        [SerializeField] List<PropertyBehaviour> m_Propertys;
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] RectTransform m_ContainerSkill;
        [SerializeField] Text m_SkillTitle;
        [SerializeField] Text m_SkillText;
 
        [SerializeField] float skillContentMinSize = 0;
        [SerializeField] float skillContentMaxSize = 0;
 
        TitleModel m_TitleModel;
        TitleModel model
        {
            get
            {
                return m_TitleModel ?? (m_TitleModel = ModelCenter.Instance.GetModel<TitleModel>());
            }
        }
 
        private Dictionary<int, int> propertys = new Dictionary<int, int>();
        private List<int> skills = new List<int>();
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_Controller.OnGetDynamicSize += OnGetDynamicSize;
        }
 
        protected override void OnPreOpen()
        {
            if (m_SkillText.font == null)
            {
                m_SkillText.font = FontUtility.preferred;
            }
            var _dict = model.GetAllGainTitle();
            m_TitleTotal.text = Language.Get("L1086", _dict.Count);
            DisplayProperty();
            DisplaySkills();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void DisplayProperty()
        {
            propertys.Clear();
            var _dict = model.GetAllGainTitle();
            foreach (int id in _dict.Keys)
            {
                var config = DienstgradConfig.Get(id);
                if (config == null)
                {
                    continue;
                }
                int[] _propertys = config.LightType;
                int[] _values = config.LightAttribute;
                if (_propertys != null && _values != null && _propertys.Length == _values.Length)
                {
                    for (int i = 0; i < _propertys.Length; i++)
                    {
                        if (!propertys.ContainsKey(_propertys[i]))
                        {
                            propertys.Add(_propertys[i], _values[i]);
                        }
                        else
                        {
                            propertys[_propertys[i]] += _values[i];
                        }
                    }
                }
            }
            int index = 0;
            foreach (int key in propertys.Keys)
            {
                m_Propertys[index].gameObject.SetActive(true);
                m_Propertys[index].Display(key, propertys[key]);
                index++;
            }
            for (int i = index; i < m_Propertys.Count; i++)
            {
                m_Propertys[i].gameObject.SetActive(false);
            }
        }
 
        private void DisplaySkills()
        {
            skills.Clear();
            m_Controller.Refresh();
            var _dict = model.GetAllGainTitle();
            foreach (int id in _dict.Keys)
            {
                var config = DienstgradConfig.Get(id);
                if (config == null)
                {
                    continue;
                }
                if (config.Skills != null && config.Skills.Length > 0)
                {
                    skills.AddRange(config.Skills);
                }
            }
            float _height = 0;
            for (int i = 0; i < skills.Count; i++)
            {
                m_Controller.AddCell(ScrollerDataType.Header, skills[i]);
                var config = SkillConfig.Get(skills[i]);
                var info = StringUtility.Contact(config.SkillName, ":", config.Description);
                _height += m_SkillText.cachedTextGeneratorForLayout.GetPreferredHeight(info, m_SkillText.GetGenerationSettings(new Vector2(m_SkillText.rectTransform.rect.size.x, 0.0f))) / m_SkillText.pixelsPerUnit;
            }
            m_Controller.Restart();
            _height += skills.Count > 0 ? 60 : 0;
            m_SkillTitle.gameObject.SetActive(skills.Count > 0);
            m_ContainerSkill.gameObject.SetActive(skills.Count > 0);
            _height = Mathf.Max(skillContentMinSize, _height);
            _height = Mathf.Min(skillContentMaxSize, _height);
            var _sizeDelta = m_ContainerSkill.sizeDelta;
            m_ContainerSkill.sizeDelta = _sizeDelta.SetY(_height);
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            (cell as TitleSkillCell).Display(cell.index);
        }
 
        private bool OnGetDynamicSize(ScrollerDataType type, int index, out float height)
        {
            height = 28;
            var config = SkillConfig.Get(index);
            if (config != null)
            {
                var info = StringUtility.Contact(config.SkillName, ":", config.Description);
                height = m_SkillText.cachedTextGeneratorForLayout.GetPreferredHeight(info, m_SkillText.GetGenerationSettings(new Vector2(m_SkillText.rectTransform.rect.size.x, 0.0f))) / m_SkillText.pixelsPerUnit;
            }
            return true;
        }
 
    }
 
}