少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, July 27, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class ViewPetDetailWin : Window ,SecondWindowInterface
    {
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] Text m_FightPower;
        [SerializeField] Text m_PetAtk;
        [SerializeField] Text m_PetAtkSpeed;
        [SerializeField] PetSkill[] m_PetSkills;
        [SerializeField] ScrollerController m_SkillController;
        [SerializeField] RawImage m_RawModel;
        [SerializeField] Button m_PetStone;
 
        [SerializeField, Header("技能一行个数")] int m_LineCount = 3;
 
        public int selectPet { get; private set; }
 
        public int lineCount { get { return m_LineCount; } }
 
        List<int> skills = new List<int>();
 
        [NonSerialized] public List<int> displayTotalSkills = new List<int>();
        [NonSerialized] public List<int> unlockTotalSkills = new List<int>();
 
        RoleParticularModel model { get { return ModelCenter.Instance.GetModel<RoleParticularModel>(); } }
        PetModel petModel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
        #region Built-in
        public Button close { get; set; }
 
        protected override void BindController()
        {
            if (this is SecondWindowInterface)
            {
                var frame = this.GetComponentInChildren<SecondFrameLoader>();
                frame.Create();
                close = frame.GetComponentInChildren<Button>();
            }
        }
 
        protected override void AddListeners()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_SkillController.OnRefreshCell += OnRefreshSkillCell;
            m_PetStone.onClick.AddListener(OnPetStone);
            close.onClick.AddListener(CloseClick);
        }
 
        protected override void OnPreOpen()
        {
            Display();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        void Display()
        {
            RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer);
            if (data == null)
            {
                return;
            }
            var pets = data.rolePlusData.pets;
            selectPet = pets[0].id;
            m_Controller.Refresh();
            for (int i = 0; i < pets.Count; i++)
            {
                CellInfo info = CellInfo.Default;
                info.infoInt1 = pets[i].lv;
                m_Controller.AddCell(ScrollerDataType.Header, pets[i].id, info);
            }
            m_Controller.Restart();
            m_FightPower.text = model.GetPetFightPower(pets).ToString();
            DisplayModel(selectPet);
            DisplayProperty(pets, data.rolePlusData.AtkSpeed);
            DisplaySkills(pets[0].id, pets[0].lv);
            DisplayTotalSkills(pets);
        }
 
        public void SelectPet(int _id)
        {
            selectPet = _id;
            RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer);
            if (data == null)
            {
                return;
            }
            var pets = data.rolePlusData.pets;
            var pet = pets.Find((x) =>
            {
                return x.id == selectPet;
            });
            if (!pet.Equals(default(RoleParticularModel.PetInfo)))
            {
                DisplaySkills(pet.id, pet.lv);
                DisplayModel(pet.id);
            }
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
        void DisplayProperty(List<RoleParticularModel.PetInfo> pets,int AtkSpeed)
        {
            m_PetAtk.text = model.GetPetAtkProperty(pets).ToString();
            m_PetAtkSpeed.text = ((float)AtkSpeed / 100).ToString();
        }
 
        void DisplaySkills(int id, int lv)
        {
            PetInfoConfig.GetPetSkills(id, lv, false,ref skills);
            for (int i = 0; i < m_PetSkills.Length; i++)
            {
                if (i < skills.Count)
                {
                    m_PetSkills[i].SetActive(true);
                    var condition = PetInfoConfig.GetPetSkillCondition(id, skills[i]);
                    m_PetSkills[i].Display(id, skills[i], lv >= condition ? 0 : condition);
                }
                else
                {
                    m_PetSkills[i].SetActive(false);
                }
            }
        }
 
        void DisplayTotalSkills(List<RoleParticularModel.PetInfo> pets)
        {
            displayTotalSkills.Clear();
            unlockTotalSkills.Clear();
 
            for (int i = 0; i < pets.Count; i++)
            {
                PetInfoConfig.GetPetSkills(pets[i].id, pets[i].lv, true, ref skills);
                unlockTotalSkills.AddRange(skills);
                foreach (var id in skills)
                {
                    var config = SkillConfig.Get(id);
                    var skillId = 0;
                    var effect = SkillConfig.GetSkillEffectValue(config);
                    if (petModel.TryGetIntegrationSkill(effect, out skillId))
                    {
                        if (!displayTotalSkills.Contains(skillId))
                        {
                            displayTotalSkills.Add(skillId);
                        }
                        continue;
                    }
                    displayTotalSkills.Add(id);
                }
            }
 
            displayTotalSkills.Sort(Compare);
 
            m_SkillController.Refresh();
            var line = Mathf.CeilToInt((float)displayTotalSkills.Count / m_LineCount);
            for (int i = 0; i < line; i++)
            {
                m_SkillController.AddCell(ScrollerDataType.Header, i);
            }
            m_SkillController.Restart();
        }
 
        private void OnPetStone()
        {
            model.viewPetStone = true;
            WindowCenter.Instance.Open<ViewPetHorseStoneWin>();
        }
 
        void DisplayModel(int id)
        {
            m_RawModel.SetActive(true);
            var npcConfig = NPCConfig.Get(id);
            UI3DModelExhibition.Instance.ShowNPC(id, npcConfig.UIModeLOffset, npcConfig.UIModelRotation, m_RawModel);
            if (UI3DModelExhibition.Instance.NpcModelPet != null)
            {
                var animator = UI3DModelExhibition.Instance.NpcModelPet.GetComponent<Animator>();
                if (animator != null)
                {
                    animator.Play(GAStaticDefine.State_Dance);
                }
            }
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            ViewPetSelectCell selectCell = cell as ViewPetSelectCell;
            var lv = cell.info.HasValue ? cell.info.Value.infoInt1 : 0;
            selectCell.Display(cell.index, lv, this);
        }
 
        private void OnRefreshSkillCell(ScrollerDataType type, CellView cell)
        {
            ViewPetSkillCell skillCell = cell as ViewPetSkillCell;
            skillCell.Display(cell.index, this);
        }
 
        int Compare(int lhs, int rhs)
        {
            var lhs_config = SkillConfig.Get(lhs);
            var rhs_config = SkillConfig.Get(rhs);
            var lhs_Id = 0;
            var rhs_Id = 0;
            var lhs_effect = SkillConfig.GetSkillEffectValue(lhs_config);
            var rhs_effect = SkillConfig.GetSkillEffectValue(rhs_config);
            var lhs_integration = petModel.TryGetIntegrationSkill(lhs_effect, out lhs_Id);
            var rhs_integration = petModel.TryGetIntegrationSkill(rhs_effect, out rhs_Id);
            if (lhs_integration != rhs_integration)
            {
                return -lhs_integration.CompareTo(rhs_integration);
            }
            if (lhs_integration && rhs_integration)
            {
                return lhs_config.Effect1.CompareTo(rhs_config.Effect1);
            }
            var lhs_petId = 0;
            var rhs_petId = 0;
            petModel.TryGetPetId(lhs, out lhs_petId);
            petModel.TryGetPetId(rhs, out rhs_petId);
            var lhs_petconfig = PetInfoConfig.Get(lhs_petId);
            var rhs_petconfig = PetInfoConfig.Get(rhs_petId);
            return lhs_petconfig.Sort.CompareTo(rhs_petconfig.Sort);
        }
 
        [Serializable]
        public class PetSkill
        {
            [SerializeField] RectTransform m_Container;
            [SerializeField] Button m_SkillBtn;
            [SerializeField] RectTransform m_ContainerLock;
            [SerializeField] Text m_Condition;
            [SerializeField] Image m_SkillIcon;
            [SerializeField] UIEffect m_Effect;
 
            int petId = 0;
            int skillId = 0;
 
            public void Display(int id, int _skillId, int condition)
            {
                var config = SkillConfig.Get(_skillId);
                if (config != null)
                {
                    m_SkillIcon.SetSprite(config.IconName);
                }
                petId = id;
                skillId = _skillId;
                m_ContainerLock.SetActive(condition > 0);
                if (condition > 0)
                {
                    m_Condition.text = Language.Get("LoadIconLV", condition);
                }
                m_SkillBtn.RemoveAllListeners();
                m_SkillBtn.AddListener(OnClickSkill);
 
                m_Effect.StopImediatly();
                var model = ModelCenter.Instance.GetModel<PetModel>();
                if (model.ListEffectSkill != null
                    && model.ListEffectSkill.Contains(_skillId))
                {
                    m_Effect.Play();
                }
            }
 
            private void OnClickSkill()
            {
                PetInfoConfig petInfo = PetInfoConfig.Get(petId);
                if (petInfo != null)
                {
                    var skillConfig = SkillConfig.Get(skillId);
                    var label1 = skillConfig.Description;
                    var label2 = Language.Get("pet_SkillTipLv", petInfo.Name, PetInfoConfig.GetPetSkillCondition(petId, skillId));
                    SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.ViewHorsePet,
                        skillConfig == null ? 0 : skillConfig.FightPower, label1, label2);
                }
            }
 
            public void SetActive(bool active)
            {
                m_Container.SetActive(active);
            }
        }
    }
 
}