少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, December 12, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    public class GatherSoulTotalPropertyWin : Window
    {
        [SerializeField] RectTransform m_Content;
        [SerializeField] PropertyBehaviour[] m_Propertys;
 
        List<PropertyBehaviour> m_ClonePropertys = new List<PropertyBehaviour>();
 
        GatheringSoulModel model
        {
            get { return ModelCenter.Instance.GetModel<GatheringSoulModel>(); }
        }
 
        Dictionary<int, int> displayPropertyDict = new Dictionary<int, int>();
        List<int> propertySorts = new List<int>();
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            model.gatherSoulHolesRefresh += GatherSoulHoleRefresh;
            DisplayProperty();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            model.gatherSoulHolesRefresh -= GatherSoulHoleRefresh;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        void DisplayProperty()
        {
            var count = model.holeCount;
            propertySorts.Clear();
            displayPropertyDict.Clear();
            for (int i = 0; i < count; i++)
            {
                GatherSoulItem item;
                if (model.TryGetItem(i, out item))
                {
                    var list = model.gatherSoulPropertys[item.id];
                    for (int k = 0; k < list.Count; k++)
                    {
                        displayPropertyDict.Add(list[k], model.GetPropertyValue(item.id, list[k], item.level));
                        propertySorts.Add(list[k]);
                    }
                }
            }
            propertySorts.Sort(Compare);
            CheckPropertyBehaviour();
 
            var index = 0;
            for (int i = 0; i < propertySorts.Count; i++)
            {
                if (index < m_Propertys.Length)
                {
                    m_Propertys[index].gameObject.SetActive(true);
                    m_Propertys[index].DisplayUpper(propertySorts[i], displayPropertyDict[propertySorts[i]]);
                }
                else if (index - m_Propertys.Length < m_ClonePropertys.Count)
                {
                    m_ClonePropertys[index - m_Propertys.Length].gameObject.SetActive(true);
                    m_ClonePropertys[index - m_Propertys.Length].DisplayUpper(propertySorts[i], displayPropertyDict[propertySorts[i]]);
                }
                index++;
            }
 
            for (int i = index; i < m_Propertys.Length; i++)
            {
                m_Propertys[i].gameObject.SetActive(false);
            }
            index = Mathf.Max(0, index - m_Propertys.Length);
            for (int i = index; i < m_ClonePropertys.Count; i++)
            {
                m_ClonePropertys[i].gameObject.SetActive(false);
            }
        }
 
        void CheckPropertyBehaviour()
        {
            if (m_Propertys.Length + m_ClonePropertys.Count >= propertySorts.Count)
            {
                return;
            }
            else
            {
                var count = propertySorts.Count - m_Propertys.Length - m_ClonePropertys.Count;
                for (int i = 0; i < count; i++)
                {
                    var behaviour = GameObject.Instantiate(m_Propertys[0]);
                    if (behaviour != null)
                    {
                        behaviour.transform.SetParent(m_Content);
                        behaviour.transform.localPosition = Vector3.zero;
                        behaviour.transform.localEulerAngles = Vector3.zero;
                        behaviour.transform.localScale = Vector3.one;
                        m_ClonePropertys.Add(behaviour);
                    }
                }
            }
        }
 
        int Compare(int lhs, int rhs)
        {
            var dict = model.propertySorts;
            if (dict.ContainsKey(lhs) && dict.ContainsKey(rhs))
            {
                return dict[lhs].CompareTo(dict[rhs]);
            }
            return 0;
        }
 
        private void GatherSoulHoleRefresh()
        {
            DisplayProperty();
        }
 
    }
 
}