少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, October 26, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//关于Buff面板的设置
namespace vnxbqy.UI
{
 
    public class BuffInfoWin : Window
    {
        public float UpperAndLower = 50f;
        public float ItemHeight = 50f;
        public float MaxHeight = 300f;
        [SerializeField] Transform Viewport;
        [SerializeField] ScrollerController m_ScrollerController;
        private ScrollRect _ScrollRect;
        private Dictionary<int, ObjBuff> objBuffic;
        private List<int> _SortList = new List<int>();//排序列表
 
        BuffModel Buffmodel {  get {    return   ModelCenter.Instance.GetModel<BuffModel>();   } }
 
        #region Built-in
        protected override void BindController()
        {
            _ScrollRect = Viewport.GetComponent<ScrollRect>();
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            objBuffic = Buffmodel._BuffDic;
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            BuffModel.Even_ObjAddBuf += AddBuff;
            BuffModel.Even_ObjDelBuff += DelBuff;
            BuffScheduling();
            UpdateControllerPosition();
            OnCreateGridLineCell(m_ScrollerController);
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
            m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
            BuffModel.Even_ObjAddBuf -= AddBuff;
            BuffModel.Even_ObjDelBuff -= DelBuff;
        }
        #endregion
 
 
        void UpdateControllerPosition()
        {
 
            if (_SortList.Count == 0)
            {
                Close();
                return;
 
            }
            if (_SortList.Count * ItemHeight >= MaxHeight)
            {
                _ScrollRect.vertical = true;
                (Viewport as RectTransform).sizeDelta = (Viewport as RectTransform).sizeDelta.SetY(MaxHeight + UpperAndLower);
            }
            else
            {
                _ScrollRect.vertical = false;
                (Viewport as RectTransform).sizeDelta = (Viewport as RectTransform).sizeDelta.SetY(_SortList.Count * ItemHeight + UpperAndLower);
            }
        }
 
        void OnCreateGridLineCell(ScrollerController gridCtrl)//预制体创建
        {
            gridCtrl.Refresh();
 
            for (int i = 0; i < _SortList.Count; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, i);
            }
            gridCtrl.Restart();
        }
        void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int _index = cell.index;
            BuffBGMScripts _buffBGM = cell.GetComponent<BuffBGMScripts>();
 
            int _INList = _SortList[_index];
            _buffBGM.b_BuffIcon.SetSprite(objBuffic[_INList].ImagKey);
            _buffBGM.b_BuffName.text = objBuffic[_INList].BuffName;
            _buffBGM.b_BuffContent.text = objBuffic[_INList].BuffConent;
            int _UseTheSecond = Mathf.FloorToInt((float)(DateTime.Now - objBuffic[_INList]._dattTime).TotalSeconds);
            if (objBuffic[_INList].LastTime - _UseTheSecond > 0)
            {
                _buffBGM.b_BuffTime.SetActive(true);
                _buffBGM._currentime = 0;
                _buffBGM._time = objBuffic[_INList].LastTime - _UseTheSecond;
                _buffBGM._OnOff = true;
 
            }
            else
            {
                _buffBGM.b_BuffTime.SetActive(false);
                _buffBGM.b_BuffTime.text = "";
            }
            if (objBuffic[_INList].Layer > 0)
            {
                _buffBGM.BiBuffText.SetActive(true);
                _buffBGM.BiBuffText.text = objBuffic[_INList].Layer.ToString();
            }
            else
            {
                _buffBGM.BiBuffText.SetActive(false);
            }
 
        }
 
 
 
        void BuffScheduling()//buff排序
        {
            _SortList.Clear();
            foreach (int key in objBuffic.Keys)
            {
                _SortList.Add(key);
            }
            _SortList.Sort(Compare);
 
        }
 
        int Compare(int x, int y)
        {
            bool havex = IsExperience(x);
            bool havey = IsExperience(y);
            if (havex.CompareTo(havey) != 0)
            {
                return -havex.CompareTo(havey);
            }
            int havex1 = TimeClassification(x);
            int havey1 = TimeClassification(y);
            if (havex1.CompareTo(havey1) != 0)
            {
                return havex1.CompareTo(havey1);
            }
            ObjBuff xPack = objBuffic[x];
            ObjBuff yPack = objBuffic[y];
            if (xPack._dattTime.CompareTo(yPack._dattTime) != 0)
            {
                return -xPack._dattTime.CompareTo(yPack._dattTime);
            }
            return 1;
        }
 
        private bool IsExperience(int BuffID)//判断是否是经验类型Buff
        {
            bool IsBool = false;
            if (objBuffic.ContainsKey(BuffID))
            {
                if (objBuffic[BuffID].BuffType == 9)
                {
                    IsBool = true;
                }
            }
            return IsBool;
        }
 
        private int TimeClassification(int BuffID)//时间分类
        {
            int Type = 0;
            return Type;
        }
 
        List<int> Priority()
        {
            List<int> _List = new List<int>();
            string[] _strList = FuncConfigConfig.Get("BuffType").Numerical2.Split('|');
            for (int i = 0; i < _strList.Length; i++)
            {
                _List.Add(int.Parse(_strList[i]));
 
            }
            return _List;
        }
 
        void AddBuff()
        {
            objBuffic = Buffmodel._BuffDic;
            BuffScheduling();
            UpdateControllerPosition();
            OnCreateGridLineCell(m_ScrollerController);
        }
 
        void DelBuff()
        {
            objBuffic = Buffmodel._BuffDic;
            BuffScheduling();
            UpdateControllerPosition();
            OnCreateGridLineCell(m_ScrollerController);
        }
 
    }
 
}