@xiacg/exia-fgui 1.0.2
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 +21 -0
- package/README.md +173 -0
- package/dist/exia-fgui.cjs +2245 -0
- package/dist/exia-fgui.d.ts +430 -0
- package/dist/exia-fgui.min.cjs +1 -0
- package/dist/exia-fgui.min.mjs +1 -0
- package/dist/exia-fgui.mjs +2239 -0
- package/package.json +42 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { GComponent } from 'fairygui-cc';
|
|
2
|
+
import { JsonAsset } from 'cc';
|
|
3
|
+
import { Module } from '@xiacg/exia-core';
|
|
4
|
+
|
|
5
|
+
/** 窗口显示时,对其他窗口的隐藏处理类型 */
|
|
6
|
+
declare enum WindowType {
|
|
7
|
+
/** 不做任何处理 */
|
|
8
|
+
Normal = 0,
|
|
9
|
+
/** 关闭所有 */
|
|
10
|
+
CloseAll = 1,
|
|
11
|
+
/** 关闭上一个 */
|
|
12
|
+
CloseOne = 2,
|
|
13
|
+
/** 隐藏所有 */
|
|
14
|
+
HideAll = 4,
|
|
15
|
+
/** 隐藏上一个 */
|
|
16
|
+
HideOne = 8
|
|
17
|
+
}
|
|
18
|
+
/** 窗口适配类型,默认全屏 */
|
|
19
|
+
declare enum AdapterType {
|
|
20
|
+
/** 全屏适配 */
|
|
21
|
+
Full = 0,
|
|
22
|
+
/** 空出刘海 */
|
|
23
|
+
Bang = 1,
|
|
24
|
+
/** 固定的 不适配 */
|
|
25
|
+
Fixed = 2
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 窗口属性基类
|
|
29
|
+
*/
|
|
30
|
+
interface IDecoratorInfo {
|
|
31
|
+
/** 构造函数 */
|
|
32
|
+
ctor: any;
|
|
33
|
+
/** 属性 */
|
|
34
|
+
props: Record<string, 1>;
|
|
35
|
+
/** 方法 */
|
|
36
|
+
callbacks: Record<string, Function>;
|
|
37
|
+
/** 控制器 */
|
|
38
|
+
controls: Record<string, 1>;
|
|
39
|
+
/** 动画 */
|
|
40
|
+
transitions: Record<string, 1>;
|
|
41
|
+
res: {
|
|
42
|
+
/** fgui包名 */
|
|
43
|
+
pkg: string;
|
|
44
|
+
/** 组件名 */
|
|
45
|
+
name: string;
|
|
46
|
+
/** 窗口组名称 可选(只有窗口才会设置) */
|
|
47
|
+
group?: string;
|
|
48
|
+
/** 内联的包名 当前界面需要引用其他包中的资源时使用 (只有窗口才会设置) */
|
|
49
|
+
inlinePkgs?: string[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @Description: 窗口顶边资源栏
|
|
55
|
+
*/
|
|
56
|
+
interface IHeader<T = any> {
|
|
57
|
+
/** 资源栏名称 */
|
|
58
|
+
name: string;
|
|
59
|
+
/** 窗口适配类型 */
|
|
60
|
+
adapterType: AdapterType;
|
|
61
|
+
/**
|
|
62
|
+
* 是否显示中
|
|
63
|
+
*/
|
|
64
|
+
isShowing(): boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare abstract class Header<T = any> extends GComponent implements IHeader<T> {
|
|
68
|
+
/** 窗口适配类型 */
|
|
69
|
+
adapterType: AdapterType;
|
|
70
|
+
protected abstract onInit(): void;
|
|
71
|
+
protected abstract onShow(userdata?: T): void;
|
|
72
|
+
protected onAdapted(): void;
|
|
73
|
+
protected onClose(): void;
|
|
74
|
+
protected onHide(): void;
|
|
75
|
+
protected onShowFromHide(): void;
|
|
76
|
+
/**
|
|
77
|
+
* 是否显示中
|
|
78
|
+
*/
|
|
79
|
+
isShowing(): boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @Description: 窗口顶部资源栏信息
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 从 Header 类型中提取 UserData 类型
|
|
88
|
+
*/
|
|
89
|
+
type ExtractHeaderUserData<T> = T extends Header<infer U> ? U : any;
|
|
90
|
+
/**
|
|
91
|
+
* 从 Header 构造函数中提取 Header 实例类型
|
|
92
|
+
*/
|
|
93
|
+
type ExtractHeaderInstance<T> = T extends new () => infer R ? R : never;
|
|
94
|
+
declare class HeaderInfo<T> {
|
|
95
|
+
/** header名字 */
|
|
96
|
+
name: string;
|
|
97
|
+
/**
|
|
98
|
+
* 创建 HeaderInfo (类型安全)
|
|
99
|
+
* @param ctor Header类构造函数
|
|
100
|
+
* @param userdata 自定义数据
|
|
101
|
+
* @returns {HeaderInfo}
|
|
102
|
+
*/
|
|
103
|
+
static create<T extends new () => Header<any>>(ctor: T, userdata?: ExtractHeaderUserData<ExtractHeaderInstance<T>>): HeaderInfo<ExtractHeaderUserData<ExtractHeaderInstance<T>>>;
|
|
104
|
+
/**
|
|
105
|
+
* 通过名称创建 HeaderInfo (非类型安全)
|
|
106
|
+
* @param name header名称
|
|
107
|
+
* @param userdata 自定义数据
|
|
108
|
+
* @returns {HeaderInfo}
|
|
109
|
+
*/
|
|
110
|
+
static createByName<T = any>(name: string, userdata?: T): HeaderInfo<T>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface IWindow<TUserData = any, THeaderData = any> {
|
|
114
|
+
/** 窗口名称 */
|
|
115
|
+
name: string;
|
|
116
|
+
/** 窗口类型 */
|
|
117
|
+
type: WindowType;
|
|
118
|
+
/** 窗口适配类型 */
|
|
119
|
+
adapterType: AdapterType;
|
|
120
|
+
/** 底部遮罩的透明度 */
|
|
121
|
+
bgAlpha: number;
|
|
122
|
+
/**
|
|
123
|
+
* 窗口是否显示
|
|
124
|
+
*/
|
|
125
|
+
isShowing(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* 窗口是否在最上层
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
isTop(): boolean;
|
|
131
|
+
/** 获取资源栏数据 */
|
|
132
|
+
getHeaderInfo(): HeaderInfo<any>;
|
|
133
|
+
/** 刷新资源栏 */
|
|
134
|
+
refreshHeader(): void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @Description: 窗口组 (在同一个窗口容器的上的窗口)
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
declare class WindowGroup {
|
|
142
|
+
/**
|
|
143
|
+
* 获取窗口组的名称。
|
|
144
|
+
* @returns {string} 窗口组的名称。
|
|
145
|
+
*/
|
|
146
|
+
get name(): string;
|
|
147
|
+
/** 获取窗口组的根节点 */
|
|
148
|
+
get root(): GComponent;
|
|
149
|
+
/**
|
|
150
|
+
* 获取当前窗口组中窗口的数量。
|
|
151
|
+
* @returns 窗口数量
|
|
152
|
+
*/
|
|
153
|
+
get size(): number;
|
|
154
|
+
/** 获取窗口组中窗口的名称列表 */
|
|
155
|
+
get windowNames(): string[];
|
|
156
|
+
/**
|
|
157
|
+
* 获取是否忽略查询的状态。
|
|
158
|
+
* @returns {boolean} 如果忽略查询,则返回 true,否则返回 false。
|
|
159
|
+
*/
|
|
160
|
+
get isIgnore(): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* 处理index下层窗口的隐藏状态的私有方法。递归调用
|
|
163
|
+
* @param index - 窗口索引
|
|
164
|
+
*/
|
|
165
|
+
private processWindowHideStatus;
|
|
166
|
+
hasWindow(name: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* 获取窗口组顶部窗口实例
|
|
169
|
+
* @returns {IWindow} 顶部窗口实例
|
|
170
|
+
*/
|
|
171
|
+
getTopWindow<T extends IWindow>(): T;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @Description: 窗口基类和fgui组件对接
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
declare abstract class WindowBase<T = any, U = any> extends GComponent implements IWindow<T, U> {
|
|
179
|
+
/** 窗口类型 */
|
|
180
|
+
type: WindowType;
|
|
181
|
+
/** 窗口适配类型 */
|
|
182
|
+
adapterType: AdapterType;
|
|
183
|
+
/** 底部遮罩的透明度 */
|
|
184
|
+
bgAlpha: number;
|
|
185
|
+
isShowing(): boolean;
|
|
186
|
+
/** 是否在最上层显示 (除忽略的窗口组外, 显示到最上层时) */
|
|
187
|
+
isTop(): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* 获取窗口顶部资源栏数据 默认返回空数组
|
|
190
|
+
* @returns {HeaderInfo}
|
|
191
|
+
*/
|
|
192
|
+
abstract getHeaderInfo(): HeaderInfo<any>;
|
|
193
|
+
/**
|
|
194
|
+
* 刷新顶部资源栏
|
|
195
|
+
* 调用这个方法会重新创建 或者 刷新header
|
|
196
|
+
* 用来在同一个界面显示不同的header
|
|
197
|
+
*/
|
|
198
|
+
refreshHeader(): void;
|
|
199
|
+
/**
|
|
200
|
+
* 用于在界面中关闭自己
|
|
201
|
+
*/
|
|
202
|
+
protected removeSelf(): void;
|
|
203
|
+
protected abstract onAdapted(): void;
|
|
204
|
+
protected abstract onInit(): void;
|
|
205
|
+
protected abstract onClose(): void;
|
|
206
|
+
protected abstract onShow(userdata?: T): void;
|
|
207
|
+
protected abstract onShowFromHide(): void;
|
|
208
|
+
protected abstract onHide(): void;
|
|
209
|
+
protected abstract onToTop(): void;
|
|
210
|
+
protected abstract onToBottom(): void;
|
|
211
|
+
protected abstract onEmptyAreaClick(): void;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare abstract class Window<T = any, U = any> extends WindowBase<T, U> {
|
|
215
|
+
protected onAdapted(): void;
|
|
216
|
+
protected abstract onInit(): void;
|
|
217
|
+
protected abstract onClose(): void;
|
|
218
|
+
protected abstract onShow(userdata?: T): void;
|
|
219
|
+
protected onHide(): void;
|
|
220
|
+
protected onShowFromHide(): void;
|
|
221
|
+
protected onToTop(): void;
|
|
222
|
+
protected onToBottom(): void;
|
|
223
|
+
/**
|
|
224
|
+
* 空白区域点击事件处理函数。
|
|
225
|
+
* 当用户点击窗口的空白区域时触发此方法。
|
|
226
|
+
*/
|
|
227
|
+
protected onEmptyAreaClick(): void;
|
|
228
|
+
/**
|
|
229
|
+
* 获取窗口顶部资源栏数据 默认返回空数组
|
|
230
|
+
* @returns {HeaderInfo}
|
|
231
|
+
*/
|
|
232
|
+
getHeaderInfo(): HeaderInfo<any>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @Description: 属性辅助类
|
|
237
|
+
*/
|
|
238
|
+
interface IPropsConfig {
|
|
239
|
+
[packageName: string]: {
|
|
240
|
+
[componentName: string]: IPropsInfo;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
interface IPropsInfo {
|
|
244
|
+
props: (string | number)[];
|
|
245
|
+
callbacks: (string | number)[];
|
|
246
|
+
controls: string[];
|
|
247
|
+
transitions: string[];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @Description: 窗口管理类
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 从窗口类型中提取 UserData 类型
|
|
256
|
+
*/
|
|
257
|
+
type ExtractUserData<T> = T extends Window<infer U, any> ? U : any;
|
|
258
|
+
/**
|
|
259
|
+
* 从窗口构造函数中提取窗口实例类型
|
|
260
|
+
*/
|
|
261
|
+
type ExtractWindowInstance<T> = T extends new () => infer R ? R : never;
|
|
262
|
+
declare class WindowManager {
|
|
263
|
+
private static _bgAlpha;
|
|
264
|
+
private static _bgColor;
|
|
265
|
+
/**
|
|
266
|
+
* 添加手动管理资源加载 和 卸载的包名
|
|
267
|
+
* @param pkgName 包名
|
|
268
|
+
*/
|
|
269
|
+
static addManualPackage(pkgName: string): void;
|
|
270
|
+
/**
|
|
271
|
+
* 提供一种特殊需求 用来手动设置包所在的 bundle名 以及包在bundle中的路径
|
|
272
|
+
* @param name 窗口名称
|
|
273
|
+
* @param bundleName bundle名 默认: resources
|
|
274
|
+
* @param path 包在bundle中的路径 默认: ui目录
|
|
275
|
+
*/
|
|
276
|
+
static setPackageInfo(pkgName: string, bundleName?: string, path?: string): void;
|
|
277
|
+
/**
|
|
278
|
+
* 用于手动设置UI导出数据
|
|
279
|
+
* @param config UI导出数据
|
|
280
|
+
*/
|
|
281
|
+
static setUIConfig(config: IPropsConfig): void;
|
|
282
|
+
/**
|
|
283
|
+
* 设置UI包加载相关回调函数
|
|
284
|
+
* @param callbacks 包含加载回调的对象
|
|
285
|
+
* @param callbacks.showWaitWindow 显示加载等待窗的回调
|
|
286
|
+
* @param callbacks.hideWaitWindow 隐藏加载等待窗的回调
|
|
287
|
+
* @param callbacks.fail 打开窗口时资源加载失败的回调 code( 1:bundle加载失败 2:包加载失败 )
|
|
288
|
+
*/
|
|
289
|
+
static setPackageCallbacks(callbacks: {
|
|
290
|
+
showWaitWindow: () => void;
|
|
291
|
+
hideWaitWindow: () => void;
|
|
292
|
+
fail: (windowName: string, code: 1 | 2, message: string) => void;
|
|
293
|
+
}): void;
|
|
294
|
+
/**
|
|
295
|
+
* 异步打开一个窗口 (如果UI包的资源未加载, 会自动加载 可以配合 WindowManager.setPackageCallbacks一起使用)
|
|
296
|
+
* @param 窗口类
|
|
297
|
+
* @param userdata 用户数据
|
|
298
|
+
*/
|
|
299
|
+
static showWindow<T extends new () => Window<any, any>>(window: T, userdata?: ExtractUserData<ExtractWindowInstance<T>>): Promise<ExtractWindowInstance<T>>;
|
|
300
|
+
/**
|
|
301
|
+
* 关闭一个窗口
|
|
302
|
+
* @param ctor 窗口类
|
|
303
|
+
*/
|
|
304
|
+
static closeWindow<T extends new () => IWindow>(window: T): void;
|
|
305
|
+
/**
|
|
306
|
+
* 通过窗口名称关闭一个窗口
|
|
307
|
+
* @param name 窗口名称
|
|
308
|
+
*/
|
|
309
|
+
static closeWindowByName(name: string): void;
|
|
310
|
+
/**
|
|
311
|
+
* 是否存在窗口
|
|
312
|
+
* @param name 窗口名称
|
|
313
|
+
*/
|
|
314
|
+
static hasWindow(name: string): boolean;
|
|
315
|
+
/**
|
|
316
|
+
* 根据窗口名称获取窗口实例。
|
|
317
|
+
* @template T 窗口类型,必须继承自IWindow接口。
|
|
318
|
+
* @param name 窗口名称
|
|
319
|
+
* @returns 如果找到窗口,则返回对应类型的窗口实例;否则返回null。
|
|
320
|
+
*/
|
|
321
|
+
static getWindow<T extends IWindow>(name: string): T | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* 获取当前最顶层的窗口实例。
|
|
324
|
+
* 默认会忽略掉忽略查询的窗口组
|
|
325
|
+
* @returns {T | null} - 返回最顶层的窗口实例,如果没有找到则返回 null。
|
|
326
|
+
*/
|
|
327
|
+
static getTopWindow<T extends IWindow, U>(isAll?: boolean): T | null;
|
|
328
|
+
/**
|
|
329
|
+
* 获取所有窗口组的名称列表(按层级顺序)
|
|
330
|
+
* @returns 窗口组的名称列表
|
|
331
|
+
*/
|
|
332
|
+
static getGroupNames(): string[];
|
|
333
|
+
/**
|
|
334
|
+
* 根据给定的组名获取窗口组。如果组不存在,则抛出错误。
|
|
335
|
+
* @param name 窗口组名称
|
|
336
|
+
* @returns 返回找到的窗口组。
|
|
337
|
+
*/
|
|
338
|
+
static getWindowGroup(name: string): WindowGroup;
|
|
339
|
+
/**
|
|
340
|
+
* 关闭所有窗口
|
|
341
|
+
* @param ignores 不关闭的窗口
|
|
342
|
+
*/
|
|
343
|
+
static closeAllWindow(ignores?: IWindow[]): void;
|
|
344
|
+
/**
|
|
345
|
+
* 释放不再使用中的自动加载的UI资源
|
|
346
|
+
* 针对在 UIModule 中设置了不自动释放资源的场景
|
|
347
|
+
*/
|
|
348
|
+
static releaseUnusedRes(): void;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @Description: UI 装饰器
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
declare namespace _uidecorator {
|
|
356
|
+
/** 获取窗口注册信息 */
|
|
357
|
+
function getWindowMaps(): Map<any, IDecoratorInfo>;
|
|
358
|
+
/** 获取组件注册信息 */
|
|
359
|
+
function getComponentMaps(): Map<any, IDecoratorInfo>;
|
|
360
|
+
/** 获取header注册信息 */
|
|
361
|
+
function getHeaderMaps(): Map<any, IDecoratorInfo>;
|
|
362
|
+
/**
|
|
363
|
+
* 窗口装饰器
|
|
364
|
+
* @param {string} groupName 窗口组名称
|
|
365
|
+
* @param {string} pkgName fgui包名
|
|
366
|
+
* @param {string} name 窗口名 (与fgui中的组件名一一对应)
|
|
367
|
+
* @param {string[] | string} inlinePkgs 内联的包名 当前界面需要引用其他包中的资源时使用 引用多个包用数组 引用单个包用字符串
|
|
368
|
+
*
|
|
369
|
+
* @example @uiclass("窗口组", "UI包名", "MyWindow", ["包名1", "包名2"])
|
|
370
|
+
* @example @uiclass("窗口组", "UI包名", "MyWindow", "包名1")
|
|
371
|
+
*/
|
|
372
|
+
function uiclass(groupName: string, pkgName: string, name: string, inlinePkgs?: string[] | string): Function;
|
|
373
|
+
/**
|
|
374
|
+
* UI组件装饰器
|
|
375
|
+
* @param {string} pkg 包名
|
|
376
|
+
* @param {string} name 组件名
|
|
377
|
+
*/
|
|
378
|
+
function uicom(pkg: string, name: string): Function;
|
|
379
|
+
/**
|
|
380
|
+
* UI header装饰器
|
|
381
|
+
* @param {string} pkg 包名
|
|
382
|
+
* @param {string} name 组件名
|
|
383
|
+
*/
|
|
384
|
+
function uiheader(pkg: string, name: string): Function;
|
|
385
|
+
/**
|
|
386
|
+
* UI属性装饰器
|
|
387
|
+
* @param {Object} target 实例成员的类的原型
|
|
388
|
+
* @param {string} name 属性名
|
|
389
|
+
*
|
|
390
|
+
* example: @uiprop node: GObject
|
|
391
|
+
*/
|
|
392
|
+
function uiprop(target: Object, name: string): any;
|
|
393
|
+
/**
|
|
394
|
+
* UI控制器装饰器
|
|
395
|
+
* @param {Object} target 实例成员的类的原型
|
|
396
|
+
* @param {string} name 属性名
|
|
397
|
+
*
|
|
398
|
+
* example: @uicontrol node: GObject
|
|
399
|
+
*/
|
|
400
|
+
function uicontrol(target: Object, name: string): any;
|
|
401
|
+
/**
|
|
402
|
+
* UI动画装饰器
|
|
403
|
+
* @param {Object} target 实例成员的类的原型
|
|
404
|
+
* @param {string} name 属性名
|
|
405
|
+
*
|
|
406
|
+
* example: @uitransition node: GObject
|
|
407
|
+
*/
|
|
408
|
+
function uitransition(target: Object, name: string): any;
|
|
409
|
+
/**
|
|
410
|
+
* 方法装饰器 (给点击事件用)
|
|
411
|
+
* @param {Object} target 实例成员的类的原型
|
|
412
|
+
* @param {string} name 方法名
|
|
413
|
+
*/
|
|
414
|
+
function uiclick(target: Object, name: string, descriptor: PropertyDescriptor): void;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @Description: cocos UI模块
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
declare class UIModule extends Module {
|
|
422
|
+
ui_config: JsonAsset;
|
|
423
|
+
bgAlpha: number;
|
|
424
|
+
autoReleaseUIRes: boolean;
|
|
425
|
+
/** 模块名称 */
|
|
426
|
+
moduleName: string;
|
|
427
|
+
onInit(): void;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export { AdapterType, Header, HeaderInfo, UIModule, Window, WindowGroup, WindowManager, WindowType, _uidecorator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t,s,i=require("fairygui-cc"),o=require("@xiacg/exia-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()};const o=e.prototype.dispose;e.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},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;this.waitRef=Math.max(0,this.waitRef-1),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*(){const s=[];for(const t of e){const e=this.loadingPromises.get(t);e&&s.push(e)}s.length>0&&(yield Promise.all(s));let o=e.filter(e=>this.getRef(e)<=0);if(o.length<=0)return void e.forEach(e=>this.addRef(e));this.addWaitRef();const n=[],a=(()=>r(this,void 0,void 0,function*(){try{let s=o.map(e=>h.getBundleName(e));yield this.loadBundles(s,t);for(const e of o)yield this.loadSingleUIPackage(e,t),n.push(e);this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),n.forEach(e=>{i.UIPackage.removePackage(e)}),e}finally{o.forEach(e=>this.loadingPromises.delete(e))}}))();o.forEach(e=>this.loadingPromises.set(e,a)),yield a})}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 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.loadingPromises=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&&o.bgAlpha>0){e=o;break}}if(e)break}}if(e&&e.parent){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)||0)+1);const i=this._headerWindowsMap.get(s);i&&i.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)-1,i=this._headerWindowsMap.get(t);i&&i.delete(e),this._headerInfos.delete(e);const o=this.getHeader(t);if(0===s)o._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const i=this.findTopWindowForHeader(t,e);i?(this._cacheHeaderTopWindow.set(t,i),this.adjustHeaderPosition(t,i),o._show(this.getHeaderUserData(i))):(this._cacheHeaderTopWindow.delete(t),o.isShowing()&&o._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!0;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<2)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)try{p.releaseHeader(t),s._close(),l.removeWindow(t)}catch(e){console.error(`关闭窗口【${t}】时发生异常:`,e)}else console.error(`[BUG] 窗口【${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}static createByName(e,t){const s=new f;return s.name=e,s.userdata=t,s}}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 k=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:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],k.prototype,"ignoreQuery",void 0),a([H({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],k.prototype,"swallowTouch",void 0),k=a([W("CocosWindowContainer"),N("exia/UIContainer")],k);const{ccclass:S,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(k))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){l.onScreenResize()}},a([y({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器导出的配置文件"})],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([S("UIModule"),P("exia/UIIModule")],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;
|
|
@@ -0,0 +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"@xiacg/exia-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,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 _(e,t,s,i){return new(s||(s=Promise))(function(o,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function r(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,r)}h((i=i.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,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}}}N._config={};class k{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(){N.serializeProps(this,s,i),this.onInit&&this.onInit()};const o=t.prototype.dispose;t.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},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)}}}}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;this.waitRef=Math.max(0,this.waitRef-1),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,s){return _(this,void 0,void 0,function*(){const i=[];for(const t of e){const e=this.loadingPromises.get(t);e&&i.push(e)}i.length>0&&(yield Promise.all(i));let o=e.filter(e=>this.getRef(e)<=0);if(o.length<=0)return void e.forEach(e=>this.addRef(e));this.addWaitRef();const n=[],a=(()=>_(this,void 0,void 0,function*(){try{let t=o.map(e=>k.getBundleName(e));yield this.loadBundles(t,s);for(const e of o)yield this.loadSingleUIPackage(e,s),n.push(e);this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),n.forEach(e=>{t.removePackage(e)}),e}finally{o.forEach(e=>this.loadingPromises.delete(e))}}))();o.forEach(e=>this.loadingPromises.set(e,a)),yield a})}static loadBundles(e,t){return _(this,void 0,void 0,function*(){let s=e.filter(e=>"resources"!==e&&!l.getBundle(e));if(!(s.length<=0))for(const e of s)yield new Promise((s,i)=>{l.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),i(new Error(`bundle【${e}】加载失败`))):s()})})})}static loadSingleUIPackage(e,s){return new Promise((i,o)=>{let n=k.getBundleName(e),a="resources"===n?d:l.getBundle(n);t.loadPackage(a,k.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))}}P.waitRef=0,P.pkgRefs=new Map,P.loadingPromises=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()}),C.onScreenResize()}static addManualPackage(e){k.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&k.addBundleName(e,t),"ui"!==s&&k.addPackagePath(e,s)}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 s=e[W.originalName];if(!s)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(s,t)}static showWindowByName(e,t){const s=k.get(e);return this.getWindowGroup(s.group).showWindow(s,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 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=v.getWindow(i);if(o&&o.bgAlpha>0){e=o;break}}if(e)break}}if(e&&e.parent){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(){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 C{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)||0)+1);const i=this._headerWindowsMap.get(s);i&&i.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)-1,i=this._headerWindowsMap.get(t);i&&i.delete(e),this._headerInfos.delete(e);const o=this.getHeader(t);if(0===s)o._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const i=this.findTopWindowForHeader(t,e);i?(this._cacheHeaderTopWindow.set(t,i),this.adjustHeaderPosition(t,i),o._show(this.getHeaderUserData(i))):(this._cacheHeaderTopWindow.delete(t),o.isShowing()&&o._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=k.getHeader(e.name),i=t.createObject(s.pkgName,e.name);return i.name=e.name,N.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!0;const s=k.get(e),i=k.get(t),o=v.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=v.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=v.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=v.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=v.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=v.getWindow(t),o=k.get(t),n=v.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=v.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}C._headers=new Map,C._refCounts=new Map,C._headerWindowsMap=new Map,C._headerInfos=new Map,C._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 _(this,void 0,void 0,function*(){let s=v.getTopWindow();if(v.hasWindow(e.name)){const i=v.getWindow(e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&(s._toBottom(),i._toTop()),i}try{yield P.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),C.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,s){let i=t.createObject(e,s);return i.name=s,N.serializeProps(i,e),i._init(this._swallowTouch),i._adapted(),this._root.addChild(i),0===this.size&&(this._root.visible=!0),this._windowNames.push(s),v.addWindow(s,i),C.requestHeader(s,i.getHeaderInfo()),i}processWindowHideStatus(e){let t=v.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),C.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 s=v.getWindow(t);s&&s.isShowing()&&(s._hide(),C.hideHeader(t))}break}if(e.type===f.HideOne){let e=this._windowNames[t-1],s=v.getWindow(e);s&&s.isShowing()&&(s._hide(),C.hideHeader(e))}else{let e=this._windowNames[t-1],s=v.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),C.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===f.CloseOne){if(this.size<2)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}】不存在,数据结构已损坏`);C.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],s=v.getWindow(t);if(s)try{C.releaseHeader(t),s._close(),v.removeWindow(t)}catch(e){console.error(`关闭窗口【${t}】时发生异常:`,e)}else console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=v.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);C.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,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 s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=v.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);C.releaseHeader(s),i._close(),v.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function y(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[W.originalName]=i,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:s,name:i}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),k.add(n,e,s,i,r),n}},e.uicom=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.addComponent(i,e,t),i}},e.uiheader=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.addHeader(s,e,t),s}},e.uiprop=function(e,t){y(e.constructor,W.prop)[t]=1},e.uicontrol=function(e,t){y(e.constructor,W.control)[t]=1},e.uitransition=function(e,t){y(e.constructor,W.transition)[t]=1},e.uiclick=function(e,t,s){y(e.constructor,W.callback)[t]=s.value}}(H||(H={}));const S=globalThis||window||global;S.getKunpoRegisterWindowMaps=function(){return H.getWindowMaps()},S.getKunpoRegisterComponentMaps=function(){return H.getComponentMaps()},S.getKunpoRegisterHeaderMaps=function(){return H.getHeaderMaps()};class I extends s{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 s=e[W.originalName];if(!s)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const i=new T;return i.name=s,i.userdata=t,i}static createByName(e,t){const s=new T;return s.name=e,s.userdata=t,s}}class R extends s{constructor(){super(...arguments),this.type=f.Normal,this.adapterType=m.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=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(){C.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 M=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),v.addWindowGroup(new b(e,t,this.ignoreQuery,this.swallowTouch))}};g([z({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],M.prototype,"ignoreQuery",void 0),g([z({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],M.prototype,"swallowTouch",void 0),M=g([A("CocosWindowContainer"),G("exia/UIContainer")],M);const{ccclass:U,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,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),v.setAlphaGraph(e);for(const e of this.getComponentsInChildren(M))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){v.onScreenResize()}};g([x({type:p,displayName:"配置文件",tooltip:"编辑器导出的配置文件"})],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([U("UIModule"),B("exia/UIIModule")],F);export{m as AdapterType,I as Header,T as HeaderInfo,F as UIModule,$ as Window,b as WindowGroup,v as WindowManager,f as WindowType,H as _uidecorator};
|