少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 a7c531aa353dae5b40b3c47f37211666ed0250a6
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, September 11, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
//红包信息
namespace Snxxz.UI
{
 
    public class RedBagTipsWin : Window
    {
        [SerializeField]
        ScrollerController m_ScrollerController;
        [SerializeField]
        ScrollerController m_ScrollerController1;
        List<int> RedBagSorting = new List<int>();//红包排序
        public static RedBagTipsWin _RedBagTipsWin;
        [SerializeField] Button _V6Btn;//V6封红包按钮
        [SerializeField] Button _CloseBtn;//关闭按钮
        private int _PlayerID;//获取玩家的ID 
        public bool _RedBool = false;//用来控制判断是否V6红包
        RedPacketModel m_RedPacket;
        RedPacketModel redPacket { get { return m_RedPacket ?? (m_RedPacket = ModelCenter.Instance.GetModel<RedPacketModel>()); } }
        #region Built-in
        protected override void BindController()
        {
            _RedBagTipsWin = this;
        }
 
        protected override void AddListeners()
        {
            _V6Btn.onClick.AddListener(V6Button);
            _CloseBtn.onClick.AddListener(CloseButton);
        }
 
        protected override void OnPreOpen()
        {
            RedPacketModel.Event_RedEnvelopeToAdd += RedEnvelopeToAdd;//红包的添加
            RedPacketModel.Event_RedEnvelopeToRefresh += RedEnvelopeToRefresh;//红包的刷新
            //PlayerRedPacketDatas.Event_DetailsRedEnvelopeRefresh += DetailsRedEnvelopeRefresh;//红包详情刷新
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            m_ScrollerController1.OnRefreshCell += BulletinBoard;
            _PlayerID = (int)PlayerDatas.Instance.baseData.PlayerID;//获取玩家的ID
            _RedBool = false;
            OnCreateGridLineCellEntry(m_ScrollerController1);
            OnCreateGridLineCell(m_ScrollerController);
        }
        protected override void OnAfterOpen()
        {
            m_ScrollerController1.lockType = EnhanceLockType.LockVerticalBottom;
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
            m_ScrollerController1.OnRefreshCell -= BulletinBoard;
            m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
            //PlayerRedPacketDatas.Event_DetailsRedEnvelopeRefresh -= DetailsRedEnvelopeRefresh;//红包详情刷新
            RedPacketModel.Event_RedEnvelopeToAdd -= RedEnvelopeToAdd;//红包的添加
            RedPacketModel.Event_RedEnvelopeToRefresh -= RedEnvelopeToRefresh;//红包的刷新
        }
 
        private void BulletinBoard(ScrollerDataType type, CellView cell)//公告栏生成位置
        {
 
            int _key = cell.index;
            if (!redPacket._DicRedBag.ContainsKey(_key))
            {
                return;
            }
            Text _particulars = cell.GetComponent<Text>();
            if (redPacket._DicRedBag[_key].MoneyType == 1)
            {
                _particulars.text = string.Format(Language.Get("RedBag_V6"), TimeUtility.GetTime((uint)redPacket._DicRedBag[_key].Time).
                ToString("MM-dd HH:mm"), UIHelper.ServerStringTrim(redPacket._DicRedBag[_key].Name), redPacket._DicRedBag[_key].MoneyNum);
            }
            else
            {
 
                _particulars.text = string.Format(Language.Get("Z1055"), TimeUtility.GetTime((uint)redPacket._DicRedBag[_key].Time).
                    ToString("MM-dd HH:mm"), UIHelper.ServerStringTrim(redPacket._DicRedBag[_key].Name),
                    RedEnvelopeContent(redPacket._DicRedBag[_key].GetWay), redPacket._DicRedBag[_key].MoneyNum);
            }
 
        }
 
        private void OnCreateGridLineCellEntry(ScrollerController gridCtrl)//动态创建
        {
            gridCtrl.Refresh();
            foreach (int key in redPacket._DicRedBag.Keys)
            {
                if (redPacket.IsDisplayInFamily(redPacket._DicRedBag[key].GetWay))
                {
                    gridCtrl.AddCell(ScrollerDataType.Header, key);
                }       
            }
            gridCtrl.Restart();
        }
        private void OnCreateGridLineCell(ScrollerController gridCtrl)//动态创建
        {
            gridCtrl.Refresh();
            RedBagSorting = RedEnvelopeSorting();
            int line = Mathf.CeilToInt((float)RedBagSorting.Count / 3);
            for (int i = 0; i < line; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, i);
            }
            gridCtrl.Restart();
        }
 
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)//属性赋值
        {
            int gridlineIndex = cell.index;
            int childCode = 0;
            for (childCode = 0; childCode < cell.transform.childCount; childCode++)
            {
                int cellCount = (cell.transform.childCount) * gridlineIndex + (childCode + 1);
                RedBagScripts _redBagS = cell.transform.GetChild(childCode).GetComponent<RedBagScripts>();
                _redBagS.RedBag.gameObject.SetActive(false);
                if (cellCount - 1 < RedBagSorting.Count)
                {
                    int INdex = cellCount - 1;
                    _redBagS.RedBag.gameObject.SetActive(true);
                    _redBagS.RedPacket(redPacket._DicRedBag[(RedBagSorting[INdex])].State, RedBagSorting[INdex]);
                }
            }
        }
        #endregion
 
        void CloseButton()//关闭按钮
        {
            Close();
        }
        void V6Button()//V6 红包
        {
            int VipLV = PlayerDatas.Instance.baseData.VIPLv;
            if (VipLV >= 6)
            {
                _RedBool = true;
                WindowCenter.Instance.Open<GiveRedBagTipsWin>();//打开发放红包界面
            }
            else
            {
                ScrollTip.ShowTip(Language.Get("BossHome_VipNoMeet"));//当前金币不足
            }
 
        }
        List<RedPackConfig> redpack = new List<RedPackConfig>();
        string RedEnvelopeContent(int _getWay)//红包显示内容
        {
            string _str = null;
            if (_getWay == 0)
            {
                _str = Language.Get("AnswerThree_Z");
                return _str;
            }
            if (redpack.Count <= 0)
            {
                redpack = RedPackConfig.GetValues();
            }
           // var redpack = RedPackConfig.GetValues();
            foreach (var value in redpack)
            {
                if (value.RedEnvelopeType == _getWay)
                {
                    _str = value.content;
                    return _str;
                }
            }
            return _str;
        }
 
        void RedEnvelopeToAdd(FamilyRedPacket _familyRedPacket)//红包的添加
        {
            OnCreateGridLineCell(m_ScrollerController);
            OnCreateGridLineCellEntry(m_ScrollerController1);
        }
        void RedEnvelopeToRefresh(FamilyRedPacket _familyRedPacket)//红包的刷新
        {
            OnCreateGridLineCell(m_ScrollerController);
        }
        void DetailsRedEnvelopeRefresh()//红包详情的刷新
        {
            //WindowCenter.Instance.Open<RedDetailsTipsWin>();
        }
        List<int> RedEnvelopeSorting()//红包排序
        {
            List<int> _list = new List<int>();
 
            foreach (int key in redPacket._DicRedBag.Keys)
            {
                if (redPacket.IsDisplayInFamily(redPacket._DicRedBag[key].GetWay))
                {
                    _list.Add(key);
                }
               
            }
            _list.Sort(Compare);
            return _list;
        }
        int Compare(int x, int y)
        {
            FamilyRedPacket xPack = redPacket._DicRedBag[x];
            FamilyRedPacket yPack = redPacket._DicRedBag[y];
            bool isGetX = xPack.State == 1;
            bool isGetY = yPack.State == 1;
            if (isGetX.CompareTo(isGetY) != 0) return -isGetX.CompareTo(isGetY);
            if (xPack.State.CompareTo(yPack.State) != 0) return xPack.State.CompareTo(yPack.State);
            if (xPack.RedPacketID.CompareTo(yPack.RedPacketID) != 0) return -xPack.RedPacketID.CompareTo(yPack.RedPacketID);
            return 1;
        }
    }
 
 
 
}