From 427bbb551d60d466dd3014dd44c75360ba7c0957 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 19 Jun 2025 11:10:21 +0800 Subject: [PATCH] =?UTF-8?q?DelegateComponent=E6=B7=BB=E5=8A=A0onCloseWindo?= =?UTF-8?q?wBefore=E7=AA=97=E5=8F=A3=E5=85=B3=E9=97=AD=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/DelegateComponent.ts | 6 ++++++ assets/module/common/ModuleUtil.ts | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/core/gui/layer/DelegateComponent.ts b/assets/core/gui/layer/DelegateComponent.ts index 43b6c5e..bd20420 100644 --- a/assets/core/gui/layer/DelegateComponent.ts +++ b/assets/core/gui/layer/DelegateComponent.ts @@ -19,6 +19,8 @@ const EventOnRemoved: string = "onRemoved"; export class DelegateComponent extends Component { /** 视图参数 */ vp: ViewParams = null!; + /** 关闭窗口之前 */ + onCloseWindowBefore: Function = null!; /** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */ onCloseWindow: Function = null!; @@ -69,6 +71,10 @@ export class DelegateComponent extends Component { /** 窗口关闭前动画处理完后的回调方法,主要用于释放资源 */ private onBeforeRemoveNext(isDestroy?: boolean) { + if (this.onCloseWindowBefore) { + this.onCloseWindowBefore(); + this.onCloseWindowBefore = null!; + } this.removed(this.vp, isDestroy); } diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index f2b10c6..9591757 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -86,26 +86,27 @@ export class ModuleUtil { * @param ctor 界面逻辑组件 * @param uiId 界面资源编号 * @param isDestroy 是否释放界面缓存(默认为释放界面缓存) - * @param onCloseWindow 窗口动画关闭完成事件 + * @param onRemoved 窗口关闭完成事件 */ - static removeViewUi(ent: ecs.Entity, ctor: CompType, uiId: number, isDestroy: boolean = true, onCloseWindow?: Function) { + static removeViewUi(ent: ecs.Entity, ctor: CompType, uiId: number, isDestroy: boolean = true, onRemoved?: Function) { const node = oops.gui.get(uiId); if (!node) { - if (onCloseWindow) onCloseWindow(); + if (onRemoved) onRemoved(); return; } const comp = node.getComponent(DelegateComponent); if (comp) { - comp.onCloseWindow = () => { + comp.onCloseWindowBefore = () => { ent.remove(ctor, isDestroy); - if (onCloseWindow) onCloseWindow(); + if (onRemoved) onRemoved(); }; } else { ent.remove(ctor, isDestroy); - if (onCloseWindow) onCloseWindow(); + if (onRemoved) onRemoved(); } + oops.gui.remove(uiId, isDestroy); } } \ No newline at end of file