少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-13 94a788f4e94b334ad14bd3db99785cb572fb34c3
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, September 06, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
using UnityEngine.EventSystems;
using Snxxz.UI;
 
namespace Snxxz.UI
{
 
    public class RoleEquipWin : Window
    {
        #region 成员变量
        [SerializeField] EquipBehaviours equipPlaces;
 
        [SerializeField] RawImage m_Role;
        [SerializeField] private Button m_OneKeySell;
        [SerializeField] private Button m_Sort; //整理
        [SerializeField] private Image m_SortImage;
        [SerializeField] private Text m_TimeCountDown;
        [SerializeField] private Text m_Copper;
        [SerializeField] private Text m_Diamond;
 
        #endregion
 
        float sortableTime = 0f;
        LogicUpdate sortableLogicUpdate;
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        private bool levelUpDirty;
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            m_OneKeySell.SetListener(OnClickOneKeySell);
            m_Sort.SetListener(OnClickSortBtn);
        }
 
        protected override void OnPreOpen()
        {
            levelUpDirty = false;
 
            packModel.refreshItemCountEvent += OnPackUpdate;
            PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataUpdate;
            WindowCenter.Instance.windowBeforeCloseEvent += BeforeWindowClose;
            GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
 
            UpdateMoney();
        }
 
        protected override void OnAfterOpen()
        {
            var config = SuccessConfig.Get(AchievementGoto.guideAchievementId);
            if (config != null && config.Type == 95)
            {
                packModel.SetJumpToOneKeySell(m_OneKeySell.transform);
            }
        }
 
        protected override void OnPreClose()
        {
            GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
            packModel.refreshItemCountEvent -= OnPackUpdate;
            WindowCenter.Instance.windowBeforeCloseEvent -= BeforeWindowClose;
            PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataUpdate;
            UI3DModelExhibition.Instance.StopShow();
        }
 
        protected override void OnAfterClose()
        {
            if (sortableLogicUpdate != null)
            {
                sortableLogicUpdate.Destroy();
                sortableLogicUpdate = null;
            }
        }
 
        protected override void OnActived()
        {
            base.OnActived();
 
            if (Time.time < sortableTime)
            {
                if (sortableLogicUpdate != null)
                {
                    sortableLogicUpdate.Destroy();
                }
                sortableLogicUpdate = new LogicUpdate(1);
                sortableLogicUpdate.Start(DisplaySortableCountDown);
            }
            else
            {
                DisplaySortableCountDown();
            }
 
            equipPlaces.DisplayAll();
            UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
        }
 
        private void BeforeWindowClose(Window window)
        {
            if ("PetMatInfoWin" != window.name && "ItemInfoWin" != window.name) return;
 
            UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
        }
 
        private void UpdateSecond()
        {
            if (levelUpDirty)
            {
                equipPlaces.DisplayAll();
                UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
                levelUpDirty = false;
            }
        }
 
        void OnPackUpdate(PackType type, int index, int Id)
        {
            if (type != PackType.Equip)
            {
                return;
            }
 
            var equipPosition = EquipSet.ServerPlaceToClientPlace(index);
            if (equipPosition.x != 0)
            {
                return;
            }
 
            var equipType = (RoleEquipType)equipPosition.y;
            if (!equipPlaces.Contain(equipType))
            {
                return;
            }
 
            equipPlaces[equipType].Display(equipType);
            UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
        }
 
        private void OnPlayerDataUpdate(PlayerDataType type)
        {
            switch (type)
            {
                case PlayerDataType.LV:
                    levelUpDirty = true;
                    break;
                case PlayerDataType.Gold:
                case PlayerDataType.GoldPaper:
                case PlayerDataType.Silver:
                case PlayerDataType.ExAttr6:
                    UpdateMoney();
                    break;
            }
        }
 
        void OnClickSortBtn()
        {
            ItemLogicUtility.Instance.ResetPack(PackType.Item);
            sortableTime = Time.time + 5f;
 
            if (sortableLogicUpdate != null)
            {
                sortableLogicUpdate.Destroy();
            }
            sortableLogicUpdate = new LogicUpdate(1);
            sortableLogicUpdate.Start(DisplaySortableCountDown);
        }
 
        private void DisplaySortableCountDown()
        {
            var countDown = sortableTime - Time.time;
            if (countDown <= 0f)
            {
                m_SortImage.SetSprite("SecondBtn1");
                m_TimeCountDown.text = Language.Get("BagWin_Sortbtn_Text_1");
                m_Sort.enabled = true;
 
                if (sortableLogicUpdate != null)
                {
                    sortableLogicUpdate.Destroy();
                    sortableLogicUpdate = null;
                }
            }
            else
            {
                m_SortImage.SetSprite("BlackBtn");
                m_TimeCountDown.text = Language.Get("BagWin_SortCDbtn_Text_1", Mathf.RoundToInt(countDown));
                m_Sort.enabled = false;
            }
        }
 
        void UpdateMoney()
        {
            m_Copper.text = PlayerDatas.Instance.baseData.diamond.ToString();
            m_Diamond.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(PlayerDatas.Instance.baseData.allCopper);
        }
 
        private void OnClickOneKeySell()
        {
            if (!ItemLogicUtility.Instance.isPackResetOk)
            {
                return;
            }
 
            if (ItemLogicUtility.Instance.GetSellItemList().Count > 0)
            {
                WindowCenter.Instance.Open<OneKeySellWin>();
            }
            else
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("KnapS129"));
            }
 
        }
 
        [System.Serializable]
        public class EquipBehaviours
        {
            public EquipPlaceCell wing;
            public EquipPlaceCell guard1;
            public EquipPlaceCell guard2;
            public EquipPlaceCell peerlessWeapon1;
            public EquipPlaceCell peerlessWeapon2;
 
            public EquipPlaceCell this[RoleEquipType type] {
                get {
                    switch (type)
                    {
                        case RoleEquipType.Wing:
                            return wing;
                        case RoleEquipType.Guard1:
                            return guard1;
                        case RoleEquipType.Guard2:
                            return guard2;
                        case RoleEquipType.PeerlessWeapon1:
                            return peerlessWeapon1;
                        case RoleEquipType.PeerlessWeapon2:
                            return peerlessWeapon2;
                        default:
                            return null;
                    }
                }
            }
 
            public bool Contain(RoleEquipType type)
            {
                return type == RoleEquipType.Wing
                    || type == RoleEquipType.Guard1 ||
                    type == RoleEquipType.Guard2 ||
                    type == RoleEquipType.PeerlessWeapon1 ||
                    type == RoleEquipType.PeerlessWeapon2;
            }
 
            public void Display(RoleEquipType type)
            {
                this[type].Display(type);
            }
 
            public void DisplayAll()
            {
                wing.Display(RoleEquipType.Wing);
                guard1.Display(RoleEquipType.Guard1);
                guard2.Display(RoleEquipType.Guard2);
                peerlessWeapon1.Display(RoleEquipType.PeerlessWeapon1);
                peerlessWeapon2.Display(RoleEquipType.PeerlessWeapon2);
            }
 
        }
 
    }
 
}