少年修仙传客户端代码仓库
hch
4 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
 
class SkillMatchWin : ILWindow
{
 
    int selectId;
    int selectPage;
 
    List<SkillMatchBehaviour> skillBehaviours;
    List<Transform> skillBehaviourTrans;
 
    List<Button> skillPages;
    List<Transform> skillPageSelects;
 
    ImageEx dragIcon;
    Text treasureName;
    Text skillName;
    Text skillLevel;
    Text skillCoolDown;
    Text skillDescription;
    ImageEx skillExpertIcon;
    Text skillExpertName;
    Button skillExpertFunc;
    Button btnClose;
 
    protected override void BindController()
    {
        base.BindController();
 
        skillBehaviours = new List<SkillMatchBehaviour>();
        skillBehaviourTrans = new List<Transform>();
 
        for (int i = 0; i < ILSkillMatchConfig.GetValues().Count; i++)
        {
            var child = this.transform.Find("Container/Container_Skills/" + i);
            var skillBehaviour = new SkillMatchBehaviour();
            skillBehaviour.Bind(child);
            skillBehaviours.Add(skillBehaviour);
            skillBehaviourTrans.Add(child);
        }
 
        skillPages = new List<Button>();
        skillPageSelects = new List<Transform>();
        for (int i = 0; i <= 2; i++)
        {
            this.skillPages.Add(this.transform.FindComponentEx<Button>("Container/Contaienr_Page/Page" + i));
            this.skillPageSelects.Add(this.transform.FindComponentEx<Transform>("Container/Contaienr_Page/Page" + i + "/Img_Select"));
        }
 
        this.dragIcon = this.transform.FindComponentEx<ImageEx>("Img_DragIcon");
        this.treasureName = this.transform.FindComponentEx<Text>("Container/Txt_TreasureName");
        this.skillName = this.transform.FindComponentEx<Text>("Container/Txt_SkillName");
        this.skillLevel = this.transform.FindComponentEx<Text>("Container/Txt_SkillLevel");
        this.skillCoolDown = this.transform.FindComponentEx<Text>("Container/Txt_SkillCoolDown");
        this.skillDescription = this.transform.FindComponentEx<Text>("Container/Txt_Description");
        this.skillExpertIcon = this.transform.FindComponentEx<ImageEx>("Container/Container_Expert/SkillWidget/Img_Icon");
        this.skillExpertName = this.transform.FindComponentEx<Text>("Container/Container_Expert/SkillWidget/Txt_SkillName");
        this.skillExpertFunc = this.transform.FindComponentEx<Button>("Container/Container_Expert/SkillWidget");
        this.btnClose = this.transform.FindComponentEx<Button>("Container/Btn_Close");
    }
 
    protected override void AddListeners()
    {
        base.AddListeners();
        this.btnClose.SetListener(() =>
        {
            WindowCenter.Instance.CloseIL<SkillMatchWin>();
        });
 
        for (int i = 0; i < skillPages.Count; i++)
        {
            var page = i;
            skillPages[i].SetListener(() =>
            {
                OnSelectPage(page);
            });
        }
    }
 
    protected override void OnPreOpen()
    {
        base.OnPreOpen();
        UIDragDropBehaviour.draging = false;
        this.dragIcon.SetActiveIL(false);
        this.selectPage = SkillMatchModel.Instance.GetSkillPage();
        var displayIds = SkillMatchModel.Instance.GetDisplayIds(this.selectPage);
        SkillMatchModel.Instance.selectId = displayIds[0];
        this.selectId = displayIds[0];
        Display();
    }
 
    protected override void OnPreClose()
    {
        base.OnPreClose();
        SkillMatchModel.Instance.SetSkillMatch(this.selectPage);
    }
 
    protected override void LateUpdate()
    {
        base.LateUpdate();
        if (this.selectId != SkillMatchModel.Instance.selectId)
        {
            this.selectId = SkillMatchModel.Instance.selectId;
            DisplayDetail();
        }
 
        if (UIDragDropBehaviour.draging)
        {
            if (this.dragIcon.gameObject.activeSelf == false)
            {
                this.dragIcon.SetActiveIL(true);
                var id = UIDragDropBehaviour.dragData;
                var skillId = SkillMatchModel.Instance.GetSkillId(id);
                var config = SkillConfig.Get(skillId);
                if (config != null)
                    this.dragIcon.SetSprite(config.IconName);
            }
 
            var mousePosition = new Vector2();
            mousePosition.x = Input.mousePosition.x;
            mousePosition.y = Input.mousePosition.y;
            Vector2 pos;
            var contain = RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, mousePosition, CameraManager.uiCamera, out pos);
            if (contain)
            {
                var position = new Vector3(pos.x, pos.y, 0);
                this.dragIcon.rectTransform.localPosition = position;
            }
 
            if (Input.GetMouseButtonUp(0))
            {
                UIDragDropBehaviour.draging = false;
                this.TrySwitchSkill();
                this.dragIcon.SetActiveIL(false);
            }
        }
    }
 
    void Display()
    {
        var displayIds = SkillMatchModel.Instance.GetDisplayIds(this.selectPage);
        for (int i = 0; i < ILSkillMatchConfig.GetValues().Count; i++)
        {
            if (i < displayIds.Length)
            {
                this.skillBehaviours[i].Dispose();
                this.skillBehaviours[i].Display(displayIds[i]);
            }
            else
            {
                this.skillBehaviours[i].Dispose();
            }
        }
 
        this.DisplayPageState();
        this.DisplayDetail();
    }
 
    void DisplayPageState()
    {
        for (int i = 0; i <= 2; i++)
        {
            this.skillPageSelects[i].SetActiveIL(this.selectPage == i);
        }
    }
 
    void DisplayDetail()
    {
        var model = ModelCenter.Instance.GetModelEx<TreasureSkillModel>();
        var skillId = SkillMatchModel.Instance.GetSkillId(SkillMatchModel.Instance.selectId);
        TreasureSkill skill;
        var exist = model.TryGetSkill(skillId, out skill);
        if (exist)
        {
            var config = SkillConfig.Get(skillId);
            this.treasureName.text = config.Skillsource;
            this.skillName.text = config.SkillName;
            if (skill.level > 0)
                this.skillLevel.text = Language.Get("SkillActLevel", skill.level);
            else
                this.skillLevel.text = Language.Get("SkillActLevel", Language.Get("TreasureSkilllock"));
            if (config.CoolDownTime == 0)
                this.skillCoolDown.text = "";
            else
                this.skillCoolDown.text = Language.Get("L1065", config.CoolDownTime / 1000);
 
            this.skillDescription.text = UIHelper.ReplaceNewLine(config.Description);
 
            int skillExpertId;
            var hasExpert = model.TryGetExpertSkill(skillId, out skillExpertId);
            this.skillExpertIcon.SetActiveIL(hasExpert);
            this.skillExpertName.SetActiveIL(hasExpert);
            this.skillExpertFunc.RemoveAllListeners();
            if (hasExpert)
            {
                var expertConfig = SkillConfig.Get(skillExpertId);
                this.skillExpertIcon.SetSprite(expertConfig.IconName);
                this.skillExpertName.text = expertConfig.SkillName;
                this.skillExpertFunc.SetListener(this.OnOpenExpert);
            }
        }
 
        for (int i = 0; i < skillBehaviours.Count; i++)
        {
            this.skillBehaviours[i].DisplaySelect();
        }
    }
    void OnSelectPage(int page)
    {
        this.selectPage = page;
        var displayIds = SkillMatchModel.Instance.GetDisplayIds(this.selectPage);
        SkillMatchModel.Instance.selectId = displayIds[0];
        this.selectId = displayIds[0];
        Display();
    }
 
    void OnOpenExpert()
    {
        var model = ModelCenter.Instance.GetModelEx<TreasureSkillModel>();
        var skillId = SkillMatchModel.Instance.GetSkillId(SkillMatchModel.Instance.selectId);
        int skillExpertId;
        var hasExpert = model.TryGetExpertSkill(skillId, out skillExpertId);
        if (hasExpert)
        {
            ExpertSkillSelectWin.skillId = skillExpertId;
            WindowCenter.Instance.OpenEx<ExpertSkillSelectWin>();
        }
    }
 
    void TrySwitchSkill()
    {
        for (int i = 0; i < skillBehaviourTrans.Count; i++)
        {
            var des = RectTransformUtility.CalculateRelativeRectTransformBounds(this.transform, this.skillBehaviourTrans[i]);
            var src = RectTransformUtility.CalculateRelativeRectTransformBounds(this.transform, this.dragIcon.transform);
            var dis = Vector3.Distance(des.center, src.center);
 
            if (dis < 50)
            {
                var id = this.skillBehaviours[i].GetId();
                if (id == UIDragDropBehaviour.dragData)
                    break;
                else
                {
                    var skillId = SkillMatchModel.Instance.GetSkillId(id);
                    var model = ModelCenter.Instance.GetModelEx<TreasureSkillModel>();
                    TreasureSkill skill;
                    var exist = model.TryGetSkill(skillId, out skill);
 
                    if (exist && skill.level > 0)
                    {
                        SkillMatchModel.Instance.SetQuickSetting(this.selectPage, i, UIDragDropBehaviour.dragData);
                        var index = this.GetIndex(UIDragDropBehaviour.dragData);
                        SkillMatchModel.Instance.SetQuickSetting(this.selectPage, index, id);
                        QuickSetting.Instance.SendPackage();
                        this.Display();
                    }
                }
                break;
            }
        }
    }
 
    int GetIndex(int id)
    {
        for (int i = 0; i < skillBehaviourTrans.Count; i++)
        {
            if (this.skillBehaviours[i].GetId() == id)
                return i;
        }
        return 0;
    }
 
}