@gongxh/bit-ui 0.0.2 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 bit老宫
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,243 +1,161 @@
1
- ## UI模块
2
-
3
- ### 特点
4
-
5
- * 基于FairyGUI, 查看[FairyGUI官方文档](https://www.fairygui.com/docs/editor)
6
-
7
- * 灵活的 UI 装饰器(配合插件 `kunpo-fgui` 使用,一键导出界面配置,省时省力省代码)
8
-
9
- * 控制窗口之间的相互关系(eg: 打开界面时,是隐藏/关闭前一个界面,还是隐藏/关闭所有界面)
10
-
11
- * 多窗口组管理
12
-
13
- * 顶部显示金币钻石的资源栏(header),一次实现,多界面复用,
14
-
15
- * 支持不同界面使用不同 header
16
-
17
- ### 插件链接
18
- * **kunpo-fgui**: [https://store.cocos.com/app/detail/7213](https://store.cocos.com/app/detail/7213)
19
-
20
- ### 使用
21
-
22
- #### *一、FairyGUI界面*
23
- > ![image-fgui-project](../image/image-fgui-project.png#pic_left)
24
-
25
- #### *二、UI 装饰器使用*
26
-
27
- > 注:只有使用了装饰器的内容才能在 `kunpo-fgui` 插件中识别,`kunpo-fgui`插件操作界面如下图
28
-
29
- > ![image-fgui-editor](../image/image-fgui-editor.png#pic_left)
30
-
31
-
32
- 1. 窗口装饰器
33
-
34
- ```typescript
35
- import { Window, _uidecorator } from 'bit-ui';
36
- const { uiclass, uiprop, uiclick } = _uidecorator;
37
-
38
- /**
39
- * 窗口装饰器
40
- * @param 参数1: 窗口容器节点名字
41
- * @param 参数2: FairyGUI中的UI包名
42
- * @param 参数3: FairyGUI中的组件名 必须和 class 类同名 这里是 MyWindow
43
- */
44
- @uiclass("Window", "UI包名", "MyWindow")
45
- export class MyWindow extends Window {
46
- // ... 窗口实现
47
- }
48
- ```
49
-
50
- 2. Header 装饰器
51
-
52
- ```typescript
53
- import { WindowHeader, _uidecorator } from 'bit-ui';
54
- const { uiheader } = _uidecorator;
55
-
56
- /**
57
- * 窗口顶部资源栏装饰器
58
- * @param 参数1: FairyGUI中的UI包名
59
- * @param 参数2: FairyGUI中的组件名 必须和 class 类同名 这里是 MyWindowHeader
60
- */
61
- @uiheader("UI包名", "WindowHeader")
62
- export class MyWindowHeader extends WindowHeader {
63
- // ... Header 实现
64
- }
65
- ```
66
-
67
- 3. UI组件装饰器
68
-
69
- ```typescript
70
- import { _uidecorator } from 'bit-ui';
71
- const { uicom, uiprop, uiclick } = _uidecorator;
72
-
73
- /**
74
- * UI组件类装饰器
75
- * @param 参数1: FairyGUI中的UI包名
76
- * @param 参数2: FairyGUI中的组件名 必须和 class 类同名 这里是 MyComponent
77
- */
78
- @uicom("Home", "MyComponent")
79
- export class MyComponent {
80
- // ... 组件实现
81
- }
82
- ```
83
-
84
- 4. UI属性装饰器
85
-
86
- ```typescript
87
- import { Window, _uidecorator } from 'bit-ui';
88
- const { uiclass, uiprop, uiclick } = _uidecorator;
89
-
90
- @uiclass("Window", "Home", "MyWindow")
91
- export class MyWindow extends Window {
92
- // FairyGUI 组件属性装饰器
93
- @uiprop private btnConfirm: GButton; // 按钮组件
94
- @uiprop private txtTitle: GTextField; // 文本组件
95
- @uiprop private listItems: GList; // 列表组件
96
- }
97
- ```
98
-
99
- 5. 点击事件装饰器
100
-
101
- ```typescript
102
- import { Window, _uidecorator } from 'bit-ui';
103
- const { uiclass, uiprop, uiclick } = _uidecorator;
104
-
105
- @uiclass("Window", "Home", "MyWindow")
106
- export class MyWindow extends Window {
107
- // 点击事件装饰器
108
- @uiclick
109
- private onTouchEvent(event: cc.Event): void {
110
- console.log('确认按钮被点击');
111
- }
112
- }
113
- ```
114
-
115
- 6. 控制器和动画装饰器
116
-
117
- ```typescript
118
- import { Window, _uidecorator } from 'bit-ui';
119
- const { uiclass, uiprop, uiclick, uicontrol, uitransition } = _uidecorator;
120
-
121
- @uiclass("Window", "Home", "MyWindow")
122
- export class MyWindow extends Window {
123
- // FairyGUI 组件属性装饰器
124
- @uicontrol private control: Controller;
125
- @uitransition private transition: Transition;
126
- }
127
- ```
128
-
129
-
130
- #### *三、创建窗口*
131
-
132
- 1. 新建窗口类
133
-
134
- ```typescript
135
- /**
136
- * 窗口名必须和FairyGUI中的组件同名
137
- */
138
- import { Window, _uidecorator } from 'bit-ui';
139
- const { uiclass, uiprop, uiclick } = _uidecorator;
140
-
141
- @uiclass("Window", "UI包名", "MyWindow")
142
- export class MyWindow extends Window {
143
- protected onInit(): void {
144
- // 初始化窗口
145
- }
146
-
147
- protected onShow(userdata?: any): void {
148
- // 窗口显示时的逻辑
149
- }
150
-
151
- protected onClose(): void {
152
- // 窗口关闭时的逻辑
153
- }
154
- }
155
- ```
156
-
157
- 2. 窗口生命周期
158
- - `onInit`: 窗口初始化时调用
159
- - `onShow`: 窗口显示时调用
160
- - `onClose`: 窗口关闭时调用
161
- - `onHide`: 窗口隐藏时调用
162
- - `onShowFromHide`: 窗口从隐藏状态恢复时调用
163
- - `onCover`: 窗口被覆盖时调用
164
- - `onRecover`: 窗口恢复时调用
165
- - `onEmptyAreaClick`: 点击窗口空白区域时调用
166
-
167
- #### *四、窗口资源加载配置*
168
- ```typescript
169
- interface IPackageConfig {
170
- /** UI所在resources中的路径 */
171
- uiPath: string;
172
- /**
173
- * 手动管理资源的包
174
- * 1. 用于基础UI包, 提供一些最基础的组件,所有其他包都可能引用其中的内容
175
- * 2. 资源header所在的包
176
- * 3. 用于一些特殊场景, 比如需要和其他资源一起加载, 并且显示进度条的包
177
- */
178
- manualPackages: string[];
179
- /**
180
- * 不推荐配置 只是提供一种特殊需求的实现方式
181
- * 窗口引用到其他包中的资源 需要的配置信息
182
- */
183
- linkPackages: { [windowName: string]: string[] };
184
-
185
- /**
186
- * 关闭界面后,需要立即释放资源的包名(建议尽量少)
187
- * 一般不建议包进行频繁装载卸载,因为每次装载卸载必然是要消耗CPU时间(意味着耗电)和产生大量GC的。UI系统占用的内存是可以精确估算的,你可以按照包的使用频率设定哪些包是需要立即释放的。
188
- * 不包括手动管理的包
189
- */
190
- imReleasePackages: string[];
191
- }
192
-
193
- export interface IPackageConfigRes {
194
- /** 配置信息 */
195
- config: IPackageConfig;
196
- /** 显示加载等待窗 */
197
- showWaitWindow: () => void;
198
- /** 隐藏加载等待窗 */
199
- hideWaitWindow: () => void;
200
- /** 打开窗口时UI包加载失败 */
201
- fail: (windowName: string, errmsg: string, pkgs: string[]) => void;
202
- }
1
+ # bit-ui
2
+
3
+ 基于 FairyGUI 的 UI 管理系统,提供灵活的窗口管理和装饰器支持。
4
+
5
+ ## 简介
6
+
7
+ `bit-ui` 是基于 FairyGUI 的 UI 管理库,提供窗口生命周期管理、资源自动加载、多窗口组管理等功能。支持配套的可视化编辑器一键导出界面配置。
8
+
9
+ **核心特性**:
10
+ - 🎨 灵活的 UI 装饰器
11
+ - 🪟 完整的窗口生命周期管理
12
+ - 📦 自动资源加载和卸载
13
+ - 🎯 窗口间关系控制(隐藏/关闭前一个界面)
14
+ - 🎪 多窗口组管理
15
+ - 📊 Header 资源栏复用
16
+ - 🖥️ 配套可视化编辑器(付费插件)
17
+
18
+ **依赖**:
19
+ - FairyGUI - [官方文档](https://www.fairygui.com/docs/editor)
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ npm install @gongxh/bit-ui
203
25
  ```
204
26
 
205
- #### *五、窗口管理接口*
206
- ```typescript
207
- export class WindowManager {
208
- /**
209
- * 配置UI包的一些信息 (可以不配置 完全手动管理资源)
210
- */
211
- public static initPackageConfig(res: IPackageConfigRes): void;
212
-
213
- /**
214
- * 异步打开一个窗口 (如果UI包的资源未加载, 会自动加载 配合 WindowManager.initPackageConfig一起使用)
215
- */
216
- public static showWindow(windowName: string, userdata?: any): Promise<void>
217
-
218
- /**
219
- * 打开一个窗口 (用于已加载过资源的窗口)
220
- */
221
- public static showWindowIm(windowName: string, userdata?: any): void;
222
-
223
- /**
224
- * 关闭窗口
225
- */
226
- public static closeWindow(windowName: string);
227
-
228
- /*
229
- * 获取窗口实例
230
- */
231
- public static getWindow<T extends Window>(windowName: string): T;
232
-
233
- /**
234
- * 获取当前最顶层窗口
235
- */
236
- public static getTopWindow(): Window;
237
-
238
- /**
239
- * 检查窗口是否存在
240
- */
241
- public static hasWindow(windowName: string): boolean;
242
- }
243
- ```
27
+ ## 可视化编辑器
28
+
29
+ 提供专业的 FairyGUI 配置编辑器,支持快速配置和导出。
30
+
31
+ **下载地址**:[Cocos Store - kunpo-fgui](https://store.cocos.com/app/detail/7213)
32
+
33
+ ## 使用说明
34
+
35
+ ### UI 装饰器
36
+
37
+ 使用装饰器简化 UI 组件定义和配置。
38
+
39
+ **窗口装饰器**:
40
+ - `@uiclass(groupName, pkgName, name, inlinePkgs?)` - 注册窗口类
41
+ - `groupName` - 窗口组名称
42
+ - `pkgName` - FairyGUI 包名
43
+ - `name` - 组件名(必须和类名相同)
44
+ - `inlinePkgs` - 内联的包名(可选,当前界面引用其他包资源时使用)
45
+
46
+ **Header 装饰器**:
47
+ - `@uiheader(pkgName, name)` - 注册 Header 类
48
+ - 用于定义窗口顶部资源栏
49
+
50
+ **UI 组件装饰器**:
51
+ - `@uicom(pkgName, name)` - 注册自定义 UI 组件类
52
+
53
+ **属性装饰器**:
54
+ - `@uiprop` - 标记 FairyGUI 组件属性(按钮、文本、列表等)
55
+ - `@uicontrol` - 标记 FairyGUI 控制器
56
+ - `@uitransition` - 标记 FairyGUI 动画
57
+
58
+ **事件装饰器**:
59
+ - `@uiclick` - 标记点击事件处理函数
60
+
61
+ ### 窗口基类 (Window)
62
+
63
+ 所有窗口的基类,提供完整的生命周期。
64
+
65
+ **生命周期方法**:
66
+ - `onInit()` - 窗口初始化
67
+ - `onShow(userdata?)` - 窗口显示
68
+ - `onHide()` - 窗口隐藏
69
+ - `onClose()` - 窗口关闭
70
+ - `onShowFromHide()` - 从隐藏状态恢复
71
+ - `onToTop()` - 窗口到顶层
72
+ - `onToBottom()` - 窗口到底层
73
+ - `onEmptyAreaClick()` - 点击空白区域
74
+ - `onAdapted()` - 窗口适配完成
75
+
76
+ ### Header 基类 (Header)
77
+
78
+ 窗口顶部资源栏基类,支持多窗口复用。
79
+
80
+ **生命周期方法**:
81
+ - `onInit()` - Header 初始化
82
+ - `onShow(userdata?)` - Header 显示
83
+ - `onHide()` - Header 隐藏
84
+ - `onClose()` - Header 关闭
85
+ - `onShowFromHide()` - 从隐藏状态恢复
86
+ - `onAdapted()` - 适配完成
87
+
88
+ ### 窗口管理器 (WindowManager)
89
+
90
+ 全局窗口管理器,负责窗口的创建、显示、关闭等。
91
+
92
+ **配置方法**:
93
+ - `setPackageCallbacks(callbacks)` - 设置 UI 包加载回调
94
+ - `callbacks.showWaitWindow` - 显示加载等待窗口
95
+ - `callbacks.hideWaitWindow` - 隐藏加载等待窗口
96
+ - `callbacks.fail` - 加载失败回调
97
+ - `addManualPackage(pkgName)` - 添加手动管理资源的包
98
+ - `setPackageInfo(pkgName, bundleName?, path?)` - 设置包所在的 bundle 和路径
99
+ - `setUIConfig(config)` - 设置 UI 导出数据
100
+
101
+ **窗口操作**:
102
+ - `showWindow<T>(windowClass, userdata?)` - 异步打开窗口(自动加载资源)
103
+ - 参数是窗口类(构造函数),非窗口名称
104
+ - `closeWindow<T>(windowClass)` - 关闭窗口(通过窗口类)
105
+ - `closeWindowByName(name)` - 关闭窗口(通过窗口名称)
106
+ - `getWindow<T>(name)` - 获取窗口实例
107
+ - `getTopWindow<T>(isAll?)` - 获取最顶层窗口
108
+ - `hasWindow(name)` - 检查窗口是否存在
109
+
110
+ **其他方法**:
111
+ - `getGroupNames()` - 获取所有窗口组名称
112
+ - `getWindowGroup(name)` - 获取指定窗口组
113
+ - `closeAllWindow(ignores?)` - 关闭所有窗口
114
+ - `releaseUnusedRes()` - 释放不再使用的 UI 资源
115
+
116
+ ### 窗口类型 (WindowType)
117
+
118
+ 定义窗口显示时对其他窗口的处理方式:
119
+
120
+ - `Normal` - 不做任何处理
121
+ - `CloseAll` - 关闭所有窗口
122
+ - `CloseOne` - 关闭上一个窗口
123
+ - `HideAll` - 隐藏所有窗口
124
+ - `HideOne` - 隐藏上一个窗口
125
+
126
+ ### 适配类型 (AdapterType)
127
+
128
+ 窗口适配类型:
129
+
130
+ - `Full` - 全屏适配(默认)
131
+ - `Bang` - 空出刘海区域
132
+ - `Fixed` - 固定尺寸,不适配
133
+
134
+ ### 典型使用流程
135
+
136
+ 1. **FairyGUI 设计** - 使用 FairyGUI 编辑器设计界面
137
+ 2. **定义窗口类** - 继承 Window 并使用 @uiclass 装饰器注册
138
+ 3. **配置属性和事件** - 使用 @uiprop 和 @uiclick 标记
139
+ 4. **配置加载回调** - 调用 `WindowManager.setPackageCallbacks()`(可选)
140
+ 5. **打开窗口** - 调用 `WindowManager.showWindow(MyWindow, userdata)`
141
+ 6. **管理生命周期** - 实现窗口生命周期方法
142
+
143
+ 详细 API 请查看 `bit-ui.d.ts` 类型定义文件和 FairyGUI 官方文档。
144
+
145
+ ## 依赖
146
+
147
+ - [FairyGUI](https://www.fairygui.com/) - UI 编辑器和运行时库
148
+
149
+ ## 许可证
150
+
151
+ MIT License
152
+
153
+ ## 作者
154
+
155
+ **bit老宫** (gongxh)
156
+ **邮箱**: gong.xinhai@163.com
157
+
158
+ ## 源码仓库
159
+
160
+ - [GitHub](https://github.com/Gongxh0901/bit-framework)
161
+ - [npm](https://www.npmjs.com/package/@gongxh/bit-ui)
package/dist/bit-ui.cjs CHANGED
@@ -4,6 +4,45 @@ var fairyguiCc = require('fairygui-cc');
4
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
@@ -491,30 +530,33 @@ class ResLoader {
491
530
  * @internal
492
531
  */
493
532
  static loadUIPackages(packages, windowName) {
494
- // 先找出来所有需要加载的包名
495
- let list = packages.filter(pkg => this.getRef(pkg) <= 0);
496
- if (list.length <= 0) {
497
- // 增加引用计数
498
- packages.forEach(pkg => this.addRef(pkg));
499
- return Promise.resolve();
500
- }
501
- // 一定有需要加载的资源
502
- this.addWaitRef();
503
- // 获取包对应的bundle名
504
- let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
505
- // 加载bundle
506
- return this.loadBundles(bundleNames, windowName).then(() => {
507
- // 顺序加载每个UI包
508
- return this.loadUIPackagesSequentially(list, windowName);
509
- }).then(() => {
510
- // 所有包加载成功后,减少等待窗引用计数
511
- this.decWaitRef();
512
- // 增加包资源的引用计数
513
- packages.forEach(pkg => this.addRef(pkg));
514
- }).catch((err) => {
515
- // 减少等待窗的引用计数
516
- this.decWaitRef();
517
- throw err;
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
+ }
518
560
  });
519
561
  }
520
562
  /**
@@ -524,35 +566,29 @@ class ResLoader {
524
566
  * @internal
525
567
  */
526
568
  static loadBundles(bundleNames, windowName) {
527
- let unloadedBundleNames = bundleNames.filter(bundleName => bundleName !== "resources" && !cc.assetManager.getBundle(bundleName));
528
- if (unloadedBundleNames.length <= 0) {
529
- return Promise.resolve();
530
- }
531
- // 递归方式实现顺序加载
532
- const loadNext = (index) => {
533
- if (index >= unloadedBundleNames.length) {
534
- return Promise.resolve();
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;
535
573
  }
536
- const bundleName = unloadedBundleNames[index];
537
- return new Promise((resolve, reject) => {
538
- cc.assetManager.loadBundle(bundleName, (err, bundle) => {
539
- if (err) {
540
- // 调用失败回调
541
- if (this._onLoadFail) {
542
- this._onLoadFail(windowName, 1, bundleName);
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}】加载失败`));
543
584
  }
544
- reject(new Error(`bundle【${bundleName}】加载失败`));
545
- }
546
- else {
547
- resolve(null);
548
- }
585
+ else {
586
+ resolve();
587
+ }
588
+ });
549
589
  });
550
- }).then(() => {
551
- // 加载下一个
552
- return loadNext(index + 1);
553
- });
554
- };
555
- return loadNext(0);
590
+ }
591
+ });
556
592
  }
557
593
  /**
558
594
  * 顺序加载多个 UI 包
@@ -561,18 +597,12 @@ class ResLoader {
561
597
  * @internal
562
598
  */
563
599
  static loadUIPackagesSequentially(packages, windowName) {
564
- // 递归方式实现顺序加载
565
- const loadNext = (index) => {
566
- if (index >= packages.length) {
567
- return Promise.resolve();
600
+ return __awaiter(this, void 0, void 0, function* () {
601
+ // 顺序加载每个UI包
602
+ for (const pkg of packages) {
603
+ yield this.loadSingleUIPackage(pkg, windowName);
568
604
  }
569
- const pkg = packages[index];
570
- return this.loadSingleUIPackage(pkg, windowName).then(() => {
571
- // 加载下一个
572
- return loadNext(index + 1);
573
- });
574
- };
575
- return loadNext(0);
605
+ });
576
606
  }
577
607
  /**
578
608
  * 加载单个 UI 包
@@ -1331,28 +1361,30 @@ class WindowGroup {
1331
1361
  * @internal
1332
1362
  */
1333
1363
  showWindow(info, userdata) {
1334
- return new Promise((resolve, reject) => {
1364
+ return __awaiter(this, void 0, void 0, function* () {
1335
1365
  let lastTopWindow = WindowManager.getTopWindow();
1336
1366
  if (WindowManager.hasWindow(info.name)) {
1337
1367
  const window = WindowManager.getWindow(info.name);
1338
1368
  this.showAdjustment(window, userdata);
1339
1369
  if (lastTopWindow && lastTopWindow.name !== window.name) {
1340
1370
  lastTopWindow._toBottom();
1371
+ window._toTop();
1341
1372
  }
1342
- window._toTop();
1343
- resolve(window);
1373
+ return window;
1344
1374
  }
1345
1375
  else {
1346
- ResLoader.loadWindowRes(info.name).then(() => {
1376
+ try {
1377
+ yield ResLoader.loadWindowRes(info.name);
1347
1378
  const window = this.createWindow(info.pkgName, info.name);
1348
1379
  this.showAdjustment(window, userdata);
1349
1380
  if (lastTopWindow && lastTopWindow.name !== window.name) {
1350
1381
  lastTopWindow._toBottom();
1351
1382
  }
1352
- resolve(window);
1353
- }).catch((err) => {
1354
- reject(new Error(`窗口【${info.name}】打开失败: ${err.message}`));
1355
- });
1383
+ return window;
1384
+ }
1385
+ catch (err) {
1386
+ throw new Error(`窗口【${info.name}】打开失败: ${err.message}`);
1387
+ }
1356
1388
  }
1357
1389
  });
1358
1390
  }
@@ -2054,35 +2086,6 @@ class Window extends WindowBase {
2054
2086
  }
2055
2087
  }
2056
2088
 
2057
- /******************************************************************************
2058
- Copyright (c) Microsoft Corporation.
2059
-
2060
- Permission to use, copy, modify, and/or distribute this software for any
2061
- purpose with or without fee is hereby granted.
2062
-
2063
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2064
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2065
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2066
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2067
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2068
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2069
- PERFORMANCE OF THIS SOFTWARE.
2070
- ***************************************************************************** */
2071
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
2072
-
2073
-
2074
- function __decorate(decorators, target, key, desc) {
2075
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2076
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2077
- 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;
2078
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2079
- }
2080
-
2081
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2082
- var e = new Error(message);
2083
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2084
- };
2085
-
2086
2089
  /**
2087
2090
  * @Author: Gongxh
2088
2091
  * @Date: 2024-12-08
@@ -1 +1 @@
1
- "use strict";var e,t,s,i=require("fairygui-cc"),o=require("@gongxh/bit-core"),n=require("cc");exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed",function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(s||(s={}));class a{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const d=o.transitions;this.serializationTransitionsNode(e,d)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}a._config={};class r{static add(e,t,s,n,a){if(this.has(n))console.warn(`窗口【${n}】已注册,跳过,请检查是否重复注册`);else if(o.debug(`窗口注册 窗口名:${n} 包名:${s} 组名:${t}`),this._windowInfos.set(n,{ctor:e,group:t,pkgName:s,name:n}),i.UIObjectFactory.setExtension(`ui://${s}/${n}`,e),this.addWindowPkg(n,s),a.length>0)for(const e of a)this.addWindowPkg(n,e)}static addHeader(e,t,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`header注册 header名:${s} 包名:${t}`),this._headerInfos.set(s,{ctor:e,pkgName:t}),i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(e,t,s){e.prototype.onConstruct=function(){a.serializeProps(this,t,s),this.onInit&&this.onInit()},i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}r._windowInfos=new Map,r._headerInfos=new Map,r._customComponents=new Set,r._customPackageBundle=new Map,r._customPackagePath=new Map,r._windowPkgs=new Map,r._manualPackages=new Set,r._dirty=!0;class d{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=r.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=r.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)return e.forEach(e=>this.addRef(e)),Promise.resolve();this.addWaitRef();let i=s.map(e=>r.getBundleName(e));return this.loadBundles(i,t).then(()=>this.loadUIPackagesSequentially(s,t)).then(()=>{this.decWaitRef(),e.forEach(e=>this.addRef(e))}).catch(e=>{throw this.decWaitRef(),e})}static loadBundles(e,t){let s=e.filter(e=>"resources"!==e&&!n.assetManager.getBundle(e));if(s.length<=0)return Promise.resolve();const i=e=>{if(e>=s.length)return Promise.resolve();const o=s[e];return new Promise((e,s)=>{n.assetManager.loadBundle(o,(i,n)=>{i?(this._onLoadFail&&this._onLoadFail(t,1,o),s(new Error(`bundle【${o}】加载失败`))):e(null)})}).then(()=>i(e+1))};return i(0)}static loadUIPackagesSequentially(e,t){const s=i=>{if(i>=e.length)return Promise.resolve();const o=e[i];return this.loadSingleUIPackage(o,t).then(()=>s(i+1))};return s(0)}static loadSingleUIPackage(e,t){return new Promise((s,o)=>{let a=r.getBundleName(e),d="resources"===a?n.resources:n.assetManager.getBundle(a);i.UIPackage.loadPackage(d,r.getPackagePath(e),i=>{i?(t&&this._onLoadFail&&this._onLoadFail(t,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const t of e)0===this.subRef(t)&&this.autoRelease&&i.UIPackage.removePackage(t)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const t of e)this.getRef(t)<=0&&(i.UIPackage.removePackage(t),this.pkgRefs.delete(t))}}d.waitRef=0,d.pkgRefs=new Map,d.autoRelease=!0,d._showWaitWindow=null,d._hideWaitWindow=null,d._onLoadFail=null;class h{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this._alphaGraph.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),l.onScreenResize()}static addManualPackage(e){r.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&r.addBundleName(e,t),"ui"!==s&&r.addPackagePath(e,s)}static setUIConfig(e){a.setConfig(e)}static setPackageCallbacks(e){d.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[s.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const s=r.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[s.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=r.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=h.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){d.releaseUnusedRes()}}h._bgAlpha=.75,h._bgColor=new n.Color(0,0,0,0),h._alphaGraph=null,h._groups=new Map,h._groupNames=[],h._windows=new Map;class l{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const t=r.getHeader(e.name),s=i.UIPackage.createObject(t.pkgName,e.name);return s.name=e.name,a.serializeProps(s,t.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const s=r.get(e),i=r.get(t),o=h.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const d=h.getWindowGroup(s.group);return d.windowNames.indexOf(e)>d.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=h.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=h.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=h.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=h.getWindow(t),o=r.get(t),n=h.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let d=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=h.getWindow(n.windowNames[e]);t&&t.isShowing()&&(d=Math.max(d,a.getChildIndex(t)))}a.setChildIndex(s,d+1)}}l._headers=new Map,l._refCounts=new Map,l._headerWindowsMap=new Map,l._headerInfos=new Map,l._cacheHeaderTopWindow=new Map;class c{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return new Promise((s,i)=>{let o=h.getTopWindow();if(h.hasWindow(e.name)){const i=h.getWindow(e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),i._toTop(),s(i)}else d.loadWindowRes(e.name).then(()=>{const i=this.createWindow(e.pkgName,e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),s(i)}).catch(t=>{i(new Error(`窗口【${e.name}】打开失败: ${t.message}`))})})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),l.showHeader(e.name),h.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,t){let s=i.UIPackage.createObject(e,t);return s.name=t,a.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(t),h.addWindow(t,s),l.requestHeader(t,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=h.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),l.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=h.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===exports.WindowType.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=h.getWindow(t);s&&s.isShowing()&&(s._hide(),l.hideHeader(t))}break}if(e.type===exports.WindowType.HideOne){let e=this._windowNames[t-1],s=h.getWindow(e);s&&s.isShowing()&&(s._hide(),l.hideHeader(e))}else{let e=this._windowNames[t-1],s=h.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),l.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===exports.WindowType.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=h.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);l.releaseHeader(e),t._close(),h.removeWindow(e)}else if(e.type===exports.WindowType.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=h.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);l.releaseHeader(t),s._close(),h.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=h.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);l.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),h.removeWindow(e),d.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?h.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=h.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);l.releaseHeader(s),i._close(),h.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function p(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}exports._uidecorator=void 0,function(e){const t=new Map,i=new Map,o=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return o},e.uiclass=function(e,i,o,n){return function(a){const d=a;a[s.originalName]=o,t.set(d,{ctor:a,props:a[s.prop]||null,callbacks:a[s.callback]||null,controls:a[s.control]||null,transitions:a[s.transition]||null,res:{group:e,pkg:i,name:o}});let h=[];return Array.isArray(n)?h=n:"string"==typeof n&&(h=[n]),r.add(a,e,i,o,h),a}},e.uicom=function(e,t){return function(o){const n=o;return o[s.originalName]=t,i.set(n,{ctor:o,props:o[s.prop]||null,callbacks:o[s.callback]||null,controls:o[s.control]||null,transitions:o[s.transition]||null,res:{pkg:e,name:t}}),r.addComponent(o,e,t),o}},e.uiheader=function(e,t){return function(i){const n=i;return i[s.originalName]=t,o.set(n,{ctor:i,props:i[s.prop]||null,callbacks:i[s.callback]||null,controls:i[s.control]||null,transitions:i[s.transition]||null,res:{pkg:e,name:t}}),r.addHeader(i,e,t),i}},e.uiprop=function(e,t){p(e.constructor,s.prop)[t]=1},e.uicontrol=function(e,t){p(e.constructor,s.control)[t]=1},e.uitransition=function(e,t){p(e.constructor,s.transition)[t]=1},e.uiclick=function(e,t,i){p(e.constructor,s.callback)[t]=i.value}}(exports._uidecorator||(exports._uidecorator={}));const u=globalThis||window||global;u.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},u.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},u.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class w extends i.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class g{static create(e,t){const i=e[s.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const o=new g;return o.name=i,o.userdata=t,o}}class _ extends i.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i.GComponent;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=h.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this._swallowNode.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){l.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){h.closeWindowByName(this.name)}}function m(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}"function"==typeof SuppressedError&&SuppressedError;const{ccclass:f,property:W,menu:H}=n._decorator;let N=class extends n.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;o.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),i.GRoot.inst.addChild(t),h.addWindowGroup(new c(e,t,this.ignoreQuery,this.swallowTouch))}};m([W({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],N.prototype,"ignoreQuery",void 0),m([W({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],N.prototype,"swallowTouch",void 0),N=m([f("CocosWindowContainer"),H("bit/UIContainer")],N);const{ccclass:S,menu:k,property:P}=n._decorator;exports.UIModule=class extends o.Module{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&a.setConfig(this.ui_config.json),d.setAutoRelease(this.autoReleaseUIRes),h.bgAlpha=this.bgAlpha,i.GRoot.create(),o.debug("初始化 WindowContainers");const e=new i.GGraph;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),e.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.GRoot.inst.addChild(e),h.setAlphaGraph(e);for(const e of this.getComponentsInChildren(N))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){h.onScreenResize()}},m([P({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],exports.UIModule.prototype,"ui_config",void 0),m([P({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],exports.UIModule.prototype,"bgAlpha",void 0),m([P({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],exports.UIModule.prototype,"autoReleaseUIRes",void 0),exports.UIModule=m([S("UIModule"),k("bit/UIModule")],exports.UIModule),exports.Header=w,exports.HeaderInfo=g,exports.Window=class extends _{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}},exports.WindowGroup=c,exports.WindowManager=h;
1
+ "use strict";var e,t,s,i=require("fairygui-cc"),o=require("@gongxh/bit-core"),n=require("cc");function a(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function r(e,t,s,i){return new(s||(s=Promise))(function(o,n){function a(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,r)}d((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed",function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(s||(s={}));class d{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const d=o.transitions;this.serializationTransitionsNode(e,d)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}d._config={};class h{static add(e,t,s,n,a){if(this.has(n))console.warn(`窗口【${n}】已注册,跳过,请检查是否重复注册`);else if(o.debug(`窗口注册 窗口名:${n} 包名:${s} 组名:${t}`),this._windowInfos.set(n,{ctor:e,group:t,pkgName:s,name:n}),i.UIObjectFactory.setExtension(`ui://${s}/${n}`,e),this.addWindowPkg(n,s),a.length>0)for(const e of a)this.addWindowPkg(n,e)}static addHeader(e,t,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`header注册 header名:${s} 包名:${t}`),this._headerInfos.set(s,{ctor:e,pkgName:t}),i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(e,t,s){e.prototype.onConstruct=function(){d.serializeProps(this,t,s),this.onInit&&this.onInit()},i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}h._windowInfos=new Map,h._headerInfos=new Map,h._customComponents=new Set,h._customPackageBundle=new Map,h._customPackagePath=new Map,h._windowPkgs=new Map,h._manualPackages=new Set,h._dirty=!0;class c{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=h.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=h.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){return r(this,void 0,void 0,function*(){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)e.forEach(e=>this.addRef(e));else{this.addWaitRef();try{let i=s.map(e=>h.getBundleName(e));yield this.loadBundles(i,t),yield this.loadUIPackagesSequentially(s,t),this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),e}}})}static loadBundles(e,t){return r(this,void 0,void 0,function*(){let s=e.filter(e=>"resources"!==e&&!n.assetManager.getBundle(e));if(!(s.length<=0))for(const e of s)yield new Promise((s,i)=>{n.assetManager.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),i(new Error(`bundle【${e}】加载失败`))):s()})})})}static loadUIPackagesSequentially(e,t){return r(this,void 0,void 0,function*(){for(const s of e)yield this.loadSingleUIPackage(s,t)})}static loadSingleUIPackage(e,t){return new Promise((s,o)=>{let a=h.getBundleName(e),r="resources"===a?n.resources:n.assetManager.getBundle(a);i.UIPackage.loadPackage(r,h.getPackagePath(e),i=>{i?(t&&this._onLoadFail&&this._onLoadFail(t,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const t of e)0===this.subRef(t)&&this.autoRelease&&i.UIPackage.removePackage(t)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const t of e)this.getRef(t)<=0&&(i.UIPackage.removePackage(t),this.pkgRefs.delete(t))}}c.waitRef=0,c.pkgRefs=new Map,c.autoRelease=!0,c._showWaitWindow=null,c._hideWaitWindow=null,c._onLoadFail=null;class l{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this._alphaGraph.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),p.onScreenResize()}static addManualPackage(e){h.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&h.addBundleName(e,t),"ui"!==s&&h.addPackagePath(e,s)}static setUIConfig(e){d.setConfig(e)}static setPackageCallbacks(e){c.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[s.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const s=h.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[s.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=h.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=l.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){c.releaseUnusedRes()}}l._bgAlpha=.75,l._bgColor=new n.Color(0,0,0,0),l._alphaGraph=null,l._groups=new Map,l._groupNames=[],l._windows=new Map;class p{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const t=h.getHeader(e.name),s=i.UIPackage.createObject(t.pkgName,e.name);return s.name=e.name,d.serializeProps(s,t.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const s=h.get(e),i=h.get(t),o=l.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=l.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=l.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=l.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=l.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=l.getWindow(t),o=h.get(t),n=l.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=l.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}p._headers=new Map,p._refCounts=new Map,p._headerWindowsMap=new Map,p._headerInfos=new Map,p._cacheHeaderTopWindow=new Map;class u{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return r(this,void 0,void 0,function*(){let s=l.getTopWindow();if(l.hasWindow(e.name)){const i=l.getWindow(e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&(s._toBottom(),i._toTop()),i}try{yield c.loadWindowRes(e.name);const i=this.createWindow(e.pkgName,e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&s._toBottom(),i}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),p.showHeader(e.name),l.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,t){let s=i.UIPackage.createObject(e,t);return s.name=t,d.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(t),l.addWindow(t,s),p.requestHeader(t,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=l.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),p.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=l.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===exports.WindowType.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=l.getWindow(t);s&&s.isShowing()&&(s._hide(),p.hideHeader(t))}break}if(e.type===exports.WindowType.HideOne){let e=this._windowNames[t-1],s=l.getWindow(e);s&&s.isShowing()&&(s._hide(),p.hideHeader(e))}else{let e=this._windowNames[t-1],s=l.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),p.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===exports.WindowType.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close(),l.removeWindow(e)}else if(e.type===exports.WindowType.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=l.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);p.releaseHeader(t),s._close(),l.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),l.removeWindow(e),c.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?l.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=l.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);p.releaseHeader(s),i._close(),l.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function w(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}exports._uidecorator=void 0,function(e){const t=new Map,i=new Map,o=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return o},e.uiclass=function(e,i,o,n){return function(a){const r=a;a[s.originalName]=o,t.set(r,{ctor:a,props:a[s.prop]||null,callbacks:a[s.callback]||null,controls:a[s.control]||null,transitions:a[s.transition]||null,res:{group:e,pkg:i,name:o}});let d=[];return Array.isArray(n)?d=n:"string"==typeof n&&(d=[n]),h.add(a,e,i,o,d),a}},e.uicom=function(e,t){return function(o){const n=o;return o[s.originalName]=t,i.set(n,{ctor:o,props:o[s.prop]||null,callbacks:o[s.callback]||null,controls:o[s.control]||null,transitions:o[s.transition]||null,res:{pkg:e,name:t}}),h.addComponent(o,e,t),o}},e.uiheader=function(e,t){return function(i){const n=i;return i[s.originalName]=t,o.set(n,{ctor:i,props:i[s.prop]||null,callbacks:i[s.callback]||null,controls:i[s.control]||null,transitions:i[s.transition]||null,res:{pkg:e,name:t}}),h.addHeader(i,e,t),i}},e.uiprop=function(e,t){w(e.constructor,s.prop)[t]=1},e.uicontrol=function(e,t){w(e.constructor,s.control)[t]=1},e.uitransition=function(e,t){w(e.constructor,s.transition)[t]=1},e.uiclick=function(e,t,i){w(e.constructor,s.callback)[t]=i.value}}(exports._uidecorator||(exports._uidecorator={}));const g=globalThis||window||global;g.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},g.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},g.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class _ extends i.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class f{static create(e,t){const i=e[s.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const o=new f;return o.name=i,o.userdata=t,o}}class m extends i.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i.GComponent;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=l.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this._swallowNode.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){p.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){l.closeWindowByName(this.name)}}const{ccclass:W,property:H,menu:N}=n._decorator;let S=class extends n.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;o.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),i.GRoot.inst.addChild(t),l.addWindowGroup(new u(e,t,this.ignoreQuery,this.swallowTouch))}};a([H({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],S.prototype,"ignoreQuery",void 0),a([H({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],S.prototype,"swallowTouch",void 0),S=a([W("CocosWindowContainer"),N("bit/UIContainer")],S);const{ccclass:k,menu:P,property:y}=n._decorator;exports.UIModule=class extends o.Module{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&d.setConfig(this.ui_config.json),c.setAutoRelease(this.autoReleaseUIRes),l.bgAlpha=this.bgAlpha,i.GRoot.create(),o.debug("初始化 WindowContainers");const e=new i.GGraph;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),e.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.GRoot.inst.addChild(e),l.setAlphaGraph(e);for(const e of this.getComponentsInChildren(S))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){l.onScreenResize()}},a([y({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],exports.UIModule.prototype,"ui_config",void 0),a([y({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],exports.UIModule.prototype,"bgAlpha",void 0),a([y({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],exports.UIModule.prototype,"autoReleaseUIRes",void 0),exports.UIModule=a([k("UIModule"),P("bit/UIModule")],exports.UIModule),exports.Header=_,exports.HeaderInfo=f,exports.Window=class extends m{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}},exports.WindowGroup=u,exports.WindowManager=l;
@@ -1 +1 @@
1
- import{UIObjectFactory as e,UIPackage as t,GComponent as s,GRoot as i,GGraph as o}from"fairygui-cc";import{debug as n,Screen as a,Module as r,Adapter as h}from"@gongxh/bit-core";import{assetManager as d,resources as l,Color as c,_decorator as u,Component as w,JsonAsset as p}from"cc";var g,_,m,f;!function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(g||(g={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(_||(_={})),function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(m||(m={}));class W{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}W._config={};class H{static add(t,s,i,o,a){if(this.has(o))console.warn(`窗口【${o}】已注册,跳过,请检查是否重复注册`);else if(n(`窗口注册 窗口名:${o} 包名:${i} 组名:${s}`),this._windowInfos.set(o,{ctor:t,group:s,pkgName:i,name:o}),e.setExtension(`ui://${i}/${o}`,t),this.addWindowPkg(o,i),a.length>0)for(const e of a)this.addWindowPkg(o,e)}static addHeader(t,s,i){this.hasHeader(i)?console.warn(`header【${i}】已注册,跳过,请检查是否重复注册`):(n(`header注册 header名:${i} 包名:${s}`),this._headerInfos.set(i,{ctor:t,pkgName:s}),e.setExtension(`ui://${s}/${i}`,t))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(n(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(t,s,i){t.prototype.onConstruct=function(){W.serializeProps(this,s,i),this.onInit&&this.onInit()},e.setExtension(`ui://${s}/${i}`,t)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}H._windowInfos=new Map,H._headerInfos=new Map,H._customComponents=new Set,H._customPackageBundle=new Map,H._customPackagePath=new Map,H._windowPkgs=new Map,H._manualPackages=new Set,H._dirty=!0;class N{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=H.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=H.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)return e.forEach(e=>this.addRef(e)),Promise.resolve();this.addWaitRef();let i=s.map(e=>H.getBundleName(e));return this.loadBundles(i,t).then(()=>this.loadUIPackagesSequentially(s,t)).then(()=>{this.decWaitRef(),e.forEach(e=>this.addRef(e))}).catch(e=>{throw this.decWaitRef(),e})}static loadBundles(e,t){let s=e.filter(e=>"resources"!==e&&!d.getBundle(e));if(s.length<=0)return Promise.resolve();const i=e=>{if(e>=s.length)return Promise.resolve();const o=s[e];return new Promise((e,s)=>{d.loadBundle(o,(i,n)=>{i?(this._onLoadFail&&this._onLoadFail(t,1,o),s(new Error(`bundle【${o}】加载失败`))):e(null)})}).then(()=>i(e+1))};return i(0)}static loadUIPackagesSequentially(e,t){const s=i=>{if(i>=e.length)return Promise.resolve();const o=e[i];return this.loadSingleUIPackage(o,t).then(()=>s(i+1))};return s(0)}static loadSingleUIPackage(e,s){return new Promise((i,o)=>{let n=H.getBundleName(e),a="resources"===n?l:d.getBundle(n);t.loadPackage(a,H.getPackagePath(e),t=>{t?(s&&this._onLoadFail&&this._onLoadFail(s,2,e),o(new Error(`UI包【${e}】加载失败`))):i()})})}static unloadUIPackages(e){for(const s of e)0===this.subRef(s)&&this.autoRelease&&t.removePackage(s)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const s of e)this.getRef(s)<=0&&(t.removePackage(s),this.pkgRefs.delete(s))}}N.waitRef=0,N.pkgRefs=new Map,N.autoRelease=!0,N._showWaitWindow=null,N._hideWaitWindow=null,N._onLoadFail=null;class k{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this._alphaGraph.setSize(a.ScreenWidth,a.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),P.onScreenResize()}static addManualPackage(e){H.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&H.addBundleName(e,t),"ui"!==s&&H.addPackagePath(e,s)}static setUIConfig(e){W.setConfig(e)}static setPackageCallbacks(e){N.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const s=e[m.originalName];if(!s)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(s,t)}static showWindowByName(e,t){const s=H.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[m.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=H.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=k.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){N.releaseUnusedRes()}}k._bgAlpha=.75,k._bgColor=new c(0,0,0,0),k._alphaGraph=null,k._groups=new Map,k._groupNames=[],k._windows=new Map;class P{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const s=H.getHeader(e.name),i=t.createObject(s.pkgName,e.name);return i.name=e.name,W.serializeProps(i,s.pkgName),i._init(),i._adapted(),i}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const s=H.get(e),i=H.get(t),o=k.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=k.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=k.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=k.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=k.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=k.getWindow(t),o=H.get(t),n=k.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=k.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}P._headers=new Map,P._refCounts=new Map,P._headerWindowsMap=new Map,P._headerInfos=new Map,P._cacheHeaderTopWindow=new Map;class b{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return new Promise((s,i)=>{let o=k.getTopWindow();if(k.hasWindow(e.name)){const i=k.getWindow(e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),i._toTop(),s(i)}else N.loadWindowRes(e.name).then(()=>{const i=this.createWindow(e.pkgName,e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),s(i)}).catch(t=>{i(new Error(`窗口【${e.name}】打开失败: ${t.message}`))})})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),P.showHeader(e.name),k.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,s){let i=t.createObject(e,s);return i.name=s,W.serializeProps(i,e),i._init(this._swallowTouch),i._adapted(),this._root.addChild(i),0===this.size&&(this._root.visible=!0),this._windowNames.push(s),k.addWindow(s,i),P.requestHeader(s,i.getHeaderInfo()),i}processWindowHideStatus(e){let t=k.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),P.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=k.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===g.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=k.getWindow(t);s&&s.isShowing()&&(s._hide(),P.hideHeader(t))}break}if(e.type===g.HideOne){let e=this._windowNames[t-1],s=k.getWindow(e);s&&s.isShowing()&&(s._hide(),P.hideHeader(e))}else{let e=this._windowNames[t-1],s=k.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),P.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===g.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=k.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);P.releaseHeader(e),t._close(),k.removeWindow(e)}else if(e.type===g.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=k.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);P.releaseHeader(t),s._close(),k.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=k.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);P.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),k.removeWindow(e),N.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?k.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=k.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);P.releaseHeader(s),i._close(),k.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function C(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}!function(e){const t=new Map,s=new Map,i=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return s},e.getHeaderMaps=function(){return i},e.uiclass=function(e,s,i,o){return function(n){const a=n;n[m.originalName]=i,t.set(a,{ctor:n,props:n[m.prop]||null,callbacks:n[m.callback]||null,controls:n[m.control]||null,transitions:n[m.transition]||null,res:{group:e,pkg:s,name:i}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),H.add(n,e,s,i,r),n}},e.uicom=function(e,t){return function(i){const o=i;return i[m.originalName]=t,s.set(o,{ctor:i,props:i[m.prop]||null,callbacks:i[m.callback]||null,controls:i[m.control]||null,transitions:i[m.transition]||null,res:{pkg:e,name:t}}),H.addComponent(i,e,t),i}},e.uiheader=function(e,t){return function(s){const o=s;return s[m.originalName]=t,i.set(o,{ctor:s,props:s[m.prop]||null,callbacks:s[m.callback]||null,controls:s[m.control]||null,transitions:s[m.transition]||null,res:{pkg:e,name:t}}),H.addHeader(s,e,t),s}},e.uiprop=function(e,t){C(e.constructor,m.prop)[t]=1},e.uicontrol=function(e,t){C(e.constructor,m.control)[t]=1},e.uitransition=function(e,t){C(e.constructor,m.transition)[t]=1},e.uiclick=function(e,t,s){C(e.constructor,m.callback)[t]=s.value}}(f||(f={}));const S=globalThis||window||global;S.getKunpoRegisterWindowMaps=function(){return f.getWindowMaps()},S.getKunpoRegisterComponentMaps=function(){return f.getComponentMaps()},S.getKunpoRegisterHeaderMaps=function(){return f.getHeaderMaps()};class v extends s{constructor(){super(...arguments),this.adapterType=_.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case _.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case _.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class I{static create(e,t){const s=e[m.originalName];if(!s)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const i=new I;return i.name=s,i.userdata=t,i}}class T extends s{constructor(){super(...arguments),this.type=g.Normal,this.adapterType=_.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new s;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=k.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case _.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case _.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this._swallowNode.setSize(a.ScreenWidth,a.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){P.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){k.closeWindowByName(this.name)}}class R extends T{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}}function y(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}"function"==typeof SuppressedError&&SuppressedError;const{ccclass:$,property:A,menu:z}=u;let G=class extends w{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;n(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new s;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(a.ScreenWidth,a.ScreenHeight,!0),i.inst.addChild(t),k.addWindowGroup(new b(e,t,this.ignoreQuery,this.swallowTouch))}};y([A({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],G.prototype,"ignoreQuery",void 0),y([A({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],G.prototype,"swallowTouch",void 0),G=y([$("CocosWindowContainer"),z("bit/UIContainer")],G);const{ccclass:U,menu:M,property:B}=u;let x=class extends r{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&W.setConfig(this.ui_config.json),N.setAutoRelease(this.autoReleaseUIRes),k.bgAlpha=this.bgAlpha,i.create(),n("初始化 WindowContainers");const e=new o;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),e.setSize(a.ScreenWidth,a.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.inst.addChild(e),k.setAlphaGraph(e);for(const e of this.getComponentsInChildren(G))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){k.onScreenResize()}};y([B({type:p,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],x.prototype,"ui_config",void 0),y([B({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],x.prototype,"bgAlpha",void 0),y([B({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],x.prototype,"autoReleaseUIRes",void 0),x=y([U("UIModule"),M("bit/UIModule")],x);export{_ as AdapterType,v as Header,I as HeaderInfo,x as UIModule,R as Window,b as WindowGroup,k as WindowManager,g as WindowType,f as _uidecorator};
1
+ import{UIObjectFactory as e,UIPackage as t,GComponent as i,GRoot as s,GGraph as o}from"fairygui-cc";import{debug as n,Screen as a,Module as r,Adapter as h}from"@gongxh/bit-core";import{resources as d,assetManager as l,Color as c,_decorator as u,Component as w,JsonAsset as p}from"cc";function g(e,t,i,s){var o,n=arguments.length,a=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,s);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,i,a):o(t,i))||a);return n>3&&a&&Object.defineProperty(t,i,a),a}function _(e,t,i,s){return new(i||(i=Promise))(function(o,n){function a(e){try{h(s.next(e))}catch(e){n(e)}}function r(e){try{h(s.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,r)}h((s=s.apply(e,t||[])).next())})}var f,m,W,H;"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(f||(f={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(m||(m={})),function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(W||(W={}));class N{static setConfig(e){this._config=e}static serializeProps(e,t,i){if(!this._config)return;const s=this._config[t];if(!s)return;const o=s[i=i||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})属性(${i})赋值,请检查节点配置是否正确`);break}e[i]=n==e?null:n}}static serializationCallbacksNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})的(${i})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[i],e)}}static serializationControlsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置控制器,请检查配置是否正确`);break}e[i]=n,s+=2}}static serializationTransitionsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置动画,请检查配置是否正确`);break}e[i]=n,s+=2}}}N._config={};class k{static add(t,i,s,o,a){if(this.has(o))console.warn(`窗口【${o}】已注册,跳过,请检查是否重复注册`);else if(n(`窗口注册 窗口名:${o} 包名:${s} 组名:${i}`),this._windowInfos.set(o,{ctor:t,group:i,pkgName:s,name:o}),e.setExtension(`ui://${s}/${o}`,t),this.addWindowPkg(o,s),a.length>0)for(const e of a)this.addWindowPkg(o,e)}static addHeader(t,i,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(n(`header注册 header名:${s} 包名:${i}`),this._headerInfos.set(s,{ctor:t,pkgName:i}),e.setExtension(`ui://${i}/${s}`,t))}static addComponent(e,t,i){const s=`${t}/${i}`;this._customComponents.has(s)?console.debug(`自定义组件【${i}】已注册,跳过,请检查是否重复注册`):(n(`自定义组件注册 组件名:${i} 包名:${t}`),this._customComponents.add(s),this.registerComponent(e,t,i))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(t,i,s){t.prototype.onConstruct=function(){N.serializeProps(this,i,s),this.onInit&&this.onInit()},e.setExtension(`ui://${i}/${s}`,t)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const i=e[t];this._manualPackages.has(i)&&e.splice(t,1)}}}}k._windowInfos=new Map,k._headerInfos=new Map,k._customComponents=new Set,k._customPackageBundle=new Map,k._customPackagePath=new Map,k._windowPkgs=new Map,k._manualPackages=new Set,k._dirty=!0;class P{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=k.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=k.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){return _(this,void 0,void 0,function*(){let i=e.filter(e=>this.getRef(e)<=0);if(i.length<=0)e.forEach(e=>this.addRef(e));else{this.addWaitRef();try{let s=i.map(e=>k.getBundleName(e));yield this.loadBundles(s,t),yield this.loadUIPackagesSequentially(i,t),this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),e}}})}static loadBundles(e,t){return _(this,void 0,void 0,function*(){let i=e.filter(e=>"resources"!==e&&!l.getBundle(e));if(!(i.length<=0))for(const e of i)yield new Promise((i,s)=>{l.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),s(new Error(`bundle【${e}】加载失败`))):i()})})})}static loadUIPackagesSequentially(e,t){return _(this,void 0,void 0,function*(){for(const i of e)yield this.loadSingleUIPackage(i,t)})}static loadSingleUIPackage(e,i){return new Promise((s,o)=>{let n=k.getBundleName(e),a="resources"===n?d:l.getBundle(n);t.loadPackage(a,k.getPackagePath(e),t=>{t?(i&&this._onLoadFail&&this._onLoadFail(i,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const i of e)0===this.subRef(i)&&this.autoRelease&&t.removePackage(i)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const i of e)this.getRef(i)<=0&&(t.removePackage(i),this.pkgRefs.delete(i))}}P.waitRef=0,P.pkgRefs=new Map,P.autoRelease=!0,P._showWaitWindow=null,P._hideWaitWindow=null,P._onLoadFail=null;class v{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this._alphaGraph.setSize(a.ScreenWidth,a.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),b.onScreenResize()}static addManualPackage(e){k.addManualPackage(e)}static setPackageInfo(e,t="resources",i="ui"){"resources"!==t&&k.addBundleName(e,t),"ui"!==i&&k.addPackagePath(e,i)}static setUIConfig(e){N.setConfig(e)}static setPackageCallbacks(e){P.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[W.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const i=k.get(e);return this.getWindowGroup(i.group).showWindow(i,t)}static closeWindow(e){const t=e[W.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=k.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let i=this.getTopWindow();i&&!i.isTop()&&i._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let i=t.length-1;i>=0;i--){const s=this.getWindowGroup(t[i]);if((!s.isIgnore||e)&&0!==s.size)return s.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const i=this._groups.get(this._groupNames[t]);if(0!==i.size){for(let t=i.windowNames.length-1;t>=0;t--){const s=i.windowNames[t],o=v.getWindow(s);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,i=t.getChildIndex(e);let s=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),s=t.numChildren-1):s=t.getChildIndex(this._alphaGraph);let o=s>=i?i:i-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){P.releaseUnusedRes()}}v._bgAlpha=.75,v._bgColor=new c(0,0,0,0),v._alphaGraph=null,v._groups=new Map,v._groupNames=[],v._windows=new Map;class b{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const i=t.name;if(!this._headers.has(i)){const e=this.createHeader(t);this._headers.set(i,e),this._refCounts.set(i,0),this._headerWindowsMap.set(i,new Set)}this._refCounts.set(i,this._refCounts.get(i)+1),this._headerWindowsMap.get(i).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&i._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);i._show(this.getHeaderUserData(e))}else i.isShowing()&&i._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const s=this.getHeader(t);if(0===i)s._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,i);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),s._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),s.isShowing()&&s._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const i=this.getHeaderName(e),s=null==t?void 0:t.name;if(i!==s)i&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(s)===e){this.getHeader(s)._show(t.userdata)}}}static createHeader(e){const i=k.getHeader(e.name),s=t.createObject(i.pkgName,e.name);return s.name=e.name,N.serializeProps(s,i.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,i){const s=this._cacheHeaderTopWindow.get(e);if(i){if(!s||this.isWindowAbove(t,s))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(s===t){const i=this.findTopWindowForHeader(e,t);if(i)this._cacheHeaderTopWindow.set(e,i),this.adjustHeaderPosition(e,i);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const i=k.get(e),s=k.get(t),o=v.getGroupNames(),n=o.indexOf(i.group),a=o.indexOf(s.group);if(n!==a)return n>a;const r=v.getWindowGroup(i.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const i=this._headerWindowsMap.get(e);if(!i||0===i.size)return null;const s=v.getGroupNames();for(let e=s.length-1;e>=0;e--){const o=v.getWindowGroup(s[e]);for(let e=o.windowNames.length-1;e>=0;e--){const s=o.windowNames[e];if(s===t)continue;if(!i.has(s))continue;const n=v.getWindow(s);if(n&&n.isShowing())return s}}return null}static adjustHeaderPosition(e,t){const i=this._headers.get(e),s=v.getWindow(t),o=k.get(t),n=v.getWindowGroup(o.group),a=n.root;i.parent!==a&&(i.removeFromParent(),a.addChild(i));let r=a.getChildIndex(s);for(let e=n.windowNames.length-1;e>=0;e--){const t=v.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(i,r+1)}}b._headers=new Map,b._refCounts=new Map,b._headerWindowsMap=new Map,b._headerInfos=new Map,b._cacheHeaderTopWindow=new Map;class C{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,i,s){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=i,this._swallowTouch=s,this._windowNames=[]}showWindow(e,t){return _(this,void 0,void 0,function*(){let i=v.getTopWindow();if(v.hasWindow(e.name)){const s=v.getWindow(e.name);return this.showAdjustment(s,t),i&&i.name!==s.name&&(i._toBottom(),s._toTop()),s}try{yield P.loadWindowRes(e.name);const s=this.createWindow(e.pkgName,e.name);return this.showAdjustment(s,t),i&&i.name!==s.name&&i._toBottom(),s}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),b.showHeader(e.name),v.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,i){let s=t.createObject(e,i);return s.name=i,N.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(i),v.addWindow(i,s),b.requestHeader(i,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=v.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),b.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=v.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===f.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const i=v.getWindow(t);i&&i.isShowing()&&(i._hide(),b.hideHeader(t))}break}if(e.type===f.HideOne){let e=this._windowNames[t-1],i=v.getWindow(e);i&&i.isShowing()&&(i._hide(),b.hideHeader(e))}else{let e=this._windowNames[t-1],i=v.getWindow(e);i&&!i.isShowing()&&(i._showFromHide(),b.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===f.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=v.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);b.releaseHeader(e),t._close(),v.removeWindow(e)}else if(e.type===f.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],i=v.getWindow(t);if(!i)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);b.releaseHeader(t),i._close(),v.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=v.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);b.releaseHeader(e),t._close();let i=this._windowNames.lastIndexOf(e);i<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(i,1),v.removeWindow(e),P.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?v.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let i=this._windowNames[t];if(e.some(e=>e.name===i))continue;const s=v.getWindow(i);if(!s)return void console.error(`[BUG] 窗口【${i}】不存在,数据结构已损坏`);b.releaseHeader(i),s._close(),v.removeWindow(i),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function S(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}!function(e){const t=new Map,i=new Map,s=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return s},e.uiclass=function(e,i,s,o){return function(n){const a=n;n[W.originalName]=s,t.set(a,{ctor:n,props:n[W.prop]||null,callbacks:n[W.callback]||null,controls:n[W.control]||null,transitions:n[W.transition]||null,res:{group:e,pkg:i,name:s}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),k.add(n,e,i,s,r),n}},e.uicom=function(e,t){return function(s){const o=s;return s[W.originalName]=t,i.set(o,{ctor:s,props:s[W.prop]||null,callbacks:s[W.callback]||null,controls:s[W.control]||null,transitions:s[W.transition]||null,res:{pkg:e,name:t}}),k.addComponent(s,e,t),s}},e.uiheader=function(e,t){return function(i){const o=i;return i[W.originalName]=t,s.set(o,{ctor:i,props:i[W.prop]||null,callbacks:i[W.callback]||null,controls:i[W.control]||null,transitions:i[W.transition]||null,res:{pkg:e,name:t}}),k.addHeader(i,e,t),i}},e.uiprop=function(e,t){S(e.constructor,W.prop)[t]=1},e.uicontrol=function(e,t){S(e.constructor,W.control)[t]=1},e.uitransition=function(e,t){S(e.constructor,W.transition)[t]=1},e.uiclick=function(e,t,i){S(e.constructor,W.callback)[t]=i.value}}(H||(H={}));const y=globalThis||window||global;y.getKunpoRegisterWindowMaps=function(){return H.getWindowMaps()},y.getKunpoRegisterComponentMaps=function(){return H.getComponentMaps()},y.getKunpoRegisterHeaderMaps=function(){return H.getHeaderMaps()};class I extends i{constructor(){super(...arguments),this.adapterType=m.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class T{static create(e,t){const i=e[W.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const s=new T;return s.name=i,s.userdata=t,s}}class R extends i{constructor(){super(...arguments),this.type=f.Normal,this.adapterType=m.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=v.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this._swallowNode.setSize(a.ScreenWidth,a.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){b.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){v.closeWindowByName(this.name)}}class $ extends R{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}}const{ccclass:A,property:z,menu:G}=u;let U=class extends w{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;n(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(a.ScreenWidth,a.ScreenHeight,!0),s.inst.addChild(t),v.addWindowGroup(new C(e,t,this.ignoreQuery,this.swallowTouch))}};g([z({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],U.prototype,"ignoreQuery",void 0),g([z({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],U.prototype,"swallowTouch",void 0),U=g([A("CocosWindowContainer"),G("bit/UIContainer")],U);const{ccclass:M,menu:B,property:x}=u;let F=class extends r{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&N.setConfig(this.ui_config.json),P.setAutoRelease(this.autoReleaseUIRes),v.bgAlpha=this.bgAlpha,s.create(),n("初始化 WindowContainers");const e=new o;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),e.setSize(a.ScreenWidth,a.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,s.inst.addChild(e),v.setAlphaGraph(e);for(const e of this.getComponentsInChildren(U))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){v.onScreenResize()}};g([x({type:p,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],F.prototype,"ui_config",void 0),g([x({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],F.prototype,"bgAlpha",void 0),g([x({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],F.prototype,"autoReleaseUIRes",void 0),F=g([M("UIModule"),B("bit/UIModule")],F);export{m as AdapterType,I as Header,T as HeaderInfo,F as UIModule,$ as Window,C as WindowGroup,v as WindowManager,f as WindowType,H as _uidecorator};
package/dist/bit-ui.mjs CHANGED
@@ -1,6 +1,45 @@
1
1
  import { UIObjectFactory, UIPackage, GComponent, GRoot, GGraph } from 'fairygui-cc';
2
2
  import { debug, Screen, Module, Adapter } from '@gongxh/bit-core';
3
- import { assetManager, resources, Color, _decorator, Component, JsonAsset } from 'cc';
3
+ import { resources, assetManager, Color, _decorator, Component, JsonAsset } from 'cc';
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
+
21
+
22
+ function __decorate(decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ 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;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ }
28
+
29
+ function __awaiter(thisArg, _arguments, P, generator) {
30
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
+ return new (P || (P = Promise))(function (resolve, reject) {
32
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ }
38
+
39
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
40
+ var e = new Error(message);
41
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
+ };
4
43
 
5
44
  /**
6
45
  * @Author: Gongxh
@@ -489,30 +528,33 @@ class ResLoader {
489
528
  * @internal
490
529
  */
491
530
  static loadUIPackages(packages, windowName) {
492
- // 先找出来所有需要加载的包名
493
- let list = packages.filter(pkg => this.getRef(pkg) <= 0);
494
- if (list.length <= 0) {
495
- // 增加引用计数
496
- packages.forEach(pkg => this.addRef(pkg));
497
- return Promise.resolve();
498
- }
499
- // 一定有需要加载的资源
500
- this.addWaitRef();
501
- // 获取包对应的bundle名
502
- let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
503
- // 加载bundle
504
- return this.loadBundles(bundleNames, windowName).then(() => {
505
- // 顺序加载每个UI包
506
- return this.loadUIPackagesSequentially(list, windowName);
507
- }).then(() => {
508
- // 所有包加载成功后,减少等待窗引用计数
509
- this.decWaitRef();
510
- // 增加包资源的引用计数
511
- packages.forEach(pkg => this.addRef(pkg));
512
- }).catch((err) => {
513
- // 减少等待窗的引用计数
514
- this.decWaitRef();
515
- throw err;
531
+ return __awaiter(this, void 0, void 0, function* () {
532
+ // 先找出来所有需要加载的包名
533
+ let list = packages.filter(pkg => this.getRef(pkg) <= 0);
534
+ if (list.length <= 0) {
535
+ // 增加引用计数
536
+ packages.forEach(pkg => this.addRef(pkg));
537
+ return;
538
+ }
539
+ // 一定有需要加载的资源
540
+ this.addWaitRef();
541
+ try {
542
+ // 获取包对应的bundle
543
+ let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
544
+ // 加载bundle
545
+ yield this.loadBundles(bundleNames, windowName);
546
+ // 顺序加载每个UI包
547
+ yield this.loadUIPackagesSequentially(list, windowName);
548
+ // 所有包加载成功后,减少等待窗引用计数
549
+ this.decWaitRef();
550
+ // 增加包资源的引用计数
551
+ packages.forEach(pkg => this.addRef(pkg));
552
+ }
553
+ catch (err) {
554
+ // 减少等待窗的引用计数
555
+ this.decWaitRef();
556
+ throw err;
557
+ }
516
558
  });
517
559
  }
518
560
  /**
@@ -522,35 +564,29 @@ class ResLoader {
522
564
  * @internal
523
565
  */
524
566
  static loadBundles(bundleNames, windowName) {
525
- let unloadedBundleNames = bundleNames.filter(bundleName => bundleName !== "resources" && !assetManager.getBundle(bundleName));
526
- if (unloadedBundleNames.length <= 0) {
527
- return Promise.resolve();
528
- }
529
- // 递归方式实现顺序加载
530
- const loadNext = (index) => {
531
- if (index >= unloadedBundleNames.length) {
532
- return Promise.resolve();
567
+ return __awaiter(this, void 0, void 0, function* () {
568
+ let unloadedBundleNames = bundleNames.filter(bundleName => bundleName !== "resources" && !assetManager.getBundle(bundleName));
569
+ if (unloadedBundleNames.length <= 0) {
570
+ return;
533
571
  }
534
- const bundleName = unloadedBundleNames[index];
535
- return new Promise((resolve, reject) => {
536
- assetManager.loadBundle(bundleName, (err, bundle) => {
537
- if (err) {
538
- // 调用失败回调
539
- if (this._onLoadFail) {
540
- this._onLoadFail(windowName, 1, bundleName);
572
+ // 顺序加载每个bundle
573
+ for (const bundleName of unloadedBundleNames) {
574
+ yield new Promise((resolve, reject) => {
575
+ assetManager.loadBundle(bundleName, (err, bundle) => {
576
+ if (err) {
577
+ // 调用失败回调
578
+ if (this._onLoadFail) {
579
+ this._onLoadFail(windowName, 1, bundleName);
580
+ }
581
+ reject(new Error(`bundle【${bundleName}】加载失败`));
541
582
  }
542
- reject(new Error(`bundle【${bundleName}】加载失败`));
543
- }
544
- else {
545
- resolve(null);
546
- }
583
+ else {
584
+ resolve();
585
+ }
586
+ });
547
587
  });
548
- }).then(() => {
549
- // 加载下一个
550
- return loadNext(index + 1);
551
- });
552
- };
553
- return loadNext(0);
588
+ }
589
+ });
554
590
  }
555
591
  /**
556
592
  * 顺序加载多个 UI 包
@@ -559,18 +595,12 @@ class ResLoader {
559
595
  * @internal
560
596
  */
561
597
  static loadUIPackagesSequentially(packages, windowName) {
562
- // 递归方式实现顺序加载
563
- const loadNext = (index) => {
564
- if (index >= packages.length) {
565
- return Promise.resolve();
598
+ return __awaiter(this, void 0, void 0, function* () {
599
+ // 顺序加载每个UI包
600
+ for (const pkg of packages) {
601
+ yield this.loadSingleUIPackage(pkg, windowName);
566
602
  }
567
- const pkg = packages[index];
568
- return this.loadSingleUIPackage(pkg, windowName).then(() => {
569
- // 加载下一个
570
- return loadNext(index + 1);
571
- });
572
- };
573
- return loadNext(0);
603
+ });
574
604
  }
575
605
  /**
576
606
  * 加载单个 UI 包
@@ -1329,28 +1359,30 @@ class WindowGroup {
1329
1359
  * @internal
1330
1360
  */
1331
1361
  showWindow(info, userdata) {
1332
- return new Promise((resolve, reject) => {
1362
+ return __awaiter(this, void 0, void 0, function* () {
1333
1363
  let lastTopWindow = WindowManager.getTopWindow();
1334
1364
  if (WindowManager.hasWindow(info.name)) {
1335
1365
  const window = WindowManager.getWindow(info.name);
1336
1366
  this.showAdjustment(window, userdata);
1337
1367
  if (lastTopWindow && lastTopWindow.name !== window.name) {
1338
1368
  lastTopWindow._toBottom();
1369
+ window._toTop();
1339
1370
  }
1340
- window._toTop();
1341
- resolve(window);
1371
+ return window;
1342
1372
  }
1343
1373
  else {
1344
- ResLoader.loadWindowRes(info.name).then(() => {
1374
+ try {
1375
+ yield ResLoader.loadWindowRes(info.name);
1345
1376
  const window = this.createWindow(info.pkgName, info.name);
1346
1377
  this.showAdjustment(window, userdata);
1347
1378
  if (lastTopWindow && lastTopWindow.name !== window.name) {
1348
1379
  lastTopWindow._toBottom();
1349
1380
  }
1350
- resolve(window);
1351
- }).catch((err) => {
1352
- reject(new Error(`窗口【${info.name}】打开失败: ${err.message}`));
1353
- });
1381
+ return window;
1382
+ }
1383
+ catch (err) {
1384
+ throw new Error(`窗口【${info.name}】打开失败: ${err.message}`);
1385
+ }
1354
1386
  }
1355
1387
  });
1356
1388
  }
@@ -2052,35 +2084,6 @@ class Window extends WindowBase {
2052
2084
  }
2053
2085
  }
2054
2086
 
2055
- /******************************************************************************
2056
- Copyright (c) Microsoft Corporation.
2057
-
2058
- Permission to use, copy, modify, and/or distribute this software for any
2059
- purpose with or without fee is hereby granted.
2060
-
2061
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2062
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2063
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2064
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2065
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2066
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2067
- PERFORMANCE OF THIS SOFTWARE.
2068
- ***************************************************************************** */
2069
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
2070
-
2071
-
2072
- function __decorate(decorators, target, key, desc) {
2073
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2074
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2075
- 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;
2076
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2077
- }
2078
-
2079
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2080
- var e = new Error(message);
2081
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2082
- };
2083
-
2084
2087
  /**
2085
2088
  * @Author: Gongxh
2086
2089
  * @Date: 2024-12-08
package/package.json CHANGED
@@ -1,57 +1,41 @@
1
1
  {
2
- "name": "@gongxh/bit-ui",
3
- "version": "0.0.2",
4
- "description": "基于creator3.0+的bit-ui库",
5
- "main": "./dist/bit-ui.cjs",
6
- "module": "./dist/bit-ui.mjs",
7
- "types": "./dist/bit-ui.d.ts",
8
- "exports": {
9
- ".": {
10
- "require": "./dist/bit-ui.cjs",
11
- "import": "./dist/bit-ui.mjs",
12
- "types": "./dist/bit-ui.d.ts",
13
- "default": "./dist/bit-ui.cjs"
14
- },
15
- "./min": {
16
- "require": "./dist/bit-ui.min.cjs",
17
- "import": "./dist/bit-ui.min.mjs"
18
- }
2
+ "name": "@gongxh/bit-ui",
3
+ "version": "0.0.6",
4
+ "description": "基于creator3.0+的bit-ui库",
5
+ "main": "./dist/bit-ui.cjs",
6
+ "module": "./dist/bit-ui.mjs",
7
+ "types": "./dist/bit-ui.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/bit-ui.cjs",
11
+ "import": "./dist/bit-ui.mjs",
12
+ "types": "./dist/bit-ui.d.ts",
13
+ "default": "./dist/bit-ui.cjs"
19
14
  },
20
- "scripts": {
21
- "clean": "rm -rf dist",
22
- "build": "npm run clean && rollup -c rollup.config.mjs",
23
- "copy": "cp -r dist/* ./../demo/node_modules/@gongxh/bit-ui/dist/",
24
- "build:all": "npm run clean && npm run build && npm run copy"
25
- },
26
- "files": [
27
- "dist/bit-ui.cjs",
28
- "dist/bit-ui.mjs",
29
- "dist/bit-ui.min.cjs",
30
- "dist/bit-ui.min.mjs",
31
- "dist/bit-ui.d.ts"
32
- ],
33
- "author": "gongxh",
34
- "license": "ISC",
35
- "repository": {
36
- "type": "gitlab",
37
- "url": "https://github.com/Gongxh0901/kunpolibrary"
38
- },
39
- "publishConfig": {
40
- "registry": "https://registry.npmjs.org/"
41
- },
42
- "dependencies": {
43
- "@gongxh/bit-core": "^0.0.4",
44
- "fairygui-cc": "^1.2.2"
45
- },
46
- "devDependencies": {
47
- "@cocos/creator-types": "^3.8.0",
48
- "@rollup/plugin-terser": "^0.4.4",
49
- "@rollup/plugin-typescript": "^12.1.2",
50
- "@types/lodash": "^4.17.13",
51
- "@types/node": "^22.10.2",
52
- "rollup": "^4.28.1",
53
- "rollup-plugin-dts": "^6.1.1",
54
- "ts-node": "^10.9.2",
55
- "tslib": "^2.6.2"
15
+ "./min": {
16
+ "require": "./dist/bit-ui.min.cjs",
17
+ "import": "./dist/bit-ui.min.mjs"
56
18
  }
57
- }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "author": "bit老宫",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/gongxh0901/bit-framework.git",
28
+ "directory": "bit-ui"
29
+ },
30
+ "publishConfig": {
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "dependencies": {
34
+ "fairygui-cc": "^1.2.2",
35
+ "@gongxh/bit-core": "0.0.6"
36
+ },
37
+ "scripts": {
38
+ "clean": "rm -rf dist",
39
+ "build": "pnpm clean && rollup -c rollup.config.mjs"
40
+ }
41
+ }