少年修仙传客户端代码仓库
hch
2023-06-14 f23c81d21c9cc4c9f06e8bed3ebb7ddbe7e15ac3
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, January 05, 2018
//--------------------------------------------------------
 
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
//坐骑面板
namespace Snxxz.UI
{
 
    public class MountSkinWin : Window, SecondWindowInterface
    {
        [SerializeField] ScrollerController m_ScrollerController;
        [SerializeField] Button m_DeblockingBtton;//解锁按钮
        [SerializeField] Button m_RideBtton;//骑乘
        [SerializeField] RawImage m_Mount3D;
        [SerializeField] Text m_FightPower;
        [SerializeField] Text m_MountName;//被选中的坐骑名
        [SerializeField] ItemCell MountItem;
        [SerializeField] Text MountItemName;
        [SerializeField] List<Text> AttrNameList;
        [SerializeField] List<Text> AttrValueList;
 
        List<Int3> sortMountlist = new List<Int3>();//坐骑顺序排列
        public int signHorseID = 0;//用来标记坐骑ID
 
        public Button close { get; set; }
        #region Built-in
 
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
        MountModel m_MountModel;
        MountModel mountModel { get { return m_MountModel ?? (m_MountModel = ModelCenter.Instance.GetModel<MountModel>()); } }
 
        RidingAndPetActivationModel ridingAndPetActivationModel { get { return ModelCenter.Instance.GetModel<RidingAndPetActivationModel>(); } }
 
 
        protected override void BindController()
        {
            if (this is SecondWindowInterface)
            {
                var frame = this.GetComponentInChildren<SecondFrameLoader>();
                frame.Create();
                close = frame.GetComponentInChildren<Button>();
            }
 
        }
 
        protected override void AddListeners()
        {
            m_DeblockingBtton.SetListener(OnClickDeblockingBtton);
            close.SetListener(() =>
            {
                CloseClick();
                WindowCenter.Instance.Open<PetWin>(false, 0);
            });
 
            m_RideBtton.SetListener(() => {
                mountModel.AppearanceSwitch((byte)mountModel.mountSkin[signHorseID], 2);
            });
        }
 
        private void onMountSkinActive()
        {
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            RefreshMountSkinPanel();
            ridingAndPetActivationModel.RidingAndPetActivationSet(RidingAndPetActivation.MountActivation, signHorseID);
            sortMountlist.Clear();
            ToAddSorting();
        }
 
        protected override void OnPreOpen()
        {
            MountModel.Event_MountHA301A += OnMountSkinAdd;
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            mountModel.onMountSkinActive += onMountSkinActive;
            MountModel.Event_MountAlteration += Event_MountAlteration;
            ToAddSorting();
            int jumpIndex = JumpSelect(OpenChooseIndex());
            OnCreateGridLineCell(m_ScrollerController);
            m_ScrollerController.JumpIndex(JumpSelect(jumpIndex));
 
            RefreshMountSkinPanel();
        }
        protected override void OnActived()
        {
            base.OnActived();
        }
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            MountModel.Event_MountHA301A -= OnMountSkinAdd;
            m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
            mountModel.onMountSkinActive -= onMountSkinActive;
            MountModel.Event_MountAlteration -= Event_MountAlteration;
            UI3DModelExhibition.Instance.StopShow();
            signHorseID = 0;
        }
 
 
 
 
        protected override void OnAfterClose()
        {
 
        }
 
 
        private int JumpIndex(int HorseID = 0)
        {
            int Index = 0;
            Index = sortMountlist.FindIndex((x) =>
            {
                return x.x == signHorseID;
            });
            if (Index == -1)
            {
                Index = 0;
            }
            return JumpSelect(Index);
        }
 
 
        private int OpenChooseIndex()
        {
            // 红点-骑乘中-第一个
            int selectIndex = 0;
            int ridingHorseSkinID = -1;
            if (mountModel.mountSkin.ContainsKey(mountModel.HorseIDNow))
            {
                ridingHorseSkinID = mountModel.mountSkin[mountModel.HorseIDNow];
            }
            int index = 0;
            foreach (var sortInfo in sortMountlist)
            {
                if (ridingHorseSkinID != -1 && ridingHorseSkinID == sortInfo[0])
                {
                    selectIndex = index;
                }
                if (mountModel.DeblockingRedPoint[sortInfo[0]].state != RedPointState.None)
                {
                    signHorseID = HorseSkinPlusConfig.Get(sortInfo[0]).HorseID;
                    return index;
                }
                index++;
            }
 
            signHorseID = HorseSkinPlusConfig.Get(sortMountlist[selectIndex][0]).HorseID;
            return selectIndex;
        }
 
        void OnCreateGridLineCell(ScrollerController gridCtrl)
        {
            gridCtrl.Refresh();
            for (int i = 0; i < sortMountlist.Count; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, HorseSkinPlusConfig.Get(sortMountlist[i].x).HorseID);
            }
            gridCtrl.Restart();
        }
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            SelectThemount selectThemount = cell.GetComponent<SelectThemount>();
            int horseID = cell.index;
            var horseConfig = HorseConfig.Get(horseID);
            selectThemount.QualityTxt1.text = ProductOrder(horseConfig.Quality.ToString());
            selectThemount.MountNameTxt.text = horseConfig.Name;
            selectThemount.MountLvActivation.SetActive(!mountModel.isMountSkinActive(horseID));
 
            if (horseID == signHorseID)
            {
                selectThemount.ChoosenImg.SetActive(true);
                selectThemount.DarkImage.SetActive(false);
            }
            else
            {
                selectThemount.ChoosenImg.SetActive(false);
                selectThemount.DarkImage.SetActive(true);
            }
            selectThemount.HidingTips.SetActive(mountModel.HorseIDNow == horseID ? true : false);
 
            selectThemount.MountButton.SetListener(()=> {
                if (signHorseID == horseID)
                    return;
                signHorseID = horseID;
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
                RefreshMountSkinPanel();
            });
 
            selectThemount.RedPoint.redpointId = mountModel.DeblockingRedPoint[mountModel.mountSkin[horseID]].id;
        }
 
        private void RefreshMountSkinPanel()
        {
            if (signHorseID == 0)
                return;
            HorseConfig _model = HorseConfig.Get(signHorseID);
            m_MountName.text = _model.Name;
 
            if (!m_Mount3D.gameObject.activeSelf)
            {
                m_Mount3D.SetActive(true);
            }
 
            UI3DModelExhibition.Instance.ShowHourse(_model.Model, m_Mount3D);
            if (UI3DModelExhibition.Instance.NpcModelHorse != null)
            {
                var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent<Animator>();
                if (animator != null)
                {
                    animator.Play(GAStaticDefine.State_Dance);
 
                }
            }
 
            ShowAttrText();
            DisplayButton();
        }
 
        private void Event_MountAlteration()
        {
            DisplayButton();
 
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
        }
 
        private void DisplayButton()
        {
            if (mountModel.isMountSkinActive(signHorseID))
            {
                m_DeblockingBtton.SetActive(false);
                m_RideBtton.SetActive(true);
                if (signHorseID == mountModel.HorseIDNow)
                {
                    m_RideBtton.SetActive(false);
                }
 
                return;
            }
            //AppearanceSwitch
            HorseConfig horsefig = HorseConfig.Get(signHorseID);
 
            ItemCellModel cellModel = new ItemCellModel(horsefig.UnlockItemID, false, 1);
            MountItem.Init(cellModel);
            MountItem.countText.SetActive(true);
            MountItem.countText.text = playerPack.GetItemCountByID(PackType.Item, horsefig.UnlockItemID).ToString();
            var itemConfig = ItemConfig.Get(horsefig.UnlockItemID);
            MountItemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
            MountItem.button.SetListener(() =>
            {
                ItemTipUtility.Show(horsefig.UnlockItemID);
            });
 
            m_DeblockingBtton.SetActive(true);
            m_RideBtton.SetActive(false);
        }
 
        private void ShowAttrText()
        {
            ClearAttrText();
            var config = HorseSkinPlusConfig.Get(mountModel.mountSkin[signHorseID]);
            int showIndex = 0;
            Dictionary<int, int> allAttr = new Dictionary<int, int>();
            foreach (var attrID in config.AttrType)
            {
                allAttr[attrID] = config.AttrValue[showIndex];
                AttrNameList[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
                AttrValueList[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, config.AttrValue[showIndex]);
                showIndex++;
            }
 
            m_FightPower.text = (UIHelper.GetFightPower(allAttr) + config.InitFightPower).ToString();
        }
 
        private void ClearAttrText()
        {
            for (int i = 0; i < AttrNameList.Count; i++)
            {
                AttrNameList[i].text = string.Empty;
                AttrValueList[i].text = string.Empty;
 
            }
 
        }
 
 
        private void OnClickDeblockingBtton()//解锁按钮
        {
            HorseConfig horsefig = HorseConfig.Get(signHorseID);
            int MaterialNumber = playerPack.GetItemCountByID(PackType.Item, horsefig.UnlockItemID);//获取背包解锁材料的数量
            if (MaterialNumber >= horsefig.UnlockItemCnt)
            {
                CA501_tagPlayerActivateHorse _tagA501 = new CA501_tagPlayerActivateHorse();
                _tagA501.HorseID = (uint)mountModel.mountSkin[signHorseID];
                GameNetSystem.Instance.SendInfo(_tagA501);
               
            }
            else
            {
                ScrollTip.ShowTip(Language.Get("Z1063"));//所需材料不足
            }
        }
 
            
        #endregion
        
        void ToAddSorting()//坐骑的列表排序
        {
 
            if (sortMountlist.Count <= 0)
            {
 
                foreach (var mountSkin in mountModel.MountSkinActive)
                {
                    var config = HorseSkinPlusConfig.Get(mountSkin.Key);
                    sortMountlist.Add(new Int3(mountSkin.Key, mountSkin.Value, config.sortIndex));
                }
            }          
            sortMountlist.Sort(Compare);
        }
        int Compare(Int3 skin1, Int3 skin2)//数组排列
        {
 
            var xActive = skin1.y;
            var yActive = skin2.y;
 
            if (xActive != yActive)
            {
                return yActive.CompareTo(xActive);
            }
            return skin1.z.CompareTo(skin2.z);
        }
        
 
        string ProductOrder(string _petProductOrder)//坐骑品质
        {
            FuncConfigConfig _PetQuality = FuncConfigConfig.Get("PetQuality");
            string[] _productlist = _PetQuality.Numerical1.Split('|');
            for (int i = 0; i < _productlist.Length; i++)
            {
                if (_petProductOrder == _productlist[i])
                {
                    string[] _productText = _PetQuality.Numerical2.Split('|');
                    string str = _productText[i];
                    return str;
                }
            }
            return null;
        }
        private int JumpSelect(int Index)
        {
            if (Index <= 4)
            {
                return 0;
            }
            return Index;
        }
 
        private void OnMountSkinAdd(int id)
        {
        }
    }
}