@gongxh/bit-ui 0.0.1 → 0.0.6

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/bit-ui.cjs CHANGED
@@ -1,9 +1,48 @@
1
1
  'use strict';
2
2
 
3
- var bitCore = require('@gongxh/bit-core');
4
3
  var fairyguiCc = require('fairygui-cc');
4
+ var bitCore = require('@gongxh/bit-core');
5
5
  var cc = require('cc');
6
6
 
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
+
23
+
24
+ function __decorate(decorators, target, key, desc) {
25
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
+ 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;
28
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
29
+ }
30
+
31
+ function __awaiter(thisArg, _arguments, P, generator) {
32
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
+ return new (P || (P = Promise))(function (resolve, reject) {
34
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
38
+ });
39
+ }
40
+
41
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
42
+ var e = new Error(message);
43
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
+ };
45
+
7
46
  /**
8
47
  * @Author: Gongxh
9
48
  * @Date: 2024-12-08
@@ -34,97 +73,20 @@ exports.AdapterType = void 0;
34
73
  /** 固定的 不适配 */
35
74
  AdapterType[AdapterType["Fixed"] = 2] = "Fixed";
36
75
  })(exports.AdapterType || (exports.AdapterType = {}));
37
-
38
- /**
39
- * @Author: Gongxh
40
- * @Date: 2025-01-11
41
- * @Description: 窗口顶边栏
42
- * 窗口顶边资源栏 同组中只会有一个显示
43
- */
44
- class UIHeader extends fairyguiCc.GComponent {
45
- constructor() {
46
- super(...arguments);
47
- /** 窗口适配类型 */
48
- this.adapterType = exports.AdapterType.Full;
49
- /** 引用计数 @internal */
50
- this._refCount = 0;
51
- }
52
- onHide() {
53
- }
54
- onAdapted() {
55
- }
56
- /**
57
- * 初始化 (内部方法)
58
- * @internal
59
- */
60
- _init() {
61
- this.onInit();
62
- }
63
- /**
64
- * 窗口适配 (内部方法)
65
- * @internal
66
- */
67
- _adapted() {
68
- this.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
69
- this.setPivot(0.5, 0.5, true);
70
- switch (this.adapterType) {
71
- case exports.AdapterType.Full:
72
- this.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
73
- break;
74
- case exports.AdapterType.Bang:
75
- this.setSize(bitCore.Screen.SafeWidth, bitCore.Screen.SafeHeight, true);
76
- break;
77
- }
78
- this.onAdapted();
79
- }
80
- /**
81
- * 显示 (内部方法)
82
- * @param {IWindow} window 所属窗口
83
- * @internal
84
- */
85
- _show(window) {
86
- var _a;
87
- this.visible = true;
88
- this.onShow(window, (_a = window.getHeaderInfo()) === null || _a === void 0 ? void 0 : _a.userdata);
89
- }
90
- /**
91
- * 隐藏 (内部方法)
92
- * @internal
93
- */
94
- _hide() {
95
- this.visible = false;
96
- this.onHide();
97
- }
98
- /**
99
- * 关闭 (内部方法)
100
- * @internal
101
- */
102
- _close() {
103
- this.onClose();
104
- this.dispose();
105
- }
106
- /**
107
- * 增加引用计数 (内部方法)
108
- * @internal
109
- */
110
- _addRef() {
111
- this._refCount++;
112
- }
113
- /**
114
- * 减少引用计数 (内部方法)
115
- * @internal
116
- */
117
- _decRef() {
118
- return --this._refCount;
119
- }
120
- /**
121
- * 屏幕大小改变时被调用 (内部方法)
122
- * @internal
123
- */
124
- _screenResize() {
125
- this._adapted();
126
- }
127
- }
76
+ /** 定义装饰器元数据的key */
77
+ var MetadataKey;
78
+ (function (MetadataKey) {
79
+ /** 属性 */
80
+ MetadataKey["prop"] = "__uipropmeta__";
81
+ /** 回调 */
82
+ MetadataKey["callback"] = "__uicbmeta__";
83
+ /** 控制器 */
84
+ MetadataKey["control"] = "__uicontrolmeta__";
85
+ /** 动画 */
86
+ MetadataKey["transition"] = "__uitransitionmeta__";
87
+ /** 原始名称 */
88
+ MetadataKey["originalName"] = "__UI_ORIGINAL_NAME__";
89
+ })(MetadataKey || (MetadataKey = {}));
128
90
 
129
91
  /**
130
92
  * @Author: Gongxh
@@ -242,698 +204,1106 @@ PropsHelper._config = {};
242
204
 
243
205
  /**
244
206
  * @Author: Gongxh
245
- * @Date: 2024-12-26
246
- * @Description: 自定义组件扩展帮助类
207
+ * @Date: 2025-12-25
208
+ * @Description: 信息池 注册的窗口、header、自定义组件的信息
247
209
  */
248
- class ComponentExtendHelper {
249
- static register() {
250
- for (const { ctor, res } of exports._uidecorator.getComponentMaps().values()) {
251
- const componentKey = `${res.pkg}/${res.name}`;
252
- if (this._registeredComponents.has(componentKey)) {
253
- console.debug(`自定义组件已注册,跳过 组件名:${res.name} 包名:${res.pkg}`);
254
- continue;
255
- }
256
- console.debug(`自定义组件注册 组件名:${res.name} 包名:${res.pkg}`);
257
- this.registerComponent(ctor, res.pkg, res.name);
258
- this._registeredComponents.add(componentKey);
259
- }
260
- }
210
+ /** @internal */
211
+ class InfoPool {
261
212
  /**
262
- * 动态注册自定义组件
263
- * @param ctor 组件构造函数
213
+ * 添加窗口信息
214
+ * @param ctor 类的构造函数
215
+ * @param group 窗口组名
264
216
  * @param pkg 包名
265
- * @param name 组件名
217
+ * @param name 窗口名
218
+ * @param bundleName bundle名
219
+ * @internal
266
220
  */
267
- static dynamicRegister(ctor, pkg, name) {
268
- const componentKey = `${pkg}/${name}`;
269
- if (this._registeredComponents.has(componentKey)) {
270
- console.debug(`自定义组件已注册,跳过 组件名:${name} 包名:${pkg}`);
221
+ static add(ctor, group, pkg, name, pkgs) {
222
+ if (this.has(name)) {
223
+ console.warn(`窗口【${name}】已注册,跳过,请检查是否重复注册`);
271
224
  return;
272
225
  }
273
- bitCore.debug(`自定义组件注册 组件名:${name} 包名:${pkg}`);
274
- this.registerComponent(ctor, pkg, name);
275
- this._registeredComponents.add(componentKey);
276
- }
277
- /**
278
- * 注册自定义组件信息
279
- * @param info
280
- * @internal
281
- */
282
- static registerComponent(ctor, pkg, name) {
283
- // 自定义组件扩展
284
- const onConstruct = function () {
285
- PropsHelper.serializeProps(this, pkg, name);
286
- this.onInit && this.onInit();
287
- };
288
- ctor.prototype.onConstruct = onConstruct;
289
- // 自定义组件扩展
226
+ bitCore.debug(`窗口注册 窗口名:${name} 包名:${pkg} 组名:${group}`);
227
+ this._windowInfos.set(name, {
228
+ ctor: ctor,
229
+ group: group,
230
+ pkgName: pkg,
231
+ name: name
232
+ });
233
+ // 窗口组件扩展
290
234
  fairyguiCc.UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
291
- }
292
- }
293
- /** 已注册的组件集合 @internal */
294
- ComponentExtendHelper._registeredComponents = new Set();
295
-
296
- /**
297
- * @Author: Gongxh
298
- * @Date: 2024-12-07
299
- * @Description: 窗口管理类
300
- */
301
- class UIManager {
302
- /** 配置UI包的一些信息 (可以不配置 完全手动管理) */
303
- static initPackageConfig(res) {
304
- this._resPool.initPackageConfig(res);
235
+ this.addWindowPkg(name, pkg);
236
+ if (pkgs.length > 0) {
237
+ for (const pkg of pkgs) {
238
+ this.addWindowPkg(name, pkg);
239
+ }
240
+ }
305
241
  }
306
242
  /**
307
- * 异步打开一个窗口 (如果UI包的资源未加载, 会自动加载 配合 UIManager.initPackageConfig一起使用)
308
- * @param windowName 窗口名
309
- * @param userdata 用户数据
243
+ * 注册窗口header信息
244
+ * @param ctor 类的构造函数
245
+ * @param pkg 包名
246
+ * @param name 窗口名
247
+ * @param bundleName bundle名
248
+ * @internal
310
249
  */
311
- static showWindow(windowName, userdata) {
312
- return new Promise((resolve, reject) => {
313
- this._resPool.loadWindowRes(windowName, {
314
- complete: () => {
315
- this.showWindowIm(windowName, userdata);
316
- resolve();
317
- },
318
- fail: (pkgs) => {
319
- reject(pkgs);
320
- }
321
- });
250
+ static addHeader(ctor, pkg, name) {
251
+ if (this.hasHeader(name)) {
252
+ console.warn(`header【${name}】已注册,跳过,请检查是否重复注册`);
253
+ return;
254
+ }
255
+ bitCore.debug(`header注册 header名:${name} 包名:${pkg}`);
256
+ this._headerInfos.set(name, {
257
+ ctor: ctor,
258
+ pkgName: pkg
322
259
  });
260
+ // 窗口header扩展
261
+ fairyguiCc.UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
323
262
  }
324
263
  /**
325
- * 显示指定名称的窗口,并传递可选的用户数据。(用于已加载过资源的窗口)
326
- * @param windowName - 窗口的名称。
327
- * @param userdata - 可选参数,用于传递给窗口的用户数据。
328
- */
329
- static showWindowIm(windowName, userdata) {
330
- const info = this._resPool.get(windowName);
331
- const windowGroup = this.getWindowGroup(info.group);
332
- this._resPool.addResRef(windowName);
333
- windowGroup.showWindow(info, userdata);
334
- }
335
- /**
336
- * 关闭窗口
337
- * @param windowName 窗口名
264
+ * 注册自定义组件信息
265
+ * @param ctor 组件构造函数
266
+ * @param pkg 包名
267
+ * @param name 组件名
268
+ * @internal
338
269
  */
339
- static closeWindow(windowName) {
340
- if (!this._windows.has(windowName)) {
341
- console.warn(`窗口不存在 ${windowName} 不需要关闭`);
270
+ static addComponent(ctor, pkg, name) {
271
+ const componentKey = `${pkg}/${name}`;
272
+ if (this._customComponents.has(componentKey)) {
273
+ console.debug(`自定义组件【${name}】已注册,跳过,请检查是否重复注册`);
342
274
  return;
343
275
  }
344
- // 先在窗口组中移除
345
- let info = this._resPool.get(windowName);
346
- const windowGroup = this.getWindowGroup(info.group);
347
- windowGroup._removeWindow(windowName);
348
- // 窗口组中没有窗口了
349
- if (windowGroup.size == 0) {
350
- let index = this._queryGroupNames.indexOf(windowGroup.name);
351
- if (index > 0 && windowGroup.name == this.getTopGroupName()) {
352
- do {
353
- const groupName = this._queryGroupNames[--index];
354
- let group = this.getWindowGroup(groupName);
355
- if (group.size > 0) {
356
- this.getWindow(group.getTopWindowName())._recover();
357
- break;
358
- }
359
- } while (index >= 0);
360
- }
361
- }
276
+ bitCore.debug(`自定义组件注册 组件名:${name} 包名:${pkg}`);
277
+ this._customComponents.add(componentKey);
278
+ this.registerComponent(ctor, pkg, name);
362
279
  }
363
280
  /**
364
- * 关闭所有窗口
365
- * @param ignoreNames 忽略关闭的窗口名
281
+ * 是否存在窗口信息
282
+ * @param name 窗口名
283
+ * @returns 是否存在
284
+ * @internal
366
285
  */
367
- static closeAllWindow(ignoreNames = []) {
368
- let existIgnore = ignoreNames.length > 0;
369
- this._windows.forEach((window, name) => {
370
- if (!existIgnore) {
371
- this.closeWindow(name);
372
- }
373
- else if (!ignoreNames.includes(name)) {
374
- this.closeWindow(name);
375
- }
376
- });
377
- if (!existIgnore) {
378
- this._windows.clear();
379
- }
380
- }
381
- /**
382
- * 获取当前最顶层的窗口实例。
383
- * @template T - 窗口实例的类型,必须继承自 IWindow 接口。
384
- * @returns {T | null} - 返回最顶层的窗口实例,如果没有找到则返回 null。
385
- * @description 该方法会遍历所有窗口组,找到最顶层的窗口并返回其实例。
386
- */
387
- static getTopWindow() {
388
- let len = this._queryGroupNames.length;
389
- for (let i = len; i > 0;) {
390
- let group = this.getWindowGroup(this._queryGroupNames[--i]);
391
- if (group.size > 0) {
392
- return this.getWindow(group.getTopWindowName());
393
- }
394
- }
395
- return null;
286
+ static has(name) {
287
+ return this._windowInfos.has(name);
396
288
  }
397
289
  /**
398
- * 根据窗口名称获取窗口实例。
399
- * @template T 窗口类型,必须继承自IWindow接口。
400
- * @param name 窗口的名称。
401
- * @returns 如果找到窗口,则返回对应类型的窗口实例;否则返回null。
290
+ * 获取窗口信息
291
+ * @param name 窗口名
292
+ * @returns 窗口信息
293
+ * @internal
402
294
  */
403
- static getWindow(name) {
404
- return this._windows.get(name);
295
+ static get(name) {
296
+ if (!this.has(name)) {
297
+ throw new Error(`窗口【${name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);
298
+ }
299
+ return this._windowInfos.get(name);
405
300
  }
406
301
  /**
407
- * 检查是否存在指定名称的窗口。
408
- * @param name 窗口的名称。
409
- * @returns 如果存在指定名称的窗口,则返回 true,否则返回 false。
302
+ * 是否存在窗口header信息
303
+ * @param name 窗口header名
304
+ * @returns 是否存在
305
+ * @internal
410
306
  */
411
- static hasWindow(name) {
412
- return this._windows.has(name);
307
+ static hasHeader(name) {
308
+ return this._headerInfos.has(name);
413
309
  }
414
310
  /**
415
- * 根据给定的组名获取窗口组。如果组不存在,则抛出错误。
416
- * @param groupName 窗口组的名称。
417
- * @returns 返回找到的窗口组。
311
+ * 获取窗口header信息
312
+ * @param name 窗口header名
313
+ * @returns 窗口header信息
314
+ * @internal
418
315
  */
419
- static getWindowGroup(groupName) {
420
- if (this._groups.has(groupName)) {
421
- return this._groups.get(groupName);
316
+ static getHeader(name) {
317
+ if (!this.hasHeader(name)) {
318
+ throw new Error(`窗口header【${name}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);
422
319
  }
423
- throw new Error(`UIManager.getWindowGroup: window group 【${groupName}】 not found`);
320
+ return this._headerInfos.get(name);
424
321
  }
425
322
  /**
426
- * 获取当前顶层窗口组的名称。
427
- * 返回第一个包含至少一个窗口的窗口组名称。(该方法只检查不忽略查询的窗口组)
428
- * 如果没有找到任何包含窗口的组,则返回空字符串。
323
+ * 设置UI包所在的bundle名
324
+ * @param pkg 包名
325
+ * @param bundleName bundle名
326
+ * @internal
429
327
  */
430
- static getTopGroupName() {
431
- let len = this._queryGroupNames.length;
432
- for (let i = len - 1; i >= 0; i--) {
433
- let name = this._queryGroupNames[i];
434
- let group = this._groups.get(name);
435
- if (group.size > 0) {
436
- return name;
437
- }
328
+ static addBundleName(pkg, bundleName) {
329
+ if (this._customPackageBundle.has(pkg)) {
330
+ console.warn(`UI包【${pkg}】已设置过包名`);
331
+ return;
438
332
  }
439
- return "";
333
+ this._customPackageBundle.set(pkg, bundleName);
440
334
  }
441
335
  /**
442
- * 初始化窗口管理器,设置资源池。 (框架内部使用)
443
- * @param resPool - 窗口资源池实例。
336
+ * 获取UI包所在的bundle名
337
+ * @param pkg 包名
338
+ * @returns bundle名
444
339
  * @internal
445
340
  */
446
- static _init(resPool) {
447
- this._resPool = resPool;
341
+ static getBundleName(pkg) {
342
+ return this._customPackageBundle.get(pkg) || "resources";
448
343
  }
449
344
  /**
450
- * 向窗口管理器添加一个新窗口。 (框架内部使用)
451
- * @param name 窗口的唯一标识符。
452
- * @param window 要添加的窗口对象,需实现 IWindow 接口。
345
+ * UI包所在的自定义路径
346
+ * @param pkg 包名
347
+ * @param path 路径
453
348
  * @internal
454
349
  */
455
- static _addWindow(name, window) {
456
- this._windows.set(name, window);
350
+ static addPackagePath(pkg, path) {
351
+ if (this._customPackagePath.has(pkg)) {
352
+ console.warn(`UI包【${pkg}】已设置过自定义路径`);
353
+ return;
354
+ }
355
+ this._customPackagePath.set(pkg, path);
457
356
  }
458
357
  /**
459
- * 移除指定名称的窗口。 (框架内部使用)
460
- * @param name 窗口的名称。
358
+ * 获取UI包所在的路径
359
+ * @param pkg 包名
360
+ * @returns 路径
461
361
  * @internal
462
362
  */
463
- static _removeWindow(name) {
464
- if (this.hasWindow(name)) {
465
- this._windows.get(name)._close();
466
- this._windows.delete(name);
467
- this._resPool.releaseWindowRes(name);
468
- }
363
+ static getPackagePath(pkg) {
364
+ return `${this._customPackagePath.get(pkg) || 'ui'}/${pkg}`;
469
365
  }
470
366
  /**
471
- * 注册所有UI窗口类到资源池中。 (框架内部使用)
472
- * 该方法遍历所有通过_uidecorator.getWindowMaps()获取的窗口映射,
473
- * 并将每个窗口的资源名称、构造函数、分组和包信息添加到资源池中。
367
+ * 添加窗口需要的包名
368
+ * @param windowName 窗口名
369
+ * @param pkg 包名
474
370
  * @internal
475
371
  */
476
- static registerUI() {
477
- // 窗口注册
478
- for (const { ctor, res } of exports._uidecorator.getWindowMaps().values()) {
479
- bitCore.debug(`窗口注册 窗口名:${res.name} 包名:${res.pkg} 组名:${res.group}`);
480
- this._resPool.add(ctor, res.group, res.pkg, res.name, res.bundle);
372
+ static addWindowPkg(windowName, pkg) {
373
+ this._dirty = true;
374
+ if (!this._windowPkgs.has(windowName)) {
375
+ this._windowPkgs.set(windowName, [pkg]);
481
376
  }
482
- // 窗口header注册
483
- for (const { ctor, res } of exports._uidecorator.getHeaderMaps().values()) {
484
- bitCore.debug(`header注册 header名:${res.name} 包名:${res.pkg}`);
485
- this._resPool.addHeader(ctor, res.pkg, res.name, res.bundle);
377
+ else {
378
+ this._windowPkgs.get(windowName).push(pkg);
486
379
  }
487
- // 组件注册
488
- ComponentExtendHelper.register();
489
- }
490
- /** 动态注册窗口到资源池中 */
491
- static dynamicRegisterWindow(ctor, group, pkg, name, bundle) {
492
- bitCore.debug(`窗口注册 窗口名:${name} 包名:${pkg} 组名:${group}`);
493
- this._resPool.add(ctor, group, pkg, name, bundle);
494
- }
495
- /** 动态注册窗口header到资源池中 */
496
- static dynamicRegisterHeader(ctor, pkg, name, bundle) {
497
- bitCore.debug(`header注册 header名:${name} 包名:${pkg}`);
498
- this._resPool.addHeader(ctor, pkg, name, bundle);
499
380
  }
500
381
  /**
501
- * 向窗口管理器添加一个窗口组 如果窗口组名称已存在,则抛出错误. (内部方法)
502
- * @param group 要添加的窗口组
382
+ * 获取窗口需要的包名列表
383
+ * @param windowName 窗口名
384
+ * @returns 包名列表
503
385
  * @internal
504
386
  */
505
- static _addWindowGroup(group) {
506
- if (this._groups.has(group.name)) {
507
- throw new Error(`UIManager._addWindowGroup: window group 【${group.name}】 already exists`);
387
+ static getWindowPkg(windowName) {
388
+ if (this._dirty) {
389
+ this.refreshWindowPackages();
390
+ this._dirty = false;
508
391
  }
509
- this._groups.set(group.name, group);
510
- // 不忽略查询 加到列表中
511
- !group.isIgnore && this._queryGroupNames.push(group.name);
392
+ return this._windowPkgs.get(windowName) || [];
512
393
  }
513
394
  /**
514
- * 屏幕大小改变时 调用所有窗口的screenResize方法 (内部方法)
395
+ * 添加手动管理资源加载 卸载的包名
396
+ * @param pkgName 包名
515
397
  * @internal
516
398
  */
517
- static _screenResize() {
518
- this._windows.forEach((window) => {
519
- window.screenResize();
520
- });
521
- this._groups.forEach((group) => {
522
- group._screenResize();
523
- });
399
+ static addManualPackage(pkgName) {
400
+ this._dirty = true;
401
+ this._manualPackages.add(pkgName);
524
402
  }
525
403
  /**
526
- * 获取资源池实例 (内部方法)
527
- * @returns {WindowResPool} 资源池实例
404
+ * 注册自定义组件信息
405
+ * @param info
528
406
  * @internal
529
407
  */
530
- static _getResPool() {
531
- return this._resPool;
532
- }
533
- }
534
- /** 窗口组 @internal */
535
- UIManager._groups = new Map();
536
- /** 不忽略查询的窗口组名 @internal */
537
- UIManager._queryGroupNames = [];
538
- /** 所有窗口全部放到这个map中 @internal */
539
- UIManager._windows = new Map();
540
-
541
- /**
542
- * @Author: Gongxh
543
- * @Date: 2024-12-11
544
- * @Description: UI 装饰器
408
+ static registerComponent(ctor, pkg, name) {
409
+ // 自定义组件扩展
410
+ const onConstruct = function () {
411
+ PropsHelper.serializeProps(this, pkg, name);
412
+ this.onInit && this.onInit();
413
+ };
414
+ ctor.prototype.onConstruct = onConstruct;
415
+ // 自定义组件扩展
416
+ fairyguiCc.UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
417
+ }
418
+ /** 刷新窗口需要的包名信息 */
419
+ static refreshWindowPackages() {
420
+ for (const packages of this._windowPkgs.values()) {
421
+ let len = packages.length;
422
+ for (let index = len - 1; index >= 0; index--) {
423
+ const name = packages[index];
424
+ if (this._manualPackages.has(name)) {
425
+ packages.splice(index, 1);
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+ /** @internal */
432
+ InfoPool._windowInfos = new Map(); // 窗口信息池 窗口名 -> 窗口信息
433
+ /** @internal */
434
+ InfoPool._headerInfos = new Map(); // 窗口header信息池 窗口header名 -> header信息
435
+ /** @internal */
436
+ InfoPool._customComponents = new Set(); // 自定义组件信息池 自定义组件名 -> 组件信息
437
+ /** @internal */
438
+ InfoPool._customPackageBundle = new Map(); // UI包所在的bundle名 1对1 默认: resources
439
+ /** @internal */
440
+ InfoPool._customPackagePath = new Map(); // 自定义UI包所在的路径 1对1
441
+ /** @internal */
442
+ InfoPool._windowPkgs = new Map(); // 窗口名对应的包名列表 窗口名 -> 包名列表
443
+ /** @internal */
444
+ InfoPool._manualPackages = new Set(); // 需要手动管理的资源包名
445
+ /** @internal */
446
+ InfoPool._dirty = true;
447
+
448
+ /**
449
+ * @Author: Gongxh
450
+ * @Date: 2024-12-13
451
+ * @Description:
545
452
  */
546
- exports._uidecorator = void 0;
547
- (function (_uidecorator) {
548
- /** @internal */
549
- const UIPropMeta = "__uipropmeta__";
550
- /** @internal */
551
- const UICBMeta = "__uicbmeta__";
552
- /** @internal */
553
- const UIControlMeta = "__uicontrolmeta__";
453
+ /** @internal */
454
+ class ResLoader {
455
+ /**
456
+ * 设置UI包加载相关回调函数
457
+ * @internal
458
+ */
459
+ static setCallbacks(callbacks) {
460
+ this._showWaitWindow = callbacks.showWaitWindow;
461
+ this._hideWaitWindow = callbacks.hideWaitWindow;
462
+ this._onLoadFail = callbacks.fail;
463
+ }
554
464
  /** @internal */
555
- const UITransitionMeta = "__uitransitionmeta__";
556
- /** 用来存储窗口注册信息 @internal */
557
- const uiclassMap = new Map();
465
+ static setAutoRelease(auto) {
466
+ this.autoRelease = auto;
467
+ }
558
468
  /**
559
- * 获取对象属性
560
- * @param obj 对象
561
- * @param key 属性名
562
- * @returns 属性值
469
+ * 增加等待窗的引用计数
470
+ * @internal
563
471
  */
564
- function getObjectProp(obj, key) {
565
- if (obj.hasOwnProperty(key)) {
566
- return obj[key];
472
+ static addWaitRef() {
473
+ var _a;
474
+ if (this.waitRef++ === 0) {
475
+ (_a = this._showWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
567
476
  }
568
- return (obj[key] = Object.assign({}, obj[key]));
569
477
  }
570
- /** 获取窗口注册信息 */
571
- function getWindowMaps() {
572
- return uiclassMap;
573
- }
574
- _uidecorator.getWindowMaps = getWindowMaps;
575
478
  /**
576
- * 窗口装饰器
577
- * @param {string} groupName 窗口组名称
578
- * @param {string} pkgName fgui包名
579
- * @param {string} name 窗口名 (与fgui中的组件名一一对应)
479
+ * 减少等待窗的引用计数
480
+ * @internal
580
481
  */
581
- function uiclass(groupName, pkgName, name, bundle) {
582
- /** target 类的构造函数 */
583
- return function (ctor) {
584
- // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
585
- const originalCtor = ctor;
586
- uiclassMap.set(originalCtor, {
587
- ctor: ctor, // 存储实际的构造函数(可能被包装过)
588
- props: ctor[UIPropMeta] || null,
589
- callbacks: ctor[UICBMeta] || null,
590
- controls: ctor[UIControlMeta] || null,
591
- transitions: ctor[UITransitionMeta] || null,
592
- res: {
593
- group: groupName,
594
- pkg: pkgName,
595
- name: name,
596
- bundle: bundle || "",
597
- },
598
- });
599
- // 首次引擎注册完成后 动态注册窗口,使用实际的构造函数
600
- _registerFinish && UIManager.dynamicRegisterWindow(ctor, groupName, pkgName, name, bundle || "");
601
- return ctor;
602
- };
482
+ static decWaitRef() {
483
+ var _a;
484
+ if (--this.waitRef === 0) {
485
+ (_a = this._hideWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
486
+ }
603
487
  }
604
- _uidecorator.uiclass = uiclass;
605
- /** 用来存储组件注册信息 @internal */
606
- let uicomponentMap = new Map();
607
- /** 获取组件注册信息 */
608
- function getComponentMaps() {
609
- return uicomponentMap;
488
+ /** @internal */
489
+ static getRef(pkg) {
490
+ return this.pkgRefs.get(pkg) || 0;
491
+ }
492
+ /** @internal */
493
+ static addRef(pkg) {
494
+ this.pkgRefs.set(pkg, this.getRef(pkg) + 1);
495
+ }
496
+ /** @internal */
497
+ static subRef(pkg) {
498
+ let ref = this.getRef(pkg) - 1;
499
+ this.pkgRefs.set(pkg, ref);
500
+ return ref;
610
501
  }
611
- _uidecorator.getComponentMaps = getComponentMaps;
612
502
  /**
613
- * UI组件装饰器
614
- * @param {string} pkg 包名
615
- * @param {string} name 组件名
503
+ * 加载窗口需要的包
504
+ * @param windowName 窗口名
616
505
  */
617
- function uicom(pkg, name) {
618
- return function (ctor) {
619
- // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
620
- const originalCtor = ctor;
621
- // log(`pkg:【${pkg}】 uicom prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
622
- uicomponentMap.set(originalCtor, {
623
- ctor: ctor, // 存储实际的构造函数(可能被包装过)
624
- props: ctor[UIPropMeta] || null,
625
- callbacks: ctor[UICBMeta] || null,
626
- controls: ctor[UIControlMeta] || null,
627
- transitions: ctor[UITransitionMeta] || null,
628
- res: {
629
- pkg: pkg,
630
- name: name,
631
- }
632
- });
633
- // 首次引擎注册完成后 动态注册自定义组件,使用实际的构造函数
634
- _registerFinish && ComponentExtendHelper.dynamicRegister(ctor, pkg, name);
635
- return ctor;
636
- };
506
+ static loadWindowRes(windowName) {
507
+ // 获取窗口需要的资源包
508
+ let packageNames = InfoPool.getWindowPkg(windowName);
509
+ if (packageNames.length <= 0) {
510
+ return Promise.resolve();
511
+ }
512
+ return this.loadUIPackages(packageNames, windowName);
637
513
  }
638
- _uidecorator.uicom = uicom;
639
- /** 用来存储组件注册信息 @internal */
640
- let uiheaderMap = new Map();
641
- /** 获取header注册信息 */
642
- function getHeaderMaps() {
643
- return uiheaderMap;
514
+ /**
515
+ * 卸载窗口需要的包
516
+ * @param windowName 窗口名
517
+ */
518
+ static unloadWindowRes(windowName) {
519
+ // 获取窗口需要的资源包
520
+ let packageNames = InfoPool.getWindowPkg(windowName);
521
+ if (packageNames.length <= 0) {
522
+ return;
523
+ }
524
+ this.unloadUIPackages(packageNames);
644
525
  }
645
- _uidecorator.getHeaderMaps = getHeaderMaps;
646
526
  /**
647
- * UI header装饰器
648
- * @param {string} pkg 包名
649
- * @param {string} name 组件名
527
+ * 根据传入的UIPackage名称集合 加载多个UI包资源
528
+ * @param packages 包名列表
529
+ * @param windowName 窗口名(用于失败回调)
530
+ * @internal
650
531
  */
651
- function uiheader(pkg, name, bundle) {
652
- return function (ctor) {
653
- // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
654
- const originalCtor = ctor;
655
- // log(`pkg:【${pkg}】 uiheader prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
656
- uiheaderMap.set(originalCtor, {
657
- ctor: ctor, // 存储实际的构造函数(可能被包装过)
658
- props: ctor[UIPropMeta] || null,
659
- callbacks: ctor[UICBMeta] || null,
660
- controls: ctor[UIControlMeta] || null,
661
- transitions: ctor[UITransitionMeta] || null,
662
- res: {
663
- pkg: pkg,
664
- name: name,
665
- bundle: bundle || "",
666
- }
667
- });
668
- // 首次引擎注册完成后 动态注册窗口header,使用实际的构造函数
669
- _registerFinish && UIManager.dynamicRegisterHeader(ctor, pkg, name, bundle || "");
670
- return ctor;
671
- };
532
+ static loadUIPackages(packages, windowName) {
533
+ return __awaiter(this, void 0, void 0, function* () {
534
+ // 先找出来所有需要加载的包名
535
+ let list = packages.filter(pkg => this.getRef(pkg) <= 0);
536
+ if (list.length <= 0) {
537
+ // 增加引用计数
538
+ packages.forEach(pkg => this.addRef(pkg));
539
+ return;
540
+ }
541
+ // 一定有需要加载的资源
542
+ this.addWaitRef();
543
+ try {
544
+ // 获取包对应的bundle名
545
+ let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
546
+ // 加载bundle
547
+ yield this.loadBundles(bundleNames, windowName);
548
+ // 顺序加载每个UI包
549
+ yield this.loadUIPackagesSequentially(list, windowName);
550
+ // 所有包加载成功后,减少等待窗引用计数
551
+ this.decWaitRef();
552
+ // 增加包资源的引用计数
553
+ packages.forEach(pkg => this.addRef(pkg));
554
+ }
555
+ catch (err) {
556
+ // 减少等待窗的引用计数
557
+ this.decWaitRef();
558
+ throw err;
559
+ }
560
+ });
672
561
  }
673
- _uidecorator.uiheader = uiheader;
674
562
  /**
675
- * UI属性装饰器
676
- * @param {Object} target 实例成员的类的原型
677
- * @param {string} name 属性名
678
- *
679
- * example: @uiprop node: GObject
563
+ * 加载多个bundle(顺序加载)
564
+ * @param bundleNames bundle名集合
565
+ * @param windowName 窗口名(用于失败回调)
566
+ * @internal
680
567
  */
681
- function uiprop(target, name) {
682
- // debug("属性装饰器:", target.constructor, name);
683
- getObjectProp(target.constructor, UIPropMeta)[name] = 1;
568
+ static loadBundles(bundleNames, windowName) {
569
+ return __awaiter(this, void 0, void 0, function* () {
570
+ let unloadedBundleNames = bundleNames.filter(bundleName => bundleName !== "resources" && !cc.assetManager.getBundle(bundleName));
571
+ if (unloadedBundleNames.length <= 0) {
572
+ return;
573
+ }
574
+ // 顺序加载每个bundle
575
+ for (const bundleName of unloadedBundleNames) {
576
+ yield new Promise((resolve, reject) => {
577
+ cc.assetManager.loadBundle(bundleName, (err, bundle) => {
578
+ if (err) {
579
+ // 调用失败回调
580
+ if (this._onLoadFail) {
581
+ this._onLoadFail(windowName, 1, bundleName);
582
+ }
583
+ reject(new Error(`bundle【${bundleName}】加载失败`));
584
+ }
585
+ else {
586
+ resolve();
587
+ }
588
+ });
589
+ });
590
+ }
591
+ });
684
592
  }
685
- _uidecorator.uiprop = uiprop;
686
593
  /**
687
- * UI控制器装饰器
688
- * @param {Object} target 实例成员的类的原型
689
- * @param {string} name 属性名
690
- *
691
- * example: @uicontrol node: GObject
594
+ * 顺序加载多个 UI
595
+ * @param packages 包名列表
596
+ * @param windowName 窗口名(用于失败回调)
597
+ * @internal
692
598
  */
693
- function uicontrol(target, name) {
694
- // debug("属性装饰器:", target.constructor, name);
695
- getObjectProp(target.constructor, UIControlMeta)[name] = 1;
599
+ static loadUIPackagesSequentially(packages, windowName) {
600
+ return __awaiter(this, void 0, void 0, function* () {
601
+ // 顺序加载每个UI包
602
+ for (const pkg of packages) {
603
+ yield this.loadSingleUIPackage(pkg, windowName);
604
+ }
605
+ });
696
606
  }
697
- _uidecorator.uicontrol = uicontrol;
698
607
  /**
699
- * UI动画装饰器
700
- * @param {Object} target 实例成员的类的原型
701
- * @param {string} name 属性名
702
- *
703
- * example: @uitransition node: GObject
608
+ * 加载单个 UI
609
+ * @param pkg 包名
610
+ * @param windowName 窗口名(用于失败回调)
611
+ * @internal
704
612
  */
705
- function uitransition(target, name) {
706
- // debug("属性装饰器:", target.constructor, name);
707
- getObjectProp(target.constructor, UITransitionMeta)[name] = 1;
613
+ static loadSingleUIPackage(pkg, windowName) {
614
+ return new Promise((resolve, reject) => {
615
+ let bundleName = InfoPool.getBundleName(pkg);
616
+ let bundle = bundleName === "resources" ? cc.resources : cc.assetManager.getBundle(bundleName);
617
+ fairyguiCc.UIPackage.loadPackage(bundle, InfoPool.getPackagePath(pkg), (err) => {
618
+ if (err) {
619
+ // 调用失败回调
620
+ if (windowName && this._onLoadFail) {
621
+ this._onLoadFail(windowName, 2, pkg);
622
+ }
623
+ reject(new Error(`UI包【${pkg}】加载失败`));
624
+ }
625
+ else {
626
+ resolve();
627
+ }
628
+ });
629
+ });
708
630
  }
709
- _uidecorator.uitransition = uitransition;
710
631
  /**
711
- * 方法装饰器 (给点击事件用)
712
- * @param {Object} target 实例成员的类的原型
713
- * @param {string} name 方法名
632
+ * 根据传入的UIPackage名称集合 卸载多个UI包资源
633
+ * @param pkgNames UIPackage名称集合
634
+ * @internal
714
635
  */
715
- function uiclick(target, name, descriptor) {
716
- // debug("方法装饰器:", target.constructor, name, descriptor);
717
- getObjectProp(target.constructor, UICBMeta)[name] = descriptor.value;
636
+ static unloadUIPackages(packages) {
637
+ for (const pkg of packages) {
638
+ if (this.subRef(pkg) === 0 && this.autoRelease) {
639
+ fairyguiCc.UIPackage.removePackage(pkg);
640
+ }
641
+ }
718
642
  }
719
- _uidecorator.uiclick = uiclick;
720
- let _registerFinish = false;
721
- /** 首次UI注册完成 */
722
- function setRegisterFinish() {
723
- _registerFinish = true;
643
+ /**
644
+ * 释放不再使用中的自动加载的UI资源
645
+ * 释放所有引用计数 <= 0 的UI资源
646
+ * @internal
647
+ */
648
+ static releaseUnusedRes() {
649
+ let keys = Array.from(this.pkgRefs.keys());
650
+ for (const key of keys) {
651
+ if (this.getRef(key) <= 0) {
652
+ fairyguiCc.UIPackage.removePackage(key);
653
+ this.pkgRefs.delete(key);
654
+ }
655
+ }
724
656
  }
725
- _uidecorator.setRegisterFinish = setRegisterFinish;
726
- })(exports._uidecorator || (exports._uidecorator = {}));
727
- const _global = (globalThis || window || global);
728
- _global["getKunpoRegisterWindowMaps"] = function () {
729
- return exports._uidecorator.getWindowMaps();
730
- };
731
- _global["getKunpoRegisterComponentMaps"] = function () {
732
- return exports._uidecorator.getComponentMaps();
733
- };
734
- _global["getKunpoRegisterHeaderMaps"] = function () {
735
- return exports._uidecorator.getHeaderMaps();
736
- };
657
+ }
658
+ /**
659
+ * 等待窗口的引用计数
660
+ * 每次加载开始时 +1 每次加载完成时 -1
661
+ * @internal
662
+ */
663
+ ResLoader.waitRef = 0;
664
+ /** 包的引用计数 包名 -> 引用计数 */
665
+ ResLoader.pkgRefs = new Map();
666
+ /**
667
+ * 自动释放UI资源
668
+ * @internal
669
+ */
670
+ ResLoader.autoRelease = true;
671
+ /** UI包加载回调 - 显示加载等待窗 @internal */
672
+ ResLoader._showWaitWindow = null;
673
+ /** UI包加载回调 - 隐藏加载等待窗 @internal */
674
+ ResLoader._hideWaitWindow = null;
675
+ /** UI包加载回调 - 打开窗口时UI包加载失败 @internal */
676
+ ResLoader._onLoadFail = null;
737
677
 
738
678
  /**
739
679
  * @Author: Gongxh
740
- * @Date: 2024-12-14
741
- * @Description: 窗口基类和fgui组件对接
680
+ * @Date: 2024-12-07
681
+ * @Description: 窗口管理类
742
682
  */
743
- class UIWindow extends fairyguiCc.GComponent {
744
- constructor() {
745
- super(...arguments);
746
- /** 窗口类型 */
747
- this.type = exports.WindowType.Normal;
748
- /** 窗口适配类型 */
749
- this.adapterType = exports.AdapterType.Full;
750
- /** header (内部使用) @internal */
751
- this._header = null;
752
- /** 窗口是否被遮挡了 @internal */
753
- this._isCover = false;
754
- /** 吞噬触摸的节点 @internal */
755
- this._swallowComponent = null;
683
+ class WindowManager {
684
+ /** @internal */
685
+ static get bgAlpha() {
686
+ return this._bgAlpha;
687
+ }
688
+ /** @internal */
689
+ static set bgAlpha(value) {
690
+ this._bgAlpha = value;
756
691
  }
757
692
  /**
758
- * 初始化方法 (框架内部使用)
759
- * @param swallowTouch 是否吞噬触摸事件
760
- * @param bgAlpha 底部遮罩的透明度
693
+ * 屏幕大小改变时 调用所有窗口的screenResize方法 (内部方法)
761
694
  * @internal
762
695
  */
763
- _init(swallowTouch, bgAlpha) {
764
- if (swallowTouch) {
765
- // 吞噬触摸事件,需要一个全屏的节点, 窗口本身可能留有安全区的边
766
- let bgNode = new fairyguiCc.GComponent();
767
- bgNode.name = "swallow";
768
- bgNode.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
769
- bgNode.setPivot(0.5, 0.5, true);
770
- bgNode.setPosition(this.width * 0.5, this.height * 0.5);
771
- this.addChild(bgNode);
772
- // 调整显示层级
773
- bgNode.parent.setChildIndex(bgNode, 0);
774
- bgNode.onClick(this.onEmptyAreaClick, this);
775
- bgNode.opaque = swallowTouch;
776
- this._swallowComponent = bgNode;
696
+ static onScreenResize() {
697
+ // 半透明遮罩适配
698
+ if (this._alphaGraph) {
699
+ this._alphaGraph.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
700
+ this._alphaGraph.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
777
701
  }
778
- // 窗口自身也要设置是否吞噬触摸
779
- this.opaque = swallowTouch;
780
- this.bgAlpha = bgAlpha;
781
- this.onInit();
702
+ // 所有窗口适配
703
+ this._windows.forEach((window) => {
704
+ window._adapted();
705
+ });
706
+ // 所有header适配
707
+ HeaderManager.onScreenResize();
782
708
  }
783
709
  /**
784
- * 适配窗口
785
- * @internal
710
+ * 添加手动管理资源加载 和 卸载的包名
711
+ * @param pkgName 包名
786
712
  */
787
- _adapted() {
788
- var _a, _b;
789
- this.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
790
- this.setPivot(0.5, 0.5, true);
791
- switch (this.adapterType) {
792
- case exports.AdapterType.Full:
793
- this.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
794
- break;
795
- case exports.AdapterType.Bang:
796
- this.setSize(bitCore.Screen.SafeWidth, bitCore.Screen.SafeHeight, true);
797
- break;
713
+ static addManualPackage(pkgName) {
714
+ InfoPool.addManualPackage(pkgName);
715
+ }
716
+ /**
717
+ * 提供一种特殊需求 用来手动设置包所在的 bundle名 以及包在bundle中的路径
718
+ * @param name 窗口名称
719
+ * @param bundleName bundle名 默认: resources
720
+ * @param path 包在bundle中的路径 默认: ui目录
721
+ */
722
+ static setPackageInfo(pkgName, bundleName = "resources", path = "ui") {
723
+ if (bundleName !== "resources") {
724
+ InfoPool.addBundleName(pkgName, bundleName);
725
+ }
726
+ if (path !== "ui") {
727
+ InfoPool.addPackagePath(pkgName, path);
798
728
  }
799
- (_a = this._swallowComponent) === null || _a === void 0 ? void 0 : _a.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
800
- (_b = this._swallowComponent) === null || _b === void 0 ? void 0 : _b.setPosition(this.width * 0.5, +this.height * 0.5);
801
- this.onAdapted();
802
729
  }
803
730
  /**
804
- * 窗口关闭 (框架内部使用)
805
- * @internal
731
+ * 用于手动设置UI导出数据
732
+ * @param config UI导出数据
806
733
  */
807
- _close() {
808
- this.onClose();
809
- this.dispose();
734
+ static setUIConfig(config) {
735
+ PropsHelper.setConfig(config);
810
736
  }
811
737
  /**
812
- * 显示窗口 (框架内部使用)
813
- * @param userdata 用户自定义数据
814
- * @internal
738
+ * 设置UI包加载相关回调函数
739
+ * @param callbacks 包含加载回调的对象
740
+ * @param callbacks.showWaitWindow 显示加载等待窗的回调
741
+ * @param callbacks.hideWaitWindow 隐藏加载等待窗的回调
742
+ * @param callbacks.fail 打开窗口时资源加载失败的回调 code( 1:bundle加载失败 2:包加载失败 )
815
743
  */
816
- _show(userdata) {
817
- this.visible = true;
818
- this.onShow(userdata);
744
+ static setPackageCallbacks(callbacks) {
745
+ ResLoader.setCallbacks(callbacks);
819
746
  }
820
747
  /**
821
- * 隐藏窗口 (框架内部使用)
748
+ * 向窗口管理器添加一个窗口组 如果窗口组名称已存在,则抛出错误. (内部方法)
749
+ * @param group 要添加的窗口组
822
750
  * @internal
823
751
  */
824
- _hide() {
825
- this.visible = false;
826
- this.onHide();
752
+ static addWindowGroup(group) {
753
+ if (this._groups.has(group.name)) {
754
+ throw new Error(`窗口组【${group.name}】已存在`);
755
+ }
756
+ this._groups.set(group.name, group);
757
+ this._groupNames.push(group.name);
827
758
  }
828
759
  /**
829
- * 从隐藏状态恢复显示
760
+ * 设置半透明遮罩
761
+ * @param alphaGraph 半透明遮罩
830
762
  * @internal
831
763
  */
832
- _showFromHide() {
833
- this.visible = true;
834
- this.onShowFromHide();
764
+ static setAlphaGraph(alphaGraph) {
765
+ this._alphaGraph = alphaGraph;
766
+ }
767
+ /**
768
+ * 异步打开一个窗口 (如果UI包的资源未加载, 会自动加载 可以配合 WindowManager.setPackageCallbacks一起使用)
769
+ * @param 窗口类
770
+ * @param userdata 用户数据
771
+ */
772
+ static showWindow(window, userdata) {
773
+ // 优先使用装饰器设置的静态属性,避免代码混淆后 constructor.name 变化
774
+ const name = window[MetadataKey.originalName];
775
+ if (!name) {
776
+ throw new Error(`窗口【${window.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);
777
+ }
778
+ return this.showWindowByName(name, userdata);
835
779
  }
836
780
  /**
837
- * 遮挡窗口 被同组或者不同组的其他窗口覆盖 (框架内部使用)
781
+ * 通过窗口名称打开一个窗口
782
+ * @param name 窗口名称
783
+ * @param userdata 用户数据
838
784
  * @internal
839
785
  */
840
- _cover() {
841
- this._isCover = true;
842
- this.onCover();
786
+ static showWindowByName(name, userdata) {
787
+ // 找到他所属的窗口组
788
+ const info = InfoPool.get(name);
789
+ const group = this.getWindowGroup(info.group);
790
+ return group.showWindow(info, userdata);
791
+ }
792
+ /**
793
+ * 关闭一个窗口
794
+ * @param ctor 窗口类
795
+ */
796
+ static closeWindow(window) {
797
+ // 取到窗口的名称,优先使用装饰器设置的静态属性
798
+ const name = window[MetadataKey.originalName];
799
+ this.closeWindowByName(name);
800
+ }
801
+ /**
802
+ * 通过窗口名称关闭一个窗口
803
+ * @param name 窗口名称
804
+ */
805
+ static closeWindowByName(name) {
806
+ if (!this.hasWindow(name)) {
807
+ console.warn(`窗口不存在 ${name} 不需要关闭`);
808
+ return;
809
+ }
810
+ const info = InfoPool.get(name);
811
+ const group = this.getWindowGroup(info.group);
812
+ group.removeWindow(name);
813
+ // 调整半透明遮罩
814
+ this.adjustAlphaGraph();
815
+ // 找到最上层的窗口 调用toTop方法
816
+ let topWindow = this.getTopWindow();
817
+ if (topWindow && !topWindow.isTop()) {
818
+ topWindow._toTop();
819
+ }
820
+ }
821
+ /**
822
+ * 是否存在窗口
823
+ * @param name 窗口名称
824
+ */
825
+ static hasWindow(name) {
826
+ return this._windows.has(name);
843
827
  }
844
828
  /**
845
- * 遮挡恢复窗口 被同组或者不同组的其他窗口覆盖恢复 (框架内部使用)
829
+ * 添加窗口
830
+ * @param name 窗口名称
831
+ * @param window 要添加的窗口对象,需实现 IWindow 接口。
846
832
  * @internal
847
833
  */
848
- _recover() {
849
- this._isCover = false;
850
- this.onRecover();
834
+ static addWindow(name, window) {
835
+ this._windows.set(name, window);
851
836
  }
852
837
  /**
853
- * 设置窗口深度
854
- * @param depth 深度
838
+ * 移除窗口
839
+ * @param name 窗口名称
855
840
  * @internal
856
841
  */
857
- _setDepth(depth) {
858
- this.parent.setChildIndex(this, depth);
842
+ static removeWindow(name) {
843
+ this._windows.delete(name);
859
844
  }
860
- isShowing() {
861
- return this.visible;
845
+ /**
846
+ * 根据窗口名称获取窗口实例。
847
+ * @template T 窗口类型,必须继承自IWindow接口。
848
+ * @param name 窗口名称
849
+ * @returns 如果找到窗口,则返回对应类型的窗口实例;否则返回null。
850
+ */
851
+ static getWindow(name) {
852
+ return this._windows.get(name);
862
853
  }
863
- isCover() {
864
- return this._isCover;
854
+ /**
855
+ * 获取当前最顶层的窗口实例。
856
+ * 默认会忽略掉忽略查询的窗口组
857
+ * @returns {T | null} - 返回最顶层的窗口实例,如果没有找到则返回 null。
858
+ */
859
+ static getTopWindow(isAll = true) {
860
+ const names = this._groupNames;
861
+ for (let i = names.length - 1; i >= 0; i--) {
862
+ const group = this.getWindowGroup(names[i]);
863
+ if (group.isIgnore && !isAll) {
864
+ continue;
865
+ }
866
+ if (group.size === 0) {
867
+ continue;
868
+ }
869
+ return group.getTopWindow();
870
+ }
871
+ return null;
865
872
  }
866
- /** @internal */
867
- screenResize() {
868
- this._adapted();
873
+ /**
874
+ * 获取所有窗口组的名称列表(按层级顺序)
875
+ * @returns 窗口组的名称列表
876
+ */
877
+ static getGroupNames() {
878
+ return this._groupNames;
869
879
  }
870
880
  /**
871
- * 获取窗口顶部资源栏数据 默认返回空数组
872
- * @returns {WindowHeaderInfo[]}
881
+ * 根据给定的组名获取窗口组。如果组不存在,则抛出错误。
882
+ * @param name 窗口组名称
883
+ * @returns 返回找到的窗口组。
873
884
  */
874
- getHeaderInfo() {
875
- return null;
885
+ static getWindowGroup(name) {
886
+ if (this._groups.has(name)) {
887
+ return this._groups.get(name);
888
+ }
889
+ throw new Error(`窗口组【${name}】不存在`);
876
890
  }
877
- getHeader() {
878
- return this._header;
891
+ /**
892
+ * 关闭所有窗口
893
+ * @param ignores 不关闭的窗口
894
+ */
895
+ static closeAllWindow(ignores = []) {
896
+ let len = this._groupNames.length;
897
+ for (let i = len - 1; i >= 0; i--) {
898
+ let group = this.getWindowGroup(this._groupNames[i]);
899
+ group.closeAllWindow(ignores);
900
+ }
901
+ // 找到最上层的窗口 调用toTop方法
902
+ let topWindow = this.getTopWindow();
903
+ if (topWindow && !topWindow.isTop()) {
904
+ topWindow._toTop();
905
+ }
879
906
  }
880
- /** @internal */
881
- _setHeader(header) {
882
- this._header = header;
907
+ /**
908
+ * 调整半透明遮罩的显示层级
909
+ * 从上到下(从所有窗口组)查找第一个bgAlpha不为0的窗口,将遮罩放到该窗口下方
910
+ * @internal
911
+ */
912
+ static adjustAlphaGraph() {
913
+ let topWindow = null;
914
+ // 从后往前遍历窗口组(后面的窗口组层级更高)
915
+ for (let i = this._groupNames.length - 1; i >= 0; i--) {
916
+ const group = this._groups.get(this._groupNames[i]);
917
+ if (group.size === 0) {
918
+ continue;
919
+ }
920
+ // 在当前窗口组中从上到下查找第一个bgAlpha不为0的窗口
921
+ for (let j = group.windowNames.length - 1; j >= 0; j--) {
922
+ const name = group.windowNames[j];
923
+ const win = WindowManager.getWindow(name);
924
+ if (win.bgAlpha > 0) {
925
+ topWindow = win;
926
+ break;
927
+ }
928
+ }
929
+ if (topWindow) {
930
+ break;
931
+ }
932
+ }
933
+ // 如果找到了需要遮罩的窗口
934
+ if (topWindow) {
935
+ // 获取窗口组的根节点
936
+ const parent = topWindow.parent;
937
+ // 将遮罩设置到目标窗口的下方
938
+ const windowIndex = parent.getChildIndex(topWindow);
939
+ let gIndex = 0;
940
+ // 确保遮罩在目标窗口组的根节点下
941
+ if (this._alphaGraph.parent !== parent) {
942
+ this._alphaGraph.removeFromParent();
943
+ parent.addChild(this._alphaGraph);
944
+ gIndex = parent.numChildren - 1;
945
+ }
946
+ else {
947
+ gIndex = parent.getChildIndex(this._alphaGraph);
948
+ }
949
+ let newIndex = gIndex >= windowIndex ? windowIndex : windowIndex - 1;
950
+ parent.setChildIndex(this._alphaGraph, newIndex);
951
+ // 显示遮罩
952
+ this._alphaGraph.visible = true;
953
+ // 半透明遮罩绘制
954
+ this._bgColor.a = topWindow.bgAlpha * 255;
955
+ this._alphaGraph.clearGraphics();
956
+ this._alphaGraph.drawRect(0, this._bgColor, this._bgColor);
957
+ }
958
+ else {
959
+ // 没有找到需要遮罩的窗口,隐藏遮罩
960
+ this._alphaGraph.visible = false;
961
+ }
962
+ }
963
+ /**
964
+ * 释放不再使用中的自动加载的UI资源
965
+ * 针对在 UIModule 中设置了不自动释放资源的场景
966
+ */
967
+ static releaseUnusedRes() {
968
+ ResLoader.releaseUnusedRes();
883
969
  }
884
970
  }
971
+ WindowManager._bgAlpha = 0.75;
972
+ WindowManager._bgColor = new cc.Color(0, 0, 0, 0);
973
+ /** @internal */
974
+ WindowManager._alphaGraph = null; // 半透明的遮罩
975
+ /** @internal */
976
+ WindowManager._groups = new Map(); // 窗口组
977
+ /** @internal */
978
+ WindowManager._groupNames = []; // 窗口组的名称列表
979
+ /** @internal */
980
+ WindowManager._windows = new Map(); // 所有窗口的引用
885
981
 
886
982
  /**
887
983
  * @Author: Gongxh
888
- * @Date: 2024-12-14
889
- * @Description:
984
+ * @Date: 2025-12-29
985
+ * @Description: header(资源栏)管理类
890
986
  */
891
- class Window extends UIWindow {
892
- onAdapted() {
987
+ class HeaderManager {
988
+ /**
989
+ * 屏幕适配
990
+ * @internal
991
+ */
992
+ static onScreenResize() {
993
+ for (const header of this._headers.values()) {
994
+ header._adapted();
995
+ }
893
996
  }
894
997
  /**
895
- * 窗口关闭时的处理逻辑。
896
- * 子类可以重写此方法以实现自定义的关闭行为。
998
+ * 为窗口请求一个header
999
+ * @param windowName 窗口名
1000
+ * @param headerInfo header信息
897
1001
  */
898
- onClose() {
1002
+ static requestHeader(windowName, headerInfo) {
1003
+ // 保存header的信息
1004
+ if (!headerInfo) {
1005
+ return;
1006
+ }
1007
+ this._headerInfos.set(windowName, headerInfo);
1008
+ const headerName = headerInfo.name;
1009
+ // 如果header不存在,创建它
1010
+ if (!this._headers.has(headerName)) {
1011
+ const header = this.createHeader(headerInfo);
1012
+ this._headers.set(headerName, header);
1013
+ this._refCounts.set(headerName, 0);
1014
+ this._headerWindowsMap.set(headerName, new Set());
1015
+ }
1016
+ // 增加引用计数
1017
+ this._refCounts.set(headerName, this._refCounts.get(headerName) + 1);
1018
+ // 记录窗口和header的关系
1019
+ this._headerWindowsMap.get(headerName).add(windowName);
899
1020
  }
900
1021
  /**
901
- * 窗口显示时的回调函数。
902
- * @param userdata 可选参数,传递给窗口显示时的用户数据。
1022
+ * 显示指定窗口的header
1023
+ * @param windowName 窗口名
1024
+ * @param fromHide 窗口是否从隐藏状态恢复显示
903
1025
  */
904
- onShow(userdata) {
1026
+ static showHeader(windowName) {
1027
+ if (!this.hasHeader(windowName)) {
1028
+ return;
1029
+ }
1030
+ const headerName = this.getHeaderName(windowName);
1031
+ const header = this.getHeader(headerName);
1032
+ // 更新最上层窗口(智能判断,只在必要时重新计算)
1033
+ this.updateTopWindow(headerName, windowName, true);
1034
+ // 只有当前窗口是最上层时才显示
1035
+ const currentTopWindow = this._cacheHeaderTopWindow.get(headerName);
1036
+ if (currentTopWindow === windowName) {
1037
+ header._show(this.getHeaderUserData(windowName));
1038
+ }
905
1039
  }
906
1040
  /**
907
- * 隐藏窗口时的处理逻辑。
908
- * 重写此方法以实现自定义的隐藏行为。
1041
+ * 隐藏指定窗口的header
1042
+ * @param windowName 窗口名
909
1043
  */
910
- onHide() {
1044
+ static hideHeader(windowName) {
1045
+ if (!this.hasHeader(windowName)) {
1046
+ return;
1047
+ }
1048
+ const headerName = this.getHeaderName(windowName);
1049
+ const header = this.getHeader(headerName);
1050
+ // 更新最上层窗口(会自动处理切换逻辑)
1051
+ this.updateTopWindow(headerName, windowName, false);
1052
+ // 如果切换到了新的窗口,传递新的userdata0
1053
+ if (this._cacheHeaderTopWindow.has(headerName)) {
1054
+ const newTopWindowName = this._cacheHeaderTopWindow.get(headerName);
1055
+ header._show(this.getHeaderUserData(newTopWindowName));
1056
+ }
1057
+ else if (header.isShowing()) {
1058
+ header._hide();
1059
+ }
911
1060
  }
912
1061
  /**
913
- * 当窗口从隐藏状态变为显示状态时调用。
914
- * 这个方法可以被子类重写以实现特定的显示逻辑。
1062
+ * 释放窗口的header(减少引用计数)
1063
+ * @param windowName 窗口名
915
1064
  */
916
- onShowFromHide() {
1065
+ static releaseHeader(windowName) {
1066
+ if (!this.hasHeader(windowName)) {
1067
+ return;
1068
+ }
1069
+ const headerName = this.getHeaderName(windowName);
1070
+ // 减少引用计数
1071
+ const refCount = this._refCounts.get(headerName) - 1;
1072
+ // 移除映射关系
1073
+ this._headerWindowsMap.get(headerName).delete(windowName);
1074
+ // 清除窗口的header信息
1075
+ this._headerInfos.delete(windowName);
1076
+ const header = this.getHeader(headerName);
1077
+ // 如果引用计数为0,销毁header
1078
+ if (refCount === 0) {
1079
+ header._close();
1080
+ this._headers.delete(headerName);
1081
+ this._refCounts.delete(headerName);
1082
+ this._headerWindowsMap.delete(headerName);
1083
+ this._cacheHeaderTopWindow.delete(headerName);
1084
+ }
1085
+ else {
1086
+ // 更新引用计数
1087
+ this._refCounts.set(headerName, refCount);
1088
+ // 查找新的最上层窗口 并显示
1089
+ const newTopWindowName = this.findTopWindowForHeader(headerName, windowName);
1090
+ if (newTopWindowName) {
1091
+ this._cacheHeaderTopWindow.set(headerName, newTopWindowName);
1092
+ this.adjustHeaderPosition(headerName, newTopWindowName);
1093
+ header._show(this.getHeaderUserData(newTopWindowName));
1094
+ }
1095
+ else {
1096
+ // 没找到需要显示的 隐藏掉
1097
+ this._cacheHeaderTopWindow.delete(headerName);
1098
+ header.isShowing() && header._hide();
1099
+ }
1100
+ }
917
1101
  }
918
1102
  /**
919
- * 当窗口被覆盖时触发的事件处理函数。
920
- * 子类可以重写此方法以添加自定义行为。
1103
+ * 获取窗口关联的header
1104
+ * @param windowName 窗口名
1105
+ * @returns header实例,如果没有则返回null
921
1106
  */
922
- onCover() {
1107
+ static getHeaderByWindow(windowName) {
1108
+ if (!this.hasHeader(windowName)) {
1109
+ return null;
1110
+ }
1111
+ const headerName = this.getHeaderName(windowName);
1112
+ return this._headers.get(headerName) || null;
923
1113
  }
924
1114
  /**
925
- * 恢复窗口状态时的处理逻辑。
926
- * 此方法在窗口从隐藏或最小化状态恢复时被调用。
1115
+ * 刷新窗口的header
1116
+ * 如果新的header和旧的header不是同一个,先释放旧的,再创建新的
1117
+ * 如果是同一个,更新userdata并重新显示
1118
+ * @param windowName 窗口名
1119
+ * @param newHeaderInfo 新的header信息
1120
+ */
1121
+ static refreshWindowHeader(windowName, newHeaderInfo) {
1122
+ const oldHeaderName = this.getHeaderName(windowName);
1123
+ const newHeaderName = newHeaderInfo === null || newHeaderInfo === void 0 ? void 0 : newHeaderInfo.name;
1124
+ // 情况1:新旧 header 名称相同,只需要更新 userdata 并重新显示
1125
+ if (oldHeaderName === newHeaderName) {
1126
+ if (newHeaderInfo) {
1127
+ // 更新保存的 userdata
1128
+ this._headerInfos.set(windowName, newHeaderInfo);
1129
+ // 重新显示 header(如果当前窗口是最上层)
1130
+ const currentTopWindow = this._cacheHeaderTopWindow.get(newHeaderName);
1131
+ if (currentTopWindow === windowName) {
1132
+ const header = this.getHeader(newHeaderName);
1133
+ header._show(newHeaderInfo.userdata);
1134
+ }
1135
+ }
1136
+ return;
1137
+ }
1138
+ // 情况2:header 名称不同,先释放旧的,再创建新的
1139
+ // 释放旧的 header
1140
+ if (oldHeaderName) {
1141
+ this.releaseHeader(windowName);
1142
+ }
1143
+ // 请求新的 header 并显示
1144
+ if (newHeaderInfo) {
1145
+ this.requestHeader(windowName, newHeaderInfo);
1146
+ this.showHeader(windowName);
1147
+ }
1148
+ }
1149
+ static createHeader(headerInfo) {
1150
+ // 创建header实例
1151
+ const info = InfoPool.getHeader(headerInfo.name);
1152
+ const header = fairyguiCc.UIPackage.createObject(info.pkgName, headerInfo.name);
1153
+ header.name = headerInfo.name;
1154
+ PropsHelper.serializeProps(header, info.pkgName);
1155
+ header._init();
1156
+ header._adapted();
1157
+ return header;
1158
+ }
1159
+ /**
1160
+ * 获取窗口记录的header userdata
1161
+ * @internal
927
1162
  */
928
- onRecover() {
1163
+ static getHeaderUserData(windowName) {
1164
+ var _a;
1165
+ return (_a = this._headerInfos.get(windowName)) === null || _a === void 0 ? void 0 : _a.userdata;
929
1166
  }
930
1167
  /**
931
- * 空白区域点击事件处理函数。
932
- * 当用户点击窗口的空白区域时触发此方法。
1168
+ * 根据窗口名字获取header名称
1169
+ * @internal
933
1170
  */
934
- onEmptyAreaClick() {
1171
+ static getHeaderName(windowName) {
1172
+ var _a;
1173
+ return (_a = this._headerInfos.get(windowName)) === null || _a === void 0 ? void 0 : _a.name;
1174
+ }
1175
+ /**
1176
+ * 窗口上是否存在header
1177
+ * @internal
1178
+ */
1179
+ static hasHeader(windowName) {
1180
+ return this._headerInfos.has(windowName);
1181
+ }
1182
+ /** 通过名称直接获取header实例 */
1183
+ static getHeader(name) {
1184
+ return this._headers.get(name);
1185
+ }
1186
+ /**
1187
+ * 更新header的最上层窗口(智能判断是否需要重新计算)
1188
+ * @internal
1189
+ */
1190
+ static updateTopWindow(headerName, changedWindowName, isShowing) {
1191
+ // 记录的最上层窗口名
1192
+ const topWindowName = this._cacheHeaderTopWindow.get(headerName);
1193
+ if (isShowing) {
1194
+ // 情况1:新窗口显示,且它在更高层级
1195
+ if (!topWindowName || this.isWindowAbove(changedWindowName, topWindowName)) {
1196
+ // 新窗口更靠上, 调整header位置并缓存
1197
+ this._cacheHeaderTopWindow.set(headerName, changedWindowName);
1198
+ this.adjustHeaderPosition(headerName, changedWindowName);
1199
+ return;
1200
+ }
1201
+ }
1202
+ else if (topWindowName === changedWindowName) {
1203
+ // 最上层的窗口需要隐藏, 查找新的最上层窗口
1204
+ const newTopWindowName = this.findTopWindowForHeader(headerName, changedWindowName);
1205
+ if (newTopWindowName) {
1206
+ this._cacheHeaderTopWindow.set(headerName, newTopWindowName);
1207
+ this.adjustHeaderPosition(headerName, newTopWindowName);
1208
+ }
1209
+ else {
1210
+ this._cacheHeaderTopWindow.delete(headerName);
1211
+ const header = this.getHeader(headerName);
1212
+ if (header && header.isShowing()) {
1213
+ header._hide();
1214
+ }
1215
+ }
1216
+ }
1217
+ }
1218
+ /**
1219
+ * 判断窗口A是否在窗口B的上层 (如果是同一个窗口,返回false)
1220
+ * @internal
1221
+ */
1222
+ static isWindowAbove(windowA, windowB) {
1223
+ if (windowA === windowB) {
1224
+ return false;
1225
+ }
1226
+ const infoA = InfoPool.get(windowA);
1227
+ const infoB = InfoPool.get(windowB);
1228
+ // 先比较窗口组
1229
+ const groupNames = WindowManager.getGroupNames();
1230
+ const groupIndexA = groupNames.indexOf(infoA.group);
1231
+ const groupIndexB = groupNames.indexOf(infoB.group);
1232
+ if (groupIndexA !== groupIndexB) {
1233
+ return groupIndexA > groupIndexB;
1234
+ }
1235
+ // 同一个组,比较窗口在组内的位置
1236
+ const group = WindowManager.getWindowGroup(infoA.group);
1237
+ const indexA = group.windowNames.indexOf(windowA);
1238
+ const indexB = group.windowNames.indexOf(windowB);
1239
+ return indexA > indexB;
1240
+ }
1241
+ /**
1242
+ * 为header查找新的最上层窗口(排除指定窗口)
1243
+ * @internal
1244
+ */
1245
+ static findTopWindowForHeader(headerName, excludeWindow) {
1246
+ const windowNames = this._headerWindowsMap.get(headerName);
1247
+ if (!windowNames || windowNames.size === 0) {
1248
+ return null;
1249
+ }
1250
+ // 从上到下遍历窗口组
1251
+ const groupNames = WindowManager.getGroupNames();
1252
+ for (let i = groupNames.length - 1; i >= 0; i--) {
1253
+ // 从上到下遍历组内窗口
1254
+ const group = WindowManager.getWindowGroup(groupNames[i]);
1255
+ for (let j = group.windowNames.length - 1; j >= 0; j--) {
1256
+ const wName = group.windowNames[j];
1257
+ if (wName === excludeWindow) {
1258
+ continue;
1259
+ }
1260
+ if (!windowNames.has(wName)) {
1261
+ continue;
1262
+ }
1263
+ const win = WindowManager.getWindow(wName);
1264
+ if (win && win.isShowing()) {
1265
+ return wName; // 找到就返回,不继续遍历
1266
+ }
1267
+ }
1268
+ }
1269
+ return null;
1270
+ }
1271
+ /**
1272
+ * 调整header到指定窗口的位置
1273
+ * @internal
1274
+ */
1275
+ static adjustHeaderPosition(headerName, windowName) {
1276
+ const header = this._headers.get(headerName);
1277
+ const window = WindowManager.getWindow(windowName);
1278
+ const info = InfoPool.get(windowName);
1279
+ const group = WindowManager.getWindowGroup(info.group);
1280
+ const parent = group.root;
1281
+ // 移动header到对应的group
1282
+ if (header.parent !== parent) {
1283
+ header.removeFromParent();
1284
+ parent.addChild(header);
1285
+ }
1286
+ // 调整层级:找到该组中最上层的显示窗口
1287
+ let maxWindowIndex = parent.getChildIndex(window);
1288
+ for (let i = group.windowNames.length - 1; i >= 0; i--) {
1289
+ const win = WindowManager.getWindow(group.windowNames[i]);
1290
+ if (win && win.isShowing()) {
1291
+ maxWindowIndex = Math.max(maxWindowIndex, parent.getChildIndex(win));
1292
+ }
1293
+ }
1294
+ parent.setChildIndex(header, maxWindowIndex + 1);
935
1295
  }
936
1296
  }
1297
+ /** @internal */
1298
+ HeaderManager._headers = new Map(); // header名 > header实例
1299
+ /** @internal */
1300
+ HeaderManager._refCounts = new Map(); // header名 > 引用计数
1301
+ /** @internal */
1302
+ HeaderManager._headerWindowsMap = new Map(); // header名 > 窗口名列表
1303
+ /** @internal */
1304
+ HeaderManager._headerInfos = new Map(); // 窗口名 > header的数据
1305
+ /** @internal */
1306
+ HeaderManager._cacheHeaderTopWindow = new Map(); // header名 > 缓存的当前显示该header的最上层窗口名
937
1307
 
938
1308
  /**
939
1309
  * @Author: Gongxh
@@ -945,23 +1315,21 @@ class WindowGroup {
945
1315
  * 获取窗口组的名称。
946
1316
  * @returns {string} 窗口组的名称。
947
1317
  */
948
- get name() {
949
- return this._name;
950
- }
1318
+ get name() { return this._name; }
1319
+ /** 获取窗口组的根节点 */
1320
+ get root() { return this._root; }
951
1321
  /**
952
1322
  * 获取当前窗口组中窗口的数量。
953
1323
  * @returns 窗口数量
954
1324
  */
955
- get size() {
956
- return this._windowNames.length;
957
- }
1325
+ get size() { return this._windowNames.length; }
1326
+ /** 获取窗口组中窗口的名称列表 */
1327
+ get windowNames() { return this._windowNames; }
958
1328
  /**
959
1329
  * 获取是否忽略查询的状态。
960
1330
  * @returns {boolean} 如果忽略查询,则返回 true,否则返回 false。
961
1331
  */
962
- get isIgnore() {
963
- return this._ignoreQuery;
964
- }
1332
+ get isIgnore() { return this._ignore; }
965
1333
  /**
966
1334
  * 实例化
967
1335
  * @param name 组名
@@ -971,357 +1339,559 @@ class WindowGroup {
971
1339
  * @param bgAlpha 半透明遮罩的透明度
972
1340
  * @internal
973
1341
  */
974
- constructor(name, root, ignoreQuery, swallowTouch, bgAlpha) {
975
- /** 窗口组的名字 @internal */
976
- this._name = "";
977
- /** 忽略顶部窗口查询 @internal */
978
- this._ignoreQuery = false;
979
- /** 吞噬触摸事件 @internal */
980
- this._swallowTouch = false;
981
- /** 窗口容器中的窗口名列表 @internal */
982
- this._windowNames = [];
983
- /** 窗口顶部资源栏 @internal */
984
- this._headers = new Map();
985
- /** 半透明遮罩的透明度 @internal */
986
- this._bgAlpha = 0;
987
- /** 半透明遮罩的颜色 @internal */
988
- this._color = new cc.Color(0, 0, 0, 255);
989
- this._name = name;
990
- this._root = root;
991
- this._ignoreQuery = ignoreQuery;
992
- this._swallowTouch = swallowTouch;
993
- this._bgAlpha = bgAlpha;
994
- const alphaGraph = new fairyguiCc.GGraph();
995
- alphaGraph.touchable = false;
996
- alphaGraph.name = "bgAlpha";
997
- alphaGraph.setPosition(root.width * 0.5, root.height * 0.5);
998
- alphaGraph.setSize(root.width, root.height, true);
999
- alphaGraph.setPivot(0.5, 0.5, true);
1000
- root.addChild(alphaGraph);
1001
- this._alphaGraph = alphaGraph;
1342
+ constructor(name, root, ignoreQuery, swallowTouch) {
1343
+ /** @internal */
1344
+ this._name = ""; // 窗口组的名字
1345
+ /** @internal */
1346
+ this._ignore = false; // 忽略查询
1347
+ /** @internal */
1348
+ this._swallowTouch = false; // 吞噬触摸事件
1349
+ /** @internal */
1350
+ this._windowNames = []; // 窗口名列表 顺序为窗口显示的层级 (最后一个显示在最上层)
1351
+ this._name = name;
1352
+ this._root = root;
1353
+ this._ignore = ignoreQuery;
1354
+ this._swallowTouch = swallowTouch;
1355
+ this._windowNames = [];
1356
+ }
1357
+ /**
1358
+ * 显示一个窗口
1359
+ * @param info 窗口信息
1360
+ * @param userdata
1361
+ * @internal
1362
+ */
1363
+ showWindow(info, userdata) {
1364
+ return __awaiter(this, void 0, void 0, function* () {
1365
+ let lastTopWindow = WindowManager.getTopWindow();
1366
+ if (WindowManager.hasWindow(info.name)) {
1367
+ const window = WindowManager.getWindow(info.name);
1368
+ this.showAdjustment(window, userdata);
1369
+ if (lastTopWindow && lastTopWindow.name !== window.name) {
1370
+ lastTopWindow._toBottom();
1371
+ window._toTop();
1372
+ }
1373
+ return window;
1374
+ }
1375
+ else {
1376
+ try {
1377
+ yield ResLoader.loadWindowRes(info.name);
1378
+ const window = this.createWindow(info.pkgName, info.name);
1379
+ this.showAdjustment(window, userdata);
1380
+ if (lastTopWindow && lastTopWindow.name !== window.name) {
1381
+ lastTopWindow._toBottom();
1382
+ }
1383
+ return window;
1384
+ }
1385
+ catch (err) {
1386
+ throw new Error(`窗口【${info.name}】打开失败: ${err.message}`);
1387
+ }
1388
+ }
1389
+ });
1390
+ }
1391
+ /**
1392
+ * show一个界面后的调整
1393
+ * @param window
1394
+ * @internal
1395
+ */
1396
+ showAdjustment(window, userdata) {
1397
+ // 如果窗口不在最上层 则调整层级
1398
+ this.moveWindowToTop(window);
1399
+ // 显示窗口
1400
+ window._show(userdata);
1401
+ // 尝试显示header
1402
+ HeaderManager.showHeader(window.name);
1403
+ // 调整半透明遮罩
1404
+ WindowManager.adjustAlphaGraph();
1405
+ }
1406
+ /**
1407
+ * 将指定名称的窗口移动到窗口组的最顶层。
1408
+ * @param name 窗口的名称。
1409
+ * @internal
1410
+ */
1411
+ moveWindowToTop(window) {
1412
+ if (window.name !== this._windowNames[this.size - 1]) {
1413
+ const index = this._windowNames.indexOf(window.name);
1414
+ if (index < 0) {
1415
+ console.error(`[BUG] 窗口【${window.name}】不在数组中,数据结构已损坏`);
1416
+ return;
1417
+ }
1418
+ this._windowNames.splice(index, 1);
1419
+ // 放到数组的末尾
1420
+ this._windowNames.push(window.name);
1421
+ }
1422
+ // 根据窗口的type, 处理上一个窗口的关闭状态
1423
+ this._processWindowCloseStatus(window);
1424
+ // 调整窗口的显示层级
1425
+ window.setDepth(this._root.numChildren - 1);
1426
+ // 处理窗口显示和隐藏状态
1427
+ this.processWindowHideStatus(this.size - 1);
1002
1428
  }
1003
1429
  /**
1004
1430
  * 根据窗口名创建窗口 并添加到显示节点
1005
1431
  * @param windowName 窗口名
1006
1432
  * @internal
1007
1433
  */
1008
- _createWindow(pkg, name) {
1434
+ createWindow(pkg, name) {
1009
1435
  let window = fairyguiCc.UIPackage.createObject(pkg, name);
1010
1436
  window.name = name;
1011
1437
  PropsHelper.serializeProps(window, pkg);
1012
- window._init(this._swallowTouch, this._bgAlpha);
1438
+ window._init(this._swallowTouch);
1013
1439
  window._adapted();
1014
- this._createHeader(window);
1015
1440
  // 添加到显示节点
1016
- this._addWindow(window);
1441
+ this._root.addChild(window);
1442
+ // 窗口组之前没有窗口, 显示窗口组节点
1443
+ if (this.size === 0) {
1444
+ this._root.visible = true;
1445
+ }
1446
+ this._windowNames.push(name);
1447
+ WindowManager.addWindow(name, window);
1448
+ // 处理header(只请求,不立即添加到节点,由adjustHeaderDepth动态管理)
1449
+ HeaderManager.requestHeader(name, window.getHeaderInfo());
1017
1450
  return window;
1018
1451
  }
1019
1452
  /**
1020
- * 添加窗口到显示节点
1021
- * @param window 窗口
1022
- * @internal
1453
+ * 处理index下层窗口的隐藏状态的私有方法。递归调用
1454
+ * @param index - 窗口索引
1023
1455
  */
1024
- _addWindow(window) {
1025
- this._root.addChild(window);
1026
- UIManager._addWindow(window.name, window);
1027
- }
1028
- showWindow(info, userdata) {
1029
- let name = info.name;
1030
- let window = UIManager.getWindow(name);
1031
- if (window) {
1032
- window._show(userdata);
1456
+ processWindowHideStatus(startIndex) {
1457
+ let curWindow = WindowManager.getWindow(this._windowNames[startIndex]);
1458
+ // 如果当前是当前组中的最后一个窗口并且当前窗口是隐藏状态 则恢复隐藏
1459
+ if (curWindow && startIndex == this.size - 1 && !curWindow.isShowing()) {
1460
+ curWindow._showFromHide();
1461
+ // 恢复显示header
1462
+ HeaderManager.showHeader(curWindow.name);
1033
1463
  }
1034
- else {
1035
- window = this._createWindow(info.pkg, name);
1036
- this._processWindowCloseStatus(window);
1037
- this._windowNames.push(name);
1038
- window._show(userdata);
1464
+ // 已经是最后一个了
1465
+ if (startIndex <= 0) {
1466
+ return;
1467
+ }
1468
+ // 遍历到倒数第二个窗口停止
1469
+ for (let index = startIndex; index > 0; index--) {
1470
+ let window = WindowManager.getWindow(this._windowNames[index]);
1471
+ if (!window) {
1472
+ console.error(`[BUG] 窗口【${this._windowNames[index]}】不存在,数据结构已损坏`);
1473
+ return;
1474
+ }
1475
+ if (window.type === exports.WindowType.HideAll) {
1476
+ // 隐藏所有
1477
+ for (let i = index - 1; i >= 0; i--) {
1478
+ let name = this._windowNames[i];
1479
+ const window = WindowManager.getWindow(name);
1480
+ if (window && window.isShowing()) {
1481
+ window._hide();
1482
+ // 隐藏header
1483
+ HeaderManager.hideHeader(name);
1484
+ }
1485
+ }
1486
+ break;
1487
+ }
1488
+ else if (window.type === exports.WindowType.HideOne) {
1489
+ // 隐藏前一个窗口
1490
+ let prevWindowName = this._windowNames[index - 1];
1491
+ let prevWindow = WindowManager.getWindow(prevWindowName);
1492
+ if (prevWindow && prevWindow.isShowing()) {
1493
+ prevWindow._hide();
1494
+ // 隐藏header
1495
+ HeaderManager.hideHeader(prevWindowName);
1496
+ }
1497
+ }
1498
+ else {
1499
+ // 如果前一个窗口是隐藏状态 需要恢复显示
1500
+ let prevWindowName = this._windowNames[index - 1];
1501
+ let prevWindow = WindowManager.getWindow(prevWindowName);
1502
+ if (prevWindow && !prevWindow.isShowing()) {
1503
+ prevWindow._showFromHide();
1504
+ // 恢复显示header(使用记录的userdata)
1505
+ HeaderManager.showHeader(prevWindowName);
1506
+ }
1507
+ }
1508
+ }
1509
+ }
1510
+ /**
1511
+ * 根据传入窗口的关闭类型, 处理上一个窗口或者所有窗口的关闭
1512
+ * @param window 新创建的窗口
1513
+ * @internal
1514
+ */
1515
+ _processWindowCloseStatus(window) {
1516
+ // 最后一个是新显示上来的窗口
1517
+ if (window.type === exports.WindowType.CloseOne) {
1518
+ // 关闭上一个窗口(倒数第二个,因为最后一个是当前窗口)
1519
+ if (this.size <= 1) {
1520
+ return;
1521
+ }
1522
+ const name = this._windowNames[this.size - 2];
1523
+ this._windowNames.splice(this.size - 2, 1);
1524
+ const win = WindowManager.getWindow(name);
1525
+ if (!win) {
1526
+ console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
1527
+ return;
1528
+ }
1529
+ // 释放header
1530
+ HeaderManager.releaseHeader(name);
1531
+ win._close();
1532
+ WindowManager.removeWindow(name);
1533
+ }
1534
+ else if (window.type === exports.WindowType.CloseAll) {
1535
+ // 关闭所有窗口 从后向前依次删除
1536
+ for (let i = this.size - 2; i >= 0; i--) {
1537
+ const name = this._windowNames[i];
1538
+ const win = WindowManager.getWindow(name);
1539
+ if (!win) {
1540
+ console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
1541
+ return;
1542
+ }
1543
+ // 释放header
1544
+ HeaderManager.releaseHeader(name);
1545
+ win._close();
1546
+ WindowManager.removeWindow(name);
1547
+ }
1548
+ // 清理数组,只保留最后一个(当前窗口)
1549
+ this._windowNames.splice(0, this.size - 1);
1039
1550
  }
1040
- this._moveWindowToTop(name);
1041
- // 处理header的显示
1042
- this._processHeaderStatus();
1043
- // 显示窗口组
1044
- this._root.visible = true;
1045
1551
  }
1046
1552
  /**
1047
1553
  * 移除指定名称的窗口。
1048
1554
  * @param name 窗口的名称。
1049
1555
  * @internal
1050
1556
  */
1051
- _removeWindow(name) {
1557
+ removeWindow(name) {
1558
+ let window = WindowManager.getWindow(name);
1559
+ if (!window) {
1560
+ console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
1561
+ return;
1562
+ }
1563
+ // 释放header引用
1564
+ HeaderManager.releaseHeader(name);
1565
+ window._close();
1566
+ // 先删除窗口组中记录的窗口名称
1052
1567
  let index = this._windowNames.lastIndexOf(name);
1053
- let lastIndex = this.size - 1;
1054
1568
  if (index < 0) {
1055
- console.warn(`窗口组${this._name}中未找到窗口${name} 删除失败`);
1569
+ console.error(`[BUG] 窗口【${name}】不在数组中,数据结构已损坏`);
1056
1570
  return;
1057
1571
  }
1058
- let window = UIManager.getWindow(name);
1059
- let header = window.getHeader();
1060
- header && this._removeHeader(header);
1061
1572
  this._windowNames.splice(index, 1);
1062
- // 关闭窗口 并从窗口map中移除
1063
- UIManager._removeWindow(name);
1064
- // 处理窗口显示和隐藏状态
1065
- this._processWindowHideStatus(this.size - 1, true);
1573
+ // 删除WindowManager中记录的窗口
1574
+ WindowManager.removeWindow(name);
1575
+ // 释放资源
1576
+ ResLoader.unloadWindowRes(name);
1066
1577
  if (this.size == 0) {
1067
- // 窗口组中不存在窗口时 隐藏窗口组节点
1068
1578
  this._root.visible = false;
1069
1579
  }
1070
- else if (lastIndex == index && index > 0) {
1071
- // 删除的窗口是最后一个 并且前边还有窗口 调整半透明节点的显示层级
1072
- let topName = this.getTopWindowName();
1073
- let window = UIManager.getWindow(topName);
1074
- // 调整半透明遮罩
1075
- this._adjustAlphaGraph(window);
1076
- // 调整窗口的显示层级
1077
- window._setDepth(this._root.numChildren - 1);
1580
+ else {
1581
+ this.processWindowHideStatus(this.size - 1);
1078
1582
  }
1079
- this._processHeaderStatus();
1583
+ }
1584
+ hasWindow(name) {
1585
+ return this._windowNames.indexOf(name) >= 0;
1080
1586
  }
1081
1587
  /**
1082
- * 将指定名称的窗口移动到窗口组的最顶层。
1083
- * @param name 窗口的名称。
1084
- * @internal
1588
+ * 获取窗口组顶部窗口实例
1589
+ * @returns {IWindow} 顶部窗口实例
1085
1590
  */
1086
- _moveWindowToTop(name) {
1087
- let isMoved = false;
1088
- if (this.size == 0) {
1089
- console.warn(`WindowGroup.moveWindowToTop: window group 【${this._name}】 is empty`);
1090
- return false;
1091
- }
1092
- if (this._windowNames[this.size - 1] == name) ;
1093
- else {
1094
- const index = this._windowNames.indexOf(name);
1095
- if (index == -1) {
1096
- console.warn(`WindowGroup.moveWindowToTop: window 【${name}】 not found in window group 【${this._name}】`);
1097
- return false;
1098
- }
1099
- if (index < this._windowNames.length - 1) {
1100
- this._windowNames.splice(index, 1);
1101
- // 放到数组的末尾
1102
- this._windowNames.push(name);
1103
- isMoved = true;
1104
- }
1591
+ getTopWindow() {
1592
+ if (this.size > 0) {
1593
+ return WindowManager.getWindow(this._windowNames[this.size - 1]);
1105
1594
  }
1106
- let window = UIManager.getWindow(name);
1107
- // 先调整半透明遮罩
1108
- this._adjustAlphaGraph(window);
1109
- // 再调整窗口的显示层级
1110
- window._setDepth(this._root.numChildren - 1);
1111
- // 处理窗口显示和隐藏状态
1112
- this._processWindowHideStatus(this.size - 1, isMoved);
1113
- return true;
1595
+ console.warn(`窗口组【${this._name}】中不存在窗口`);
1596
+ return null;
1114
1597
  }
1115
1598
  /**
1116
- * 处理index下层窗口的隐藏状态的私有方法。递归调用
1117
- * @param index - 窗口索引
1118
- * @param isRecursion - 是否递归调用
1599
+ * 关闭窗口组中的所有窗口
1600
+ * @param ignores 不关闭的窗口名
1119
1601
  * @internal
1120
1602
  */
1121
- _processWindowHideStatus(index, isRecursion = true) {
1122
- if (index < 0) {
1123
- return;
1124
- }
1125
- let windowName = this._windowNames[index];
1126
- let curWindow = UIManager.getWindow(windowName);
1127
- // 如果当前是当前组中的最后一个窗口并且当前窗口是隐藏状态 则恢复隐藏
1128
- if (index == this.size - 1 && !curWindow.isShowing()) {
1129
- curWindow._showFromHide();
1130
- }
1131
- if (index == 0) {
1132
- return;
1133
- }
1134
- let windowType = curWindow.type;
1135
- if (windowType == exports.WindowType.HideAll) {
1136
- for (let i = index - 1; i >= 0; --i) {
1137
- let name = this._windowNames[i];
1138
- const window = UIManager.getWindow(name);
1139
- window.isShowing() && window._hide();
1603
+ closeAllWindow(ignores = []) {
1604
+ let len = this.size - 1;
1605
+ for (let i = len; i >= 0; i--) {
1606
+ let name = this._windowNames[i];
1607
+ // 如果当前窗口在ignores列表中,跳过
1608
+ if (ignores.some(ignore => ignore.name === name)) {
1609
+ continue;
1140
1610
  }
1141
- return;
1142
- }
1143
- else if (windowType == exports.WindowType.HideOne) {
1144
- // 隐藏前一个
1145
- let prevWindowName = this._windowNames[index - 1];
1146
- let prevWindow = UIManager.getWindow(prevWindowName);
1147
- prevWindow.isShowing() && prevWindow._hide();
1611
+ const window = WindowManager.getWindow(name);
1612
+ if (!window) {
1613
+ console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
1614
+ return;
1615
+ }
1616
+ // 释放header
1617
+ HeaderManager.releaseHeader(name);
1618
+ window._close();
1619
+ WindowManager.removeWindow(name);
1620
+ // 从数组中删除
1621
+ this._windowNames.splice(i, 1);
1622
+ }
1623
+ // 统一处理窗口的显示状态
1624
+ if (this.size == 0) {
1625
+ this._root.visible = false;
1148
1626
  }
1149
1627
  else {
1150
- // 如果前一个窗口被隐藏了 需要恢复显示
1151
- let prevWindowName = this._windowNames[index - 1];
1152
- let prevWindow = UIManager.getWindow(prevWindowName);
1153
- !prevWindow.isShowing() && prevWindow._showFromHide();
1628
+ this.processWindowHideStatus(this.size - 1);
1154
1629
  }
1155
- isRecursion && this._processWindowHideStatus(index - 1, isRecursion);
1156
1630
  }
1631
+ }
1632
+
1633
+ /**
1634
+ * @Author: Gongxh
1635
+ * @Date: 2024-12-11
1636
+ * @Description: UI 装饰器
1637
+ */
1638
+ /**
1639
+ * 获取对象属性
1640
+ * @param obj 对象
1641
+ * @param key 属性名
1642
+ * @returns 属性值
1643
+ */
1644
+ function getObjectProp(obj, key) {
1645
+ if (obj.hasOwnProperty(key)) {
1646
+ return obj[key];
1647
+ }
1648
+ return (obj[key] = Object.assign({}, obj[key]));
1649
+ }
1650
+ exports._uidecorator = void 0;
1651
+ (function (_uidecorator) {
1652
+ /** @internal */
1653
+ const uiclassMap = new Map(); // 窗口注册信息
1654
+ /** @internal */
1655
+ const uicomponentMap = new Map(); // 组件注册信息
1656
+ /** @internal */
1657
+ const uiheaderMap = new Map(); // header注册信息
1658
+ /** 获取窗口注册信息 */
1659
+ function getWindowMaps() { return uiclassMap; }
1660
+ _uidecorator.getWindowMaps = getWindowMaps;
1661
+ /** 获取组件注册信息 */
1662
+ function getComponentMaps() { return uicomponentMap; }
1663
+ _uidecorator.getComponentMaps = getComponentMaps;
1664
+ /** 获取header注册信息 */
1665
+ function getHeaderMaps() { return uiheaderMap; }
1666
+ _uidecorator.getHeaderMaps = getHeaderMaps;
1157
1667
  /**
1158
- * 新创建窗口时,根据新创建的窗口类型
1159
- * 处理上一个窗口或者所有窗口的关闭
1160
- * @param window 新创建的窗口
1161
- * @internal
1668
+ * 窗口装饰器
1669
+ * @param {string} groupName 窗口组名称
1670
+ * @param {string} pkgName fgui包名
1671
+ * @param {string} name 窗口名 (与fgui中的组件名一一对应)
1672
+ * @param {string[] | string} inlinePkgs 内联的包名 当前界面需要引用其他包中的资源时使用 引用多个包用数组 引用单个包用字符串
1673
+ *
1674
+ * @example @uiclass("窗口组", "UI包名", "MyWindow", ["包名1", "包名2"])
1675
+ * @example @uiclass("窗口组", "UI包名", "MyWindow", "包名1")
1162
1676
  */
1163
- _processWindowCloseStatus(window) {
1164
- // 新创建窗口 如果需要关闭窗口或者关闭所有窗口 处理窗口的关闭
1165
- if (window.type == exports.WindowType.CloseOne) {
1166
- let size = this.size;
1167
- while (size > 0) {
1168
- let name = this._windowNames.pop();
1169
- let window = UIManager.getWindow(name);
1170
- let header = window.getHeader();
1171
- header && this._removeHeader(header);
1172
- UIManager._removeWindow(name);
1173
- break;
1677
+ function uiclass(groupName, pkgName, name, inlinePkgs) {
1678
+ /** target 类的构造函数 */
1679
+ return function (ctor) {
1680
+ // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
1681
+ const originalCtor = ctor;
1682
+ // 给构造函数添加静态属性,存储窗口名称(避免混淆后 constructor.name 变化)
1683
+ ctor[MetadataKey.originalName] = name;
1684
+ uiclassMap.set(originalCtor, {
1685
+ ctor: ctor, // 存储实际的构造函数(可能被包装过)
1686
+ props: ctor[MetadataKey.prop] || null,
1687
+ callbacks: ctor[MetadataKey.callback] || null,
1688
+ controls: ctor[MetadataKey.control] || null,
1689
+ transitions: ctor[MetadataKey.transition] || null,
1690
+ res: {
1691
+ group: groupName,
1692
+ pkg: pkgName,
1693
+ name: name,
1694
+ },
1695
+ });
1696
+ let pkgs = [];
1697
+ if (Array.isArray(inlinePkgs)) {
1698
+ pkgs = inlinePkgs;
1174
1699
  }
1175
- }
1176
- else if (window.type == exports.WindowType.CloseAll) {
1177
- let size = this.size;
1178
- for (let i = size; i > 0;) {
1179
- let name = this._windowNames[--i];
1180
- let window = UIManager.getWindow(name);
1181
- let header = window.getHeader();
1182
- header && this._removeHeader(header);
1183
- UIManager._removeWindow(name);
1700
+ else if (typeof inlinePkgs === "string") {
1701
+ pkgs = [inlinePkgs];
1184
1702
  }
1185
- this._windowNames.length = 0;
1186
- }
1703
+ InfoPool.add(ctor, groupName, pkgName, name, pkgs);
1704
+ return ctor;
1705
+ };
1187
1706
  }
1707
+ _uidecorator.uiclass = uiclass;
1188
1708
  /**
1189
- * 处理header的显示状态 并调整层级
1190
- * @internal
1709
+ * UI组件装饰器
1710
+ * @param {string} pkg 包名
1711
+ * @param {string} name 组件名
1191
1712
  */
1192
- _processHeaderStatus() {
1193
- // 找到第一个要显示的header
1194
- let firstHeader = null;
1195
- let firstWindow = null;
1196
- let index = this.size - 1;
1197
- for (let i = this.size - 1; i >= 0; --i) {
1198
- let name = this._windowNames[i];
1199
- let window = UIManager.getWindow(name);
1200
- if (window.isShowing() && window.getHeader()) {
1201
- firstWindow = window;
1202
- firstHeader = window.getHeader();
1203
- index = i;
1204
- break;
1205
- }
1206
- }
1207
- this._headers.forEach((header, name) => {
1208
- this._root.setChildIndex(header, 0);
1209
- if (!firstHeader && header.visible) {
1210
- header._hide();
1211
- }
1212
- else if (firstHeader) {
1213
- if (firstHeader.name == name && !header.visible) {
1214
- header._show(firstWindow);
1713
+ function uicom(pkg, name) {
1714
+ return function (ctor) {
1715
+ // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
1716
+ const originalCtor = ctor;
1717
+ // log(`pkg:【${pkg}】 uicom prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
1718
+ ctor[MetadataKey.originalName] = name;
1719
+ uicomponentMap.set(originalCtor, {
1720
+ ctor: ctor, // 存储实际的构造函数(可能被包装过)
1721
+ props: ctor[MetadataKey.prop] || null,
1722
+ callbacks: ctor[MetadataKey.callback] || null,
1723
+ controls: ctor[MetadataKey.control] || null,
1724
+ transitions: ctor[MetadataKey.transition] || null,
1725
+ res: {
1726
+ pkg: pkg,
1727
+ name: name,
1215
1728
  }
1216
- else if (firstHeader.name != name && header.visible) {
1217
- header._hide();
1729
+ });
1730
+ InfoPool.addComponent(ctor, pkg, name);
1731
+ return ctor;
1732
+ };
1733
+ }
1734
+ _uidecorator.uicom = uicom;
1735
+ /**
1736
+ * UI header装饰器
1737
+ * @param {string} pkg 包名
1738
+ * @param {string} name 组件名
1739
+ */
1740
+ function uiheader(pkg, name) {
1741
+ return function (ctor) {
1742
+ // 检查是否有原始构造函数引用(由其他装饰器如 @dataclass 提供)
1743
+ const originalCtor = ctor;
1744
+ // log(`pkg:【${pkg}】 uiheader prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
1745
+ ctor[MetadataKey.originalName] = name;
1746
+ uiheaderMap.set(originalCtor, {
1747
+ ctor: ctor, // 存储实际的构造函数(可能被包装过)
1748
+ props: ctor[MetadataKey.prop] || null,
1749
+ callbacks: ctor[MetadataKey.callback] || null,
1750
+ controls: ctor[MetadataKey.control] || null,
1751
+ transitions: ctor[MetadataKey.transition] || null,
1752
+ res: {
1753
+ pkg: pkg,
1754
+ name: name,
1218
1755
  }
1219
- }
1220
- });
1221
- if (firstHeader) {
1222
- if (index == this.size - 1) {
1223
- this._root.setChildIndex(firstHeader, this._root.numChildren - 1);
1224
- }
1225
- else {
1226
- this._root.setChildIndex(firstHeader, this._root.numChildren - this.size + index - 1);
1227
- }
1228
- }
1756
+ });
1757
+ InfoPool.addHeader(ctor, pkg, name);
1758
+ return ctor;
1759
+ };
1229
1760
  }
1761
+ _uidecorator.uiheader = uiheader;
1230
1762
  /**
1231
- * 调整指定窗口的透明度图形。并根据窗口的背景透明度绘制半透明遮罩。
1232
- * @param window - 需要调整透明度的窗口对象。
1233
- * @internal
1763
+ * UI属性装饰器
1764
+ * @param {Object} target 实例成员的类的原型
1765
+ * @param {string} name 属性名
1766
+ *
1767
+ * example: @uiprop node: GObject
1234
1768
  */
1235
- _adjustAlphaGraph(window) {
1236
- this._root.setChildIndex(this._alphaGraph, this._root.numChildren - 1);
1237
- // 半透明遮罩绘制
1238
- this._color.a = window.bgAlpha * 255;
1239
- this._alphaGraph.clearGraphics();
1240
- this._alphaGraph.drawRect(0, this._color, this._color);
1769
+ function uiprop(target, name) {
1770
+ // debug("属性装饰器:", target.constructor, name);
1771
+ getObjectProp(target.constructor, MetadataKey.prop)[name] = 1;
1241
1772
  }
1242
- hasWindow(name) {
1243
- return this._windowNames.indexOf(name) >= 0;
1773
+ _uidecorator.uiprop = uiprop;
1774
+ /**
1775
+ * UI控制器装饰器
1776
+ * @param {Object} target 实例成员的类的原型
1777
+ * @param {string} name 属性名
1778
+ *
1779
+ * example: @uicontrol node: GObject
1780
+ */
1781
+ function uicontrol(target, name) {
1782
+ // debug("属性装饰器:", target.constructor, name);
1783
+ getObjectProp(target.constructor, MetadataKey.control)[name] = 1;
1784
+ }
1785
+ _uidecorator.uicontrol = uicontrol;
1786
+ /**
1787
+ * UI动画装饰器
1788
+ * @param {Object} target 实例成员的类的原型
1789
+ * @param {string} name 属性名
1790
+ *
1791
+ * example: @uitransition node: GObject
1792
+ */
1793
+ function uitransition(target, name) {
1794
+ // debug("属性装饰器:", target.constructor, name);
1795
+ getObjectProp(target.constructor, MetadataKey.transition)[name] = 1;
1796
+ }
1797
+ _uidecorator.uitransition = uitransition;
1798
+ /**
1799
+ * 方法装饰器 (给点击事件用)
1800
+ * @param {Object} target 实例成员的类的原型
1801
+ * @param {string} name 方法名
1802
+ */
1803
+ function uiclick(target, name, descriptor) {
1804
+ // debug("方法装饰器:", target.constructor, name, descriptor);
1805
+ getObjectProp(target.constructor, MetadataKey.callback)[name] = descriptor.value;
1806
+ }
1807
+ _uidecorator.uiclick = uiclick;
1808
+ })(exports._uidecorator || (exports._uidecorator = {}));
1809
+ const _global = (globalThis || window || global);
1810
+ _global["getKunpoRegisterWindowMaps"] = function () {
1811
+ return exports._uidecorator.getWindowMaps();
1812
+ };
1813
+ _global["getKunpoRegisterComponentMaps"] = function () {
1814
+ return exports._uidecorator.getComponentMaps();
1815
+ };
1816
+ _global["getKunpoRegisterHeaderMaps"] = function () {
1817
+ return exports._uidecorator.getHeaderMaps();
1818
+ };
1819
+
1820
+ /**
1821
+ * @Author: Gongxh
1822
+ * @Date: 2025-01-11
1823
+ * @Description: 窗口顶边栏
1824
+ * 窗口顶边资源栏 同组中只会有一个显示
1825
+ */
1826
+ class Header extends fairyguiCc.GComponent {
1827
+ constructor() {
1828
+ super(...arguments);
1829
+ /** 窗口适配类型 */
1830
+ this.adapterType = exports.AdapterType.Full;
1831
+ }
1832
+ onAdapted() { }
1833
+ ;
1834
+ onClose() { }
1835
+ ;
1836
+ onHide() { }
1837
+ ;
1838
+ onShowFromHide() { }
1839
+ ;
1840
+ /**
1841
+ * 是否显示中
1842
+ */
1843
+ isShowing() {
1844
+ return this.visible;
1244
1845
  }
1245
1846
  /**
1246
- * 获取窗口组中顶部窗口的名称。
1247
- * @returns {string} 顶部窗口的名称。
1847
+ * 初始化 (内部方法)
1848
+ * @internal
1849
+ */
1850
+ _init() {
1851
+ this.opaque = false;
1852
+ this.onInit();
1853
+ }
1854
+ /**
1855
+ * 关闭 (内部方法)
1856
+ * @internal
1248
1857
  */
1249
- getTopWindowName() {
1250
- if (this.size > 0) {
1251
- return this._windowNames[this.size - 1];
1252
- }
1253
- console.warn(`WindowGroup.getTopWindowName: window group 【${this._name}】 is empty`);
1254
- return "";
1858
+ _close() {
1859
+ this.onClose();
1860
+ this.dispose();
1255
1861
  }
1256
- /** 根据窗口 创建顶部资源栏 (内部方法) @internal */
1257
- _createHeader(window) {
1258
- // 只有创建界面的时候, 才会尝试创建顶部资源栏
1259
- let headerInfo = window.getHeaderInfo();
1260
- if (!headerInfo) {
1261
- return;
1262
- }
1263
- let name = headerInfo.name;
1264
- let header = this._getHeader(name);
1265
- if (header) {
1266
- window._setHeader(header);
1267
- header._addRef();
1268
- }
1269
- else {
1270
- // 创建header节点
1271
- let { pkg } = UIManager._getResPool().getHeader(name);
1272
- let newHeader = fairyguiCc.UIPackage.createObject(pkg, name);
1273
- newHeader.name = name;
1274
- newHeader.opaque = false;
1275
- window._setHeader(newHeader);
1276
- newHeader.visible = false;
1277
- PropsHelper.serializeProps(newHeader, pkg);
1278
- newHeader._init();
1279
- newHeader._adapted();
1280
- this._root.addChild(newHeader);
1281
- // 添加到显示节点
1282
- newHeader._addRef();
1283
- this._headers.set(newHeader.name, newHeader);
1284
- }
1285
- }
1286
- /**
1287
- * 顶部资源栏窗口 从管理器中移除 (内部方法)
1288
- * @param header 资源栏
1862
+ /**
1863
+ * 窗口适配
1289
1864
  * @internal
1290
1865
  */
1291
- _removeHeader(header) {
1292
- if (this._headers.has(header.name)) {
1293
- let refCount = header._decRef();
1294
- if (refCount <= 0) {
1295
- this._headers.delete(header.name);
1296
- header._close();
1297
- }
1866
+ _adapted() {
1867
+ this.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
1868
+ this.setPivot(0.5, 0.5, true);
1869
+ switch (this.adapterType) {
1870
+ case exports.AdapterType.Full:
1871
+ this.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
1872
+ break;
1873
+ case exports.AdapterType.Bang:
1874
+ this.setSize(bitCore.Screen.SafeWidth, bitCore.Screen.SafeHeight, true);
1875
+ break;
1298
1876
  }
1877
+ this.onAdapted();
1299
1878
  }
1300
1879
  /**
1301
- * 获取顶部资源栏 (内部方法)
1302
- * @param name 资源栏的名称
1880
+ * 显示
1881
+ * @param userdata 用户数据
1303
1882
  * @internal
1304
1883
  */
1305
- _getHeader(name) {
1306
- return this._headers.get(name);
1307
- }
1308
- /** 屏幕大小改变时被调用 (内部方法) @internal */
1309
- _screenResize() {
1310
- this._headers.forEach((header) => {
1311
- header._screenResize();
1312
- });
1313
- this._alphaGraph.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
1314
- this._alphaGraph.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
1315
- this._alphaGraph.setPivot(0.5, 0.5, true);
1884
+ _show(userdata) {
1885
+ this.visible = true;
1886
+ this.onShow(userdata);
1316
1887
  }
1317
1888
  /**
1318
- * 关闭窗口组中的所有窗口
1889
+ * 隐藏
1890
+ * @internal
1319
1891
  */
1320
- closeAllWindow() {
1321
- while (this.size > 0) {
1322
- let name = this.getTopWindowName();
1323
- UIManager.closeWindow(name);
1324
- }
1892
+ _hide() {
1893
+ this.visible = false;
1894
+ this.onHide();
1325
1895
  }
1326
1896
  }
1327
1897
 
@@ -1330,335 +1900,189 @@ class WindowGroup {
1330
1900
  * @Date: 2025-01-10
1331
1901
  * @Description: 窗口顶部资源栏信息
1332
1902
  */
1333
- class WindowHeaderInfo {
1903
+ class HeaderInfo {
1334
1904
  /**
1335
1905
  * 创建 WindowHeaderInfo
1336
1906
  * @param {string} name header窗口名
1337
1907
  * @param {*} [userdata] 自定义数据
1338
- * @returns {WindowHeaderInfo}
1908
+ * @returns {HeaderInfo}
1339
1909
  */
1340
- static create(name, userdata) {
1341
- const info = new WindowHeaderInfo();
1910
+ static create(ctor, userdata) {
1911
+ // 优先使用装饰器设置的静态属性,避免代码混淆后 constructor.name 变化
1912
+ const name = ctor[MetadataKey.originalName];
1913
+ if (!name) {
1914
+ throw new Error(`header【${ctor.name}】未注册,请使用 _uidecorator.uiheader 注册header`);
1915
+ }
1916
+ const info = new HeaderInfo();
1342
1917
  info.name = name;
1343
1918
  info.userdata = userdata;
1344
1919
  return info;
1345
1920
  }
1346
1921
  }
1347
1922
 
1348
- /******************************************************************************
1349
- Copyright (c) Microsoft Corporation.
1350
-
1351
- Permission to use, copy, modify, and/or distribute this software for any
1352
- purpose with or without fee is hereby granted.
1353
-
1354
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1355
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1356
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1357
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1358
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1359
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1360
- PERFORMANCE OF THIS SOFTWARE.
1361
- ***************************************************************************** */
1362
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1363
-
1364
-
1365
- function __decorate(decorators, target, key, desc) {
1366
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1367
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1368
- 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;
1369
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1370
- }
1371
-
1372
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1373
- var e = new Error(message);
1374
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1375
- };
1376
-
1377
1923
  /**
1378
1924
  * @Author: Gongxh
1379
- * @Date: 2024-12-13
1380
- * @Description:
1925
+ * @Date: 2024-12-14
1926
+ * @Description: 窗口基类和fgui组件对接
1381
1927
  */
1382
- /** @internal */
1383
- class WindowResPool {
1928
+ class WindowBase extends fairyguiCc.GComponent {
1384
1929
  constructor() {
1385
- /** 窗口信息池 @internal */
1386
- this._windowInfos = new Map();
1387
- /** 窗口header信息池 @internal */
1388
- this._headerInfos = new Map();
1389
- /** UI包所在的bundle名 */
1390
- this._pkgBundles = new Map();
1391
- /** 是否设置过配置内容 @internal */
1392
- this._isInit = false;
1393
- /** 窗口名对应的包名列表 @internal */
1394
- this._windowPkgs = new Map();
1395
- /** 包的引用计数 @internal */
1396
- this._pkgRefs = {};
1397
- /** UI包路径 @internal */
1398
- // private _uipath: string = "";
1399
- /** UI包在bundle中的路径 @internal */
1400
- this._uiPaths = {};
1401
- /** 手动管理的包 @internal */
1402
- this._manualPackages = new Set();
1403
- /** 立即释放的包 @internal */
1404
- this._imReleasePackages = new Set();
1405
- /** 注册的回调函数 @internal */
1406
- this._showWaitWindow = null;
1407
- /** 隐藏等待窗口的回调函数 @internal */
1408
- this._hideWaitWindow = null;
1409
- /** 加载失败回调函数 @internal */
1410
- this._fail = null;
1411
- /** 等待窗口的引用计数 @internal */
1412
- this._waitRef = 0;
1413
- }
1414
- /**
1415
- * 注册窗口信息
1416
- * @param info
1417
- */
1418
- add(ctor, group, pkg, name, bundle) {
1419
- if (this.has(name)) {
1420
- return;
1421
- }
1422
- this._windowInfos.set(name, {
1423
- ctor: ctor,
1424
- group: group,
1425
- pkg: pkg,
1426
- name: name,
1427
- bundle: bundle
1428
- });
1429
- this._pkgBundles.set(pkg, bundle || "resources");
1430
- this.addWindowPkg(name, pkg);
1431
- // 窗口组件扩展
1432
- fairyguiCc.UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
1433
- }
1434
- has(name) {
1435
- return this._windowInfos.has(name);
1930
+ super(...arguments);
1931
+ /** 窗口类型 */
1932
+ this.type = exports.WindowType.Normal;
1933
+ /** 窗口适配类型 */
1934
+ this.adapterType = exports.AdapterType.Full;
1935
+ /** @internal */
1936
+ this._swallowNode = null; // 吞噬触摸的节点
1937
+ /** @internal */
1938
+ this._isTop = true;
1436
1939
  }
1437
- get(name) {
1438
- if (!this.has(name)) {
1439
- throw new Error(`窗口【${name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);
1440
- }
1441
- return this._windowInfos.get(name);
1940
+ /**
1941
+ * 初始化方法 (框架内部使用)
1942
+ * @param swallowTouch 是否吞噬触摸事件
1943
+ * @param bgAlpha 底部遮罩的透明度
1944
+ * @internal
1945
+ */
1946
+ _init(swallowTouch) {
1947
+ // 窗口本身可能留有安全区的边, 所以需要一个全屏的节点来吞噬触摸事件
1948
+ let bgNode = new fairyguiCc.GComponent();
1949
+ bgNode.name = "swallow";
1950
+ bgNode.setPivot(0.5, 0.5, true);
1951
+ this.addChild(bgNode);
1952
+ bgNode.parent.setChildIndex(bgNode, 0); // 调整显示层级
1953
+ bgNode.onClick(this.onEmptyAreaClick, this); // 空白区域点击事件
1954
+ bgNode.opaque = swallowTouch;
1955
+ this._swallowNode = bgNode;
1956
+ // 窗口自身也要设置是否吞噬触摸
1957
+ this.opaque = swallowTouch;
1958
+ this._isTop = true;
1959
+ this.bgAlpha = WindowManager.bgAlpha;
1960
+ this.onInit();
1442
1961
  }
1443
1962
  /**
1444
- * 注册窗口header信息
1445
- * @param info
1963
+ * 适配窗口
1964
+ * @internal
1446
1965
  */
1447
- addHeader(ctor, pkg, name, bundle) {
1448
- if (this.hasHeader(name)) {
1449
- return;
1966
+ _adapted() {
1967
+ this.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
1968
+ this.setPivot(0.5, 0.5, true);
1969
+ switch (this.adapterType) {
1970
+ case exports.AdapterType.Full:
1971
+ this.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
1972
+ break;
1973
+ case exports.AdapterType.Bang:
1974
+ this.setSize(bitCore.Screen.SafeWidth, bitCore.Screen.SafeHeight, true);
1975
+ break;
1450
1976
  }
1451
- this._headerInfos.set(name, {
1452
- ctor: ctor,
1453
- pkg: pkg,
1454
- bundle: bundle
1455
- });
1456
- this._pkgBundles.set(pkg, bundle || "resources");
1457
- // 窗口header扩展
1458
- fairyguiCc.UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
1459
- }
1460
- hasHeader(name) {
1461
- return this._headerInfos.has(name);
1977
+ // 屏幕的宽高
1978
+ this._swallowNode.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
1979
+ // 位置放在窗口的中心
1980
+ this._swallowNode.setPosition(this.width * 0.5, this.height * 0.5);
1981
+ this.onAdapted();
1462
1982
  }
1463
- getHeader(name) {
1464
- if (!this.hasHeader(name)) {
1465
- throw new Error(`窗口header【${name}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);
1466
- }
1467
- return this._headerInfos.get(name);
1983
+ /**
1984
+ * 窗口关闭
1985
+ * @internal
1986
+ */
1987
+ _close() {
1988
+ this.onClose();
1989
+ this.dispose();
1468
1990
  }
1469
- /** 资源配置相关接口 */
1470
- initPackageConfig(res) {
1471
- var _a, _b;
1472
- if (!res || !res.config) {
1473
- return;
1474
- }
1475
- if (this._isInit) {
1476
- throw new Error("资源配置已初始化,请勿重复设置");
1477
- }
1478
- this._isInit = true;
1479
- this._showWaitWindow = res === null || res === void 0 ? void 0 : res.showWaitWindow;
1480
- this._hideWaitWindow = res === null || res === void 0 ? void 0 : res.hideWaitWindow;
1481
- this._fail = res === null || res === void 0 ? void 0 : res.fail;
1482
- this._uiPaths = ((_a = res.config) === null || _a === void 0 ? void 0 : _a.bundlePaths) || {};
1483
- this._uiPaths["resources"] = ((_b = res.config) === null || _b === void 0 ? void 0 : _b.uiPath) || "";
1484
- for (const bundle in this._uiPaths) {
1485
- if (this._uiPaths[bundle] != "" && !this._uiPaths[bundle].endsWith("/")) {
1486
- this._uiPaths[bundle] += "/";
1487
- }
1488
- }
1489
- this._manualPackages = new Set(res.config.manualPackages || []);
1490
- this._imReleasePackages = new Set(res.config.imReleasePackages || []);
1491
- let windowPkgs = res.config.linkPackages || {};
1492
- for (const windowName in windowPkgs) {
1493
- let pkgs = windowPkgs[windowName];
1494
- for (const pkg of pkgs || []) {
1495
- this.addWindowPkg(windowName, pkg);
1496
- }
1497
- }
1498
- // 遍历一遍,剔除手动管理的包
1499
- this._windowPkgs.forEach((pkgs, windowName) => {
1500
- for (let i = pkgs.length - 1; i >= 0; i--) {
1501
- if (this._manualPackages.has(pkgs[i])) {
1502
- pkgs.splice(i, 1);
1503
- }
1504
- }
1505
- if (pkgs.length <= 0) {
1506
- this._windowPkgs.delete(windowName);
1507
- }
1508
- });
1991
+ /**
1992
+ * 显示窗口 (框架内部使用)
1993
+ * @param userdata 用户自定义数据
1994
+ * @internal
1995
+ */
1996
+ _show(userdata) {
1997
+ this.visible = true;
1998
+ this.onShow(userdata);
1509
1999
  }
1510
- /** 添加窗口对应的包名 */
1511
- addWindowPkg(windowName, pkgName) {
1512
- if (!this._windowPkgs.has(windowName)) {
1513
- this._windowPkgs.set(windowName, [pkgName]);
1514
- }
1515
- else {
1516
- this._windowPkgs.get(windowName).push(pkgName);
1517
- }
2000
+ /**
2001
+ * 隐藏窗口 (框架内部使用)
2002
+ * @internal
2003
+ */
2004
+ _hide() {
2005
+ this.visible = false;
2006
+ this.onHide();
1518
2007
  }
1519
2008
  /**
1520
- * 加载窗口需要的包资源
1521
- * @param windowName 窗口名
2009
+ * 从隐藏状态恢复显示
2010
+ * @internal
1522
2011
  */
1523
- loadWindowRes(windowName, listenter) {
1524
- var _a;
1525
- // 资源配置未初始化 直接返回成功
1526
- if (!this._isInit) {
1527
- console.warn(`UI包信息未配置 将手动管理所有UI包资源的加载,如果需要配置,请使用 【UIManager.initPackageConfig】接口`);
1528
- listenter.complete();
1529
- return;
1530
- }
1531
- // 不需要包资源 直接返回成功
1532
- if (!this.hasWindowPkg(windowName)) {
1533
- listenter.complete();
1534
- return;
1535
- }
1536
- if (this._waitRef++ <= 0) {
1537
- // 调用注入的回调函数 用来显示等待窗
1538
- (_a = this._showWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
1539
- }
1540
- this.loadPackages({
1541
- pkgs: this.getWindowPkgs(windowName),
1542
- complete: () => {
1543
- var _a;
1544
- if (--this._waitRef <= 0) {
1545
- // 调用注入的回调函数 关闭等待窗
1546
- listenter.complete();
1547
- (_a = this._hideWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
1548
- }
1549
- },
1550
- fail: (pkgs) => {
1551
- var _a, _b;
1552
- console.warn(`界面${windowName}打开失败`);
1553
- listenter.fail(pkgs);
1554
- (_a = this._fail) === null || _a === void 0 ? void 0 : _a.call(this, windowName, "UI包加载失败", pkgs);
1555
- if (--this._waitRef <= 0) {
1556
- // 调用注入的回调函数 关闭等待窗
1557
- (_b = this._hideWaitWindow) === null || _b === void 0 ? void 0 : _b.call(this);
1558
- }
1559
- }
1560
- });
2012
+ _showFromHide() {
2013
+ this.visible = true;
2014
+ this.onShowFromHide();
1561
2015
  }
1562
- addResRef(windowName) {
1563
- if (!this._isInit) {
1564
- return;
1565
- }
1566
- // 不需要包资源 直接返回成功
1567
- if (!this.hasWindowPkg(windowName)) {
1568
- return;
1569
- }
1570
- let pkgs = this.getWindowPkgs(windowName);
1571
- for (const pkg of pkgs) {
1572
- this.addRef(pkg);
1573
- }
2016
+ /**
2017
+ * 除忽略的窗口组外, 显示到最上层时
2018
+ * @internal
2019
+ */
2020
+ _toTop() {
2021
+ this._isTop = true;
2022
+ this.onToTop();
1574
2023
  }
1575
2024
  /**
1576
- * 释放窗口资源
1577
- * @param windowName 窗口名
2025
+ * 除忽略的窗口组外, 被上层窗口覆盖时
2026
+ * @internal
1578
2027
  */
1579
- releaseWindowRes(windowName) {
1580
- if (!this._isInit || !this.hasWindowPkg(windowName)) {
1581
- return;
1582
- }
1583
- let pkgs = this.getWindowPkgs(windowName);
1584
- for (const pkg of pkgs) {
1585
- this.decRef(pkg);
1586
- }
2028
+ _toBottom() {
2029
+ this._isTop = false;
2030
+ this.onToBottom();
1587
2031
  }
1588
2032
  /**
1589
- * 加载fgui包
1590
- * @param pkgs 包名集合
1591
- * @param progress 进度回调
1592
- * @param complete 加载完成回调
2033
+ * 设置窗口深度
2034
+ * @param depth 深度
2035
+ * @internal
1593
2036
  */
1594
- loadPackages(res) {
1595
- // 过滤已经加载的包
1596
- let needLoadPkgs = res.pkgs.filter(pkg => this.getRef(pkg) <= 0);
1597
- let successPkgs = [];
1598
- let failPkgs = [];
1599
- let total = needLoadPkgs.length;
1600
- if (total <= 0) {
1601
- res.complete();
1602
- return;
1603
- }
1604
- for (const pkg of needLoadPkgs) {
1605
- let bundleName = this.getPkgBundle(pkg);
1606
- let bundle = bundleName === "resources" ? cc.resources : cc.assetManager.getBundle(bundleName);
1607
- if (!bundle) {
1608
- throw new Error(`UI包【${pkg}】所在的bundle【${bundleName}】未加载`);
1609
- }
1610
- fairyguiCc.UIPackage.loadPackage(bundle, this.getPkgPath(pkg), (err) => {
1611
- total--;
1612
- err ? failPkgs.push(pkg) : successPkgs.push(pkg);
1613
- if (total > 0) {
1614
- return;
1615
- }
1616
- if (failPkgs.length > 0) {
1617
- res.fail(failPkgs);
1618
- }
1619
- else {
1620
- res.complete();
1621
- }
1622
- });
1623
- }
2037
+ setDepth(depth) {
2038
+ this.parent.setChildIndex(this, depth);
1624
2039
  }
1625
- /** 获取UI包所在的bundle名 */
1626
- getPkgBundle(pkg) {
1627
- return this._pkgBundles.get(pkg) || "resources";
2040
+ isShowing() {
2041
+ return this.visible;
1628
2042
  }
1629
- /** 获取UI包在bundle中的路径 */
1630
- getPkgPath(pkg) {
1631
- let bundle = this._pkgBundles.get(pkg);
1632
- return this._uiPaths[bundle] + pkg;
2043
+ /** 是否在最上层显示 (除忽略的窗口组外, 显示到最上层时) */
2044
+ isTop() {
2045
+ return this._isTop;
1633
2046
  }
1634
- /** 获取窗口对应的包名列表 */
1635
- getWindowPkgs(windowName) {
1636
- if (this._windowPkgs.has(windowName)) {
1637
- return this._windowPkgs.get(windowName);
1638
- }
1639
- return [];
2047
+ /** @internal */
2048
+ screenResize() {
2049
+ this._adapted();
2050
+ }
2051
+ /**
2052
+ * 刷新顶部资源栏
2053
+ * 调用这个方法会重新创建 或者 刷新header
2054
+ * 用来在同一个界面显示不同的header
2055
+ */
2056
+ refreshHeader() {
2057
+ HeaderManager.refreshWindowHeader(this.name, this.getHeaderInfo());
1640
2058
  }
1641
- hasWindowPkg(windowName) {
1642
- return this._windowPkgs.has(windowName);
2059
+ /**
2060
+ * 用于在界面中关闭自己
2061
+ */
2062
+ removeSelf() {
2063
+ WindowManager.closeWindowByName(this.name);
1643
2064
  }
1644
- /** 获取包的引用计数 */
1645
- getRef(pkg) {
1646
- return this._pkgRefs[pkg] ? this._pkgRefs[pkg] : 0;
2065
+ }
2066
+
2067
+ class Window extends WindowBase {
2068
+ onAdapted() {
1647
2069
  }
1648
- /** 增加包的引用计数 */
1649
- addRef(pkg) {
1650
- this._pkgRefs[pkg] = this.getRef(pkg) + 1;
2070
+ onHide() { }
2071
+ onShowFromHide() { }
2072
+ onToTop() { }
2073
+ onToBottom() { }
2074
+ /**
2075
+ * 空白区域点击事件处理函数。
2076
+ * 当用户点击窗口的空白区域时触发此方法。
2077
+ */
2078
+ onEmptyAreaClick() {
1651
2079
  }
1652
- /** 减少包的引用计数 */
1653
- decRef(pkg) {
1654
- this._pkgRefs[pkg] = this.getRef(pkg) - 1;
1655
- if (this.getRef(pkg) <= 0) {
1656
- delete this._pkgRefs[pkg];
1657
- // 如果需要立即释放 释放包资源
1658
- if (this._imReleasePackages.has(pkg)) {
1659
- fairyguiCc.UIPackage.removePackage(pkg);
1660
- }
1661
- }
2080
+ /**
2081
+ * 获取窗口顶部资源栏数据 默认返回空数组
2082
+ * @returns {HeaderInfo}
2083
+ */
2084
+ getHeaderInfo() {
2085
+ return null;
1662
2086
  }
1663
2087
  }
1664
2088
 
@@ -1673,7 +2097,6 @@ let CocosWindowContainer = class CocosWindowContainer extends cc.Component {
1673
2097
  super(...arguments);
1674
2098
  this.ignoreQuery = false;
1675
2099
  this.swallowTouch = false;
1676
- this.bgAlpha = 0.75;
1677
2100
  }
1678
2101
  /**
1679
2102
  * 初始化窗口容器
@@ -1689,7 +2112,7 @@ let CocosWindowContainer = class CocosWindowContainer extends cc.Component {
1689
2112
  root.opaque = this.swallowTouch;
1690
2113
  root.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
1691
2114
  fairyguiCc.GRoot.inst.addChild(root);
1692
- UIManager._addWindowGroup(new WindowGroup(name, root, this.ignoreQuery, this.swallowTouch, this.bgAlpha));
2115
+ WindowManager.addWindowGroup(new WindowGroup(name, root, this.ignoreQuery, this.swallowTouch));
1693
2116
  }
1694
2117
  };
1695
2118
  __decorate([
@@ -1698,52 +2121,68 @@ __decorate([
1698
2121
  __decorate([
1699
2122
  property$1({ displayName: "吞噬触摸事件", tooltip: "窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件" })
1700
2123
  ], CocosWindowContainer.prototype, "swallowTouch", void 0);
1701
- __decorate([
1702
- property$1({ displayName: "底部遮罩透明度", tooltip: "底部半透明遮罩的默认透明度", min: 0, max: 1, step: 0.01 })
1703
- ], CocosWindowContainer.prototype, "bgAlpha", void 0);
1704
2124
  CocosWindowContainer = __decorate([
1705
2125
  ccclass$1("CocosWindowContainer"),
1706
- menu$1("kunpo/UI/UIContainer")
2126
+ menu$1("bit/UIContainer")
1707
2127
  ], CocosWindowContainer);
1708
2128
 
1709
2129
  const { ccclass, menu, property } = cc._decorator;
1710
- exports.UIModule = class UIModule extends cc.Component {
2130
+ exports.UIModule = class UIModule extends bitCore.Module {
1711
2131
  constructor() {
1712
2132
  super(...arguments);
2133
+ this.ui_config = null;
2134
+ this.bgAlpha = 0.75;
2135
+ this.autoReleaseUIRes = true;
1713
2136
  /** 模块名称 */
1714
2137
  this.moduleName = "UI模块";
1715
2138
  }
1716
- /** 模块初始化 (内部使用) @internal */
1717
- init() {
2139
+ onInit() {
2140
+ this.ui_config && PropsHelper.setConfig(this.ui_config.json);
2141
+ ResLoader.setAutoRelease(this.autoReleaseUIRes);
2142
+ // 设置底部遮罩的默认透明度
2143
+ WindowManager.bgAlpha = this.bgAlpha;
1718
2144
  /** 初始化窗口管理系统 */
1719
- UIManager._init(new WindowResPool());
1720
2145
  fairyguiCc.GRoot.create();
1721
2146
  bitCore.debug("初始化 WindowContainers");
1722
- for (const child of this.node.children) {
1723
- const containerComponent = child.getComponent(CocosWindowContainer);
1724
- containerComponent === null || containerComponent === void 0 ? void 0 : containerComponent.init();
2147
+ const alphaGraph = new fairyguiCc.GGraph();
2148
+ alphaGraph.touchable = false;
2149
+ alphaGraph.name = "bgAlpha";
2150
+ alphaGraph.setPosition(bitCore.Screen.ScreenWidth * 0.5, bitCore.Screen.ScreenHeight * 0.5);
2151
+ alphaGraph.setSize(bitCore.Screen.ScreenWidth, bitCore.Screen.ScreenHeight, true);
2152
+ alphaGraph.setPivot(0.5, 0.5, true);
2153
+ alphaGraph.visible = false;
2154
+ fairyguiCc.GRoot.inst.addChild(alphaGraph);
2155
+ WindowManager.setAlphaGraph(alphaGraph);
2156
+ for (const container of this.getComponentsInChildren(CocosWindowContainer)) {
2157
+ container.init();
1725
2158
  }
1726
- // fgui.UIObjectFactory.setLoaderExtension(GLoader);
1727
- // this._uiInitializer = new UIInitializer(this.node, this.getPackageLoader());
1728
- // this._uiInitializer.init(this.reAdaptWhenScreenResize, this.fullIfWideScreen);
1729
2159
  this.node.destroyAllChildren();
1730
- /** 注册窗口信息 */
1731
- UIManager.registerUI();
1732
- exports._uidecorator.setRegisterFinish();
1733
- this.onInit();
2160
+ bitCore.Adapter.instance.addResizeListener(this.onScreenResize.bind(this));
1734
2161
  }
1735
- /** 模块初始化完成后调用的函数 */
1736
- onInit() {
1737
- bitCore.debug("UIModule init complete");
2162
+ /**
2163
+ * 屏幕大小改变时被调用
2164
+ * @internal
2165
+ */
2166
+ onScreenResize(...args) {
2167
+ WindowManager.onScreenResize();
1738
2168
  }
1739
2169
  };
2170
+ __decorate([
2171
+ property({ type: cc.JsonAsset, displayName: "配置文件", tooltip: "编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件" })
2172
+ ], exports.UIModule.prototype, "ui_config", void 0);
2173
+ __decorate([
2174
+ property({ displayName: "底部遮罩透明度", tooltip: "半透明遮罩的默认透明度", min: 0, max: 1, step: 0.01 })
2175
+ ], exports.UIModule.prototype, "bgAlpha", void 0);
2176
+ __decorate([
2177
+ property({ displayName: "自动释放UI资源", tooltip: "界面关闭时自动释放加载的资源" })
2178
+ ], exports.UIModule.prototype, "autoReleaseUIRes", void 0);
1740
2179
  exports.UIModule = __decorate([
1741
2180
  ccclass("UIModule"),
1742
- menu("kunpo/UIModule")
2181
+ menu("bit/UIModule")
1743
2182
  ], exports.UIModule);
1744
2183
 
1745
- exports.UIHeader = UIHeader;
1746
- exports.UIManager = UIManager;
2184
+ exports.Header = Header;
2185
+ exports.HeaderInfo = HeaderInfo;
1747
2186
  exports.Window = Window;
1748
2187
  exports.WindowGroup = WindowGroup;
1749
- exports.WindowHeaderInfo = WindowHeaderInfo;
2188
+ exports.WindowManager = WindowManager;