ModuleUtil.addGui支持自定义窗口动画参数

This commit is contained in:
dgflash
2025-09-09 20:07:32 +08:00
parent 819ab99bbd
commit 4ad205d309
4 changed files with 9 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ export class LayerUIElement extends Component {
/** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */
private onCloseWindow: Function = null!;
/** 窗口添加 */
/** 添加界面且界面设置到父节点之前 */
add(): Promise<boolean> {
return new Promise(async (resolve, reject) => {
// 触发窗口组件上添加到父节点后的事件

View File

@@ -46,7 +46,7 @@ export abstract class CCComp extends GameComponent implements ecs.IComp {
remove(params?: UIRemove) {
const cct = ECSModel.compCtors[this.tid];
if (this.ent) {
ModuleUtil.remove(this.ent, cct, params);
ModuleUtil.removeGui(this.ent, cct, params);
}
else {
console.error(`组件 ${this.name} 移除失败,实体不存在`);

View File

@@ -58,7 +58,7 @@ export abstract class CCVMParentComp extends VMParent implements ecs.IComp {
remove(params?: UIRemove) {
const cct = ECSModel.compCtors[this.tid];
if (this.ent) {
ModuleUtil.remove(this.ent, cct, params);
ModuleUtil.removeGui(this.ent, cct, params);
}
else {
console.error(`组件 ${this.name} 移除失败,实体不存在`);

View File

@@ -20,15 +20,17 @@ export class ModuleUtil {
* @param uiArgs 界面参数
* @returns 界面节点
*/
static add<T extends CCVMParentComp | CCComp>(ent: ecs.Entity, ctor: ECSCtor<T>, uiArgs: any = null): Promise<Node | null> {
static addGui<T extends CCVMParentComp | CCComp>(ent: ecs.Entity, ctor: ECSCtor<T>, uiArgs?: any, anim?: UICallbacks): Promise<Node | null> {
return new Promise<Node | null>((resolve, reject) => {
const uic: UICallbacks = {
onAdded: (node: Node, params: any) => {
const comp = node.getComponent(ctor) as ecs.Comp;
ent.add(comp);
if (anim && anim.onAdded) anim.onAdded(node, params);
resolve(node);
},
onLoadFailure: () => {
if (anim && anim.onLoadFailure) anim.onLoadFailure();
resolve(null);
}
};
@@ -51,7 +53,7 @@ export class ModuleUtil {
* @param isDestroy 是否释放界面缓存(默认为释放界面缓存)
* @param onRemoved 窗口关闭完成事件
*/
static remove(ent: ecs.Entity, ctor: CompType<ecs.IComp>, params?: UIRemove) {
static removeGui(ent: ecs.Entity, ctor: CompType<ecs.IComp>, params?: UIRemove) {
if (params == null) {
params = { isDestroy: true };
}
@@ -98,6 +100,7 @@ export class ModuleUtil {
node.parent = parent;
}
//#region deprecated
/**
* 添加界面组件
* @param ent 模块实体
@@ -168,4 +171,5 @@ export class ModuleUtil {
oops.gui.remove(uiId, isDestroy);
}
}
//#endregion
}