少年修仙传客户端代码仓库
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, December 11, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    public class GatherSoulEquipListWin : Window
    {
        [SerializeField] RectTransform m_Container;
        [SerializeField] Button m_Close;
        [SerializeField] ScrollerController m_ScrollerControl;
 
        public static int selectHole = 0;
 
        bool existHoleItem = false;
 
        GatheringSoulModel model
        {
            get { return ModelCenter.Instance.GetModel<GatheringSoulModel>(); }
        }
 
        List<GatherSoulItem> equipList = new List<GatherSoulItem>();
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Close.onClick.AddListener(CloseClick);
            m_ScrollerControl.OnRefreshCell += OnRefreshCell;
        }
 
        protected override void OnPreOpen()
        {
            GatherSoulItem item;
            if (model.TryGetItem(selectHole, out item))
            {
                existHoleItem = true;
            }
            else
            {
                existHoleItem = false;
            }
 
            Display();
            model.gatherSoulPackRefresh += GatherSoulPackRefresh;
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            equipList.Clear();
            model.gatherSoulPackRefresh -= GatherSoulPackRefresh;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            var equipCell = cell as GatherSoulEquipCell;
            if (cell.index < equipList.Count)
            {
                equipCell.Display(equipList[cell.index], false);
            }
        }
 
        void Display()
        {
            GatherSoulItem item;
            if (model.TryGetItem(selectHole, out item))
            {
                model.TryGetSatisfyReplaceSouls(selectHole, ref equipList);
            }
            else
            {
                model.TryGetSatisfyEquipSouls(selectHole, ref equipList);
            }
            EliminateSameItem();
            equipList.Sort(model.CommonSort);
            m_ScrollerControl.Refresh();
            for (int i = 0; i < equipList.Count; i++)
            {
                m_ScrollerControl.AddCell(ScrollerDataType.Header, i, EquipGatherSoul);
            }
            m_ScrollerControl.Restart();
        }
 
        void EliminateSameItem()
        {
            List<int> removeIndexs = new List<int>();
            for (int i = 0; i < equipList.Count; i++)
            {
                var item = equipList[i];
                if (removeIndexs.Contains(i))
                {
                    continue;
                }
                for (int k = i + 1; k < equipList.Count; k++)
                {
                    if (removeIndexs.Contains(k))
                    {
                        continue;
                    }
                    var compare = item.Compare(equipList[k]);
                    if (item.ExistSameProperty(equipList[k].id))
                    {
                        if(compare == 1 || compare == 0)
                        {
                            removeIndexs.Add(k);
                        }
                        else
                        {
                            removeIndexs.Add(i);
                            break;
                        }
                    }
                }
            }
            removeIndexs.Sort();
            for (int i = removeIndexs.Count - 1; i >= 0; i--)
            {
                equipList.RemoveAt(removeIndexs[i]);
            }
        }
 
        private void GatherSoulPackRefresh()
        {
            Display();
        }
 
        private void EquipGatherSoul(CellView cell)
        {
            if (cell.index < equipList.Count)
            {
                var item = equipList[cell.index];
                GatherSoulItem holeItem;
                if(model.TryGetItem(selectHole,out holeItem))
                {
                    model.TryExecuteReplaceSoul(selectHole, item);
                }
                else
                {
                    model.ExecuteEquipSoul(item, selectHole);
                }
                CloseImmediately();
            }
        }
    }
 
}