@shimotsuki/core 1.0.40 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -2833
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2833 +1 @@
|
|
|
1
|
-
import { AudioSource, _decorator, AudioClip, error, Node, director, log, sys, Component, Prefab, instantiate, isValid, Layers, view, Widget, v3, tween, Enum, game, UITransform, UIOpacity, Tween, Label, BlockInputEvents, Button, Director, warn, assetManager, Asset, resources, SpriteFrame, Sprite, AsyncDelegate } from 'cc';
|
|
2
|
-
import { PREVIEW, DEBUG } from 'cc/env';
|
|
3
|
-
import { makeObservable, observable, autorun, reaction } from '@shimotsuki/mobx';
|
|
4
|
-
import CryptoES from 'crypto-es';
|
|
5
|
-
import { clone, create } from '@bufbuild/protobuf';
|
|
6
|
-
import { SocialGameClient, AudienceOptionsSchema } from 'sgc';
|
|
7
|
-
import 'core-js/es/array/index.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @describe 音频公共类
|
|
11
|
-
* @author 游金宇(KM)
|
|
12
|
-
* @date 2024-09-12 11:42:58
|
|
13
|
-
*/
|
|
14
|
-
class CommonAudio extends AudioSource {
|
|
15
|
-
cat;
|
|
16
|
-
initAudio(cat) {
|
|
17
|
-
this.cat = cat;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @describe 音效
|
|
24
|
-
* @author 游金宇(KM)
|
|
25
|
-
* @date 2023-08-03 10:59:44
|
|
26
|
-
*/
|
|
27
|
-
const { ccclass: ccclass$b, menu: menu$1 } = _decorator;
|
|
28
|
-
/**
|
|
29
|
-
* 注:用playOneShot播放的音乐效果,在播放期间暂时没办法即时关闭音乐
|
|
30
|
-
*/
|
|
31
|
-
/** 游戏音效 */
|
|
32
|
-
class AudioEffect extends CommonAudio {
|
|
33
|
-
effects = new Map();
|
|
34
|
-
/**
|
|
35
|
-
* 加载音效并播放
|
|
36
|
-
* @param url 音效资源地址
|
|
37
|
-
* @param callback 资源加载完成并开始播放回调
|
|
38
|
-
*/
|
|
39
|
-
load(url) {
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
this.cat.res.load(url, AudioClip, (err, data) => {
|
|
42
|
-
if (err) {
|
|
43
|
-
return reject(err);
|
|
44
|
-
}
|
|
45
|
-
this.effects.set(url, data);
|
|
46
|
-
this.playOneShot(data, this.volume);
|
|
47
|
-
resolve(data);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/** 释放所有已使用过的音效资源 */
|
|
52
|
-
release() {
|
|
53
|
-
for (let key in this.effects) {
|
|
54
|
-
this.cat.res.release(key);
|
|
55
|
-
}
|
|
56
|
-
this.effects.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @describe 音乐
|
|
62
|
-
* @author 游金宇(KM)
|
|
63
|
-
* @date 2023-02-14 14:41:11
|
|
64
|
-
*/
|
|
65
|
-
const { ccclass: ccclass$a, menu } = _decorator;
|
|
66
|
-
/** 背景音乐 */
|
|
67
|
-
class AudioMusic extends CommonAudio {
|
|
68
|
-
/** 背景音乐播放完成回调 */
|
|
69
|
-
onComplete = null;
|
|
70
|
-
_progress = 0;
|
|
71
|
-
_url = null;
|
|
72
|
-
_isPlay = false;
|
|
73
|
-
/** 获取音乐播放进度 */
|
|
74
|
-
get progress() {
|
|
75
|
-
if (this.duration > 0)
|
|
76
|
-
this._progress = this.currentTime / this.duration;
|
|
77
|
-
return this._progress;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* 设置音乐当前播放进度
|
|
81
|
-
* @param value 进度百分比0到1之间
|
|
82
|
-
*/
|
|
83
|
-
set progress(value) {
|
|
84
|
-
this._progress = value;
|
|
85
|
-
this.currentTime = value * this.duration;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 加载音乐并播放
|
|
89
|
-
* @param url 音乐资源地址
|
|
90
|
-
* @param callback 加载完成回调
|
|
91
|
-
*/
|
|
92
|
-
load(url, callback) {
|
|
93
|
-
this.cat.res.load(url, AudioClip, (err, data) => {
|
|
94
|
-
if (err) {
|
|
95
|
-
error(err);
|
|
96
|
-
}
|
|
97
|
-
if (this.playing) {
|
|
98
|
-
this._isPlay = false;
|
|
99
|
-
this.stop();
|
|
100
|
-
this.cat.res.release(this._url);
|
|
101
|
-
}
|
|
102
|
-
this.playOnAwake = false;
|
|
103
|
-
this.enabled = true;
|
|
104
|
-
this.clip = data;
|
|
105
|
-
this._url = url;
|
|
106
|
-
// 注:事件定义在这里,是为了在播放前设置初始播放位置数据
|
|
107
|
-
callback && callback();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/** cc.Component 生命周期方法,验证背景音乐播放完成逻辑,建议不要主动调用 */
|
|
111
|
-
update(dt) {
|
|
112
|
-
if (this.currentTime > 0) {
|
|
113
|
-
this._isPlay = true;
|
|
114
|
-
}
|
|
115
|
-
if (this._isPlay && this.playing == false) {
|
|
116
|
-
this._isPlay = false;
|
|
117
|
-
this.enabled = false;
|
|
118
|
-
this.onComplete && this.onComplete();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/** 释放当前背景音乐资源 */
|
|
122
|
-
release() {
|
|
123
|
-
if (this._url) {
|
|
124
|
-
this.cat.res.release(this._url);
|
|
125
|
-
this._url = null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @describe 基础管理类
|
|
132
|
-
* @author 游金宇(KM)
|
|
133
|
-
* @date 2024-09-12 11:49:30
|
|
134
|
-
*/
|
|
135
|
-
class BaseManager {
|
|
136
|
-
cat;
|
|
137
|
-
constructor(manager) {
|
|
138
|
-
this.cat = manager;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
var AudioEventConstant;
|
|
143
|
-
(function (AudioEventConstant) {
|
|
144
|
-
/**音乐开 */
|
|
145
|
-
AudioEventConstant["MUSIC_ON"] = "AudioEventConstant/MUSIC_ON";
|
|
146
|
-
/**音乐关 */
|
|
147
|
-
AudioEventConstant["MUSIC_OFF"] = "AudioEventConstant/MUSIC_OFF";
|
|
148
|
-
/**音效开 */
|
|
149
|
-
AudioEventConstant["EFFECT_ON"] = "AudioEventConstant/EFFECT_ON";
|
|
150
|
-
/**音效关 */
|
|
151
|
-
AudioEventConstant["EFFECT_OFF"] = "AudioEventConstant/EFFECT_OFF";
|
|
152
|
-
/**暂停音频 */
|
|
153
|
-
AudioEventConstant["PAUSE_AUDIO"] = "AudioEventConstant/PAUSE_AUDIO";
|
|
154
|
-
/**恢复音频 */
|
|
155
|
-
AudioEventConstant["RESUME_AUDIO"] = "AudioEventConstant/RESUME_AUDIO";
|
|
156
|
-
})(AudioEventConstant || (AudioEventConstant = {}));
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @describe 音频管理
|
|
160
|
-
* @author 游金宇(KM)
|
|
161
|
-
* @date 2023-08-03 17:54:31
|
|
162
|
-
*/
|
|
163
|
-
/**
|
|
164
|
-
* 音频管理
|
|
165
|
-
*/
|
|
166
|
-
class AudioManager extends BaseManager {
|
|
167
|
-
local_data = {};
|
|
168
|
-
music;
|
|
169
|
-
effect;
|
|
170
|
-
_volume_music = 1;
|
|
171
|
-
_volume_effect = 1;
|
|
172
|
-
_switch_music = true;
|
|
173
|
-
_switch_effect = true;
|
|
174
|
-
local_store_key = 'game_audio';
|
|
175
|
-
extra = {};
|
|
176
|
-
constructor(cat) {
|
|
177
|
-
super(cat);
|
|
178
|
-
this.local_store_key = this.cat.audio_local_store_key;
|
|
179
|
-
var node = new Node('UIAudioManager');
|
|
180
|
-
director.addPersistRootNode(node);
|
|
181
|
-
var music = new Node('UIMusic');
|
|
182
|
-
music.parent = node;
|
|
183
|
-
this.music = music.addComponent(AudioMusic).initAudio(cat);
|
|
184
|
-
var effect = new Node('UIEffect');
|
|
185
|
-
effect.parent = node;
|
|
186
|
-
this.effect = effect.addComponent(AudioEffect).initAudio(cat);
|
|
187
|
-
this.load();
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* 设置背景音乐播放完成回调
|
|
191
|
-
* @param callback 背景音乐播放完成回调
|
|
192
|
-
*/
|
|
193
|
-
setMusicComplete(callback = null) {
|
|
194
|
-
this.music.onComplete = callback;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 播放背景音乐
|
|
198
|
-
* @param url 资源地址
|
|
199
|
-
* @param callback 音乐播放完成事件
|
|
200
|
-
*/
|
|
201
|
-
playMusic(url, callback) {
|
|
202
|
-
this.music.loop = true;
|
|
203
|
-
url && this.music.load(url, () => {
|
|
204
|
-
this._switch_music && this.music?.play();
|
|
205
|
-
callback && callback();
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* 停止音乐
|
|
210
|
-
*/
|
|
211
|
-
stopMusic() {
|
|
212
|
-
if (this.music.state != 0)
|
|
213
|
-
this.music?.stop();
|
|
214
|
-
}
|
|
215
|
-
/**暂停音乐 */
|
|
216
|
-
pauseMusic() {
|
|
217
|
-
if (this.music.state == 1)
|
|
218
|
-
this.music?.pause();
|
|
219
|
-
}
|
|
220
|
-
/**恢复音乐 */
|
|
221
|
-
resumeMusic() {
|
|
222
|
-
if ([0, 2].includes(this.music.state))
|
|
223
|
-
this.music?.play();
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* 获取背景音乐播放进度
|
|
227
|
-
*/
|
|
228
|
-
get progressMusic() {
|
|
229
|
-
return this.music.progress;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* 设置背景乐播放进度
|
|
233
|
-
* @param value 播放进度值
|
|
234
|
-
*/
|
|
235
|
-
set progressMusic(value) {
|
|
236
|
-
this.music.progress = value;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* 获取背景音乐音量
|
|
240
|
-
*/
|
|
241
|
-
get volumeMusic() {
|
|
242
|
-
return this._volume_music;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* 设置背景音乐音量
|
|
246
|
-
* @param value 音乐音量值
|
|
247
|
-
*/
|
|
248
|
-
set volumeMusic(value) {
|
|
249
|
-
this._volume_music = value;
|
|
250
|
-
this.music.volume = value;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* 获取背景音乐开关值
|
|
254
|
-
*/
|
|
255
|
-
get switchMusic() {
|
|
256
|
-
return this._switch_music;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* 设置背景音乐开关值
|
|
260
|
-
* @param value 开关值
|
|
261
|
-
*/
|
|
262
|
-
set switchMusic(value) {
|
|
263
|
-
log('设置背景音乐开关值', value, this._switch_music);
|
|
264
|
-
if (value == this._switch_music)
|
|
265
|
-
return;
|
|
266
|
-
this._switch_music = value;
|
|
267
|
-
value ? this.resumeMusic() : this.pauseMusic();
|
|
268
|
-
const nonce = value ? AudioEventConstant.MUSIC_ON : AudioEventConstant.MUSIC_OFF;
|
|
269
|
-
if (this.cat.event.has(nonce))
|
|
270
|
-
this.cat.event.dispatchEvent(nonce);
|
|
271
|
-
this.save();
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* 播放音效
|
|
275
|
-
* @param url 资源地址
|
|
276
|
-
*/
|
|
277
|
-
async playEffect(url) {
|
|
278
|
-
if (!this._switch_effect)
|
|
279
|
-
return;
|
|
280
|
-
url && await this.effect.load(url).then(() => {
|
|
281
|
-
this.effect.play();
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* 停止音效
|
|
286
|
-
*/
|
|
287
|
-
stopEffect() {
|
|
288
|
-
this.effect?.stop();
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* 获取音效音量
|
|
292
|
-
*/
|
|
293
|
-
get volumeEffect() {
|
|
294
|
-
return this._volume_effect;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* 设置获取音效音量
|
|
298
|
-
* @param value 音效音量值
|
|
299
|
-
*/
|
|
300
|
-
set volumeEffect(value) {
|
|
301
|
-
this._volume_effect = value;
|
|
302
|
-
this.effect.volume = value;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 获取音效开关值
|
|
306
|
-
*/
|
|
307
|
-
get switchEffect() {
|
|
308
|
-
return this._switch_effect;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* 设置音效开关值
|
|
312
|
-
* @param value 音效开关值
|
|
313
|
-
*/
|
|
314
|
-
set switchEffect(value) {
|
|
315
|
-
if (value == this._switch_effect)
|
|
316
|
-
return;
|
|
317
|
-
this._switch_effect = value;
|
|
318
|
-
value ? this.effect?.play() : this.effect?.stop();
|
|
319
|
-
const nonce = value ? AudioEventConstant.EFFECT_ON : AudioEventConstant.EFFECT_OFF;
|
|
320
|
-
if (this.cat.event.has(nonce))
|
|
321
|
-
this.cat.event.dispatchEvent(nonce);
|
|
322
|
-
this.save();
|
|
323
|
-
}
|
|
324
|
-
/** 恢复当前暂停的音乐与音效播放 */
|
|
325
|
-
resumeAll() {
|
|
326
|
-
this.switchMusic && this.music?.play();
|
|
327
|
-
this.switchEffect && this.effect?.play();
|
|
328
|
-
}
|
|
329
|
-
/** 暂停当前音乐与音效的播放 */
|
|
330
|
-
pauseAll() {
|
|
331
|
-
this.music?.pause();
|
|
332
|
-
this.effect?.pause();
|
|
333
|
-
}
|
|
334
|
-
/** 停止当前音乐与音效的播放 */
|
|
335
|
-
stopAll() {
|
|
336
|
-
this.music?.stop();
|
|
337
|
-
this.effect?.stop();
|
|
338
|
-
}
|
|
339
|
-
/** 保存音乐音效的音量、开关配置数据到本地 */
|
|
340
|
-
save() {
|
|
341
|
-
this.local_data.volume_music = this._volume_music;
|
|
342
|
-
this.local_data.volume_effect = this._volume_effect;
|
|
343
|
-
this.local_data.switch_music = this._switch_music;
|
|
344
|
-
this.local_data.switch_effect = this._switch_effect;
|
|
345
|
-
this.local_data.extra = this.extra;
|
|
346
|
-
let data = JSON.stringify(this.local_data);
|
|
347
|
-
this.cat.storage.set(this.local_store_key, data);
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
/** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
|
|
351
|
-
load() {
|
|
352
|
-
try {
|
|
353
|
-
let data = this.cat.storage.get(this.local_store_key);
|
|
354
|
-
this.local_data = JSON.parse(data);
|
|
355
|
-
this._volume_music = this.local_data.volume_music;
|
|
356
|
-
this._volume_effect = this.local_data.volume_effect;
|
|
357
|
-
this._switch_music = this.local_data.switch_music;
|
|
358
|
-
this._switch_effect = this.local_data.switch_effect;
|
|
359
|
-
this.extra = this.local_data.extra;
|
|
360
|
-
}
|
|
361
|
-
catch (e) {
|
|
362
|
-
this.local_data = {};
|
|
363
|
-
this._volume_music = 0.6;
|
|
364
|
-
this._volume_effect = 1.0;
|
|
365
|
-
this._switch_music = true;
|
|
366
|
-
this._switch_effect = true;
|
|
367
|
-
this.extra = {};
|
|
368
|
-
}
|
|
369
|
-
if (this.music)
|
|
370
|
-
this.music.volume = this._volume_music;
|
|
371
|
-
if (this.effect)
|
|
372
|
-
this.effect.volume = this._volume_effect;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* @describe 本地存储管理
|
|
378
|
-
* @author 游金宇(KM)
|
|
379
|
-
* @date 2023-08-03 17:58:51
|
|
380
|
-
*/
|
|
381
|
-
class StorageManager extends BaseManager {
|
|
382
|
-
_key = null;
|
|
383
|
-
_iv = null;
|
|
384
|
-
_id = '';
|
|
385
|
-
/**
|
|
386
|
-
* 初始化密钥
|
|
387
|
-
* @param key aes加密的key
|
|
388
|
-
* @param iv aes加密的iv
|
|
389
|
-
*/
|
|
390
|
-
init(key, iv) {
|
|
391
|
-
this.cat.util.encryptUtil.initCrypto(key, iv);
|
|
392
|
-
this._key = this.cat.util.encryptUtil.md5(key);
|
|
393
|
-
this._iv = this.cat.util.encryptUtil.md5(iv);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* 设置用户唯一标识
|
|
397
|
-
* @param id
|
|
398
|
-
*/
|
|
399
|
-
setUser(id) {
|
|
400
|
-
this._id = id;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* 存储本地数据
|
|
404
|
-
* @param key 存储key
|
|
405
|
-
* @param value 存储值
|
|
406
|
-
* @returns
|
|
407
|
-
*/
|
|
408
|
-
set(key, value) {
|
|
409
|
-
key = `${key}_${this._id}`;
|
|
410
|
-
if (null == key) {
|
|
411
|
-
console.error('存储的key不能为空');
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
if (!PREVIEW) {
|
|
415
|
-
key = this.cat.util.encryptUtil.md5(key);
|
|
416
|
-
}
|
|
417
|
-
if (null == value) {
|
|
418
|
-
console.warn('存储的值为空,则直接移除该存储');
|
|
419
|
-
this.remove(key);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
if (typeof value === 'function') {
|
|
423
|
-
console.error('储存的值不能为方法');
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
if (typeof value === 'object') {
|
|
427
|
-
try {
|
|
428
|
-
value = JSON.stringify(value);
|
|
429
|
-
}
|
|
430
|
-
catch (e) {
|
|
431
|
-
console.error(`解析失败,str = ${value}`);
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
else if (typeof value === 'number') {
|
|
436
|
-
value = value + '';
|
|
437
|
-
}
|
|
438
|
-
if (!PREVIEW && null != this._key && null != this._iv) {
|
|
439
|
-
value = this.cat.util.encryptUtil.aesEncrypt(`${value}`, this._key, this._iv);
|
|
440
|
-
}
|
|
441
|
-
sys.localStorage.setItem(key, value);
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* 获取指定关键字的数据
|
|
445
|
-
* @param key 获取的关键字
|
|
446
|
-
* @param defaultValue 获取的默认值
|
|
447
|
-
* @returns
|
|
448
|
-
*/
|
|
449
|
-
get(key, defaultValue) {
|
|
450
|
-
if (null == key) {
|
|
451
|
-
console.error('存储的key不能为空');
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
key = `${key}_${this._id}`;
|
|
455
|
-
if (!PREVIEW) {
|
|
456
|
-
key = this.cat.util.encryptUtil.md5(key);
|
|
457
|
-
}
|
|
458
|
-
let str = sys.localStorage.getItem(key);
|
|
459
|
-
if (null != str && '' !== str && !PREVIEW && null != this._key && null != this._iv) {
|
|
460
|
-
str = this.cat.util.encryptUtil.aesDecrypt(str, this._key, this._iv);
|
|
461
|
-
}
|
|
462
|
-
if (null === str) {
|
|
463
|
-
return defaultValue;
|
|
464
|
-
}
|
|
465
|
-
return str;
|
|
466
|
-
}
|
|
467
|
-
/** 获取指定关键字的数值 */
|
|
468
|
-
getNumber(key, defaultValue = 0) {
|
|
469
|
-
var r = this.get(key);
|
|
470
|
-
return Number(r) || defaultValue;
|
|
471
|
-
}
|
|
472
|
-
/** 获取指定关键字的布尔值 */
|
|
473
|
-
getBoolean(key) {
|
|
474
|
-
var r = this.get(key);
|
|
475
|
-
return Boolean(r) || false;
|
|
476
|
-
}
|
|
477
|
-
/** 获取指定关键字的JSON对象 */
|
|
478
|
-
getJson(key, defaultValue) {
|
|
479
|
-
var r = this.get(key);
|
|
480
|
-
return (r && JSON.parse(r)) || defaultValue;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* 删除指定关键字的数据
|
|
484
|
-
* @param key 需要移除的关键字
|
|
485
|
-
* @returns
|
|
486
|
-
*/
|
|
487
|
-
remove(key) {
|
|
488
|
-
if (null == key) {
|
|
489
|
-
console.error('存储的key不能为空');
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
key = `${key}_${this._id}`;
|
|
493
|
-
if (!PREVIEW) {
|
|
494
|
-
key = this.cat.util.encryptUtil.md5(key);
|
|
495
|
-
}
|
|
496
|
-
sys.localStorage.removeItem(key);
|
|
497
|
-
}
|
|
498
|
-
/** 清空整个本地存储 */
|
|
499
|
-
clear() {
|
|
500
|
-
sys.localStorage.clear();
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/******************************************************************************
|
|
505
|
-
Copyright (c) Microsoft Corporation.
|
|
506
|
-
|
|
507
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
508
|
-
purpose with or without fee is hereby granted.
|
|
509
|
-
|
|
510
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
511
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
512
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
513
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
514
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
515
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
516
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
517
|
-
***************************************************************************** */
|
|
518
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
function __decorate(decorators, target, key, desc) {
|
|
522
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
523
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
524
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
525
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function __metadata(metadataKey, metadataValue) {
|
|
529
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
533
|
-
var e = new Error(message);
|
|
534
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* @describe 组件基类
|
|
539
|
-
* @author 游金宇(KM)
|
|
540
|
-
* @date 2023-09-19 12:32:22
|
|
541
|
-
*/
|
|
542
|
-
/**参数 */
|
|
543
|
-
class BaseComponent extends Component {
|
|
544
|
-
/**组件(传值)属性 */
|
|
545
|
-
props = {};
|
|
546
|
-
/**自由属性 */
|
|
547
|
-
data = {};
|
|
548
|
-
/**autorun销毁 */
|
|
549
|
-
autorunDisposers = [];
|
|
550
|
-
/**reaction销毁 */
|
|
551
|
-
reactionDisposers = [];
|
|
552
|
-
messageManagers = [];
|
|
553
|
-
hook = {
|
|
554
|
-
destroyed: () => { },
|
|
555
|
-
started: () => { },
|
|
556
|
-
};
|
|
557
|
-
/**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
|
|
558
|
-
initUI() {
|
|
559
|
-
}
|
|
560
|
-
__preload() {
|
|
561
|
-
this.initUI();
|
|
562
|
-
this.onAutoObserver();
|
|
563
|
-
}
|
|
564
|
-
constructor() {
|
|
565
|
-
super();
|
|
566
|
-
makeObservable(this, {
|
|
567
|
-
props: observable,
|
|
568
|
-
data: observable
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
/**依赖收集生命周期(可以在该生命周期中注册依赖收集回调) */
|
|
572
|
-
onAutoObserver() {
|
|
573
|
-
}
|
|
574
|
-
/**添加自动收集 */
|
|
575
|
-
addAutorun(cb) {
|
|
576
|
-
const cbs = Array.isArray(cb) ? cb : [cb];
|
|
577
|
-
cbs.forEach(item => {
|
|
578
|
-
const disposer = autorun(item);
|
|
579
|
-
this.autorunDisposers.push(disposer);
|
|
580
|
-
});
|
|
581
|
-
return this;
|
|
582
|
-
}
|
|
583
|
-
/**添加自动收集 */
|
|
584
|
-
addReaction(expression, effect, opts) {
|
|
585
|
-
const disposer = reaction(expression, effect, opts);
|
|
586
|
-
this.reactionDisposers.push(disposer);
|
|
587
|
-
return this;
|
|
588
|
-
}
|
|
589
|
-
// /**添加自动收集 */
|
|
590
|
-
// protected addReaction<T, FireImmediately extends boolean = false>(option: ReactionParameters<T, FireImmediately>) {
|
|
591
|
-
// const disposer = reaction(...option)
|
|
592
|
-
// this.reactionDisposers.push(disposer)
|
|
593
|
-
// return this
|
|
594
|
-
// }
|
|
595
|
-
addAudoListener(messageManager) {
|
|
596
|
-
if (!this.messageManagers.includes(messageManager)) {
|
|
597
|
-
this.messageManagers.push(messageManager);
|
|
598
|
-
}
|
|
599
|
-
return messageManager;
|
|
600
|
-
}
|
|
601
|
-
_onPreDestroy() {
|
|
602
|
-
this.autorunDisposers.forEach((item) => {
|
|
603
|
-
item();
|
|
604
|
-
});
|
|
605
|
-
this.reactionDisposers.forEach((item) => {
|
|
606
|
-
item();
|
|
607
|
-
});
|
|
608
|
-
this.autorunDisposers = [];
|
|
609
|
-
this.reactionDisposers = [];
|
|
610
|
-
super._onPreDestroy();
|
|
611
|
-
}
|
|
612
|
-
onDisable() {
|
|
613
|
-
this.onHide();
|
|
614
|
-
cat.event.deleteEventByComponent(this);
|
|
615
|
-
this.messageManagers.forEach(item => {
|
|
616
|
-
item.deleteEventByComponent(this);
|
|
617
|
-
});
|
|
618
|
-
this.messageManagers = [];
|
|
619
|
-
this.removeListener();
|
|
620
|
-
}
|
|
621
|
-
onEnable() {
|
|
622
|
-
this.onShow();
|
|
623
|
-
this.addListener();
|
|
624
|
-
this.onEventListener();
|
|
625
|
-
}
|
|
626
|
-
/**子类继承该方法(全局事件(cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
|
|
627
|
-
onEventListener() { }
|
|
628
|
-
/**子类继承该方法 */
|
|
629
|
-
addListener() { }
|
|
630
|
-
/**子类继承该方法 */
|
|
631
|
-
removeListener() { }
|
|
632
|
-
/**
|
|
633
|
-
* 添加到父节点
|
|
634
|
-
* @param parent 父节点
|
|
635
|
-
* @param option 参数
|
|
636
|
-
* @returns 自身组件
|
|
637
|
-
*/
|
|
638
|
-
addToParent(parent, options) {
|
|
639
|
-
let _parent = parent instanceof Prefab ? instantiate(parent) : parent instanceof Component ? parent.node : parent;
|
|
640
|
-
this.setOptions(options);
|
|
641
|
-
_parent.addChild(this.node);
|
|
642
|
-
return this;
|
|
643
|
-
}
|
|
644
|
-
/**设置属性(覆盖原有属性) */
|
|
645
|
-
setOptions(options) {
|
|
646
|
-
// 使用类型断言来确保 options 的正确类型
|
|
647
|
-
if (!options)
|
|
648
|
-
return;
|
|
649
|
-
// 如果 options 是 IUIOption<T> 类型,则可以安全地访问 props 属性
|
|
650
|
-
for (let key in options) {
|
|
651
|
-
switch (key) {
|
|
652
|
-
case 'hook':
|
|
653
|
-
options.hook && (this.hook = options.hook);
|
|
654
|
-
break;
|
|
655
|
-
case 'props':
|
|
656
|
-
if (options.props !== null && typeof options.props === "object") {
|
|
657
|
-
this.props = options.props;
|
|
658
|
-
}
|
|
659
|
-
break;
|
|
660
|
-
case 'data':
|
|
661
|
-
if (options.data !== null && typeof options.data === "object") {
|
|
662
|
-
this.data = options.data;
|
|
663
|
-
}
|
|
664
|
-
break;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
/**设置data属性(更新) */
|
|
669
|
-
setUpdateData(data) {
|
|
670
|
-
data && Object.assign(this.data, data);
|
|
671
|
-
return this;
|
|
672
|
-
}
|
|
673
|
-
/**设置props属性(更新)*/
|
|
674
|
-
setUpdateProps(props) {
|
|
675
|
-
if (!this.props)
|
|
676
|
-
debugger;
|
|
677
|
-
props && Object.assign(this.props, props);
|
|
678
|
-
return this;
|
|
679
|
-
}
|
|
680
|
-
/**从父节点移除并销毁 */
|
|
681
|
-
removeAndDestroy() {
|
|
682
|
-
if (isValid(this?.node)) {
|
|
683
|
-
this.node.removeFromParent();
|
|
684
|
-
this.node.destroy();
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
/**设置坐标 */
|
|
688
|
-
setPosition(positin) {
|
|
689
|
-
this.node.setPosition(positin);
|
|
690
|
-
return this;
|
|
691
|
-
}
|
|
692
|
-
setScale(scale) {
|
|
693
|
-
this.node.setScale(scale);
|
|
694
|
-
return this;
|
|
695
|
-
}
|
|
696
|
-
setAngle(angle) {
|
|
697
|
-
this.node.angle = angle;
|
|
698
|
-
return this;
|
|
699
|
-
}
|
|
700
|
-
setRotation(rotation) {
|
|
701
|
-
this.node.setRotation(rotation);
|
|
702
|
-
return this;
|
|
703
|
-
}
|
|
704
|
-
setRotationFromEuler(rotation) {
|
|
705
|
-
this.node.setRotationFromEuler(rotation);
|
|
706
|
-
return this;
|
|
707
|
-
}
|
|
708
|
-
/**显示(同onEnable) */
|
|
709
|
-
onShow() {
|
|
710
|
-
}
|
|
711
|
-
/**隐藏(同onDisable) */
|
|
712
|
-
onHide() {
|
|
713
|
-
}
|
|
714
|
-
/**设置节点和子节点的层级 */
|
|
715
|
-
setNodeAndChildrenLayer(layer) {
|
|
716
|
-
setNodeAndChildrenLayer(this.node, layer);
|
|
717
|
-
return this;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
/**设置节点及子节点的层级 */
|
|
721
|
-
const setNodeAndChildrenLayer = (node, layer) => {
|
|
722
|
-
node.layer = (typeof layer === 'string' ? 2 ** Layers.nameToLayer(layer) : layer);
|
|
723
|
-
node?.children.forEach(item => {
|
|
724
|
-
setNodeAndChildrenLayer(item, layer);
|
|
725
|
-
});
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* @describe UI层 所有的UI层需继承自该自组件
|
|
730
|
-
* @author 游金宇(KM)
|
|
731
|
-
* @date 2023-08-04 10:42:26
|
|
732
|
-
*/
|
|
733
|
-
class UILayer extends BaseComponent {
|
|
734
|
-
/**上次进入的方向 */
|
|
735
|
-
lastEnterDirection = 'center';
|
|
736
|
-
/**屏幕尺寸 */
|
|
737
|
-
screen;
|
|
738
|
-
/**是否正在关闭 */
|
|
739
|
-
isClosing = false;
|
|
740
|
-
/**组件所在的UI最顶层(不包含UI) */
|
|
741
|
-
root;
|
|
742
|
-
constructor() {
|
|
743
|
-
super();
|
|
744
|
-
this._init();
|
|
745
|
-
}
|
|
746
|
-
_init() {
|
|
747
|
-
this.root = this.node;
|
|
748
|
-
this.screen = view.getVisibleSize();
|
|
749
|
-
}
|
|
750
|
-
// protected onLoad() {
|
|
751
|
-
// // TODO 预留做弹窗动画
|
|
752
|
-
// this.node.addComponent(BlockInputEvents)
|
|
753
|
-
// }
|
|
754
|
-
/**显示动画 */
|
|
755
|
-
async showTween({ isMotion = true, direction = 'center', duration = 0.1, isBounce = true, bounceDuration = 0.05 }) {
|
|
756
|
-
this.lastEnterDirection = direction;
|
|
757
|
-
if (isMotion) {
|
|
758
|
-
const widget = this.node.getComponent(Widget);
|
|
759
|
-
if (widget) {
|
|
760
|
-
widget.updateAlignment();
|
|
761
|
-
widget.enabled = false;
|
|
762
|
-
}
|
|
763
|
-
// 起点坐标
|
|
764
|
-
let start;
|
|
765
|
-
// 终点坐标
|
|
766
|
-
let end;
|
|
767
|
-
// 回弹坐标 TODO
|
|
768
|
-
v3(1.1, 1.1, 1);
|
|
769
|
-
if (direction == 'center') {
|
|
770
|
-
// 从中间放大
|
|
771
|
-
start = v3(0.01, 0.01, 0.01);
|
|
772
|
-
end = v3(1, 1, 1);
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
if (direction == 'left') {
|
|
776
|
-
start = v3(-this.screen.width, 0, 0);
|
|
777
|
-
}
|
|
778
|
-
else if (direction == 'right') {
|
|
779
|
-
start = v3(this.screen.width, 0, 0);
|
|
780
|
-
}
|
|
781
|
-
else if (direction == 'top') {
|
|
782
|
-
start = v3(0, this.screen.height, 0);
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
start = v3(0, -this.screen.height, 0);
|
|
786
|
-
}
|
|
787
|
-
end = v3(0, 0, 0);
|
|
788
|
-
}
|
|
789
|
-
await this.handle(direction, duration, start, end, isBounce);
|
|
790
|
-
if (widget)
|
|
791
|
-
widget.enabled = true;
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
/**隐藏动画 */
|
|
795
|
-
async hideTween({ isMotion = true, direction, duration = 0.1 }) {
|
|
796
|
-
direction = direction || this.lastEnterDirection;
|
|
797
|
-
// 避免重复点击关闭
|
|
798
|
-
if (this.isClosing)
|
|
799
|
-
return;
|
|
800
|
-
this.isClosing = true;
|
|
801
|
-
// 停止当前动画
|
|
802
|
-
tween(this.node).removeSelf();
|
|
803
|
-
if (isMotion) {
|
|
804
|
-
const widget = this.node.getComponent(Widget);
|
|
805
|
-
if (widget)
|
|
806
|
-
widget.enabled = false;
|
|
807
|
-
// 设置起始坐标
|
|
808
|
-
// 起点坐标
|
|
809
|
-
let start;
|
|
810
|
-
// 终点坐标
|
|
811
|
-
let end;
|
|
812
|
-
if (direction == 'center') {
|
|
813
|
-
// 从中间缩小
|
|
814
|
-
start = this.node.scale;
|
|
815
|
-
end = v3(0, 0, 0);
|
|
816
|
-
}
|
|
817
|
-
else {
|
|
818
|
-
if (direction == 'left') {
|
|
819
|
-
end = v3(-this.screen.width, 0, 0);
|
|
820
|
-
}
|
|
821
|
-
else if (direction == 'right') {
|
|
822
|
-
end = v3(this.screen.width, 0, 0);
|
|
823
|
-
}
|
|
824
|
-
else if (direction == 'top') {
|
|
825
|
-
end = v3(0, this.screen.height, 0);
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
end = v3(0, -this.screen.height, 0);
|
|
829
|
-
}
|
|
830
|
-
start = this.node.getPosition();
|
|
831
|
-
}
|
|
832
|
-
await this.handle(direction, duration, start, end, false);
|
|
833
|
-
}
|
|
834
|
-
this.removeAndDestroy();
|
|
835
|
-
}
|
|
836
|
-
async handle(direction, duration, start, end, isBounce) {
|
|
837
|
-
if (direction == 'center') {
|
|
838
|
-
// 从中间放大
|
|
839
|
-
this.node.setScale(start);
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
this.node.setPosition(start);
|
|
843
|
-
}
|
|
844
|
-
await this.deftween(duration, { [direction == 'center' ? 'scale' : 'position']: end }, isBounce);
|
|
845
|
-
}
|
|
846
|
-
deftween(duration, props, isBounce, cb) {
|
|
847
|
-
return new Promise((resolve, reject) => {
|
|
848
|
-
tween(this.node)
|
|
849
|
-
.to(duration, props)
|
|
850
|
-
.call(() => {
|
|
851
|
-
// tween_node.removeSelf();
|
|
852
|
-
resolve();
|
|
853
|
-
})
|
|
854
|
-
.start();
|
|
855
|
-
// if (options.isBounce) {
|
|
856
|
-
// this.node.scale = start;
|
|
857
|
-
// const tween_node = tween(this.node)
|
|
858
|
-
// .to(options.duration, { scale: bounce })
|
|
859
|
-
// .to(options.bounceDuration, { scale: end })
|
|
860
|
-
// .call(() => {
|
|
861
|
-
// tween_node.removeSelf()
|
|
862
|
-
// })
|
|
863
|
-
// .start();
|
|
864
|
-
// }
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/**
|
|
870
|
-
* @describe 音频组件基类
|
|
871
|
-
* @author 游金宇(KM)
|
|
872
|
-
* @date 2023-12-22 16:20:20
|
|
873
|
-
*/
|
|
874
|
-
const { ccclass: ccclass$9, property: property$9 } = _decorator;
|
|
875
|
-
/**
|
|
876
|
-
* EFFECT 音效
|
|
877
|
-
* BGM 音乐
|
|
878
|
-
*/
|
|
879
|
-
var AudioTypeEnum;
|
|
880
|
-
(function (AudioTypeEnum) {
|
|
881
|
-
AudioTypeEnum[AudioTypeEnum["EFFECT"] = 0] = "EFFECT";
|
|
882
|
-
AudioTypeEnum[AudioTypeEnum["BGM"] = 1] = "BGM";
|
|
883
|
-
})(AudioTypeEnum || (AudioTypeEnum = {}));
|
|
884
|
-
class AudioSourceBaseComponent extends BaseComponent {
|
|
885
|
-
type = AudioTypeEnum.EFFECT;
|
|
886
|
-
clip = null;
|
|
887
|
-
loop = false;
|
|
888
|
-
volume = 1;
|
|
889
|
-
playOnAwake = false;
|
|
890
|
-
audioSource = new AudioSource();
|
|
891
|
-
onEnable() {
|
|
892
|
-
super.onEnable();
|
|
893
|
-
this.clip && (this.audioSource.clip = this.clip);
|
|
894
|
-
this.audioSource.loop = this.loop;
|
|
895
|
-
this.audioSource.volume = this.volume;
|
|
896
|
-
this.audioSource.playOnAwake = this.playOnAwake;
|
|
897
|
-
cat.event.on(AudioEventConstant.EFFECT_ON, this.onPlayEffectHandler, this)
|
|
898
|
-
.on(AudioEventConstant.EFFECT_OFF, this.onStopEffectHandler, this)
|
|
899
|
-
.on(AudioEventConstant.MUSIC_ON, this.onPlayMusicHandler, this)
|
|
900
|
-
.on(AudioEventConstant.MUSIC_OFF, this.onStopMusicHandler, this);
|
|
901
|
-
}
|
|
902
|
-
__preload() {
|
|
903
|
-
super.__preload();
|
|
904
|
-
const { volumeEffect, volumeMusic } = cat.audio;
|
|
905
|
-
this.audioSource.volume = this.type === AudioTypeEnum.BGM ? volumeMusic : volumeEffect;
|
|
906
|
-
}
|
|
907
|
-
start() { }
|
|
908
|
-
stopAudio() {
|
|
909
|
-
this.audioSource.stop();
|
|
910
|
-
}
|
|
911
|
-
playAudio() {
|
|
912
|
-
const { switchEffect, switchMusic } = cat.audio;
|
|
913
|
-
// @ts-ignore 保证在游戏运行的时候才播放
|
|
914
|
-
if (!this.audioSource.playing && (this.type === AudioTypeEnum.BGM ? switchMusic : switchEffect) && !game._paused)
|
|
915
|
-
this.audioSource.play();
|
|
916
|
-
}
|
|
917
|
-
onPlayEffectHandler() {
|
|
918
|
-
}
|
|
919
|
-
onStopEffectHandler() {
|
|
920
|
-
this.stopAudio();
|
|
921
|
-
}
|
|
922
|
-
onPlayMusicHandler() {
|
|
923
|
-
}
|
|
924
|
-
onStopMusicHandler() {
|
|
925
|
-
this.stopAudio();
|
|
926
|
-
}
|
|
927
|
-
_onPreDestroy() {
|
|
928
|
-
this.onStopMusicHandler();
|
|
929
|
-
super._onPreDestroy();
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
__decorate([
|
|
933
|
-
property$9({
|
|
934
|
-
tooltip: `类型:
|
|
935
|
-
EFFECT 音效
|
|
936
|
-
BGM 音乐`,
|
|
937
|
-
type: Enum(AudioTypeEnum)
|
|
938
|
-
}),
|
|
939
|
-
__metadata("design:type", Object)
|
|
940
|
-
], AudioSourceBaseComponent.prototype, "type", void 0);
|
|
941
|
-
__decorate([
|
|
942
|
-
property$9({ tooltip: '音源', type: AudioClip }),
|
|
943
|
-
__metadata("design:type", Object)
|
|
944
|
-
], AudioSourceBaseComponent.prototype, "clip", void 0);
|
|
945
|
-
__decorate([
|
|
946
|
-
property$9({ tooltip: '循环' }),
|
|
947
|
-
__metadata("design:type", Object)
|
|
948
|
-
], AudioSourceBaseComponent.prototype, "loop", void 0);
|
|
949
|
-
__decorate([
|
|
950
|
-
property$9({ tooltip: '音量' }),
|
|
951
|
-
__metadata("design:type", Object)
|
|
952
|
-
], AudioSourceBaseComponent.prototype, "volume", void 0);
|
|
953
|
-
__decorate([
|
|
954
|
-
property$9({ tooltip: '是否启用自动播放' }),
|
|
955
|
-
__metadata("design:type", Object)
|
|
956
|
-
], AudioSourceBaseComponent.prototype, "playOnAwake", void 0);
|
|
957
|
-
|
|
958
|
-
const { ccclass: ccclass$8, property: property$8 } = _decorator;
|
|
959
|
-
/**带有音频通道的UIlayer组件 */
|
|
960
|
-
class AudioSourceUILayer extends UILayer {
|
|
961
|
-
type = AudioTypeEnum.EFFECT;
|
|
962
|
-
clip = null;
|
|
963
|
-
loop = false;
|
|
964
|
-
volume = 1;
|
|
965
|
-
playOnAwake = false;
|
|
966
|
-
audioSource = new AudioSource();
|
|
967
|
-
onEnable() {
|
|
968
|
-
super.onEnable();
|
|
969
|
-
cat.event.on(AudioEventConstant.EFFECT_ON, this.onPlayEffectHandler, this)
|
|
970
|
-
.on(AudioEventConstant.EFFECT_OFF, this.onStopEffectHandler, this)
|
|
971
|
-
.on(AudioEventConstant.MUSIC_ON, this.onPlayMusicHandler, this)
|
|
972
|
-
.on(AudioEventConstant.MUSIC_OFF, this.onStopMusicHandler, this);
|
|
973
|
-
}
|
|
974
|
-
__preload() {
|
|
975
|
-
this.clip && (this.audioSource.clip = this.clip);
|
|
976
|
-
this.audioSource.loop = this.loop;
|
|
977
|
-
this.audioSource.volume = this.volume;
|
|
978
|
-
this.audioSource.playOnAwake = this.playOnAwake;
|
|
979
|
-
super.__preload();
|
|
980
|
-
const { volumeEffect, volumeMusic } = cat.audio;
|
|
981
|
-
this.audioSource.volume = this.type === AudioTypeEnum.BGM ? volumeMusic : volumeEffect;
|
|
982
|
-
}
|
|
983
|
-
stopAudio() {
|
|
984
|
-
this.audioSource.stop();
|
|
985
|
-
}
|
|
986
|
-
playAudio() {
|
|
987
|
-
const { switchEffect, switchMusic } = cat.audio;
|
|
988
|
-
// @ts-ignore 保证在游戏运行的时候才播放
|
|
989
|
-
if (!this.audioSource.playing && (this.type === AudioTypeEnum.BGM ? switchMusic : switchEffect) && !game._paused)
|
|
990
|
-
this.audioSource.play();
|
|
991
|
-
}
|
|
992
|
-
onPlayEffectHandler() {
|
|
993
|
-
}
|
|
994
|
-
onStopEffectHandler() {
|
|
995
|
-
this.stopAudio();
|
|
996
|
-
}
|
|
997
|
-
onPlayMusicHandler() {
|
|
998
|
-
}
|
|
999
|
-
onStopMusicHandler() {
|
|
1000
|
-
this.stopAudio();
|
|
1001
|
-
}
|
|
1002
|
-
_onPreDestroy() {
|
|
1003
|
-
this.onStopMusicHandler();
|
|
1004
|
-
super._onPreDestroy();
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
__decorate([
|
|
1008
|
-
property$8({
|
|
1009
|
-
tooltip: `类型:
|
|
1010
|
-
EFFECT 音效
|
|
1011
|
-
BGM 音乐`,
|
|
1012
|
-
type: Enum(AudioTypeEnum)
|
|
1013
|
-
}),
|
|
1014
|
-
__metadata("design:type", Object)
|
|
1015
|
-
], AudioSourceUILayer.prototype, "type", void 0);
|
|
1016
|
-
__decorate([
|
|
1017
|
-
property$8({ tooltip: '音源', type: AudioClip }),
|
|
1018
|
-
__metadata("design:type", Object)
|
|
1019
|
-
], AudioSourceUILayer.prototype, "clip", void 0);
|
|
1020
|
-
__decorate([
|
|
1021
|
-
property$8({ tooltip: '循环' }),
|
|
1022
|
-
__metadata("design:type", Object)
|
|
1023
|
-
], AudioSourceUILayer.prototype, "loop", void 0);
|
|
1024
|
-
__decorate([
|
|
1025
|
-
property$8({ tooltip: '音量' }),
|
|
1026
|
-
__metadata("design:type", Object)
|
|
1027
|
-
], AudioSourceUILayer.prototype, "volume", void 0);
|
|
1028
|
-
__decorate([
|
|
1029
|
-
property$8({ tooltip: '是否启用自动播放' }),
|
|
1030
|
-
__metadata("design:type", Object)
|
|
1031
|
-
], AudioSourceUILayer.prototype, "playOnAwake", void 0);
|
|
1032
|
-
|
|
1033
|
-
/**
|
|
1034
|
-
* @describe TOAST弹窗组件
|
|
1035
|
-
* @author 游金宇(KM)
|
|
1036
|
-
* @date 2024-09-12 11:42:29
|
|
1037
|
-
*/
|
|
1038
|
-
const { ccclass: ccclass$7, property: property$7 } = _decorator;
|
|
1039
|
-
var ToastType;
|
|
1040
|
-
(function (ToastType) {
|
|
1041
|
-
ToastType[ToastType["FIXED"] = 0] = "FIXED";
|
|
1042
|
-
ToastType[ToastType["SLIDE"] = 1] = "SLIDE";
|
|
1043
|
-
})(ToastType || (ToastType = {}));
|
|
1044
|
-
let CoreToast = class CoreToast extends BaseComponent {
|
|
1045
|
-
fixed_node;
|
|
1046
|
-
slide_node;
|
|
1047
|
-
fixed_label;
|
|
1048
|
-
slide_label;
|
|
1049
|
-
onLoad() {
|
|
1050
|
-
this.fixed_node.active = this.slide_node.active = false;
|
|
1051
|
-
}
|
|
1052
|
-
start() {
|
|
1053
|
-
this.show();
|
|
1054
|
-
}
|
|
1055
|
-
async show() {
|
|
1056
|
-
return new Promise(async (resolve, _reject) => {
|
|
1057
|
-
const { title, type, fixed_time } = this.props;
|
|
1058
|
-
if (type == ToastType.FIXED) {
|
|
1059
|
-
this.fixed_node.active = true;
|
|
1060
|
-
this.fixed_label.string = `${title}`;
|
|
1061
|
-
// v2.4
|
|
1062
|
-
// this.fixed_label['_forceUpdateRenderData'](true);
|
|
1063
|
-
// v3.0
|
|
1064
|
-
this.fixed_label.updateRenderData(true);
|
|
1065
|
-
const fixed_label_height = this.fixed_label.node.getComponent(UITransform).height;
|
|
1066
|
-
const fixed_node_height = this.fixed_node.getComponent(UITransform).height;
|
|
1067
|
-
if (fixed_label_height - fixed_node_height > 0) {
|
|
1068
|
-
this.fixed_node.getComponent(UITransform).height = fixed_label_height + 100;
|
|
1069
|
-
}
|
|
1070
|
-
this.scheduleOnce(() => {
|
|
1071
|
-
this.node.destroy();
|
|
1072
|
-
resolve();
|
|
1073
|
-
}, fixed_time);
|
|
1074
|
-
}
|
|
1075
|
-
else {
|
|
1076
|
-
this.slide_node.active = true;
|
|
1077
|
-
this.slide_label.string = `${title}`;
|
|
1078
|
-
// v2.4
|
|
1079
|
-
// this.slide_label['_forceUpdateRenderData'](true);
|
|
1080
|
-
// v3.0
|
|
1081
|
-
this.slide_label.updateRenderData(true);
|
|
1082
|
-
const deslabelW = this.slide_label.node.getComponent(UITransform).width;
|
|
1083
|
-
const bgw = this.slide_node.getComponent(UITransform).width;
|
|
1084
|
-
if (bgw - deslabelW < 100) {
|
|
1085
|
-
this.slide_node.getComponent(UITransform).width = deslabelW + 100;
|
|
1086
|
-
}
|
|
1087
|
-
this.playAnim(this.node).then(() => {
|
|
1088
|
-
resolve();
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
playAnim(node) {
|
|
1094
|
-
return new Promise((resolve, reject) => {
|
|
1095
|
-
const delay = 1.2;
|
|
1096
|
-
const duration = 0.5;
|
|
1097
|
-
const uiOpacity = this.node.getComponent(UIOpacity);
|
|
1098
|
-
const uiOpacityTween = tween(uiOpacity)
|
|
1099
|
-
.delay(delay)
|
|
1100
|
-
.to(duration, { opacity: 0 })
|
|
1101
|
-
.call(() => {
|
|
1102
|
-
Tween.stopAllByTarget(node);
|
|
1103
|
-
this.node.destroy();
|
|
1104
|
-
resolve();
|
|
1105
|
-
});
|
|
1106
|
-
tween(node)
|
|
1107
|
-
.by(duration, { position: v3(0, 400, 0) })
|
|
1108
|
-
.call(() => {
|
|
1109
|
-
uiOpacityTween.start();
|
|
1110
|
-
})
|
|
1111
|
-
.start();
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
onDestroy() {
|
|
1115
|
-
Tween.stopAllByTarget(this.node);
|
|
1116
|
-
this.unscheduleAllCallbacks();
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
|
-
__decorate([
|
|
1120
|
-
property$7({ type: Node, tooltip: '固定节点' }),
|
|
1121
|
-
__metadata("design:type", Node)
|
|
1122
|
-
], CoreToast.prototype, "fixed_node", void 0);
|
|
1123
|
-
__decorate([
|
|
1124
|
-
property$7({ type: Node, tooltip: '滑动节点' }),
|
|
1125
|
-
__metadata("design:type", Node)
|
|
1126
|
-
], CoreToast.prototype, "slide_node", void 0);
|
|
1127
|
-
__decorate([
|
|
1128
|
-
property$7({ type: Label, tooltip: '固定标签节点' }),
|
|
1129
|
-
__metadata("design:type", Label)
|
|
1130
|
-
], CoreToast.prototype, "fixed_label", void 0);
|
|
1131
|
-
__decorate([
|
|
1132
|
-
property$7({ type: Label, tooltip: '滑动标签节点' }),
|
|
1133
|
-
__metadata("design:type", Label)
|
|
1134
|
-
], CoreToast.prototype, "slide_label", void 0);
|
|
1135
|
-
CoreToast = __decorate([
|
|
1136
|
-
ccclass$7('CoreToast')
|
|
1137
|
-
], CoreToast);
|
|
1138
|
-
|
|
1139
|
-
/**
|
|
1140
|
-
* @describe 全局事件监听方法
|
|
1141
|
-
* @author 游金宇(KM)
|
|
1142
|
-
* @date 2023-08-03 18:13:36
|
|
1143
|
-
*/
|
|
1144
|
-
var GlobalEventConstant;
|
|
1145
|
-
(function (GlobalEventConstant) {
|
|
1146
|
-
/** 游戏从后台进入 */
|
|
1147
|
-
GlobalEventConstant["EVENT_SHOW"] = "GlobalEventConstant/EVENT_SHOW";
|
|
1148
|
-
/** 游戏切到后台 */
|
|
1149
|
-
GlobalEventConstant["EVENT_HIDE"] = "GlobalEventConstant/EVENT_HIDE";
|
|
1150
|
-
/** 游戏画笔尺寸变化事件 */
|
|
1151
|
-
GlobalEventConstant["GAME_RESIZE"] = "GlobalEventConstant/GAME_RESIZE";
|
|
1152
|
-
/**游戏关闭时间 */
|
|
1153
|
-
GlobalEventConstant["EVENT_CLOSE"] = "GlobalEventConstant/EVENT_CLOSE";
|
|
1154
|
-
/**网络连接 */
|
|
1155
|
-
GlobalEventConstant["ONLINE"] = "GlobalEventConstant/ONLINE";
|
|
1156
|
-
/**网络断开 */
|
|
1157
|
-
GlobalEventConstant["OFFLINE"] = "GlobalEventConstant/OFFLINE";
|
|
1158
|
-
/**ROOT_MASK更新 */
|
|
1159
|
-
GlobalEventConstant["ROOT_MASK_UPDATE"] = "GlobalEventConstant/ROOT_MASK_UPDATE";
|
|
1160
|
-
/**ROOT_MASK更新变化 */
|
|
1161
|
-
GlobalEventConstant["ROOT_MASK_CHANGE"] = "GlobalEventConstant/ROOT_MASK_CHANGE";
|
|
1162
|
-
})(GlobalEventConstant || (GlobalEventConstant = {}));
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* @describe UI容器管理 在场景节点下 会随着场景销毁(非常驻节点)
|
|
1166
|
-
* @author 游金宇(KM)
|
|
1167
|
-
* @date 2024-09-12 11:45:31
|
|
1168
|
-
*/
|
|
1169
|
-
const { ccclass: ccclass$6, property: property$6 } = _decorator;
|
|
1170
|
-
let CoreUIContainer = class CoreUIContainer extends UILayer {
|
|
1171
|
-
scene_mask_node;
|
|
1172
|
-
ui_container;
|
|
1173
|
-
gui = null;
|
|
1174
|
-
onLoad() {
|
|
1175
|
-
this.setSceneMaskActive(false);
|
|
1176
|
-
}
|
|
1177
|
-
get scene_mask() {
|
|
1178
|
-
return this.scene_mask_node.getComponent(CoreBlackMask);
|
|
1179
|
-
}
|
|
1180
|
-
get brother() {
|
|
1181
|
-
return this.ui_container.children || [];
|
|
1182
|
-
}
|
|
1183
|
-
get tweenChildren() {
|
|
1184
|
-
return this.scene_mask.tween.children;
|
|
1185
|
-
}
|
|
1186
|
-
onEventListener() {
|
|
1187
|
-
cat.event.on(GlobalEventConstant.ROOT_MASK_CHANGE, this.uiMaskChanged, this);
|
|
1188
|
-
}
|
|
1189
|
-
/**增加层级 */
|
|
1190
|
-
addMask() {
|
|
1191
|
-
const last = this.brother[this.brother.length - 1];
|
|
1192
|
-
last && this.scene_mask.node.setSiblingIndex(last.getSiblingIndex());
|
|
1193
|
-
this.blockMaskSiblingIndexChanged();
|
|
1194
|
-
}
|
|
1195
|
-
/**减少层级 */
|
|
1196
|
-
subMask() {
|
|
1197
|
-
const last = this.brother[this.brother.length - 2];
|
|
1198
|
-
last && this.scene_mask.node.setSiblingIndex(last.getSiblingIndex());
|
|
1199
|
-
this.blockMaskSiblingIndexChanged();
|
|
1200
|
-
}
|
|
1201
|
-
blockMaskSiblingIndexChanged() {
|
|
1202
|
-
(this.tweenChildren.length > 1 || this.brother.length > 1) ? this.show() : this.hide();
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* 将UI节点挂载在tween上执行动画
|
|
1206
|
-
* @param node 节点
|
|
1207
|
-
*/
|
|
1208
|
-
addNodeToTween(node) {
|
|
1209
|
-
if (isValid(this) && this.scene_mask) {
|
|
1210
|
-
this.scene_mask.tween.addChild(node);
|
|
1211
|
-
}
|
|
1212
|
-
return this;
|
|
1213
|
-
}
|
|
1214
|
-
show() {
|
|
1215
|
-
this.setSceneMaskActive(true);
|
|
1216
|
-
}
|
|
1217
|
-
hide() {
|
|
1218
|
-
this.setSceneMaskActive(false);
|
|
1219
|
-
}
|
|
1220
|
-
setGui(gui) {
|
|
1221
|
-
this.gui = gui;
|
|
1222
|
-
return this;
|
|
1223
|
-
}
|
|
1224
|
-
/**根层的变化 */
|
|
1225
|
-
uiMaskChanged() {
|
|
1226
|
-
this.blockMaskSiblingIndexChanged();
|
|
1227
|
-
}
|
|
1228
|
-
setSceneMaskActive(active) {
|
|
1229
|
-
this.scene_mask.node.active = this.gui.root_mask.active ? false : active;
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
|
-
__decorate([
|
|
1233
|
-
property$6({ type: Node }),
|
|
1234
|
-
__metadata("design:type", Node)
|
|
1235
|
-
], CoreUIContainer.prototype, "scene_mask_node", void 0);
|
|
1236
|
-
__decorate([
|
|
1237
|
-
property$6({ type: Node }),
|
|
1238
|
-
__metadata("design:type", Node)
|
|
1239
|
-
], CoreUIContainer.prototype, "ui_container", void 0);
|
|
1240
|
-
CoreUIContainer = __decorate([
|
|
1241
|
-
ccclass$6('CoreUIContainer')
|
|
1242
|
-
], CoreUIContainer);
|
|
1243
|
-
|
|
1244
|
-
/**
|
|
1245
|
-
* @describe 根级别的UI层 所有的ROOT UI层需继承自该自组件
|
|
1246
|
-
* @author 游金宇(KM)
|
|
1247
|
-
* @date 2023-08-04 10:42:26
|
|
1248
|
-
*/
|
|
1249
|
-
class RootUILayer extends UILayer {
|
|
1250
|
-
onEnable() {
|
|
1251
|
-
super.onEnable();
|
|
1252
|
-
this.updateMask();
|
|
1253
|
-
}
|
|
1254
|
-
onDisable() {
|
|
1255
|
-
super.onDisable();
|
|
1256
|
-
this.updateMask();
|
|
1257
|
-
}
|
|
1258
|
-
updateMask() {
|
|
1259
|
-
cat.event.dispatchEvent(GlobalEventConstant.ROOT_MASK_UPDATE);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
const { ccclass: ccclass$5, property: property$5 } = _decorator;
|
|
1264
|
-
/**
|
|
1265
|
-
* @describe 加载框
|
|
1266
|
-
* @author 游金宇(KM)
|
|
1267
|
-
* @date 2024-09-12 11:49:51
|
|
1268
|
-
*/
|
|
1269
|
-
let CoreShowLoading = class CoreShowLoading extends RootUILayer {
|
|
1270
|
-
title;
|
|
1271
|
-
loadingTween;
|
|
1272
|
-
// @property({ type: Node, tooltip: '遮罩' })
|
|
1273
|
-
// black: Node
|
|
1274
|
-
loading_rotate = 0;
|
|
1275
|
-
onAutoObserver() {
|
|
1276
|
-
this.addAutorun([
|
|
1277
|
-
() => {
|
|
1278
|
-
if (this.props?.title) {
|
|
1279
|
-
this.title.string = `${this.props?.title}`;
|
|
1280
|
-
}
|
|
1281
|
-
this.title.node.active = !!(this.props?.title?.length);
|
|
1282
|
-
},
|
|
1283
|
-
() => {
|
|
1284
|
-
this.getComponent(BlockInputEvents).enabled = !!(this.props?.mask);
|
|
1285
|
-
}
|
|
1286
|
-
]);
|
|
1287
|
-
}
|
|
1288
|
-
update(deltaTime) {
|
|
1289
|
-
this.loading_rotate += deltaTime * 220;
|
|
1290
|
-
this.loadingTween.setRotationFromEuler(0, 0, -this.loading_rotate % 360);
|
|
1291
|
-
if (this.loading_rotate > 360) {
|
|
1292
|
-
this.loading_rotate -= 360;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
__decorate([
|
|
1297
|
-
property$5({ type: Label, tooltip: '标题' }),
|
|
1298
|
-
__metadata("design:type", Label)
|
|
1299
|
-
], CoreShowLoading.prototype, "title", void 0);
|
|
1300
|
-
__decorate([
|
|
1301
|
-
property$5({ type: Node, tooltip: '动画' }),
|
|
1302
|
-
__metadata("design:type", Node
|
|
1303
|
-
// @property({ type: Node, tooltip: '遮罩' })
|
|
1304
|
-
// black: Node
|
|
1305
|
-
)
|
|
1306
|
-
], CoreShowLoading.prototype, "loadingTween", void 0);
|
|
1307
|
-
CoreShowLoading = __decorate([
|
|
1308
|
-
ccclass$5('CoreShowLoading')
|
|
1309
|
-
], CoreShowLoading);
|
|
1310
|
-
|
|
1311
|
-
const { ccclass: ccclass$4, property: property$4 } = _decorator;
|
|
1312
|
-
var ReconnectPrompt;
|
|
1313
|
-
(function (ReconnectPrompt) {
|
|
1314
|
-
ReconnectPrompt["RECONNECTED"] = "\u91CD\u8FDE\u6210\u529F";
|
|
1315
|
-
ReconnectPrompt["RECONNECTING"] = "\u6B63\u5728\u91CD\u8FDE";
|
|
1316
|
-
ReconnectPrompt["MAX_RECONNECT"] = "\u91CD\u8FDE\u6B21\u6570\u8D85\u51FA\u9650\u5236,\u8BF7\u68C0\u67E5\u7F51\u7EDC";
|
|
1317
|
-
ReconnectPrompt["RECONNECTED_ERROR"] = "\u91CD\u8FDE\u5931\u8D25,\u8BF7\u68C0\u67E5\u7F51\u7EDC";
|
|
1318
|
-
ReconnectPrompt["CONNECT_PARAM_ERROR"] = "\u6E38\u620F\u53C2\u6570\u9519\u8BEF,\u8BF7\u91CD\u65B0\u52A0\u8F7D";
|
|
1319
|
-
ReconnectPrompt["KICK"] = "\u8D26\u53F7\u5DF2\u4E0B\u7EBF";
|
|
1320
|
-
ReconnectPrompt["OFFLINE"] = "\u7F51\u7EDC\u5DF2\u65AD\u5F00";
|
|
1321
|
-
ReconnectPrompt["ONLINE"] = "\u7F51\u7EDC\u5DF2\u8FDE\u63A5";
|
|
1322
|
-
ReconnectPrompt["GAME_ERROR"] = "\u8FDE\u63A5\u6E38\u620F\u670D\u9519\u8BEF";
|
|
1323
|
-
})(ReconnectPrompt || (ReconnectPrompt = {}));
|
|
1324
|
-
/**
|
|
1325
|
-
* @describe 重连框
|
|
1326
|
-
* @author 游金宇(KM)
|
|
1327
|
-
* @date 2024-09-12 11:49:51
|
|
1328
|
-
*/
|
|
1329
|
-
let CoreReconnection = class CoreReconnection extends RootUILayer {
|
|
1330
|
-
common_prompt_text;
|
|
1331
|
-
btn_confirm;
|
|
1332
|
-
is_close = false;
|
|
1333
|
-
props = {
|
|
1334
|
-
content: null
|
|
1335
|
-
};
|
|
1336
|
-
initUI() {
|
|
1337
|
-
this.btn_confirm.node.active = false;
|
|
1338
|
-
}
|
|
1339
|
-
onLoad() {
|
|
1340
|
-
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfirmHandler, this);
|
|
1341
|
-
this.addAutorun([
|
|
1342
|
-
() => {
|
|
1343
|
-
this.common_prompt_text.string = this.props.content ?? '';
|
|
1344
|
-
}
|
|
1345
|
-
]);
|
|
1346
|
-
}
|
|
1347
|
-
onDestroy() {
|
|
1348
|
-
this.unscheduleAllCallbacks();
|
|
1349
|
-
// this.is_close && cat.platform.back()
|
|
1350
|
-
}
|
|
1351
|
-
updateProps(props) {
|
|
1352
|
-
this.updatePromptText(props, props == ReconnectPrompt.RECONNECTING);
|
|
1353
|
-
}
|
|
1354
|
-
/**更新提示文案 */
|
|
1355
|
-
updatePromptText(text, isAnim = false) {
|
|
1356
|
-
// 停止之前的动画效果
|
|
1357
|
-
this.unscheduleAllCallbacks();
|
|
1358
|
-
this.props.content = text;
|
|
1359
|
-
log('更新提示文案:', text);
|
|
1360
|
-
// 如果需要应用动画效果
|
|
1361
|
-
if (isAnim) {
|
|
1362
|
-
let index = 0;
|
|
1363
|
-
const updateText = () => {
|
|
1364
|
-
index = (index + 1) % 4;
|
|
1365
|
-
this.common_prompt_text.string = text + ['', '·', '··', '···'][index];
|
|
1366
|
-
};
|
|
1367
|
-
this.schedule(updateText, 0.5);
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
onConfirmHandler() {
|
|
1371
|
-
this.is_close = true;
|
|
1372
|
-
// 销毁ws
|
|
1373
|
-
// cat.ws.destroy()
|
|
1374
|
-
// gui.close(this)
|
|
1375
|
-
cat.gui.hideReconnect();
|
|
1376
|
-
}
|
|
1377
|
-
};
|
|
1378
|
-
__decorate([
|
|
1379
|
-
property$4({ type: Label, tooltip: '通用提示文本' }),
|
|
1380
|
-
__metadata("design:type", Label)
|
|
1381
|
-
], CoreReconnection.prototype, "common_prompt_text", void 0);
|
|
1382
|
-
__decorate([
|
|
1383
|
-
property$4({ type: Button, tooltip: '确定按钮' }),
|
|
1384
|
-
__metadata("design:type", Button)
|
|
1385
|
-
], CoreReconnection.prototype, "btn_confirm", void 0);
|
|
1386
|
-
CoreReconnection = __decorate([
|
|
1387
|
-
ccclass$4('CoreReconnection')
|
|
1388
|
-
], CoreReconnection);
|
|
1389
|
-
|
|
1390
|
-
const { ccclass: ccclass$3, property: property$3 } = _decorator;
|
|
1391
|
-
/**
|
|
1392
|
-
* @describe 通知框
|
|
1393
|
-
* @author 游金宇(KM)
|
|
1394
|
-
* @date 2024-09-12 11:49:51
|
|
1395
|
-
*/
|
|
1396
|
-
let CoreNotice = class CoreNotice extends RootUILayer {
|
|
1397
|
-
text;
|
|
1398
|
-
btn_confirm;
|
|
1399
|
-
onLoad() {
|
|
1400
|
-
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfrimHandler, this);
|
|
1401
|
-
}
|
|
1402
|
-
start() {
|
|
1403
|
-
this.props && this.updateProps(this.props);
|
|
1404
|
-
}
|
|
1405
|
-
onConfrimHandler() {
|
|
1406
|
-
this.props?.confrim?.();
|
|
1407
|
-
cat.gui.hideNotice();
|
|
1408
|
-
}
|
|
1409
|
-
updateProps(props) {
|
|
1410
|
-
this.text.string = `${props.text}`;
|
|
1411
|
-
}
|
|
1412
|
-
};
|
|
1413
|
-
__decorate([
|
|
1414
|
-
property$3({ type: Label, tooltip: '提示文本' }),
|
|
1415
|
-
__metadata("design:type", Label)
|
|
1416
|
-
], CoreNotice.prototype, "text", void 0);
|
|
1417
|
-
__decorate([
|
|
1418
|
-
property$3({ type: Button, tooltip: '确定按钮' }),
|
|
1419
|
-
__metadata("design:type", Button)
|
|
1420
|
-
], CoreNotice.prototype, "btn_confirm", void 0);
|
|
1421
|
-
CoreNotice = __decorate([
|
|
1422
|
-
ccclass$3('CoreNotice')
|
|
1423
|
-
], CoreNotice);
|
|
1424
|
-
|
|
1425
|
-
/**
|
|
1426
|
-
* @describe Scene层 所有的UI层需继承自该自组件
|
|
1427
|
-
* @author 游金宇(KM)
|
|
1428
|
-
* @date 2023-08-04 10:42:26
|
|
1429
|
-
*/
|
|
1430
|
-
class SceneLayer extends BaseComponent {
|
|
1431
|
-
/**是否为重新加载场景 */
|
|
1432
|
-
isReload;
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
/**
|
|
1436
|
-
* @describe GUI组件类
|
|
1437
|
-
* @author 游金宇(KM)
|
|
1438
|
-
* @date 2024-09-12 11:46:22
|
|
1439
|
-
*/
|
|
1440
|
-
const { ccclass: ccclass$2, property: property$2 } = _decorator;
|
|
1441
|
-
var LayerType;
|
|
1442
|
-
(function (LayerType) {
|
|
1443
|
-
LayerType[LayerType["UI"] = 0] = "UI";
|
|
1444
|
-
/**加载 */
|
|
1445
|
-
LayerType[LayerType["LOADING"] = 1] = "LOADING";
|
|
1446
|
-
/**提示 */
|
|
1447
|
-
LayerType[LayerType["TOAST"] = 2] = "TOAST";
|
|
1448
|
-
/**断线重连 */
|
|
1449
|
-
LayerType[LayerType["RECONNECTTION"] = 3] = "RECONNECTTION";
|
|
1450
|
-
/**系统服务通知(停机维护) */
|
|
1451
|
-
LayerType[LayerType["NOTICE"] = 4] = "NOTICE";
|
|
1452
|
-
})(LayerType || (LayerType = {}));
|
|
1453
|
-
/**Gui层 */
|
|
1454
|
-
let Gui = class Gui extends BaseComponent {
|
|
1455
|
-
reconnection_ui_prefab;
|
|
1456
|
-
toast_ui_prefab;
|
|
1457
|
-
loading_ui_prefab;
|
|
1458
|
-
notice_ui_prefab;
|
|
1459
|
-
ui_prefab;
|
|
1460
|
-
root_ui;
|
|
1461
|
-
root_toast;
|
|
1462
|
-
root_mask;
|
|
1463
|
-
cat;
|
|
1464
|
-
/**场景中的UI层 */
|
|
1465
|
-
ui_container_component;
|
|
1466
|
-
/**断线重连UI弹窗 */
|
|
1467
|
-
reconnection_ui_component;
|
|
1468
|
-
/**公告UI弹窗组件 */
|
|
1469
|
-
notice_ui_component;
|
|
1470
|
-
/**加载UI弹窗 */
|
|
1471
|
-
loading_ui_component;
|
|
1472
|
-
/**提示UI弹窗 */
|
|
1473
|
-
toast_ui_component;
|
|
1474
|
-
/**当前场景对象名 */
|
|
1475
|
-
currentScene;
|
|
1476
|
-
onEventListener() {
|
|
1477
|
-
this.cat.event.on(GlobalEventConstant.ROOT_MASK_UPDATE, this.onRootUpdate, this);
|
|
1478
|
-
}
|
|
1479
|
-
init(cat) {
|
|
1480
|
-
this.cat = cat;
|
|
1481
|
-
const scene = director.getScene();
|
|
1482
|
-
log('init scene');
|
|
1483
|
-
scene && this.changeScene(scene);
|
|
1484
|
-
return this;
|
|
1485
|
-
}
|
|
1486
|
-
start() {
|
|
1487
|
-
this.onRootUpdate();
|
|
1488
|
-
}
|
|
1489
|
-
toastQueue = [];
|
|
1490
|
-
isScheduling = false; // 新增调度锁
|
|
1491
|
-
minInterval = 0.2; // 改为秒单位,与scheduleOnce一致
|
|
1492
|
-
showToast(props) {
|
|
1493
|
-
this.toastQueue.push(props);
|
|
1494
|
-
if (!this.isScheduling) {
|
|
1495
|
-
this.processQueueWithInterval();
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
processQueueWithInterval() {
|
|
1499
|
-
if (this.toastQueue.length === 0) {
|
|
1500
|
-
this.isScheduling = false;
|
|
1501
|
-
return;
|
|
1502
|
-
}
|
|
1503
|
-
this.isScheduling = true;
|
|
1504
|
-
const props = this.toastQueue.shift();
|
|
1505
|
-
// 实际显示逻辑
|
|
1506
|
-
const show = () => {
|
|
1507
|
-
const node = instantiate(this.toast_ui_prefab);
|
|
1508
|
-
const toastComponent = node.getComponent(CoreToast);
|
|
1509
|
-
toastComponent.addToParent(this.root_toast, { props });
|
|
1510
|
-
// 使用游戏时间计算下一个
|
|
1511
|
-
this.scheduleOnce(() => {
|
|
1512
|
-
this.processQueueWithInterval();
|
|
1513
|
-
}, this.minInterval);
|
|
1514
|
-
};
|
|
1515
|
-
// 立即显示第一个
|
|
1516
|
-
if (this.root_toast.children.length === 0) {
|
|
1517
|
-
show();
|
|
1518
|
-
}
|
|
1519
|
-
else {
|
|
1520
|
-
this.scheduleOnce(show, this.minInterval);
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
/** 隐藏并清除所有提示 */
|
|
1524
|
-
hideToast() {
|
|
1525
|
-
// 1. 销毁正在显示的Toast
|
|
1526
|
-
if (this.root_toast) {
|
|
1527
|
-
this.root_toast.children.forEach(child => {
|
|
1528
|
-
child.getComponent(CoreToast)?.removeAndDestroy();
|
|
1529
|
-
});
|
|
1530
|
-
}
|
|
1531
|
-
// 2. 清空等待队列
|
|
1532
|
-
this.toastQueue = [];
|
|
1533
|
-
// 3. 取消预定的队列处理
|
|
1534
|
-
this.unschedule(this.processQueueWithInterval);
|
|
1535
|
-
this.isScheduling = false;
|
|
1536
|
-
return this;
|
|
1537
|
-
}
|
|
1538
|
-
/**显示Loading */
|
|
1539
|
-
showLoading({ title = '', mask = true, black = true } = {}) {
|
|
1540
|
-
log('showLoading', title);
|
|
1541
|
-
if (this.loading_ui_component) {
|
|
1542
|
-
this.loading_ui_component.setOptions({
|
|
1543
|
-
props: {
|
|
1544
|
-
title,
|
|
1545
|
-
mask,
|
|
1546
|
-
black
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
}
|
|
1550
|
-
else {
|
|
1551
|
-
const node = instantiate(this.loading_ui_prefab);
|
|
1552
|
-
this.loading_ui_component = node.getComponent(CoreShowLoading).addToParent(this.root_ui, {
|
|
1553
|
-
props: {
|
|
1554
|
-
title,
|
|
1555
|
-
mask,
|
|
1556
|
-
black
|
|
1557
|
-
}
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
return this;
|
|
1561
|
-
}
|
|
1562
|
-
/**隐藏Loading */
|
|
1563
|
-
hideLoading() {
|
|
1564
|
-
this.loading_ui_component?.removeAndDestroy();
|
|
1565
|
-
this.loading_ui_component = null;
|
|
1566
|
-
return this;
|
|
1567
|
-
}
|
|
1568
|
-
/**
|
|
1569
|
-
* 显示断线重连
|
|
1570
|
-
* @param option 状态提示文案
|
|
1571
|
-
*/
|
|
1572
|
-
showReconnect(option) {
|
|
1573
|
-
if (!this.reconnection_ui_component) {
|
|
1574
|
-
const node = instantiate(this.reconnection_ui_prefab);
|
|
1575
|
-
this.reconnection_ui_component = node.getComponent(CoreReconnection).addToParent(this.root_ui, {
|
|
1576
|
-
props: {
|
|
1577
|
-
content: option
|
|
1578
|
-
}
|
|
1579
|
-
});
|
|
1580
|
-
}
|
|
1581
|
-
else {
|
|
1582
|
-
this.reconnection_ui_component.setUpdateProps({
|
|
1583
|
-
content: option
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
return this;
|
|
1587
|
-
}
|
|
1588
|
-
/**隐藏断线重连 */
|
|
1589
|
-
hideReconnect() {
|
|
1590
|
-
this.reconnection_ui_component?.removeAndDestroy();
|
|
1591
|
-
this.reconnection_ui_component = null;
|
|
1592
|
-
return this;
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* 显示公告
|
|
1596
|
-
* @param option 参数
|
|
1597
|
-
*/
|
|
1598
|
-
showNotice(option) {
|
|
1599
|
-
const node = instantiate(this.notice_ui_prefab);
|
|
1600
|
-
this.notice_ui_component = node.getComponent(CoreNotice).addToParent(this.root_ui, { props: option });
|
|
1601
|
-
return this;
|
|
1602
|
-
}
|
|
1603
|
-
/**隐藏公告 */
|
|
1604
|
-
hideNotice() {
|
|
1605
|
-
this.notice_ui_component?.removeAndDestroy();
|
|
1606
|
-
return this;
|
|
1607
|
-
}
|
|
1608
|
-
// 方法实现
|
|
1609
|
-
loadScene(sceneName, options, isReload) {
|
|
1610
|
-
log('加载场景', sceneName, options, isReload);
|
|
1611
|
-
let _options = {};
|
|
1612
|
-
let _isReload = isReload ?? false;
|
|
1613
|
-
if (typeof options === 'boolean') {
|
|
1614
|
-
_isReload = options;
|
|
1615
|
-
}
|
|
1616
|
-
else {
|
|
1617
|
-
_options = options ?? {};
|
|
1618
|
-
}
|
|
1619
|
-
log('当前场景', director.getScene()?.uuid, director.getScene()?.name);
|
|
1620
|
-
director.once(Director.EVENT_BEFORE_SCENE_LAUNCH, (scene) => {
|
|
1621
|
-
log('Director.EVENT_BEFORE_SCENE_LAUNCH', scene);
|
|
1622
|
-
this.changeScene(scene, _options, _isReload);
|
|
1623
|
-
});
|
|
1624
|
-
director.loadScene(sceneName);
|
|
1625
|
-
return this;
|
|
1626
|
-
}
|
|
1627
|
-
/**重置场景(清除当前默认当前场景) */
|
|
1628
|
-
resetScene(sceneName = '') {
|
|
1629
|
-
sceneName = sceneName || this.currentScene;
|
|
1630
|
-
return this.loadScene(sceneName);
|
|
1631
|
-
}
|
|
1632
|
-
/**清除场景 */
|
|
1633
|
-
cleanScene() {
|
|
1634
|
-
// 清理全局UI
|
|
1635
|
-
this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast();
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* 场景变化
|
|
1639
|
-
* @param scene 场景
|
|
1640
|
-
* @param options 选项
|
|
1641
|
-
* @param isReload 是否重新加载
|
|
1642
|
-
*/
|
|
1643
|
-
changeScene(scene, options, isReload) {
|
|
1644
|
-
this.currentScene = scene.name;
|
|
1645
|
-
// 获取当前场景
|
|
1646
|
-
// const canvas = scene.getComponentsInChildren(Canvas);
|
|
1647
|
-
// let ui2dCanvas = canvas.find(item => {
|
|
1648
|
-
// // return item.node.layer == Layers.Enum.UI_2D;
|
|
1649
|
-
// // UI_IN_SCENE
|
|
1650
|
-
// return item.node.layer == 2 ** 15;
|
|
1651
|
-
// });
|
|
1652
|
-
// if (!ui2dCanvas) {
|
|
1653
|
-
// ui2dCanvas = canvas.find(item => {
|
|
1654
|
-
// return item.node.layer == Layers.Enum.UI_2D;
|
|
1655
|
-
// });
|
|
1656
|
-
// }
|
|
1657
|
-
// const canvasNode = ui2dCanvas!.node;
|
|
1658
|
-
// 创建UI层
|
|
1659
|
-
this.createUILayer(scene);
|
|
1660
|
-
// 给场景传递属性值
|
|
1661
|
-
const crrentScene = scene.getComponentInChildren(SceneLayer);
|
|
1662
|
-
if (crrentScene) {
|
|
1663
|
-
crrentScene.isReload = isReload ?? false;
|
|
1664
|
-
}
|
|
1665
|
-
// 更新场景props
|
|
1666
|
-
crrentScene?.setOptions(options);
|
|
1667
|
-
}
|
|
1668
|
-
createUILayer(scene) {
|
|
1669
|
-
this.ui_container_component?.removeAndDestroy();
|
|
1670
|
-
this.ui_container_component = null;
|
|
1671
|
-
const node = instantiate(this.ui_prefab);
|
|
1672
|
-
this.ui_container_component = node.getComponent(CoreUIContainer).setGui(this).addToParent(scene);
|
|
1673
|
-
}
|
|
1674
|
-
/**重新加载当前场景 */
|
|
1675
|
-
reloadScene() {
|
|
1676
|
-
this.loadScene(this.currentScene, true);
|
|
1677
|
-
}
|
|
1678
|
-
/**关闭UI */
|
|
1679
|
-
async closeUI(ui, options) {
|
|
1680
|
-
const { component } = this.findUIBaseLayer(ui, false);
|
|
1681
|
-
if (component) {
|
|
1682
|
-
component.setOptions({
|
|
1683
|
-
...(options?.hook ?? {}),
|
|
1684
|
-
...(options?.props ?? {})
|
|
1685
|
-
});
|
|
1686
|
-
// 调用uiNode组件下的showTween方法
|
|
1687
|
-
await component.hideTween(options || {});
|
|
1688
|
-
// 移除层级遮罩
|
|
1689
|
-
this.ui_container_component?.subMask();
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* 打开ui层
|
|
1694
|
-
* @param ui 界面的节点或组件
|
|
1695
|
-
* @param options 动画参数选项
|
|
1696
|
-
*/
|
|
1697
|
-
async openUI(ui, options) {
|
|
1698
|
-
// 查询根节点
|
|
1699
|
-
const { rootNode, component } = this.findUIBaseLayer(ui, true);
|
|
1700
|
-
// 获取根组件
|
|
1701
|
-
rootNode.getComponent(UILayer);
|
|
1702
|
-
// 配置选项
|
|
1703
|
-
component?.setOptions(options);
|
|
1704
|
-
// 动画
|
|
1705
|
-
if (rootNode) {
|
|
1706
|
-
// 添加层级遮罩
|
|
1707
|
-
this.ui_container_component?.addNodeToTween(rootNode).addMask();
|
|
1708
|
-
}
|
|
1709
|
-
if (component) {
|
|
1710
|
-
// 调用uiNode组件下的showTween方法
|
|
1711
|
-
await component.showTween(options || {});
|
|
1712
|
-
}
|
|
1713
|
-
// 运动结束之后,添加界面到UI层
|
|
1714
|
-
this.ui_container_component?.ui_container && component?.addToParent(this.ui_container_component.ui_container);
|
|
1715
|
-
}
|
|
1716
|
-
/**根据节点或组件 查询根UI层(继承自UILayer的)节点或组件 */
|
|
1717
|
-
findUIBaseLayer(ui, isOpen) {
|
|
1718
|
-
let rootNode;
|
|
1719
|
-
let component = null;
|
|
1720
|
-
if (ui instanceof Node) {
|
|
1721
|
-
// ui为节点
|
|
1722
|
-
rootNode = ui;
|
|
1723
|
-
// 获取组件
|
|
1724
|
-
const extendsBaseLayer = ui.components.filter(item => {
|
|
1725
|
-
return (item instanceof UILayer);
|
|
1726
|
-
});
|
|
1727
|
-
if (extendsBaseLayer.length) {
|
|
1728
|
-
if (extendsBaseLayer.length == 1) {
|
|
1729
|
-
component = extendsBaseLayer[0];
|
|
1730
|
-
}
|
|
1731
|
-
else {
|
|
1732
|
-
warn(`${ui.name}节点存在多个继承自BaseLayer的组件`);
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
else {
|
|
1736
|
-
error(`${ui.name}节点未找到继承自BaseLayer的组件`);
|
|
1737
|
-
return { rootNode, component };
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
else {
|
|
1741
|
-
// ui为T组件
|
|
1742
|
-
// 定义一个变量用于保存根节点
|
|
1743
|
-
rootNode = ui.node;
|
|
1744
|
-
component = ui;
|
|
1745
|
-
if (isOpen) {
|
|
1746
|
-
// 循环向上查找根节点,直到找到没有父节点的节点
|
|
1747
|
-
while (rootNode.parent) {
|
|
1748
|
-
rootNode = rootNode.parent;
|
|
1749
|
-
}
|
|
1750
|
-
component.root = rootNode;
|
|
1751
|
-
}
|
|
1752
|
-
else {
|
|
1753
|
-
rootNode = ui.root;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return { rootNode, component };
|
|
1757
|
-
}
|
|
1758
|
-
/**根层的变化 */
|
|
1759
|
-
onRootUpdate() {
|
|
1760
|
-
// 如果根ui节点 没有子节点 则隐藏根遮罩
|
|
1761
|
-
const last_active_index = this.root_ui.children.findLastIndex(item => item.active && item != this.root_mask);
|
|
1762
|
-
// 显示
|
|
1763
|
-
this.root_mask.active = last_active_index != -1;
|
|
1764
|
-
// 调整层级
|
|
1765
|
-
if (last_active_index > -1) {
|
|
1766
|
-
// 更新根遮罩层级
|
|
1767
|
-
const last = this.root_ui.children[last_active_index];
|
|
1768
|
-
this.root_mask.setSiblingIndex(last.getSiblingIndex() - 1);
|
|
1769
|
-
}
|
|
1770
|
-
// 通知ui层级变化
|
|
1771
|
-
this.cat.event.dispatchEvent(GlobalEventConstant.ROOT_MASK_CHANGE);
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
__decorate([
|
|
1775
|
-
property$2({ type: Prefab, tooltip: '断线重连UI预制体' }),
|
|
1776
|
-
__metadata("design:type", Prefab)
|
|
1777
|
-
], Gui.prototype, "reconnection_ui_prefab", void 0);
|
|
1778
|
-
__decorate([
|
|
1779
|
-
property$2({ type: Prefab, tooltip: '提示UI预制体' }),
|
|
1780
|
-
__metadata("design:type", Prefab)
|
|
1781
|
-
], Gui.prototype, "toast_ui_prefab", void 0);
|
|
1782
|
-
__decorate([
|
|
1783
|
-
property$2({ type: Prefab, tooltip: '加载UI预制体' }),
|
|
1784
|
-
__metadata("design:type", Prefab)
|
|
1785
|
-
], Gui.prototype, "loading_ui_prefab", void 0);
|
|
1786
|
-
__decorate([
|
|
1787
|
-
property$2({ type: Prefab, tooltip: '公告UI预制体' }),
|
|
1788
|
-
__metadata("design:type", Prefab)
|
|
1789
|
-
], Gui.prototype, "notice_ui_prefab", void 0);
|
|
1790
|
-
__decorate([
|
|
1791
|
-
property$2({ type: Prefab, tooltip: 'UI层预制体' }),
|
|
1792
|
-
__metadata("design:type", Prefab)
|
|
1793
|
-
], Gui.prototype, "ui_prefab", void 0);
|
|
1794
|
-
__decorate([
|
|
1795
|
-
property$2({ type: Node, tooltip: 'root-UI层' }),
|
|
1796
|
-
__metadata("design:type", Node)
|
|
1797
|
-
], Gui.prototype, "root_ui", void 0);
|
|
1798
|
-
__decorate([
|
|
1799
|
-
property$2({ type: Node, tooltip: 'root-组件层' }),
|
|
1800
|
-
__metadata("design:type", Node)
|
|
1801
|
-
], Gui.prototype, "root_toast", void 0);
|
|
1802
|
-
__decorate([
|
|
1803
|
-
property$2({ type: Node, tooltip: 'root-mask' }),
|
|
1804
|
-
__metadata("design:type", Node)
|
|
1805
|
-
], Gui.prototype, "root_mask", void 0);
|
|
1806
|
-
Gui = __decorate([
|
|
1807
|
-
ccclass$2('Gui')
|
|
1808
|
-
], Gui);
|
|
1809
|
-
|
|
1810
|
-
/**遮罩管理 TODO (每个层级都有一个遮罩 但是同时只能出现1个) */
|
|
1811
|
-
const { ccclass: ccclass$1, property: property$1 } = _decorator;
|
|
1812
|
-
let CoreBlackMask = class CoreBlackMask extends BaseComponent {
|
|
1813
|
-
tween;
|
|
1814
|
-
};
|
|
1815
|
-
__decorate([
|
|
1816
|
-
property$1({ type: Node, tooltip: '动画节点' }),
|
|
1817
|
-
__metadata("design:type", Node)
|
|
1818
|
-
], CoreBlackMask.prototype, "tween", void 0);
|
|
1819
|
-
CoreBlackMask = __decorate([
|
|
1820
|
-
ccclass$1('CoreBlackMask')
|
|
1821
|
-
], CoreBlackMask);
|
|
1822
|
-
|
|
1823
|
-
/**
|
|
1824
|
-
* @describe 层级界面管理
|
|
1825
|
-
* @author 游金宇(KM)
|
|
1826
|
-
* @date 2023-08-03 20:02:45
|
|
1827
|
-
*/
|
|
1828
|
-
/**预制体路径 */
|
|
1829
|
-
var BasePrefab;
|
|
1830
|
-
(function (BasePrefab) {
|
|
1831
|
-
BasePrefab["Root"] = "prefabs/root";
|
|
1832
|
-
BasePrefab["Toast"] = "prefabs/toast";
|
|
1833
|
-
BasePrefab["BlackMask"] = "prefabs/black-mask";
|
|
1834
|
-
BasePrefab["Loading"] = "prefabs/loading";
|
|
1835
|
-
BasePrefab["Notice"] = "prefabs/notice";
|
|
1836
|
-
BasePrefab["Reconnection"] = "prefabs/reconnection";
|
|
1837
|
-
})(BasePrefab || (BasePrefab = {}));
|
|
1838
|
-
class GuiManager extends BaseManager {
|
|
1839
|
-
/**常驻顶层UI节点层级 */
|
|
1840
|
-
gui;
|
|
1841
|
-
#bundleName = 'resources';
|
|
1842
|
-
/**
|
|
1843
|
-
* 获取预制体
|
|
1844
|
-
* @param type 类型
|
|
1845
|
-
* @returns
|
|
1846
|
-
*/
|
|
1847
|
-
getGuiPrefabByType = (bundleName, type) => {
|
|
1848
|
-
return new Promise((resolve, reject) => {
|
|
1849
|
-
console.log(bundleName, `${type}`);
|
|
1850
|
-
this.cat.res.load(bundleName, type, (err, prefab) => {
|
|
1851
|
-
if (err) {
|
|
1852
|
-
reject(err);
|
|
1853
|
-
}
|
|
1854
|
-
else {
|
|
1855
|
-
resolve(prefab);
|
|
1856
|
-
}
|
|
1857
|
-
});
|
|
1858
|
-
});
|
|
1859
|
-
};
|
|
1860
|
-
/**初始化 */
|
|
1861
|
-
async init() {
|
|
1862
|
-
this.#bundleName = this.cat.gui_bundle_name;
|
|
1863
|
-
// 初始化常驻节点
|
|
1864
|
-
const root_prefab = await this.getGuiPrefabByType(this.#bundleName, BasePrefab.Root);
|
|
1865
|
-
const root = instantiate(root_prefab);
|
|
1866
|
-
this.gui = root.getComponent(Gui).init(this.cat);
|
|
1867
|
-
director.addPersistRootNode(root);
|
|
1868
|
-
// 更新场景
|
|
1869
|
-
return this;
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
/**
|
|
1874
|
-
* @describe 游戏资管理
|
|
1875
|
-
* @author 游金宇(KM)
|
|
1876
|
-
* @date 2023-08-03 17:40:51
|
|
1877
|
-
*/
|
|
1878
|
-
class ResLoader {
|
|
1879
|
-
/**
|
|
1880
|
-
* 获取资源
|
|
1881
|
-
* @param path 资源路径
|
|
1882
|
-
* @param type 资源类型
|
|
1883
|
-
* @param bundleName 远程资源包名
|
|
1884
|
-
*/
|
|
1885
|
-
get = (path, type, bundleName = 'resources') => {
|
|
1886
|
-
var bundle = assetManager.getBundle(bundleName);
|
|
1887
|
-
return bundle.get(path, type);
|
|
1888
|
-
};
|
|
1889
|
-
/**
|
|
1890
|
-
* 获取资源类型
|
|
1891
|
-
*/
|
|
1892
|
-
isAssetType = (value) => {
|
|
1893
|
-
return typeof value === 'function' && value.prototype instanceof Asset;
|
|
1894
|
-
};
|
|
1895
|
-
async load(...args) {
|
|
1896
|
-
let bundleName = null;
|
|
1897
|
-
let type = null;
|
|
1898
|
-
let onProgress = null;
|
|
1899
|
-
// 判断前两个参数是否都为字符串
|
|
1900
|
-
if (typeof args[0] === 'string' && typeof args[1] === 'string') {
|
|
1901
|
-
// 取出包名参数
|
|
1902
|
-
bundleName = args.shift();
|
|
1903
|
-
}
|
|
1904
|
-
// 取出路径参数
|
|
1905
|
-
let paths = args.shift();
|
|
1906
|
-
// 取出类型参数
|
|
1907
|
-
if (this.isAssetType(args[0])) {
|
|
1908
|
-
type = args.shift();
|
|
1909
|
-
}
|
|
1910
|
-
// 取出进度回调参数
|
|
1911
|
-
if (args.length == 2) {
|
|
1912
|
-
onProgress = args.shift();
|
|
1913
|
-
}
|
|
1914
|
-
// 取出完成回调参数
|
|
1915
|
-
const onComplete = args.shift();
|
|
1916
|
-
let nonce = resources;
|
|
1917
|
-
if (bundleName && bundleName != 'resources') {
|
|
1918
|
-
// bundleName不存在
|
|
1919
|
-
if (!assetManager.bundles.has(bundleName)) {
|
|
1920
|
-
await this.loadBundle(bundleName);
|
|
1921
|
-
}
|
|
1922
|
-
let bundle = assetManager.bundles.get(bundleName);
|
|
1923
|
-
if (bundle) {
|
|
1924
|
-
nonce = bundle;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
if (onProgress && onComplete) {
|
|
1928
|
-
nonce.load(paths, type, onProgress, onComplete);
|
|
1929
|
-
}
|
|
1930
|
-
else if (onComplete) {
|
|
1931
|
-
nonce.load(paths, type, onComplete);
|
|
1932
|
-
}
|
|
1933
|
-
else {
|
|
1934
|
-
nonce.load(paths, type);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
async loadDir(...args) {
|
|
1938
|
-
let bundleName = null;
|
|
1939
|
-
let type = null;
|
|
1940
|
-
let onProgress = null;
|
|
1941
|
-
let onComplete = null;
|
|
1942
|
-
// 获取bundleName是否存在
|
|
1943
|
-
// 判断前两个参数是否都为字符串
|
|
1944
|
-
if (typeof args[0] === 'string' && typeof args[1] === 'string') {
|
|
1945
|
-
bundleName = args.shift();
|
|
1946
|
-
}
|
|
1947
|
-
let paths = args.shift();
|
|
1948
|
-
if (this.isAssetType(args[0])) {
|
|
1949
|
-
type = args.shift();
|
|
1950
|
-
}
|
|
1951
|
-
if (args.length == 2) {
|
|
1952
|
-
onProgress = args.shift();
|
|
1953
|
-
}
|
|
1954
|
-
onComplete = args.shift();
|
|
1955
|
-
let nonce = resources;
|
|
1956
|
-
if (bundleName && bundleName != 'resources') {
|
|
1957
|
-
// bundleName不存在
|
|
1958
|
-
if (!assetManager.bundles.has(bundleName)) {
|
|
1959
|
-
await this.loadBundle(bundleName);
|
|
1960
|
-
}
|
|
1961
|
-
let bundle = assetManager.bundles.get(bundleName);
|
|
1962
|
-
if (bundle) {
|
|
1963
|
-
nonce = bundle;
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
if (onProgress && onComplete) {
|
|
1967
|
-
nonce.loadDir(paths, type, onProgress, onComplete);
|
|
1968
|
-
}
|
|
1969
|
-
else if (onComplete) {
|
|
1970
|
-
nonce.loadDir(paths, type, onComplete);
|
|
1971
|
-
}
|
|
1972
|
-
else {
|
|
1973
|
-
nonce.loadDir(paths, type);
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
loadRemote(url, ...args) {
|
|
1977
|
-
var options = null;
|
|
1978
|
-
var onComplete = null;
|
|
1979
|
-
if (args.length == 2) {
|
|
1980
|
-
options = args.shift();
|
|
1981
|
-
}
|
|
1982
|
-
onComplete = args.shift();
|
|
1983
|
-
assetManager.loadRemote(url, { ext: ".png", ...options }, onComplete);
|
|
1984
|
-
}
|
|
1985
|
-
/**
|
|
1986
|
-
* 加载bundle
|
|
1987
|
-
* @param url 资源地址 <远程路径或者bundleName>
|
|
1988
|
-
* @param complete 完成事件
|
|
1989
|
-
* @param v 资源版本号
|
|
1990
|
-
* @example
|
|
1991
|
-
*/
|
|
1992
|
-
loadBundle = (url, version) => {
|
|
1993
|
-
return new Promise((resolve, reject) => {
|
|
1994
|
-
const onComplete = (err, bundle) => {
|
|
1995
|
-
if (err) {
|
|
1996
|
-
return reject(err);
|
|
1997
|
-
}
|
|
1998
|
-
resolve(bundle);
|
|
1999
|
-
};
|
|
2000
|
-
version ?
|
|
2001
|
-
assetManager.loadBundle(url, { version }, onComplete) :
|
|
2002
|
-
assetManager.loadBundle(url, onComplete);
|
|
2003
|
-
});
|
|
2004
|
-
};
|
|
2005
|
-
/** 释放预制依赖资源 */
|
|
2006
|
-
releasePrefabtDepsRecursively = (uuid) => {
|
|
2007
|
-
var asset = assetManager.assets.get(uuid);
|
|
2008
|
-
assetManager.releaseAsset(asset);
|
|
2009
|
-
if (asset instanceof Prefab) {
|
|
2010
|
-
var uuids = assetManager.dependUtil.getDepsRecursively(uuid);
|
|
2011
|
-
uuids.forEach(uuid => {
|
|
2012
|
-
var asset = assetManager.assets.get(uuid);
|
|
2013
|
-
asset.decRef();
|
|
2014
|
-
});
|
|
2015
|
-
}
|
|
2016
|
-
};
|
|
2017
|
-
/**
|
|
2018
|
-
* 通过资源相对路径释放资源
|
|
2019
|
-
* @param path 资源路径
|
|
2020
|
-
* @param bundleName 远程资源包名
|
|
2021
|
-
*/
|
|
2022
|
-
release = (path, bundleName = 'resources') => {
|
|
2023
|
-
var bundle = assetManager.getBundle(bundleName);
|
|
2024
|
-
if (bundle) {
|
|
2025
|
-
var asset = bundle.get(path);
|
|
2026
|
-
if (asset) {
|
|
2027
|
-
this.releasePrefabtDepsRecursively(asset._uuid);
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2031
|
-
/**
|
|
2032
|
-
* 通过相对文件夹路径删除所有文件夹中资源
|
|
2033
|
-
* @param path 资源文件夹路径
|
|
2034
|
-
* @param bundleName 远程资源包名
|
|
2035
|
-
*/
|
|
2036
|
-
releaseDir = (path, bundleName = 'resources') => {
|
|
2037
|
-
var bundle = assetManager.getBundle(bundleName);
|
|
2038
|
-
var infos = bundle?.getDirWithPath(path);
|
|
2039
|
-
infos?.map(info => {
|
|
2040
|
-
this.releasePrefabtDepsRecursively(info.uuid);
|
|
2041
|
-
});
|
|
2042
|
-
if (!path && bundleName != 'resources' && bundle) {
|
|
2043
|
-
assetManager.removeBundle(bundle);
|
|
2044
|
-
}
|
|
2045
|
-
};
|
|
2046
|
-
/** 打印缓存中所有资源信息 */
|
|
2047
|
-
dump = () => {
|
|
2048
|
-
assetManager.assets.forEach((value, key) => {
|
|
2049
|
-
log(assetManager.assets.get(key));
|
|
2050
|
-
});
|
|
2051
|
-
log(`当前资源总数:${assetManager.assets.count}`);
|
|
2052
|
-
};
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
/**
|
|
2056
|
-
* @describe 事件消息管理
|
|
2057
|
-
* @author 游金宇(KM)
|
|
2058
|
-
* @date 2023-08-03 18:15:38
|
|
2059
|
-
*/
|
|
2060
|
-
class MessageManager {
|
|
2061
|
-
events = new Map();
|
|
2062
|
-
/**
|
|
2063
|
-
* 注册全局事件
|
|
2064
|
-
* @param event 事件名
|
|
2065
|
-
* @param listener 处理事件的侦听器函数
|
|
2066
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
2067
|
-
*/
|
|
2068
|
-
on(event, listener, obj) {
|
|
2069
|
-
if (!event || !listener) {
|
|
2070
|
-
warn(`注册【${event}】事件的侦听器函数为空`);
|
|
2071
|
-
return this;
|
|
2072
|
-
}
|
|
2073
|
-
// 获取事件
|
|
2074
|
-
const _event = this.events.get(event) ?? this.events.set(event, new Map()).get(event);
|
|
2075
|
-
if (_event.has(obj)) {
|
|
2076
|
-
warn(`名为【${event}】的事件重复注册侦听器`);
|
|
2077
|
-
return this;
|
|
2078
|
-
}
|
|
2079
|
-
_event.set(obj, listener);
|
|
2080
|
-
return this;
|
|
2081
|
-
}
|
|
2082
|
-
/**
|
|
2083
|
-
* 监听一次事件,事件响应后,该监听自动移除
|
|
2084
|
-
* @param event 事件名
|
|
2085
|
-
* @param listener 事件触发回调方法
|
|
2086
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
2087
|
-
*/
|
|
2088
|
-
once(event, listener, obj) {
|
|
2089
|
-
let _listener = ($event, $args) => {
|
|
2090
|
-
this.off(event, _listener, obj);
|
|
2091
|
-
_listener = null;
|
|
2092
|
-
listener.call(obj, $event, $args);
|
|
2093
|
-
};
|
|
2094
|
-
this.on(event, _listener, obj);
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* 移除单个事件
|
|
2098
|
-
* @param event 事件名
|
|
2099
|
-
* @param listener 处理事件的侦听器函数
|
|
2100
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
2101
|
-
*/
|
|
2102
|
-
off(event, listener, obj) {
|
|
2103
|
-
if (!this.events.get(event)?.has(obj)) {
|
|
2104
|
-
// warn(`${event}事件未注册`)
|
|
2105
|
-
return this;
|
|
2106
|
-
}
|
|
2107
|
-
const _object = this.events.get(event);
|
|
2108
|
-
if (_object.get(obj) !== listener) {
|
|
2109
|
-
error(`${obj}注册事件和取消事件不一致`);
|
|
2110
|
-
return this;
|
|
2111
|
-
}
|
|
2112
|
-
_object.delete(obj);
|
|
2113
|
-
return this;
|
|
2114
|
-
}
|
|
2115
|
-
/**
|
|
2116
|
-
* 触发全局事件
|
|
2117
|
-
* @param event(string) 事件名
|
|
2118
|
-
* @param args(any) 事件参数
|
|
2119
|
-
*/
|
|
2120
|
-
dispatchEvent(event, args) {
|
|
2121
|
-
let _event = this.events.has(event);
|
|
2122
|
-
if (!_event) {
|
|
2123
|
-
// warn(`${event}事件未注册`)
|
|
2124
|
-
return this;
|
|
2125
|
-
}
|
|
2126
|
-
const _listeners = this.events.get(event);
|
|
2127
|
-
for (const [key, value] of _listeners) {
|
|
2128
|
-
value.call(key, args, event);
|
|
2129
|
-
}
|
|
2130
|
-
return this;
|
|
2131
|
-
}
|
|
2132
|
-
/**移除所有事件 */
|
|
2133
|
-
offAll() {
|
|
2134
|
-
this.events.clear();
|
|
2135
|
-
}
|
|
2136
|
-
/**是否存在事件 */
|
|
2137
|
-
has(event) {
|
|
2138
|
-
return this.events.has(event);
|
|
2139
|
-
}
|
|
2140
|
-
/**删除事件通过组件 */
|
|
2141
|
-
deleteEventByComponent(component) {
|
|
2142
|
-
for (const [event, objects] of this.events) {
|
|
2143
|
-
for (const [obj] of objects) {
|
|
2144
|
-
if (obj === component) {
|
|
2145
|
-
objects.delete(obj);
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
if (objects.size === 0) {
|
|
2149
|
-
this.events.delete(event);
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
/**
|
|
2156
|
-
* @describe 加密工具
|
|
2157
|
-
* @author 游金宇(KM)
|
|
2158
|
-
* @date 2023-01-30 17:20:24
|
|
2159
|
-
*/
|
|
2160
|
-
let _iv = null;
|
|
2161
|
-
/**
|
|
2162
|
-
* MD5加密
|
|
2163
|
-
* @param msg 加密信息
|
|
2164
|
-
*/
|
|
2165
|
-
const md5 = (msg) => {
|
|
2166
|
-
return CryptoES.MD5(msg).toString();
|
|
2167
|
-
};
|
|
2168
|
-
/** 初始化加密库 */
|
|
2169
|
-
const initCrypto = (key, iv) => {
|
|
2170
|
-
_iv = CryptoES.enc.Hex.parse(iv);
|
|
2171
|
-
};
|
|
2172
|
-
/**
|
|
2173
|
-
* AES 加密
|
|
2174
|
-
* @param msg 加密信息
|
|
2175
|
-
* @param key aes加密的key
|
|
2176
|
-
* @param iv aes加密的iv
|
|
2177
|
-
*/
|
|
2178
|
-
const aesEncrypt = (msg, key, iv) => {
|
|
2179
|
-
return CryptoES.AES.encrypt(msg, key, {
|
|
2180
|
-
iv: _iv,
|
|
2181
|
-
format: JsonFormatter,
|
|
2182
|
-
}).toString();
|
|
2183
|
-
};
|
|
2184
|
-
/**
|
|
2185
|
-
* AES 解密
|
|
2186
|
-
* @param str 解密字符串
|
|
2187
|
-
* @param key aes加密的key
|
|
2188
|
-
* @param iv aes加密的iv
|
|
2189
|
-
*/
|
|
2190
|
-
const aesDecrypt = (str, key, iv) => {
|
|
2191
|
-
const decrypted = CryptoES.AES.decrypt(str, key, {
|
|
2192
|
-
iv: _iv,
|
|
2193
|
-
format: JsonFormatter,
|
|
2194
|
-
});
|
|
2195
|
-
return decrypted.toString(CryptoES.enc.Utf8);
|
|
2196
|
-
};
|
|
2197
|
-
const JsonFormatter = {
|
|
2198
|
-
stringify: (cipherParams) => {
|
|
2199
|
-
const jsonObj = { ct: cipherParams.ciphertext.toString(CryptoES.enc.Base64) };
|
|
2200
|
-
if (cipherParams.iv) {
|
|
2201
|
-
jsonObj.iv = cipherParams.iv.toString();
|
|
2202
|
-
}
|
|
2203
|
-
if (cipherParams.salt) {
|
|
2204
|
-
jsonObj.s = cipherParams.salt.toString();
|
|
2205
|
-
}
|
|
2206
|
-
return JSON.stringify(jsonObj);
|
|
2207
|
-
},
|
|
2208
|
-
parse: (jsonStr) => {
|
|
2209
|
-
const jsonObj = JSON.parse(jsonStr);
|
|
2210
|
-
const cipherParams = CryptoES.lib.CipherParams.create({ ciphertext: CryptoES.enc.Base64.parse(jsonObj.ct) });
|
|
2211
|
-
if (jsonObj.iv) {
|
|
2212
|
-
cipherParams.iv = CryptoES.enc.Hex.parse(jsonObj.iv);
|
|
2213
|
-
}
|
|
2214
|
-
if (jsonObj.s) {
|
|
2215
|
-
cipherParams.salt = CryptoES.enc.Hex.parse(jsonObj.s);
|
|
2216
|
-
}
|
|
2217
|
-
return cipherParams;
|
|
2218
|
-
},
|
|
2219
|
-
};
|
|
2220
|
-
|
|
2221
|
-
var EncryptUtil = /*#__PURE__*/Object.freeze({
|
|
2222
|
-
__proto__: null,
|
|
2223
|
-
JsonFormatter: JsonFormatter,
|
|
2224
|
-
aesDecrypt: aesDecrypt,
|
|
2225
|
-
aesEncrypt: aesEncrypt,
|
|
2226
|
-
initCrypto: initCrypto,
|
|
2227
|
-
md5: md5
|
|
2228
|
-
});
|
|
2229
|
-
|
|
2230
|
-
/**
|
|
2231
|
-
* @describe 工具类
|
|
2232
|
-
* @author 游金宇(KM)
|
|
2233
|
-
* @date 2023-08-02 20:16:42
|
|
2234
|
-
*/
|
|
2235
|
-
// 扩展 Manager 接口,添加 Util 属性
|
|
2236
|
-
class CoreUtil extends BaseManager {
|
|
2237
|
-
encryptUtil = EncryptUtil;
|
|
2238
|
-
}
|
|
2239
|
-
|
|
2240
|
-
/**
|
|
2241
|
-
* @describe 基于社交游戏封装的游戏基础ws类
|
|
2242
|
-
* @author 游金宇(KM)
|
|
2243
|
-
* @date 2024-09-12 11:47:51
|
|
2244
|
-
*/
|
|
2245
|
-
class WrapperSocialGameClient extends SocialGameClient {
|
|
2246
|
-
/**需要重连(标记接下来需要重连) */
|
|
2247
|
-
isNeedReconnect = false;
|
|
2248
|
-
/**网络在线 */
|
|
2249
|
-
isOnline = true;
|
|
2250
|
-
/**在后台 */
|
|
2251
|
-
isInBackground = false;
|
|
2252
|
-
/**状态机运行 */
|
|
2253
|
-
running = false;
|
|
2254
|
-
index = 0;
|
|
2255
|
-
/**日志黑名单 */
|
|
2256
|
-
logBlackList = [];
|
|
2257
|
-
constructor(opts, eventResponsePairs, clientOption) {
|
|
2258
|
-
super(opts, eventResponsePairs, clientOption);
|
|
2259
|
-
this.running = true;
|
|
2260
|
-
// this.handleEvent.next(); // 初始化状态机
|
|
2261
|
-
this.addEvent();
|
|
2262
|
-
}
|
|
2263
|
-
/**初始化 */
|
|
2264
|
-
addEvent() {
|
|
2265
|
-
this.on("connected", () => this.handleEvent({ type: 'connected' }))
|
|
2266
|
-
.on("reconnected", () => this.handleEvent({ type: 'reconnected' }))
|
|
2267
|
-
.on("disconnect", (ev) => this.handleEvent({ type: 'disconnect', ev }))
|
|
2268
|
-
.on("handshakeError", (ret) => this.handleEvent({ type: 'handshakeError', ret }))
|
|
2269
|
-
.on("kick", () => this.handleEvent({ type: 'kick' }))
|
|
2270
|
-
.on("reconnecting", () => this.handleEvent({ type: 'reconnecting' }))
|
|
2271
|
-
// .on("reconnectTimeout", () => this.handleEvent({ type: 'reconnectTimeout' }))
|
|
2272
|
-
.on("maxReconnect", () => this.handleEvent({ type: 'maxReconnect' }))
|
|
2273
|
-
.on("error", (ev) => this.handleEvent({ type: 'error', ev }));
|
|
2274
|
-
cat.event.on(GlobalEventConstant.EVENT_SHOW, this.onShowHandler, this)
|
|
2275
|
-
.on(GlobalEventConstant.EVENT_HIDE, this.onHideHandler, this)
|
|
2276
|
-
.on(GlobalEventConstant.ONLINE, this.onOnlineHandler, this)
|
|
2277
|
-
.on(GlobalEventConstant.OFFLINE, this.onOfflineHandler, this);
|
|
2278
|
-
}
|
|
2279
|
-
removeEvent() {
|
|
2280
|
-
this.removeAllListeners();
|
|
2281
|
-
cat.event.off(GlobalEventConstant.EVENT_SHOW, this.onShowHandler, this)
|
|
2282
|
-
.off(GlobalEventConstant.EVENT_HIDE, this.onHideHandler, this)
|
|
2283
|
-
.off(GlobalEventConstant.ONLINE, this.onOnlineHandler, this)
|
|
2284
|
-
.off(GlobalEventConstant.OFFLINE, this.onOfflineHandler, this);
|
|
2285
|
-
}
|
|
2286
|
-
onShowHandler() {
|
|
2287
|
-
log('[SHOW]');
|
|
2288
|
-
this.isInBackground = false;
|
|
2289
|
-
if (this.isNeedReconnect && this.isOnline) {
|
|
2290
|
-
this.handleEvent({ type: 'show' });
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
onHideHandler(cb) {
|
|
2294
|
-
log('[HIDE]');
|
|
2295
|
-
cb().finally(() => {
|
|
2296
|
-
this.isInBackground = true;
|
|
2297
|
-
this.handleEvent({ type: 'hide' });
|
|
2298
|
-
});
|
|
2299
|
-
}
|
|
2300
|
-
/**网络在线处理 */
|
|
2301
|
-
onOnlineHandler() {
|
|
2302
|
-
this.isOnline = true;
|
|
2303
|
-
log(`正在检查网络状态:${this.isOnline ? '在线' : '断开'}`);
|
|
2304
|
-
this.handleEvent({ type: 'online' });
|
|
2305
|
-
}
|
|
2306
|
-
/**网络断开处理 */
|
|
2307
|
-
onOfflineHandler() {
|
|
2308
|
-
this.isOnline = false;
|
|
2309
|
-
log(`正在检查网络状态:${this.isOnline ? '在线' : '断开'}`);
|
|
2310
|
-
this.handleEvent({ type: 'offline' });
|
|
2311
|
-
}
|
|
2312
|
-
async handleEvent(event) {
|
|
2313
|
-
if (!this.running)
|
|
2314
|
-
return;
|
|
2315
|
-
switch (event.type) {
|
|
2316
|
-
case 'init': //初始状态
|
|
2317
|
-
break;
|
|
2318
|
-
case 'connected': //连接成功状态
|
|
2319
|
-
log('ws连接成功状态 connected');
|
|
2320
|
-
this.isNeedReconnect = false;
|
|
2321
|
-
break;
|
|
2322
|
-
case 'reconnected': //重连成功状态
|
|
2323
|
-
log('ws重连成功状态 reconnected', this.isSocketConnected);
|
|
2324
|
-
this.isNeedReconnect = false;
|
|
2325
|
-
log(`%c 重连成功状态`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', this.index);
|
|
2326
|
-
try {
|
|
2327
|
-
// 区分链接游戏服还是观众服
|
|
2328
|
-
// 获取玩家正在
|
|
2329
|
-
await this.connectRequest();
|
|
2330
|
-
log('重连成功状态 connectRequest ');
|
|
2331
|
-
cat.gui.showToast({ title: ReconnectPrompt.RECONNECTED });
|
|
2332
|
-
cat.gui.hideReconnect().hideLoading();
|
|
2333
|
-
cat.gui.reloadScene();
|
|
2334
|
-
}
|
|
2335
|
-
catch (err) {
|
|
2336
|
-
console.error(err);
|
|
2337
|
-
cat.gui.showReconnect(ReconnectPrompt.GAME_ERROR);
|
|
2338
|
-
}
|
|
2339
|
-
break;
|
|
2340
|
-
case 'disconnect': //断开连接状态
|
|
2341
|
-
log('断开连接状态 disconnect', event.ev);
|
|
2342
|
-
log(`%c 断开连接状态`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', this.index);
|
|
2343
|
-
this.isNeedReconnect = true;
|
|
2344
|
-
this.handleEvent({ type: 'reconnect' });
|
|
2345
|
-
// if (this.isReconnecting) { //正在重连则说明此次重连失败
|
|
2346
|
-
// // cat.gui.showReconnect(ReconnectPrompt.RECONNECTED_ERROR);
|
|
2347
|
-
// // cat.gui.showToast({ title: ReconnectPrompt.RECONNECTED_ERROR })
|
|
2348
|
-
// } else {
|
|
2349
|
-
// }
|
|
2350
|
-
break;
|
|
2351
|
-
case 'handshakeError': //参数错误状态
|
|
2352
|
-
log('参数错误状态 handshakeError', event.ret);
|
|
2353
|
-
cat.gui.showReconnect(ReconnectPrompt.CONNECT_PARAM_ERROR);
|
|
2354
|
-
this.handleEvent({ type: 'destroy' });
|
|
2355
|
-
break;
|
|
2356
|
-
case 'kick': //被踢出状态
|
|
2357
|
-
log(`%c 被踢出状态`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', this.index);
|
|
2358
|
-
log('被踢出状态 kick');
|
|
2359
|
-
cat.gui.showReconnect(ReconnectPrompt.KICK);
|
|
2360
|
-
this.handleEvent({ type: 'destroy' });
|
|
2361
|
-
break;
|
|
2362
|
-
case 'reconnecting': //正在重连状态
|
|
2363
|
-
log('正在重连状态 reconnecting');
|
|
2364
|
-
if (this.isOnline && !this.isInBackground) ;
|
|
2365
|
-
break;
|
|
2366
|
-
// case 'reconnectTimeout'://重连倒计时状态
|
|
2367
|
-
// log('重连倒计时状态 reconnectTimeout');
|
|
2368
|
-
// cat.gui.showReconnect(ReconnectPrompt.RECONNECTING);
|
|
2369
|
-
// break;
|
|
2370
|
-
case 'maxReconnect': //超出最大重连状态
|
|
2371
|
-
log('超出最大重连状态 maxReconnect');
|
|
2372
|
-
cat.gui.showReconnect(ReconnectPrompt.MAX_RECONNECT);
|
|
2373
|
-
break;
|
|
2374
|
-
case 'error': //ws报错状态
|
|
2375
|
-
if (this.isOnline) {
|
|
2376
|
-
log('ws报错状态 error', event.ev);
|
|
2377
|
-
if (typeof event.ev === 'string') {
|
|
2378
|
-
cat.gui.showToast({ title: event.ev });
|
|
2379
|
-
}
|
|
2380
|
-
cat.gui.showReconnect(ReconnectPrompt.RECONNECTED_ERROR);
|
|
2381
|
-
}
|
|
2382
|
-
break;
|
|
2383
|
-
case 'online': //在线状态
|
|
2384
|
-
cat.gui.showReconnect(ReconnectPrompt.ONLINE);
|
|
2385
|
-
log('在线状态 online');
|
|
2386
|
-
this.handleEvent({ type: 'reconnect' });
|
|
2387
|
-
break;
|
|
2388
|
-
case 'offline': //离线状态
|
|
2389
|
-
// 为了彻底清除上一次的ws(避免有重新连接已发起 但是没完成 导致下次重连时 可能重复重连) 需要将上一次的ws状态清理
|
|
2390
|
-
this.disconnect(true);
|
|
2391
|
-
log('离线状态 offline');
|
|
2392
|
-
this.isNeedReconnect = true;
|
|
2393
|
-
cat.gui.showReconnect(ReconnectPrompt.OFFLINE);
|
|
2394
|
-
break;
|
|
2395
|
-
case 'show': //前台状态
|
|
2396
|
-
log('前台状态 show');
|
|
2397
|
-
this.handleEvent({ type: 'reconnect' });
|
|
2398
|
-
break;
|
|
2399
|
-
case 'hide': //后台状态
|
|
2400
|
-
log('后台状态 hide');
|
|
2401
|
-
this.disconnect(true);
|
|
2402
|
-
this.isNeedReconnect = true;
|
|
2403
|
-
break;
|
|
2404
|
-
case 'reconnect': //重连状态
|
|
2405
|
-
log('重连状态 reconnect');
|
|
2406
|
-
if (this.isNeedReconnect && !this.isInBackground && this.isOnline) {
|
|
2407
|
-
cat.gui.showLoading({ title: '正在重连' });
|
|
2408
|
-
this.reset();
|
|
2409
|
-
this.index += 1;
|
|
2410
|
-
log(`%c ws重连次数`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', this.index);
|
|
2411
|
-
// 立即重连
|
|
2412
|
-
this.reconnectImmediately();
|
|
2413
|
-
}
|
|
2414
|
-
break;
|
|
2415
|
-
case 'destroy': //销毁状态
|
|
2416
|
-
log('销毁状态 destroy');
|
|
2417
|
-
this.destroyStateMachine();
|
|
2418
|
-
break;
|
|
2419
|
-
default:
|
|
2420
|
-
log('Unknown event:', event.type);
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
destroy() {
|
|
2424
|
-
this.handleEvent({ type: 'destroy' });
|
|
2425
|
-
}
|
|
2426
|
-
/**
|
|
2427
|
-
* 断开
|
|
2428
|
-
* @param activeDisconnect 主动断开
|
|
2429
|
-
*/
|
|
2430
|
-
disconnect(activeDisconnect = false) {
|
|
2431
|
-
super.disconnect(activeDisconnect);
|
|
2432
|
-
}
|
|
2433
|
-
destroyStateMachine() {
|
|
2434
|
-
log('Destroying state machine');
|
|
2435
|
-
this.running = false;
|
|
2436
|
-
this.removeEvent();
|
|
2437
|
-
this.disconnect(true);
|
|
2438
|
-
}
|
|
2439
|
-
request(route, reqReflect, resSchema) {
|
|
2440
|
-
if (DEBUG) {
|
|
2441
|
-
log(`%c ws客户端消息 %c [Request][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7d3d ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(reqReflect.desc, reqReflect.message));
|
|
2442
|
-
}
|
|
2443
|
-
return new Promise((resolve, reject) => {
|
|
2444
|
-
super.request(route, reqReflect, resSchema).then((res) => {
|
|
2445
|
-
if (DEBUG) {
|
|
2446
|
-
log(`%c ws服务端消息 %c [Response][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7daa ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(resSchema, res));
|
|
2447
|
-
}
|
|
2448
|
-
resolve(res);
|
|
2449
|
-
}, (err) => {
|
|
2450
|
-
// cat.gui.showToast({ title: err.msg })
|
|
2451
|
-
error('request err', err);
|
|
2452
|
-
reject(err);
|
|
2453
|
-
});
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
async Request(route, reqReflect, resSchema, { audOptions = {
|
|
2457
|
-
forwardReq: false,
|
|
2458
|
-
forwardResp: false,
|
|
2459
|
-
}, show_log = true } = {}) {
|
|
2460
|
-
if (!this.isSocketConnected) {
|
|
2461
|
-
throw `${!this.isSocketConnected ? 'Socket未连接' : '未加入战局/观战'}`;
|
|
2462
|
-
}
|
|
2463
|
-
if (DEBUG && show_log) {
|
|
2464
|
-
log(`%c ws客户端消息 %c [Request][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7d3d ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(reqReflect.desc, reqReflect.message));
|
|
2465
|
-
}
|
|
2466
|
-
return this.GameRequest(route, reqReflect, resSchema, create(AudienceOptionsSchema, audOptions));
|
|
2467
|
-
}
|
|
2468
|
-
async GameRequest(route, reqReflect, resp, audOptions) {
|
|
2469
|
-
return new Promise((resolve, reject) => {
|
|
2470
|
-
super.GameRequest(route, reqReflect, resp, audOptions).then((res) => {
|
|
2471
|
-
if (DEBUG) {
|
|
2472
|
-
log(`%c ws服务端消息 %c [Response][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7daa ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(resp, res));
|
|
2473
|
-
}
|
|
2474
|
-
resolve(res);
|
|
2475
|
-
}, (err) => {
|
|
2476
|
-
cat.gui.showToast({ title: err.msg });
|
|
2477
|
-
reject(err);
|
|
2478
|
-
});
|
|
2479
|
-
});
|
|
2480
|
-
}
|
|
2481
|
-
async gameRequest(route, reqReflect, resSchema) {
|
|
2482
|
-
if (DEBUG) {
|
|
2483
|
-
log(`%c ws客户端消息 %c [Request][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7d3d ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(reqReflect.desc, reqReflect.message));
|
|
2484
|
-
}
|
|
2485
|
-
return super.gameRequest(route, reqReflect, resSchema);
|
|
2486
|
-
}
|
|
2487
|
-
GameNotify = async (route, reqReflect, audOptions) => {
|
|
2488
|
-
try {
|
|
2489
|
-
super.GameNotify(route, reqReflect, audOptions);
|
|
2490
|
-
}
|
|
2491
|
-
catch (err) {
|
|
2492
|
-
console.error(`Error in connectRequest for route ${route}: `, err);
|
|
2493
|
-
throw err;
|
|
2494
|
-
}
|
|
2495
|
-
};
|
|
2496
|
-
Notify = async (route, reqReflect, { audOptions = {
|
|
2497
|
-
forwardReq: false,
|
|
2498
|
-
forwardResp: false,
|
|
2499
|
-
}, show_log = true } = {}) => {
|
|
2500
|
-
if (!this.isSocketConnected) {
|
|
2501
|
-
return;
|
|
2502
|
-
}
|
|
2503
|
-
if (DEBUG && show_log) {
|
|
2504
|
-
log(`%c ws客户端消息 %c[Notify][${new Date()}] %c ${route} %c`, 'background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#3d7d3d ; padding: 1px; color: #fff', 'background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(reqReflect.desc, reqReflect.message));
|
|
2505
|
-
}
|
|
2506
|
-
this.GameNotify(route, reqReflect, create(AudienceOptionsSchema, audOptions));
|
|
2507
|
-
};
|
|
2508
|
-
subscribe(route, respType, fn) {
|
|
2509
|
-
super.subscribe(route, respType, (data) => {
|
|
2510
|
-
if (DEBUG && !this.logBlackList.includes(route)) {
|
|
2511
|
-
log(`%c ws服务端消息:[${new Date()}] %c ${route} %c`, 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', 'background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', 'background:transparent', clone(respType, data));
|
|
2512
|
-
}
|
|
2513
|
-
cat.event.dispatchEvent(route, clone(respType, data));
|
|
2514
|
-
fn?.(data);
|
|
2515
|
-
});
|
|
2516
|
-
return this;
|
|
2517
|
-
}
|
|
2518
|
-
onData(body) {
|
|
2519
|
-
super.onData(body);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
|
-
const { ccclass, property } = _decorator;
|
|
2524
|
-
/**
|
|
2525
|
-
* @describe 模态框
|
|
2526
|
-
* @author 游金宇(KM)
|
|
2527
|
-
* @date 2024-09-12 11:49:51
|
|
2528
|
-
*/
|
|
2529
|
-
let CoreUIModal = class CoreUIModal extends UILayer {
|
|
2530
|
-
default_title = null;
|
|
2531
|
-
title;
|
|
2532
|
-
prompt_content_str;
|
|
2533
|
-
prompt_content_spriteFrame;
|
|
2534
|
-
btn_confirm;
|
|
2535
|
-
confirm_spriteFrame;
|
|
2536
|
-
btn_cancel;
|
|
2537
|
-
cancel_spriteFrame;
|
|
2538
|
-
btn_close;
|
|
2539
|
-
isConfirm = false;
|
|
2540
|
-
props = {
|
|
2541
|
-
title: this.default_title,
|
|
2542
|
-
content: null,
|
|
2543
|
-
confirmCB: () => { },
|
|
2544
|
-
cancelCB: () => { },
|
|
2545
|
-
style: null
|
|
2546
|
-
};
|
|
2547
|
-
onLoad() {
|
|
2548
|
-
this.btn_cancel.node.on(Button.EventType.CLICK, this.onCancelHandler, this);
|
|
2549
|
-
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfirmHandler, this);
|
|
2550
|
-
this.btn_close.node.on(Button.EventType.CLICK, this.onCloseHandler, this);
|
|
2551
|
-
this.addAutorun([
|
|
2552
|
-
() => {
|
|
2553
|
-
this.title.spriteFrame = this.props?.title || this.default_title;
|
|
2554
|
-
},
|
|
2555
|
-
() => {
|
|
2556
|
-
if (this.props.content instanceof SpriteFrame) { //图片
|
|
2557
|
-
this.prompt_content_spriteFrame.spriteFrame = this.props.content;
|
|
2558
|
-
}
|
|
2559
|
-
else if (typeof this.props.content === 'string') {
|
|
2560
|
-
this.prompt_content_str.string = this.props.content;
|
|
2561
|
-
}
|
|
2562
|
-
else {
|
|
2563
|
-
console.error('未知类型的【UIModal】内容');
|
|
2564
|
-
}
|
|
2565
|
-
},
|
|
2566
|
-
() => {
|
|
2567
|
-
if (this.props?.style?.confirm === null) {
|
|
2568
|
-
this.btn_confirm.node.active = false;
|
|
2569
|
-
}
|
|
2570
|
-
else {
|
|
2571
|
-
this.btn_confirm.node.active = true;
|
|
2572
|
-
this.btn_confirm.getComponent(Sprite).spriteFrame = this.props.style?.confirm || this.confirm_spriteFrame;
|
|
2573
|
-
}
|
|
2574
|
-
if (this.props?.style?.cancel === null) {
|
|
2575
|
-
this.btn_cancel.node.active = false;
|
|
2576
|
-
}
|
|
2577
|
-
else {
|
|
2578
|
-
this.btn_cancel.node.active = true;
|
|
2579
|
-
this.btn_cancel.getComponent(Sprite).spriteFrame = this.props.style?.cancel || this.cancel_spriteFrame;
|
|
2580
|
-
}
|
|
2581
|
-
}
|
|
2582
|
-
]);
|
|
2583
|
-
}
|
|
2584
|
-
close() {
|
|
2585
|
-
this.props.cancelCB?.();
|
|
2586
|
-
cat.gui.closeUI(this);
|
|
2587
|
-
}
|
|
2588
|
-
onCancelHandler() {
|
|
2589
|
-
this.close();
|
|
2590
|
-
}
|
|
2591
|
-
onConfirmHandler() {
|
|
2592
|
-
this.props.confirmCB?.();
|
|
2593
|
-
}
|
|
2594
|
-
onDestroy() {
|
|
2595
|
-
if (this.isConfirm)
|
|
2596
|
-
this.props.onDestroy?.();
|
|
2597
|
-
}
|
|
2598
|
-
onCloseHandler() {
|
|
2599
|
-
this.close();
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
__decorate([
|
|
2603
|
-
property({ type: SpriteFrame, tooltip: '默认标题' }),
|
|
2604
|
-
__metadata("design:type", SpriteFrame)
|
|
2605
|
-
], CoreUIModal.prototype, "default_title", void 0);
|
|
2606
|
-
__decorate([
|
|
2607
|
-
property({ type: Sprite, tooltip: '标题节点' }),
|
|
2608
|
-
__metadata("design:type", Sprite)
|
|
2609
|
-
], CoreUIModal.prototype, "title", void 0);
|
|
2610
|
-
__decorate([
|
|
2611
|
-
property({ type: Label, tooltip: '字符串内容按钮' }),
|
|
2612
|
-
__metadata("design:type", Label)
|
|
2613
|
-
], CoreUIModal.prototype, "prompt_content_str", void 0);
|
|
2614
|
-
__decorate([
|
|
2615
|
-
property({ type: Sprite, tooltip: '图片精灵内容按钮' }),
|
|
2616
|
-
__metadata("design:type", Sprite)
|
|
2617
|
-
], CoreUIModal.prototype, "prompt_content_spriteFrame", void 0);
|
|
2618
|
-
__decorate([
|
|
2619
|
-
property({ type: Button, tooltip: '确认按钮' }),
|
|
2620
|
-
__metadata("design:type", Button)
|
|
2621
|
-
], CoreUIModal.prototype, "btn_confirm", void 0);
|
|
2622
|
-
__decorate([
|
|
2623
|
-
property({ type: SpriteFrame, tooltip: '确认按钮精灵图' }),
|
|
2624
|
-
__metadata("design:type", SpriteFrame)
|
|
2625
|
-
], CoreUIModal.prototype, "confirm_spriteFrame", void 0);
|
|
2626
|
-
__decorate([
|
|
2627
|
-
property({ type: Button, tooltip: '取消按钮' }),
|
|
2628
|
-
__metadata("design:type", Button)
|
|
2629
|
-
], CoreUIModal.prototype, "btn_cancel", void 0);
|
|
2630
|
-
__decorate([
|
|
2631
|
-
property({ type: SpriteFrame, tooltip: '取消按钮精灵图' }),
|
|
2632
|
-
__metadata("design:type", SpriteFrame)
|
|
2633
|
-
], CoreUIModal.prototype, "cancel_spriteFrame", void 0);
|
|
2634
|
-
__decorate([
|
|
2635
|
-
property({ type: Button, tooltip: '关闭按钮' }),
|
|
2636
|
-
__metadata("design:type", Button)
|
|
2637
|
-
], CoreUIModal.prototype, "btn_close", void 0);
|
|
2638
|
-
CoreUIModal = __decorate([
|
|
2639
|
-
ccclass('CoreUIModal')
|
|
2640
|
-
], CoreUIModal);
|
|
2641
|
-
|
|
2642
|
-
/**
|
|
2643
|
-
* @describe 时间管理
|
|
2644
|
-
* @author 游金宇(KM)
|
|
2645
|
-
* @date 2024-09-12 11:49:19
|
|
2646
|
-
*/
|
|
2647
|
-
var TimerType;
|
|
2648
|
-
(function (TimerType) {
|
|
2649
|
-
TimerType[TimerType["Delay"] = 0] = "Delay";
|
|
2650
|
-
TimerType[TimerType["Interval"] = 1] = "Interval";
|
|
2651
|
-
})(TimerType || (TimerType = {}));
|
|
2652
|
-
class TimerEntry {
|
|
2653
|
-
/** 唯一标识符 */
|
|
2654
|
-
tag;
|
|
2655
|
-
/** 计时器类型(计时器或延时器) */
|
|
2656
|
-
type;
|
|
2657
|
-
/** 回调函数 */
|
|
2658
|
-
callback;
|
|
2659
|
-
/** 触发剩余时间(毫秒)*/
|
|
2660
|
-
remainingTime;
|
|
2661
|
-
/** 执行时间(毫秒)*/
|
|
2662
|
-
executionTime = 0;
|
|
2663
|
-
/** 初始时间(仅适用于计时器) */
|
|
2664
|
-
initialTime;
|
|
2665
|
-
/**
|
|
2666
|
-
* 创建一个新的计时器或延时器条目
|
|
2667
|
-
* @param tag 唯一标识符
|
|
2668
|
-
* @param type 计时器类型(计时器或延时器)
|
|
2669
|
-
* @param time 剩余时间(毫秒)
|
|
2670
|
-
* @param callback 回调函数
|
|
2671
|
-
* @param initialTime 初始间隔时间(仅适用于计时器)
|
|
2672
|
-
*/
|
|
2673
|
-
constructor(tag, type, time, callback) {
|
|
2674
|
-
this.tag = tag;
|
|
2675
|
-
this.type = type;
|
|
2676
|
-
this.remainingTime = time;
|
|
2677
|
-
this.initialTime = time; // 新增字段,仅适用于计时器
|
|
2678
|
-
this.callback = callback;
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
class TimerManager extends BaseManager {
|
|
2682
|
-
timers = new Map();
|
|
2683
|
-
lastUpdateTime = Date.now();
|
|
2684
|
-
constructor(cat) {
|
|
2685
|
-
super(cat);
|
|
2686
|
-
cat.event.on(GlobalEventConstant.EVENT_HIDE, this.onHandleAppBackground, this);
|
|
2687
|
-
cat.event.on(GlobalEventConstant.EVENT_SHOW, this.onHandleAppForeground, this);
|
|
2688
|
-
// 在构造函数中启动一个定时器,以每帧调用 update 方法
|
|
2689
|
-
setInterval(this.update.bind(this), 1000);
|
|
2690
|
-
}
|
|
2691
|
-
onHandleAppBackground() {
|
|
2692
|
-
this.lastUpdateTime = Date.now();
|
|
2693
|
-
}
|
|
2694
|
-
onHandleAppForeground() {
|
|
2695
|
-
const currentTime = Date.now();
|
|
2696
|
-
const elapsedTime = (currentTime - this.lastUpdateTime);
|
|
2697
|
-
log('elapsedTime', elapsedTime);
|
|
2698
|
-
for (const entry of this.timers.values()) {
|
|
2699
|
-
if (entry.remainingTime > 0) {
|
|
2700
|
-
entry.remainingTime -= elapsedTime;
|
|
2701
|
-
entry.executionTime += elapsedTime;
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
this.lastUpdateTime = currentTime;
|
|
2705
|
-
}
|
|
2706
|
-
/**
|
|
2707
|
-
* 注册一个计时器
|
|
2708
|
-
* @param tag 注册计时器的对象
|
|
2709
|
-
* @param interval 间隔时间(毫秒)
|
|
2710
|
-
* @param callback 计时器回调函数
|
|
2711
|
-
* @returns 计时器的唯一标识
|
|
2712
|
-
*/
|
|
2713
|
-
registerInterval(tag, interval, callback) {
|
|
2714
|
-
if (this.has(tag)) {
|
|
2715
|
-
return error(`${tag}定时器已存在,请勿重复注册`);
|
|
2716
|
-
}
|
|
2717
|
-
const timerEntry = new TimerEntry(tag, TimerType.Interval, interval, callback);
|
|
2718
|
-
this.timers.set(tag, timerEntry);
|
|
2719
|
-
}
|
|
2720
|
-
/**
|
|
2721
|
-
* 注册一个延时器
|
|
2722
|
-
* @param tag 注册延时器的对象
|
|
2723
|
-
* @param delay 延时时间(毫秒)
|
|
2724
|
-
* @param callback 延时器回调函数
|
|
2725
|
-
* @returns 延时器的唯一标识
|
|
2726
|
-
*/
|
|
2727
|
-
registerDelay(tag, delay, callback) {
|
|
2728
|
-
if (this.has(tag)) {
|
|
2729
|
-
return error(`${tag}延时器已存在,请勿重复注册`);
|
|
2730
|
-
}
|
|
2731
|
-
const timerEntry = new TimerEntry(tag, TimerType.Delay, delay, callback);
|
|
2732
|
-
this.timers.set(tag, timerEntry);
|
|
2733
|
-
}
|
|
2734
|
-
/**
|
|
2735
|
-
* 取消一个计时器或延时器
|
|
2736
|
-
* @param tag 计时器或延时器的唯一标识
|
|
2737
|
-
*/
|
|
2738
|
-
unregister(tag) {
|
|
2739
|
-
if (this.has(tag)) {
|
|
2740
|
-
this.timers.delete(tag);
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
/**是否拥有定时器 */
|
|
2744
|
-
has(object) {
|
|
2745
|
-
return this.timers.has(object);
|
|
2746
|
-
}
|
|
2747
|
-
/**
|
|
2748
|
-
* 更新计时器状态
|
|
2749
|
-
* @param dt 间隔时间(毫秒)
|
|
2750
|
-
*/
|
|
2751
|
-
update() {
|
|
2752
|
-
const entriesToRemove = [];
|
|
2753
|
-
for (const [id, entry] of this.timers.entries()) {
|
|
2754
|
-
entry.remainingTime -= 1000;
|
|
2755
|
-
if (entry.remainingTime <= 0) {
|
|
2756
|
-
if (entry.type === TimerType.Interval) {
|
|
2757
|
-
entry.executionTime += entry.initialTime;
|
|
2758
|
-
}
|
|
2759
|
-
// 触发回调
|
|
2760
|
-
entry.callback(entry.executionTime);
|
|
2761
|
-
// 如果是计时器,重置剩余时间
|
|
2762
|
-
if (entry.type === TimerType.Interval) {
|
|
2763
|
-
entry.remainingTime = entry.initialTime; // 重置为初始间隔时间
|
|
2764
|
-
}
|
|
2765
|
-
else {
|
|
2766
|
-
// 如果是延时器,标记为待删除
|
|
2767
|
-
entriesToRemove.push(id);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
// 删除已完成的延时器
|
|
2772
|
-
for (const idToRemove of entriesToRemove) {
|
|
2773
|
-
this.timers.delete(idToRemove);
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
|
|
2778
|
-
/**
|
|
2779
|
-
* @describe 管理类
|
|
2780
|
-
* @author 游金宇(KM)
|
|
2781
|
-
* @date 2024-09-12 11:49:44
|
|
2782
|
-
*/
|
|
2783
|
-
class Manager {
|
|
2784
|
-
static #ins;
|
|
2785
|
-
static get instance() {
|
|
2786
|
-
if (!this.#ins) {
|
|
2787
|
-
this.#ins = new Manager();
|
|
2788
|
-
}
|
|
2789
|
-
return this.#ins;
|
|
2790
|
-
}
|
|
2791
|
-
onAppInitDelegate = new AsyncDelegate();
|
|
2792
|
-
/**音频 */
|
|
2793
|
-
audio;
|
|
2794
|
-
/**事件 */
|
|
2795
|
-
event;
|
|
2796
|
-
/**gui */
|
|
2797
|
-
gui;
|
|
2798
|
-
/**本地存储 */
|
|
2799
|
-
storage;
|
|
2800
|
-
/**资源 */
|
|
2801
|
-
res;
|
|
2802
|
-
/**工具类 */
|
|
2803
|
-
util;
|
|
2804
|
-
/**GUI */
|
|
2805
|
-
gui_bundle_name = '';
|
|
2806
|
-
/**音效本地存储key */
|
|
2807
|
-
audio_local_store_key = '';
|
|
2808
|
-
/**GUI资源配置 */
|
|
2809
|
-
setConfig = ({ gui_bundleName = 'resources', audio_local_store_key = 'game_audio' } = {}) => {
|
|
2810
|
-
this.gui_bundle_name = gui_bundleName;
|
|
2811
|
-
this.audio_local_store_key = audio_local_store_key;
|
|
2812
|
-
return this;
|
|
2813
|
-
};
|
|
2814
|
-
/**启动 */
|
|
2815
|
-
async boot() {
|
|
2816
|
-
this.res = new ResLoader();
|
|
2817
|
-
this.util = new CoreUtil(this);
|
|
2818
|
-
this.storage = new StorageManager(this);
|
|
2819
|
-
this.event = new MessageManager();
|
|
2820
|
-
this.audio = new AudioManager(this);
|
|
2821
|
-
this.gui = (await (new GuiManager(this)).init()).gui;
|
|
2822
|
-
}
|
|
2823
|
-
}
|
|
2824
|
-
const cat = Manager.instance;
|
|
2825
|
-
// 项目数据初始化之后的处理APP初始化事务
|
|
2826
|
-
game.onPostProjectInitDelegate.add(async () => {
|
|
2827
|
-
console.time('[Init App]');
|
|
2828
|
-
await cat.boot();
|
|
2829
|
-
await cat.onAppInitDelegate.dispatch();
|
|
2830
|
-
console.timeEnd('[Init App]');
|
|
2831
|
-
});
|
|
2832
|
-
|
|
2833
|
-
export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, CoreReconnection, CoreShowLoading, CoreToast, CoreUIContainer, CoreUIModal, CoreUtil, GlobalEventConstant, Gui, GuiManager, LayerType, Manager, MessageManager, ReconnectPrompt, RootUILayer, SceneLayer, TimerManager, ToastType, UILayer, WrapperSocialGameClient, cat };
|
|
1
|
+
import{AudioSource as e,_decorator as t,AudioClip as s,error as i,Node as o,director as n,log as r,sys as a,Component as c,Prefab as l,instantiate as h,isValid as d,Layers as p,view as u,Widget as f,v3 as _,tween as g,Enum as m,game as y,UITransform as v,UIOpacity as E,Tween as b,Label as C,BlockInputEvents as w,Button as k,Director as O,warn as x,assetManager as S,Asset as T,resources as N,SpriteFrame as I,Sprite as R,AsyncDelegate as A}from"cc";import{PREVIEW as M,DEBUG as D}from"cc/env";import{makeObservable as F,observable as U,autorun as H,reaction as P}from"@shimotsuki/mobx";import L from"crypto-es";import{clone as B,create as G}from"@bufbuild/protobuf";import{SocialGameClient as $,AudienceOptionsSchema as j}from"sgc";import"core-js/es/array/index.js";class q extends e{cat;initAudio(e){return this.cat=e,this}}const{ccclass:K,menu:V}=t;class W extends q{effects=new Map;load(e){return new Promise(((t,i)=>{this.cat.res.load(e,s,((s,o)=>{if(s)return i(s);this.effects.set(e,o),this.playOneShot(o,this.volume),t(o)}))}))}release(){for(let e in this.effects)this.cat.res.release(e);this.effects.clear()}}const{ccclass:Q,menu:J}=t;class X extends q{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(e){this._progress=e,this.currentTime=e*this.duration}load(e,t){this.cat.res.load(e,s,((s,o)=>{s&&i(s),this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=o,this._url=e,t&&t()}))}update(e){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class z{cat;constructor(e){this.cat=e}}var Z;!function(e){e.MUSIC_ON="AudioEventConstant/MUSIC_ON",e.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",e.EFFECT_ON="AudioEventConstant/EFFECT_ON",e.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",e.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",e.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(Z||(Z={}));class Y extends z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(e){super(e),this.local_store_key=this.cat.audio_local_store_key;var t=new o("UIAudioManager");n.addPersistRootNode(t);var s=new o("UIMusic");s.parent=t,this.music=s.addComponent(X).initAudio(e);var i=new o("UIEffect");i.parent=t,this.effect=i.addComponent(W).initAudio(e),this.load()}setMusicComplete(e=null){this.music.onComplete=e}playMusic(e,t){this.music.loop=!0,e&&this.music.load(e,(()=>{this._switch_music&&this.music?.play(),t&&t()}))}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){[0,2].includes(this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(e){this.music.progress=e}get volumeMusic(){return this._volume_music}set volumeMusic(e){this._volume_music=e,this.music.volume=e}get switchMusic(){return this._switch_music}set switchMusic(e){if(r("设置背景音乐开关值",e,this._switch_music),e==this._switch_music)return;this._switch_music=e,e?this.resumeMusic():this.pauseMusic();const t=e?Z.MUSIC_ON:Z.MUSIC_OFF;this.cat.event.has(t)&&this.cat.event.dispatchEvent(t),this.save()}async playEffect(e){this._switch_effect&&e&&await this.effect.load(e).then((()=>{this.effect.play()}))}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(e){this._volume_effect=e,this.effect.volume=e}get switchEffect(){return this._switch_effect}set switchEffect(e){if(e==this._switch_effect)return;this._switch_effect=e,e?this.effect?.play():this.effect?.stop();const t=e?Z.EFFECT_ON:Z.EFFECT_OFF;this.cat.event.has(t)&&this.cat.event.dispatchEvent(t),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let e=JSON.stringify(this.local_data);return this.cat.storage.set(this.local_store_key,e),this}load(){try{let e=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(e),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class ee extends z{_key=null;_iv=null;_id="";init(e,t){this.cat.util.encryptUtil.initCrypto(e,t),this._key=this.cat.util.encryptUtil.md5(e),this._iv=this.cat.util.encryptUtil.md5(t)}setUser(e){this._id=e}set(e,t){if(null!=(e=`${e}_${this._id}`)){if(M||(e=this.cat.util.encryptUtil.md5(e)),null==t)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(e);if("function"!=typeof t){if("object"==typeof t)try{t=JSON.stringify(t)}catch(e){return void console.error(`解析失败,str = ${t}`)}else"number"==typeof t&&(t+="");M||null==this._key||null==this._iv||(t=this.cat.util.encryptUtil.aesEncrypt(`${t}`,this._key,this._iv)),a.localStorage.setItem(e,t)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(e,t){if(null==e)return console.error("存储的key不能为空"),null;e=`${e}_${this._id}`,M||(e=this.cat.util.encryptUtil.md5(e));let s=a.localStorage.getItem(e);return null==s||""===s||M||null==this._key||null==this._iv||(s=this.cat.util.encryptUtil.aesDecrypt(s,this._key,this._iv)),null===s?t:s}getNumber(e,t=0){var s=this.get(e);return Number(s)||t}getBoolean(e){var t=this.get(e);return Boolean(t)||!1}getJson(e,t){var s=this.get(e);return s&&JSON.parse(s)||t}remove(e){null!=e?(e=`${e}_${this._id}`,M||(e=this.cat.util.encryptUtil.md5(e)),a.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function te(e,t,s,i){var o,n=arguments.length,r=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,s,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,s,r):o(t,s))||r);return n>3&&r&&Object.defineProperty(t,s,r),r}function se(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class ie extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];messageManagers=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),F(this,{props:U,data:U})}onAutoObserver(){}addAutorun(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=H(e);this.autorunDisposers.push(t)})),this}addReaction(e,t,s){const i=P(e,t,s);return this.reactionDisposers.push(i),this}addAudoListener(e){return this.messageManagers.includes(e)||this.messageManagers.push(e),e}_onPreDestroy(){this.autorunDisposers.forEach((e=>{e()})),this.reactionDisposers.forEach((e=>{e()})),this.autorunDisposers=[],this.reactionDisposers=[],super._onPreDestroy()}onDisable(){this.onHide(),st.event.deleteEventByComponent(this),this.messageManagers.forEach((e=>{e.deleteEventByComponent(this)})),this.messageManagers=[],this.removeListener()}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(e,t){let s=e instanceof l?h(e):e instanceof c?e.node:e;return this.setOptions(t),s.addChild(this.node),this}setOptions(e){if(e)for(let t in e)switch(t){case"hook":e.hook&&(this.hook=e.hook);break;case"props":null!==e.props&&"object"==typeof e.props&&(this.props=e.props);break;case"data":null!==e.data&&"object"==typeof e.data&&(this.data=e.data)}}setUpdateData(e){return e&&Object.assign(this.data,e),this}setUpdateProps(e){return this.props,e&&Object.assign(this.props,e),this}removeAndDestroy(){d(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(e){return this.node.setPosition(e),this}setScale(e){return this.node.setScale(e),this}setAngle(e){return this.node.angle=e,this}setRotation(e){return this.node.setRotation(e),this}setRotationFromEuler(e){return this.node.setRotationFromEuler(e),this}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return oe(this.node,e),this}}const oe=(e,t)=>{e.layer="string"==typeof t?2**p.nameToLayer(t):t,e?.children.forEach((e=>{oe(e,t)}))};class ne extends ie{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=u.getVisibleSize()}async showTween({isMotion:e=!0,direction:t="center",duration:s=.1,isBounce:i=!0,bounceDuration:o=.05}){if(this.lastEnterDirection=t,e){const e=this.node.getComponent(f);let o,n;e&&(e.updateAlignment(),e.enabled=!1),_(1.1,1.1,1),"center"==t?(o=_(.01,.01,.01),n=_(1,1,1)):(o="left"==t?_(-this.screen.width,0,0):"right"==t?_(this.screen.width,0,0):_(0,"top"==t?this.screen.height:-this.screen.height,0),n=_(0,0,0)),await this.handle(t,s,o,n,i),e&&(e.enabled=!0)}}async hideTween({isMotion:e=!0,direction:t,duration:s=.1}){if(t=t||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,g(this.node).removeSelf(),e){const e=this.node.getComponent(f);let i,o;e&&(e.enabled=!1),"center"==t?(i=this.node.scale,o=_(0,0,0)):(o="left"==t?_(-this.screen.width,0,0):"right"==t?_(this.screen.width,0,0):_(0,"top"==t?this.screen.height:-this.screen.height,0),i=this.node.getPosition()),await this.handle(t,s,i,o,!1)}this.removeAndDestroy()}}async handle(e,t,s,i,o){"center"==e?this.node.setScale(s):this.node.setPosition(s),await this.deftween(t,{["center"==e?"scale":"position"]:i},o)}deftween(e,t,s,i){return new Promise(((s,i)=>{g(this.node).to(e,t).call((()=>{s()})).start()}))}}const{ccclass:re,property:ae}=t;var ce;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(ce||(ce={}));class le extends ie{type=ce.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,st.event.on(Z.EFFECT_ON,this.onPlayEffectHandler,this).on(Z.EFFECT_OFF,this.onStopEffectHandler,this).on(Z.MUSIC_ON,this.onPlayMusicHandler,this).on(Z.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=st.audio;this.audioSource.volume=this.type===ce.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=st.audio;this.audioSource.playing||!(this.type===ce.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}te([ae({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:m(ce)}),se("design:type",Object)],le.prototype,"type",void 0),te([ae({tooltip:"音源",type:s}),se("design:type",Object)],le.prototype,"clip",void 0),te([ae({tooltip:"循环"}),se("design:type",Object)],le.prototype,"loop",void 0),te([ae({tooltip:"音量"}),se("design:type",Object)],le.prototype,"volume",void 0),te([ae({tooltip:"是否启用自动播放"}),se("design:type",Object)],le.prototype,"playOnAwake",void 0);const{ccclass:he,property:de}=t;class pe extends ne{type=ce.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),st.event.on(Z.EFFECT_ON,this.onPlayEffectHandler,this).on(Z.EFFECT_OFF,this.onStopEffectHandler,this).on(Z.MUSIC_ON,this.onPlayMusicHandler,this).on(Z.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:e,volumeMusic:t}=st.audio;this.audioSource.volume=this.type===ce.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=st.audio;this.audioSource.playing||!(this.type===ce.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}te([de({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:m(ce)}),se("design:type",Object)],pe.prototype,"type",void 0),te([de({tooltip:"音源",type:s}),se("design:type",Object)],pe.prototype,"clip",void 0),te([de({tooltip:"循环"}),se("design:type",Object)],pe.prototype,"loop",void 0),te([de({tooltip:"音量"}),se("design:type",Object)],pe.prototype,"volume",void 0),te([de({tooltip:"是否启用自动播放"}),se("design:type",Object)],pe.prototype,"playOnAwake",void 0);const{ccclass:ue,property:fe}=t;var _e;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(_e||(_e={}));let ge=class extends ie{fixed_node;slide_node;fixed_label;slide_label;onLoad(){this.fixed_node.active=this.slide_node.active=!1}start(){this.show()}async show(){return new Promise((async(e,t)=>{const{title:s,type:i,fixed_time:o}=this.props;if(i==_e.FIXED){this.fixed_node.active=!0,this.fixed_label.string=`${s}`,this.fixed_label.updateRenderData(!0);const t=this.fixed_label.node.getComponent(v).height;t-this.fixed_node.getComponent(v).height>0&&(this.fixed_node.getComponent(v).height=t+100),this.scheduleOnce((()=>{this.node.destroy(),e()}),o)}else{this.slide_node.active=!0,this.slide_label.string=`${s}`,this.slide_label.updateRenderData(!0);const t=this.slide_label.node.getComponent(v).width;this.slide_node.getComponent(v).width-t<100&&(this.slide_node.getComponent(v).width=t+100),this.playAnim(this.node).then((()=>{e()}))}}))}playAnim(e){return new Promise(((t,s)=>{const i=this.node.getComponent(E),o=g(i).delay(1.2).to(.5,{opacity:0}).call((()=>{b.stopAllByTarget(e),this.node.destroy(),t()}));g(e).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){b.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var me;te([fe({type:o,tooltip:"固定节点"}),se("design:type",o)],ge.prototype,"fixed_node",void 0),te([fe({type:o,tooltip:"滑动节点"}),se("design:type",o)],ge.prototype,"slide_node",void 0),te([fe({type:C,tooltip:"固定标签节点"}),se("design:type",C)],ge.prototype,"fixed_label",void 0),te([fe({type:C,tooltip:"滑动标签节点"}),se("design:type",C)],ge.prototype,"slide_label",void 0),ge=te([ue("CoreToast")],ge),function(e){e.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",e.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",e.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",e.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",e.ONLINE="GlobalEventConstant/ONLINE",e.OFFLINE="GlobalEventConstant/OFFLINE",e.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",e.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(me||(me={}));const{ccclass:ye,property:ve}=t;let Ee=class extends ne{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Le)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){st.event.on(me.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const e=this.brother[this.brother.length-1];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const e=this.brother[this.brother.length-2];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(e){return d(this)&&this.scene_mask&&this.scene_mask.tween.addChild(e),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(e){return this.gui=e,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(e){this.scene_mask.node.active=!this.gui.root_mask.active&&e}};te([ve({type:o}),se("design:type",o)],Ee.prototype,"scene_mask_node",void 0),te([ve({type:o}),se("design:type",o)],Ee.prototype,"ui_container",void 0),Ee=te([ye("CoreUIContainer")],Ee);class be extends ne{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){st.event.dispatchEvent(me.ROOT_MASK_UPDATE)}}const{ccclass:Ce,property:we}=t;let ke=class extends be{title;loadingTween;loading_rotate=0;onAutoObserver(){this.addAutorun([()=>{this.props?.title&&(this.title.string=`${this.props?.title}`),this.title.node.active=!!this.props?.title?.length},()=>{this.getComponent(w).enabled=!!this.props?.mask}])}update(e){this.loading_rotate+=220*e,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};te([we({type:C,tooltip:"标题"}),se("design:type",C)],ke.prototype,"title",void 0),te([we({type:o,tooltip:"动画"}),se("design:type",o)],ke.prototype,"loadingTween",void 0),ke=te([Ce("CoreShowLoading")],ke);const{ccclass:Oe,property:xe}=t;var Se;!function(e){e.RECONNECTED="重连成功",e.RECONNECTING="正在重连",e.MAX_RECONNECT="重连次数超出限制,请检查网络",e.RECONNECTED_ERROR="重连失败,请检查网络",e.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",e.KICK="账号已下线",e.OFFLINE="网络已断开",e.ONLINE="网络已连接",e.GAME_ERROR="连接游戏服错误"}(Se||(Se={}));let Te=class extends be{common_prompt_text;btn_confirm;is_close=!1;props={content:null};initUI(){this.btn_confirm.node.active=!1}onLoad(){this.btn_confirm.node.on(k.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(e){this.updatePromptText(e,e==Se.RECONNECTING)}updatePromptText(e,t=!1){if(this.unscheduleAllCallbacks(),this.props.content=e,r("更新提示文案:",e),t){let t=0;const s=()=>{t=(t+1)%4,this.common_prompt_text.string=e+["","·","··","···"][t]};this.schedule(s,.5)}}onConfirmHandler(){this.is_close=!0,st.gui.hideReconnect()}};te([xe({type:C,tooltip:"通用提示文本"}),se("design:type",C)],Te.prototype,"common_prompt_text",void 0),te([xe({type:k,tooltip:"确定按钮"}),se("design:type",k)],Te.prototype,"btn_confirm",void 0),Te=te([Oe("CoreReconnection")],Te);const{ccclass:Ne,property:Ie}=t;let Re=class extends be{text;btn_confirm;onLoad(){this.btn_confirm.node.on(k.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),st.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};te([Ie({type:C,tooltip:"提示文本"}),se("design:type",C)],Re.prototype,"text",void 0),te([Ie({type:k,tooltip:"确定按钮"}),se("design:type",k)],Re.prototype,"btn_confirm",void 0),Re=te([Ne("CoreNotice")],Re);class Ae extends ie{isReload}const{ccclass:Me,property:De}=t;var Fe;!function(e){e[e.UI=0]="UI",e[e.LOADING=1]="LOADING",e[e.TOAST=2]="TOAST",e[e.RECONNECTTION=3]="RECONNECTTION",e[e.NOTICE=4]="NOTICE"}(Fe||(Fe={}));let Ue=class extends ie{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;cat;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;onEventListener(){this.cat.event.on(me.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(e){this.cat=e;const t=n.getScene();return r("init scene"),t&&this.changeScene(t),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(e){this.toastQueue.push(e),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const e=this.toastQueue.shift(),t=()=>{h(this.toast_ui_prefab).getComponent(ge).addToParent(this.root_toast,{props:e}),this.scheduleOnce((()=>{this.processQueueWithInterval()}),this.minInterval)};0===this.root_toast.children.length?t():this.scheduleOnce(t,this.minInterval)}hideToast(){return this.root_toast&&this.root_toast.children.forEach((e=>{e.getComponent(ge)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:e="",mask:t=!0,black:s=!0}={}){if(r("showLoading",e),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:e,mask:t,black:s}});else{const i=h(this.loading_ui_prefab);this.loading_ui_component=i.getComponent(ke).addToParent(this.root_ui,{props:{title:e,mask:t,black:s}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(e){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:e});else{const t=h(this.reconnection_ui_prefab);this.reconnection_ui_component=t.getComponent(Te).addToParent(this.root_ui,{props:{content:e}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(e){const t=h(this.notice_ui_prefab);return this.notice_ui_component=t.getComponent(Re).addToParent(this.root_ui,{props:e}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(e,t,s){r("加载场景",e,t,s);let i={},o=s??!1;return"boolean"==typeof t?o=t:i=t??{},r("当前场景",n.getScene()?.uuid,n.getScene()?.name),n.once(O.EVENT_BEFORE_SCENE_LAUNCH,(e=>{r("Director.EVENT_BEFORE_SCENE_LAUNCH",e),this.changeScene(e,i,o)})),n.loadScene(e),this}resetScene(e=""){return e=e||this.currentScene,this.loadScene(e)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(e,t,s){this.currentScene=e.name,this.createUILayer(e);const i=e.getComponentInChildren(Ae);i&&(i.isReload=s??!1),i?.setOptions(t)}createUILayer(e){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const t=h(this.ui_prefab);this.ui_container_component=t.getComponent(Ee).setGui(this).addToParent(e)}reloadScene(){this.loadScene(this.currentScene,!0)}async closeUI(e,t){const{component:s}=this.findUIBaseLayer(e,!1);s&&(s.setOptions({...t?.hook??{},...t?.props??{}}),await s.hideTween(t||{}),this.ui_container_component?.subMask())}async openUI(e,t){const{rootNode:s,component:i}=this.findUIBaseLayer(e,!0);s.getComponent(ne),i?.setOptions(t),s&&this.ui_container_component?.addNodeToTween(s).addMask(),i&&await i.showTween(t||{}),this.ui_container_component?.ui_container&&i?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(e,t){let s,n=null;if(e instanceof o){s=e;const t=e.components.filter((e=>e instanceof ne));if(!t.length)return i(`${e.name}节点未找到继承自BaseLayer的组件`),{rootNode:s,component:n};1==t.length?n=t[0]:x(`${e.name}节点存在多个继承自BaseLayer的组件`)}else if(s=e.node,n=e,t){for(;s.parent;)s=s.parent;n.root=s}else s=e.root;return{rootNode:s,component:n}}onRootUpdate(){const e=this.root_ui.children.findLastIndex((e=>e.active&&e!=this.root_mask));if(this.root_mask.active=-1!=e,e>-1){const t=this.root_ui.children[e];this.root_mask.setSiblingIndex(t.getSiblingIndex()-1)}this.cat.event.dispatchEvent(me.ROOT_MASK_CHANGE)}};te([De({type:l,tooltip:"断线重连UI预制体"}),se("design:type",l)],Ue.prototype,"reconnection_ui_prefab",void 0),te([De({type:l,tooltip:"提示UI预制体"}),se("design:type",l)],Ue.prototype,"toast_ui_prefab",void 0),te([De({type:l,tooltip:"加载UI预制体"}),se("design:type",l)],Ue.prototype,"loading_ui_prefab",void 0),te([De({type:l,tooltip:"公告UI预制体"}),se("design:type",l)],Ue.prototype,"notice_ui_prefab",void 0),te([De({type:l,tooltip:"UI层预制体"}),se("design:type",l)],Ue.prototype,"ui_prefab",void 0),te([De({type:o,tooltip:"root-UI层"}),se("design:type",o)],Ue.prototype,"root_ui",void 0),te([De({type:o,tooltip:"root-组件层"}),se("design:type",o)],Ue.prototype,"root_toast",void 0),te([De({type:o,tooltip:"root-mask"}),se("design:type",o)],Ue.prototype,"root_mask",void 0),Ue=te([Me("Gui")],Ue);const{ccclass:He,property:Pe}=t;let Le=class extends ie{tween};var Be;te([Pe({type:o,tooltip:"动画节点"}),se("design:type",o)],Le.prototype,"tween",void 0),Le=te([He("CoreBlackMask")],Le),function(e){e.Root="prefabs/root",e.Toast="prefabs/toast",e.BlackMask="prefabs/black-mask",e.Loading="prefabs/loading",e.Notice="prefabs/notice",e.Reconnection="prefabs/reconnection"}(Be||(Be={}));class Ge extends z{gui;#e="resources";getGuiPrefabByType=(e,t)=>new Promise(((s,i)=>{console.log(e,`${t}`),this.cat.res.load(e,t,((e,t)=>{e?i(e):s(t)}))}));async init(){this.#e=this.cat.gui_bundle_name;const e=await this.getGuiPrefabByType(this.#e,Be.Root),t=h(e);return this.gui=t.getComponent(Ue).init(this.cat),n.addPersistRootNode(t),this}}class $e{get=(e,t,s="resources")=>S.getBundle(s).get(e,t);isAssetType=e=>"function"==typeof e&&e.prototype instanceof T;async load(...e){let t=null,s=null,i=null;"string"==typeof e[0]&&"string"==typeof e[1]&&(t=e.shift());let o=e.shift();this.isAssetType(e[0])&&(s=e.shift()),2==e.length&&(i=e.shift());const n=e.shift();let r=N;if(t&&"resources"!=t){S.bundles.has(t)||await this.loadBundle(t);let e=S.bundles.get(t);e&&(r=e)}i&&n?r.load(o,s,i,n):n?r.load(o,s,n):r.load(o,s)}async loadDir(...e){let t=null,s=null,i=null,o=null;"string"==typeof e[0]&&"string"==typeof e[1]&&(t=e.shift());let n=e.shift();this.isAssetType(e[0])&&(s=e.shift()),2==e.length&&(i=e.shift()),o=e.shift();let r=N;if(t&&"resources"!=t){S.bundles.has(t)||await this.loadBundle(t);let e=S.bundles.get(t);e&&(r=e)}i&&o?r.loadDir(n,s,i,o):o?r.loadDir(n,s,o):r.loadDir(n,s)}loadRemote(e,...t){var s,i=null;2==t.length&&(i=t.shift()),s=t.shift(),S.loadRemote(e,{ext:".png",...i},s)}loadBundle=(e,t)=>new Promise(((s,i)=>{const o=(e,t)=>{if(e)return i(e);s(t)};t?S.loadBundle(e,{version:t},o):S.loadBundle(e,o)}));releasePrefabtDepsRecursively=e=>{var t=S.assets.get(e);(S.releaseAsset(t),t instanceof l)&&S.dependUtil.getDepsRecursively(e).forEach((e=>{S.assets.get(e).decRef()}))};release=(e,t="resources")=>{var s=S.getBundle(t);if(s){var i=s.get(e);i&&this.releasePrefabtDepsRecursively(i._uuid)}};releaseDir=(e,t="resources")=>{var s=S.getBundle(t),i=s?.getDirWithPath(e);i?.map((e=>{this.releasePrefabtDepsRecursively(e.uuid)})),!e&&"resources"!=t&&s&&S.removeBundle(s)};dump=()=>{S.assets.forEach(((e,t)=>{r(S.assets.get(t))})),r(`当前资源总数:${S.assets.count}`)}}class je{events=new Map;on(e,t,s){if(!e||!t)return x(`注册【${e}】事件的侦听器函数为空`),this;const i=this.events.get(e)??this.events.set(e,new Map).get(e);return i.has(s)?(x(`名为【${e}】的事件重复注册侦听器`),this):(i.set(s,t),this)}once(e,t,s){let i=(o,n)=>{this.off(e,i,s),i=null,t.call(s,o,n)};this.on(e,i,s)}off(e,t,s){if(!this.events.get(e)?.has(s))return this;const o=this.events.get(e);return o.get(s)!==t?(i(`${s}注册事件和取消事件不一致`),this):(o.delete(s),this)}dispatchEvent(e,t){if(!this.events.has(e))return this;const s=this.events.get(e);for(const[i,o]of s)o.call(i,t,e);return this}offAll(){this.events.clear()}has(e){return this.events.has(e)}deleteEventByComponent(e){for(const[t,s]of this.events){for(const[t]of s)t===e&&s.delete(t);0===s.size&&this.events.delete(t)}}}let qe=null;const Ke={stringify:e=>{const t={ct:e.ciphertext.toString(L.enc.Base64)};return e.iv&&(t.iv=e.iv.toString()),e.salt&&(t.s=e.salt.toString()),JSON.stringify(t)},parse:e=>{const t=JSON.parse(e),s=L.lib.CipherParams.create({ciphertext:L.enc.Base64.parse(t.ct)});return t.iv&&(s.iv=L.enc.Hex.parse(t.iv)),t.s&&(s.salt=L.enc.Hex.parse(t.s)),s}};var Ve=Object.freeze({__proto__:null,JsonFormatter:Ke,aesDecrypt:(e,t,s)=>L.AES.decrypt(e,t,{iv:qe,format:Ke}).toString(L.enc.Utf8),aesEncrypt:(e,t,s)=>L.AES.encrypt(e,t,{iv:qe,format:Ke}).toString(),initCrypto:(e,t)=>{qe=L.enc.Hex.parse(t)},md5:e=>L.MD5(e).toString()});class We extends z{encryptUtil=Ve}class Qe extends ${isNeedReconnect=!1;isOnline=!0;isInBackground=!1;running=!1;index=0;logBlackList=[];constructor(e,t,s){super(e,t,s),this.running=!0,this.addEvent()}addEvent(){this.on("connected",(()=>this.handleEvent({type:"connected"}))).on("reconnected",(()=>this.handleEvent({type:"reconnected"}))).on("disconnect",(e=>this.handleEvent({type:"disconnect",ev:e}))).on("handshakeError",(e=>this.handleEvent({type:"handshakeError",ret:e}))).on("kick",(()=>this.handleEvent({type:"kick"}))).on("reconnecting",(()=>this.handleEvent({type:"reconnecting"}))).on("maxReconnect",(()=>this.handleEvent({type:"maxReconnect"}))).on("error",(e=>this.handleEvent({type:"error",ev:e}))),st.event.on(me.EVENT_SHOW,this.onShowHandler,this).on(me.EVENT_HIDE,this.onHideHandler,this).on(me.ONLINE,this.onOnlineHandler,this).on(me.OFFLINE,this.onOfflineHandler,this)}removeEvent(){this.removeAllListeners(),st.event.off(me.EVENT_SHOW,this.onShowHandler,this).off(me.EVENT_HIDE,this.onHideHandler,this).off(me.ONLINE,this.onOnlineHandler,this).off(me.OFFLINE,this.onOfflineHandler,this)}onShowHandler(){r("[SHOW]"),this.isInBackground=!1,this.isNeedReconnect&&this.isOnline&&this.handleEvent({type:"show"})}onHideHandler(e){r("[HIDE]"),e().finally((()=>{this.isInBackground=!0,this.handleEvent({type:"hide"})}))}onOnlineHandler(){this.isOnline=!0,r("正在检查网络状态:"+(this.isOnline?"在线":"断开")),this.handleEvent({type:"online"})}onOfflineHandler(){this.isOnline=!1,r("正在检查网络状态:"+(this.isOnline?"在线":"断开")),this.handleEvent({type:"offline"})}async handleEvent(e){if(this.running)switch(e.type){case"init":break;case"connected":r("ws连接成功状态 connected"),this.isNeedReconnect=!1;break;case"reconnected":r("ws重连成功状态 reconnected",this.isSocketConnected),this.isNeedReconnect=!1,r("%c 重连成功状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index);try{await this.connectRequest(),r("重连成功状态 connectRequest "),st.gui.showToast({title:Se.RECONNECTED}),st.gui.hideReconnect().hideLoading(),st.gui.reloadScene()}catch(e){console.error(e),st.gui.showReconnect(Se.GAME_ERROR)}break;case"disconnect":r("断开连接状态 disconnect",e.ev),r("%c 断开连接状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),this.isNeedReconnect=!0,this.handleEvent({type:"reconnect"});break;case"handshakeError":r("参数错误状态 handshakeError",e.ret),st.gui.showReconnect(Se.CONNECT_PARAM_ERROR),this.handleEvent({type:"destroy"});break;case"kick":r("%c 被踢出状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),r("被踢出状态 kick"),st.gui.showReconnect(Se.KICK),this.handleEvent({type:"destroy"});break;case"reconnecting":r("正在重连状态 reconnecting"),this.isOnline&&this.isInBackground;break;case"maxReconnect":r("超出最大重连状态 maxReconnect"),st.gui.showReconnect(Se.MAX_RECONNECT);break;case"error":this.isOnline&&(r("ws报错状态 error",e.ev),"string"==typeof e.ev&&st.gui.showToast({title:e.ev}),st.gui.showReconnect(Se.RECONNECTED_ERROR));break;case"online":st.gui.showReconnect(Se.ONLINE),r("在线状态 online"),this.handleEvent({type:"reconnect"});break;case"offline":this.disconnect(!0),r("离线状态 offline"),this.isNeedReconnect=!0,st.gui.showReconnect(Se.OFFLINE);break;case"show":r("前台状态 show"),this.handleEvent({type:"reconnect"});break;case"hide":r("后台状态 hide"),this.disconnect(!0),this.isNeedReconnect=!0;break;case"reconnect":r("重连状态 reconnect"),this.isNeedReconnect&&!this.isInBackground&&this.isOnline&&(st.gui.showLoading({title:"正在重连"}),this.reset(),this.index+=1,r("%c ws重连次数","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),this.reconnectImmediately());break;case"destroy":r("销毁状态 destroy"),this.destroyStateMachine();break;default:r("Unknown event:",e.type)}}destroy(){this.handleEvent({type:"destroy"})}disconnect(e=!1){super.disconnect(e)}destroyStateMachine(){r("Destroying state machine"),this.running=!1,this.removeEvent(),this.disconnect(!0)}request(e,t,s){return D&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),new Promise(((o,n)=>{super.request(e,t,s).then((t=>{D&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(s,t)),o(t)}),(e=>{i("request err",e),n(e)}))}))}async Request(e,t,s,{audOptions:i={forwardReq:!1,forwardResp:!1},show_log:o=!0}={}){if(!this.isSocketConnected)throw""+(this.isSocketConnected?"未加入战局/观战":"Socket未连接");return D&&o&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),this.GameRequest(e,t,s,G(j,i))}async GameRequest(e,t,s,i){return new Promise(((o,n)=>{super.GameRequest(e,t,s,i).then((t=>{D&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(s,t)),o(t)}),(e=>{st.gui.showToast({title:e.msg}),n(e)}))}))}async gameRequest(e,t,s){return D&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),super.gameRequest(e,t,s)}GameNotify=async(e,t,s)=>{try{super.GameNotify(e,t,s)}catch(t){throw console.error(`Error in connectRequest for route ${e}: `,t),t}};Notify=async(e,t,{audOptions:s={forwardReq:!1,forwardResp:!1},show_log:i=!0}={})=>{this.isSocketConnected&&(D&&i&&r(`%c ws客户端消息 %c[Notify][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),this.GameNotify(e,t,G(j,s)))};subscribe(e,t,s){return super.subscribe(e,t,(i=>{D&&!this.logBlackList.includes(e)&&r(`%c ws服务端消息:[${new Date}] %c ${e} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t,i)),st.event.dispatchEvent(e,B(t,i)),s?.(i)})),this}onData(e){super.onData(e)}}const{ccclass:Je,property:Xe}=t;let ze=class extends ne{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(k.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(k.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(k.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content instanceof I?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容")},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(R).spriteFrame=this.props.style?.confirm||this.confirm_spriteFrame),null===this.props?.style?.cancel?this.btn_cancel.node.active=!1:(this.btn_cancel.node.active=!0,this.btn_cancel.getComponent(R).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),st.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Ze;te([Xe({type:I,tooltip:"默认标题"}),se("design:type",I)],ze.prototype,"default_title",void 0),te([Xe({type:R,tooltip:"标题节点"}),se("design:type",R)],ze.prototype,"title",void 0),te([Xe({type:C,tooltip:"字符串内容按钮"}),se("design:type",C)],ze.prototype,"prompt_content_str",void 0),te([Xe({type:R,tooltip:"图片精灵内容按钮"}),se("design:type",R)],ze.prototype,"prompt_content_spriteFrame",void 0),te([Xe({type:k,tooltip:"确认按钮"}),se("design:type",k)],ze.prototype,"btn_confirm",void 0),te([Xe({type:I,tooltip:"确认按钮精灵图"}),se("design:type",I)],ze.prototype,"confirm_spriteFrame",void 0),te([Xe({type:k,tooltip:"取消按钮"}),se("design:type",k)],ze.prototype,"btn_cancel",void 0),te([Xe({type:I,tooltip:"取消按钮精灵图"}),se("design:type",I)],ze.prototype,"cancel_spriteFrame",void 0),te([Xe({type:k,tooltip:"关闭按钮"}),se("design:type",k)],ze.prototype,"btn_close",void 0),ze=te([Je("CoreUIModal")],ze),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(Ze||(Ze={}));class Ye{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(e,t,s,i){this.tag=e,this.type=t,this.remainingTime=s,this.initialTime=s,this.callback=i}}class et extends z{timers=new Map;lastUpdateTime=Date.now();constructor(e){super(e),e.event.on(me.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(me.EVENT_SHOW,this.onHandleAppForeground,this),setInterval(this.update.bind(this),1e3)}onHandleAppBackground(){this.lastUpdateTime=Date.now()}onHandleAppForeground(){const e=Date.now(),t=e-this.lastUpdateTime;r("elapsedTime",t);for(const e of this.timers.values())e.remainingTime>0&&(e.remainingTime-=t,e.executionTime+=t);this.lastUpdateTime=e}registerInterval(e,t,s){if(this.has(e))return i(`${e}定时器已存在,请勿重复注册`);const o=new Ye(e,Ze.Interval,t,s);this.timers.set(e,o)}registerDelay(e,t,s){if(this.has(e))return i(`${e}延时器已存在,请勿重复注册`);const o=new Ye(e,Ze.Delay,t,s);this.timers.set(e,o)}unregister(e){this.has(e)&&this.timers.delete(e)}has(e){return this.timers.has(e)}update(){const e=[];for(const[t,s]of this.timers.entries())s.remainingTime-=1e3,s.remainingTime<=0&&(s.type===Ze.Interval&&(s.executionTime+=s.initialTime),s.callback(s.executionTime),s.type===Ze.Interval?s.remainingTime=s.initialTime:e.push(t));for(const t of e)this.timers.delete(t)}}class tt{static#t;static get instance(){return this.#t||(this.#t=new tt),this.#t}onAppInitDelegate=new A;audio;event;gui;storage;res;util;gui_bundle_name="";audio_local_store_key="";setConfig=({gui_bundleName:e="resources",audio_local_store_key:t="game_audio"}={})=>(this.gui_bundle_name=e,this.audio_local_store_key=t,this);async boot(){this.res=new $e,this.util=new We(this),this.storage=new ee(this),this.event=new je,this.audio=new Y(this),this.gui=(await new Ge(this).init()).gui}}const st=tt.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await st.boot(),await st.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{Z as AudioEventConstant,Y as AudioManager,le as AudioSourceBaseComponent,pe as AudioSourceUILayer,ce as AudioTypeEnum,ie as BaseComponent,z as BaseManager,Be as BasePrefab,Le as CoreBlackMask,Re as CoreNotice,Te as CoreReconnection,ke as CoreShowLoading,ge as CoreToast,Ee as CoreUIContainer,ze as CoreUIModal,We as CoreUtil,me as GlobalEventConstant,Ue as Gui,Ge as GuiManager,Fe as LayerType,tt as Manager,je as MessageManager,Se as ReconnectPrompt,be as RootUILayer,Ae as SceneLayer,et as TimerManager,_e as ToastType,ne as UILayer,Qe as WrapperSocialGameClient,st as cat};
|