少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, August 16, 2018
//--------------------------------------------------------
 
using EnhancedUI.EnhancedScroller;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//神兽强化
namespace Snxxz.UI
{
    public class GodBeastClass
    {
        public int GodBeastNumber;//神兽编号
        public int GodBeastPart;//神兽部位
        public int GodBeastLv;//神兽等级
        public int GodBeasProficiency;//熟练度
        public int GodBeastQuality;//神兽品质
        public int GodBeastStar;//神兽星级
        public int LocationMarker;//位置标记
        public int EquipScore;//装备评分
        public int ItemPlace;//背包装备位置
        public int GodBeastId;//神兽ID
    }
    public class GodBeastReinforcementWin : Window
    {
        [SerializeField] ScrollerController m_ScrollerController;
        [SerializeField] GodBeastSlidingList m_GodBeastSlidingList;
        [SerializeField] GameObject m_Listprompt_Text;
        [SerializeField] GodBeastAttributes m_GodBeastAttributes;
        [SerializeField] UIEffect m_UIEffect;
        DogzModel Dogz_model;
        DogzModel dogz_model { get { return Dogz_model ?? (Dogz_model = ModelCenter.Instance.GetModel<DogzModel>()); } }
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
        GodBeastModel GodBeastModel;
        GodBeastModel godBeastModel { get { return GodBeastModel ?? (GodBeastModel = ModelCenter.Instance.GetModel<GodBeastModel>()); } }
        public static event Action<int> ChooseToModify;
        private List<GodBeastClass> GodBeastList = new List<GodBeastClass>();
        private int CurrentlySelected = 0;
        private int JumpIndex = 0;
        public int Offset = 0;//偏移量
        #region Built-in
        protected override void BindController()
        {
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
        }
 
        protected override void AddListeners()
        {
           
        }
 
        protected override void OnPreOpen()
        {
            CurrentlySelected = 0;
            GetGodBeast();//获取神兽强化装备信息
           
            if (godBeastModel.ItemPlace != -1)//装备强化跳转选中
            {
                for (int i = 0; i < GodBeastList.Count; i++)
                {
                    if (GodBeastList[i].ItemPlace == godBeastModel.ItemPlace)
                    {
                        CurrentlySelected = GodBeastList[i].LocationMarker;
                        GetDogZBagIndex();
                        int Index = 0;
                        Index = GodBeastList.FindIndex((x) =>
                        {
                            return x.ItemPlace == godBeastModel.ItemPlace;
                        });
                        JumpIndex = Index;
                    }
                }
            }
            else
            {
 
                if (godBeastModel.redPointStre1.state == RedPointState.Simple)//强化红点选中
                {
                    for (int i = 0; i < GodBeastList.Count; i++)
                    {
                        if (GodBeastList[i].ItemPlace == godBeastModel.IndexId)
                        {
                            JumpIndex = i;
                            CurrentlySelected = GodBeastList[i].LocationMarker;
                            GetDogZBagIndex();
                        }
                    }
                }
                else
                {
                    if (GodBeastList.Count > 0)//默认选中个
                    {
                        CurrentlySelected = GodBeastList[0].LocationMarker;
                        GetDogZBagIndex();
                        JumpIndex = 0;
                    }
                }
            }
            OnCreateGridLineCell(m_ScrollerController);
            m_GodBeastSlidingList.Init();
            m_GodBeastAttributes.Init();
            m_GodBeastAttributes.GetGodBeastLocationMarker(CurrentlySelected);
           
 
 
 
        }
 
        protected override void OnActived()
        {
            var offset = 0f;
            m_ScrollerController.JumpIndex(JumpIndex,ref offset);
            m_ScrollerController.JumpIndex(Offset + offset, 0, EnhancedScroller.TweenType.immediate);
        }
        protected override void OnAfterOpen()
        {
            playerPack.refreshItemCountEvent += RefreshItemCountAct;
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += MakeItemAnswerEvent;
        }
 
        protected override void OnPreClose()
        {
            JumpIndex = 0;
            godBeastModel.ItemPlace = -1;
            playerPack.refreshItemCountEvent -= RefreshItemCountAct;
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= MakeItemAnswerEvent;
        }
 
        private void MakeItemAnswerEvent(H0721_tagMakeItemAnswer obj)
        {
            if ((int)obj.MakeType == (int)MakeType.DogzEquipPlus)
            {
                m_UIEffect.Play();
            }
        }
 
        private void RefreshItemCountAct(PackType arg1, int arg2, int arg3)
        {
            if (arg1 == PackType.DogzEquip)
            {
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
                m_GodBeastSlidingList.Init();
                m_GodBeastAttributes.Init();
                m_GodBeastAttributes.GetGodBeastLocationMarker(CurrentlySelected);
            }
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void GetGodBeast()//存储神兽强化列表数据和排序
        {
            GodBeastList.Clear();
            var DogzEquipDict = dogz_model.dogzAssistStateDict;
            foreach (var key in DogzEquipDict.Keys)
            {
                if (DogzEquipDict[key] == 1)
                {
 
                    List<ItemModel> itemModel = dogz_model.GetDogzEquips(key);
                    for (int i = 0; i < itemModel.Count; i++)
                    {
                        GodBeastClass godBeastClass = new GodBeastClass();
                        godBeastClass.GodBeastNumber = key;
                        godBeastClass.GodBeastPart = itemModel[i].config.EquipPlace;
                        godBeastClass.GodBeastQuality = itemModel[i].config.ItemColor;
                        godBeastClass.GodBeastStar = itemModel[i].config.StarLevel;
                        godBeastClass.EquipScore = itemModel[i].score;
                        godBeastClass.ItemPlace = itemModel[i].gridIndex;
                        godBeastClass.GodBeastId = key;
                        var IudetDogzEquipPlus = itemModel[i].GetUseData((int)ItemUseDataKey.dogzEquipPlus);// 神兽装备强化信息列表 [强化等级, 强化熟练度]
                        if (IudetDogzEquipPlus == null)
                        {
                            godBeastClass.GodBeastLv = 0;
                            godBeastClass.GodBeasProficiency = 0;
                        }
                        else
                        {
                            godBeastClass.GodBeastLv = IudetDogzEquipPlus[0];
                            godBeastClass.GodBeasProficiency = IudetDogzEquipPlus[1];
                        }
                        godBeastClass.LocationMarker = itemModel[i].config.EquipPlace * 100 + key;
                        GodBeastList.Add(godBeastClass);
                    }
                }
            }
            GodBeastList.Sort(Compare);
        }
        int Compare(GodBeastClass x, GodBeastClass y)
        {
            if (x.GodBeastQuality.CompareTo(y.GodBeastQuality) != 0)//品质
            {
                return -x.GodBeastQuality.CompareTo(y.GodBeastQuality);
            }
            if (x.GodBeastStar.CompareTo(y.GodBeastStar) != 0)//星级
            {
                return -x.GodBeastStar.CompareTo(y.GodBeastStar);
            }
            if (x.GodBeastPart.CompareTo(y.GodBeastPart) != 0)//装备位
            {
                return x.GodBeastPart.CompareTo(y.GodBeastPart);
            }
            if (x.GodBeastLv.CompareTo(y.GodBeastLv) != 0)//强化等级
            {
                return -x.GodBeastLv.CompareTo(y.GodBeastLv);
            }
            if (x.GodBeasProficiency.CompareTo(y.GodBeasProficiency) != 0)//熟练度
            {
                return -x.GodBeasProficiency.CompareTo(y.GodBeasProficiency);
            }
            if (x.EquipScore.CompareTo(y.EquipScore) != 0)//装备评分
            {
                return -x.EquipScore.CompareTo(y.EquipScore);
            }
            return 1;
        }
        void OnCreateGridLineCell(ScrollerController gridCtrl)
        {
            gridCtrl.Refresh();
            if (GodBeastList.Count > 0)
            {
                m_Listprompt_Text.SetActive(false);
            }
            else
            {
                m_Listprompt_Text.SetActive(true);
            }
            for (int i = 0; i < GodBeastList.Count; i++)
            {
                int locationMarker = GodBeastList[i].LocationMarker;
                gridCtrl.AddCell(ScrollerDataType.Header, locationMarker);
            }
            gridCtrl.Restart();
 
        }
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            GodBeastEntry godBeastEntry = cell.GetComponent<GodBeastEntry>();
            int locationMarker = cell.index;
            godBeastEntry.GetGodBeastLocationMarker(locationMarker, CurrentlySelected);
            godBeastEntry.GodBeastButton.RemoveAllListeners();
            godBeastEntry.GodBeastButton.AddListener(() =>
            {
                if (locationMarker != CurrentlySelected)
                {
                    CurrentlySelected = locationMarker;
                    GetDogZBagIndex();
                    m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
                    if (ChooseToModify != null)
                    {
                        ChooseToModify(CurrentlySelected);
                    }
                }
            });
        }
 
        private void GetDogZBagIndex()//获取选择的神兽装备的装备下标
        {
            for (int i = 0; i < GodBeastList.Count; i++)
            {
                if (CurrentlySelected == GodBeastList[i].LocationMarker)
                {
                    godBeastModel.DogZBagIndex = GodBeastList[i].ItemPlace;
                   // DebugEx.LogError(godBeastModel.DogZBagIndex);
                    return;
                }
            }
 
        }
    }
 
}