少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 aecb6a5a62d8a4cfc7b924ce957a9c7ea90c235d
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, July 27, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class ViewPetDetailWin : Window
    {
        [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] Button m_CloseBtn;
 
        [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> activeSkills = new List<int>();
 
        RoleParticularModel model { get { return ModelCenter.Instance.GetModel<RoleParticularModel>(); } }
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_SkillController.OnRefreshCell += OnRefreshSkillCell;
            m_PetStone.onClick.AddListener(OnPetStone);
            m_CloseBtn.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)
        {
            activeSkills.Clear();
            for (int i = 0; i < pets.Count; i++)
            {
                PetInfoConfig.GetPetSkills(pets[i].id, pets[i].lv, true, ref skills);
                activeSkills.AddRange(skills);
            }
            m_SkillController.Refresh();
            var line = Mathf.CeilToInt((float)activeSkills.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.gameObject.SetActive(true);
            var npcConfig = Config.Instance.Get<NPCConfig>(id);
            UI3DModelExhibition.Instance.BeginShowNPC(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);
        }
 
        [Serializable]
        public class PetSkill
        {
            [SerializeField] RectTransform m_Container;
            [SerializeField] Button m_SkillBtn;
            [SerializeField] RectTransform m_ContainerLock;
            [SerializeField] Text m_Condition;
            [SerializeField] Image m_SkillIcon;
 
            int petId = 0;
            int skillId = 0;
 
            public void Display(int id, int _skillId, int condition)
            {
                var config = Config.Instance.Get<SkillConfig>(_skillId);
                if (config != null)
                {
                    m_SkillIcon.SetSprite(config.IconName);
                }
                petId = id;
                skillId = _skillId;
                m_ContainerLock.gameObject.SetActive(condition > 0);
                if (condition > 0)
                {
                    m_Condition.text = Language.Get("LoadIconLV", condition);
                }
                m_SkillBtn.RemoveAllListeners();
                m_SkillBtn.AddListener(OnClickSkill);
            }
 
            private void OnClickSkill()
            {
                PetInfoConfig petInfo = Config.Instance.Get<PetInfoConfig>(petId);
                if (petInfo != null)
                {
                    var skillConfig = Config.Instance.Get<SkillConfig>(skillId);
                    SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.ViewHorsePet, skillConfig == null ? 0 : skillConfig.FightPower,
                         Language.Get("pet_SkillTipLv", petInfo.Name, PetInfoConfig.GetPetSkillCondition(petId, skillId)));
                }
            }
 
            public void SetActive(bool active)
            {
                m_Container.gameObject.SetActive(active);
            }
        }
    }
 
}