kunpolibrary/src/ui/UIDecorator.ts

224 lines
6.9 KiB
TypeScript
Raw Normal View History

2025-02-20 11:27:28 +08:00
/**
* @Author: Gongxh
* @Date: 2024-12-11
* @Description: UI
*/
import { ObjectHelper } from "../tool/helper/ObjectHelper";
export namespace _uidecorator {
2025-03-07 16:02:00 +08:00
/** @internal */
2025-02-20 11:27:28 +08:00
const UIPropMeta = "__uipropmeta__"
2025-03-07 16:02:00 +08:00
/** @internal */
2025-02-20 11:27:28 +08:00
const UICBMeta = "__uicbmeta__"
2025-05-09 19:18:29 +08:00
/** @internal */
const UIControlMeta = "__uicontrolmeta__"
/** @internal */
const UITransitionMeta = "__uitransitionmeta__"
2025-03-07 16:02:00 +08:00
2025-02-20 11:27:28 +08:00
interface IUIInfoBase {
/** 构造函数 */
ctor: any;
/** 属性 */
props: Record<string, 1>;
/** 方法 */
callbacks: Record<string, Function>;
2025-05-09 19:18:29 +08:00
/** 控制器 */
controls: Record<string, 1>;
/** 动画 */
transitions: Record<string, 1>;
2025-02-20 11:27:28 +08:00
}
/**
*
*/
interface UIWindowInfo extends IUIInfoBase {
/** 配置信息 */
res: {
/** 窗口组名称 */
group: string;
/** fgui包名 */
pkg: string;
/** 窗口名 */
name: string;
/** 窗口bundle名 */
bundle: string;
2025-02-20 11:27:28 +08:00
};
}
2025-03-07 16:02:00 +08:00
/** 用来存储窗口注册信息 @internal */
2025-02-20 11:27:28 +08:00
const uiclassMap: Map<any, UIWindowInfo> = new Map();
/** 获取窗口注册信息 */
export function getWindowMaps(): Map<any, UIWindowInfo> {
return uiclassMap;
}
/**
*
* @param {string} groupName
* @param {string} pkgName fgui包名
* @param {string} name (fgui中的组件名一一对应)
*/
export function uiclass(groupName: string, pkgName: string, name: string, bundle?: string): Function {
2025-02-20 11:27:28 +08:00
/** target 类的构造函数 */
return function (ctor: any): void {
// debug(`uiclass >${JSON.stringify(res)}<`);
// debug(`uiclass prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
uiclassMap.set(ctor, {
ctor: ctor,
props: ctor[UIPropMeta] || null,
callbacks: ctor[UICBMeta] || null,
2025-05-09 19:18:29 +08:00
controls: ctor[UIControlMeta] || null,
transitions: ctor[UITransitionMeta] || null,
2025-02-20 11:27:28 +08:00
res: {
group: groupName,
pkg: pkgName,
name: name,
bundle: bundle || "",
2025-02-20 11:27:28 +08:00
},
});
};
}
/**
*
*/
interface IUIComInfo extends IUIInfoBase {
/** 配置信息 */
res: {
/** fgui包名 */
pkg: string;
/** 组件名 */
name: string;
};
}
2025-03-07 16:02:00 +08:00
/** 用来存储组件注册信息 @internal */
2025-02-20 11:27:28 +08:00
let uicomponentMap: Map<string, IUIComInfo> = new Map();
/** 获取组件注册信息 */
export function getComponentMaps(): Map<any, IUIComInfo> {
return uicomponentMap;
}
/**
* UI组件装饰器
* @param {string} pkg
* @param {string} name
*/
export function uicom(pkg: string, name: string): Function {
return function (ctor: any): void {
// log(`pkg:【${pkg}】 uicom prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
uicomponentMap.set(ctor, {
ctor: ctor,
props: ctor[UIPropMeta] || null,
callbacks: ctor[UICBMeta] || null,
2025-05-09 19:18:29 +08:00
controls: ctor[UIControlMeta] || null,
transitions: ctor[UITransitionMeta] || null,
2025-02-20 11:27:28 +08:00
res: {
pkg: pkg,
name: name,
}
});
};
}
/** header属性注册数据结构 */
2025-02-20 11:27:28 +08:00
interface IUIHeaderInfo extends IUIInfoBase {
/** 配置信息 */
res: {
/** fgui包名 */
pkg: string;
/** 组件名 */
name: string;
/** headerbundle名 */
bundle: string;
2025-02-20 11:27:28 +08:00
};
}
2025-03-07 16:02:00 +08:00
/** 用来存储组件注册信息 @internal */
2025-02-20 11:27:28 +08:00
let uiheaderMap: Map<string, IUIHeaderInfo> = new Map();
/** 获取header注册信息 */
export function getHeaderMaps(): Map<any, IUIHeaderInfo> {
return uiheaderMap;
}
/**
* UI header装饰器
* @param {string} pkg
* @param {string} name
*/
export function uiheader(pkg: string, name: string, bundle?: string): Function {
2025-02-20 11:27:28 +08:00
return function (ctor: any): void {
// log(`pkg:【${pkg}】 uiheader prop >${JSON.stringify(ctor[UIPropMeta] || {})}<`);
uiheaderMap.set(ctor, {
ctor: ctor,
props: ctor[UIPropMeta] || null,
callbacks: ctor[UICBMeta] || null,
2025-05-09 19:18:29 +08:00
controls: ctor[UIControlMeta] || null,
transitions: ctor[UITransitionMeta] || null,
2025-02-20 11:27:28 +08:00
res: {
pkg: pkg,
name: name,
bundle: bundle || "",
2025-02-20 11:27:28 +08:00
}
});
};
}
/**
* UI属性装饰器
* @param {Object} target
* @param {string} name
*
* example: @uiprop node: GObject
*/
export function uiprop(target: Object, name: string): any {
// debug("属性装饰器:", target.constructor, name);
ObjectHelper.getObjectProp(target.constructor, UIPropMeta)[name] = 1;
}
2025-05-09 19:18:29 +08:00
/**
* UI控制器装饰器
* @param {Object} target
* @param {string} name
*
* example: @uicontrol node: GObject
*/
export function uicontrol(target: Object, name: string): any {
// debug("属性装饰器:", target.constructor, name);
ObjectHelper.getObjectProp(target.constructor, UIControlMeta)[name] = 1;
}
/**
* UI动画装饰器
* @param {Object} target
* @param {string} name
*
* example: @uitransition node: GObject
*/
export function uitransition(target: Object, name: string): any {
// debug("属性装饰器:", target.constructor, name);
ObjectHelper.getObjectProp(target.constructor, UITransitionMeta)[name] = 1;
}
2025-02-20 11:27:28 +08:00
/**
* ()
* @param {Object} target
* @param {string} name
*/
export function uiclick(target: Object, name: string, descriptor: PropertyDescriptor): void {
// debug("方法装饰器:", target.constructor, name, descriptor);
ObjectHelper.getObjectProp(target.constructor, UICBMeta)[name] = descriptor.value;
}
}
let _global = globalThis || window || global;
(_global as any)["getKunpoRegisterWindowMaps"] = function () {
return _uidecorator.getWindowMaps() as any;
};
(_global as any)["getKunpoRegisterComponentMaps"] = function () {
return _uidecorator.getComponentMaps() as any;
};
(_global as any)["getKunpoRegisterHeaderMaps"] = function () {
return _uidecorator.getHeaderMaps() as any;
};