diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index 87f3dde..fc5fb57 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -59,37 +59,38 @@ export class LayerUI extends Node { /** * 加载界面资源 - * @param vp 显示参数 + * @param uip 显示参数 * @param bundle 远程资源包名,如果为空就是默认本地资源包 */ - protected async load(vp: UIParams, bundle?: string) { + protected async load(uip: UIParams, bundle?: string) { // 加载界面资源超时提示 const timerId = setTimeout(this.onLoadingTimeoutGui, oops.config.game.loadingTimeoutGui); - if (vp && vp.node) { - await this.showUi(vp); + if (uip && uip.node) { + await this.showUi(uip); } else { // 优先加载配置的指定资源包中资源,如果没配置则加载默认资源包资源 bundle = bundle || oops.res.defaultBundleName; - const res = await oops.res.loadAsync(bundle, vp.config.prefab, Prefab); + const res = await oops.res.loadAsync(bundle, uip.config.prefab, Prefab); if (res) { - vp.node = instantiate(res); + uip.node = instantiate(res); + // 是否启动真机安全区域显示 - if (vp.config.safeArea) vp.node.addComponent(SafeArea); + if (uip.config.safeArea) uip.node.addComponent(SafeArea); // 窗口事件委托 - const dc = vp.node.addComponent(LayerUIElement); - dc.params = vp; + const dc = uip.node.addComponent(LayerUIElement); + dc.params = uip; //@ts-ignore dc.onCloseWindow = this.onCloseWindow.bind(this); // 显示界面 - await this.showUi(vp); + await this.showUi(uip); } else { - console.warn(`路径为【${vp.config.prefab}】的预制加载失败`); - this.failure(vp); + console.warn(`路径为【${uip.config.prefab}】的预制加载失败`); + this.failure(uip); } } diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index d97867f..7814aa1 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -3,13 +3,14 @@ import { oops } from "../../core/Oops"; import { resLoader } from "../../core/common/loader/ResLoader"; import { Uiid } from "../../core/gui/layer/LayerEnum"; import { LayerUIElement, UICallbacks } from "../../core/gui/layer/LayerUIElement"; -import { UIConfig } from "../../core/gui/layer/UIConfig"; import { ViewUtil } from "../../core/utils/ViewUtil"; import { ecs } from "../../libs/ecs/ECS"; import { CompType } from "../../libs/ecs/ECSModel"; import { CCComp } from "./CCComp"; import { CCVMParentComp } from "./CCVMParentComp"; +export type ECSCtor = __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor; + export class ModuleUtil { /** * 添加界面组件 @@ -18,11 +19,7 @@ export class ModuleUtil { * @param uiId 界面资源编号 * @param uiArgs 界面参数 */ - static addViewUi( - ent: ecs.Entity, - ctor: __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor, - uiId: number, - uiArgs: any = null) { + static addViewUi(ent: ecs.Entity, ctor: ECSCtor, uiId: Uiid, uiArgs: any = null) { const uic: UICallbacks = { onAdded: (node: Node, params: any) => { const comp = node.getComponent(ctor) as ecs.Comp; @@ -41,11 +38,7 @@ export class ModuleUtil { * @param uiArgs 界面参数 * @returns 界面节点 */ - static addViewUiAsync( - ent: ecs.Entity, - ctor: __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor, - uiId: number | UIConfig, - uiArgs: any = null): Promise { + static addViewUiAsync(ent: ecs.Entity, ctor: ECSCtor, uiId: Uiid, uiArgs: any = null): Promise { return new Promise((resolve, reject) => { const uic: UICallbacks = { onAdded: (node: Node, params: any) => { @@ -69,12 +62,7 @@ export class ModuleUtil { * @param url 显示资源地址 * @param bundleName 资源包名称 */ - static addView( - ent: ecs.Entity, - ctor: __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor, - parent: Node, - url: string, - bundleName: string = resLoader.defaultBundleName) { + static addView(ent: ecs.Entity, ctor: ECSCtor, parent: Node, url: string, bundleName: string = resLoader.defaultBundleName) { const node = ViewUtil.createPrefabNode(url, bundleName); const comp = node.getComponent(ctor)!; ent.add(comp);