添加Gui参数配置错误提示

This commit is contained in:
dgflash
2025-09-09 18:29:43 +08:00
parent f592ebb684
commit 819ab99bbd
7 changed files with 56 additions and 28 deletions

View File

@@ -7,25 +7,37 @@ export namespace gui {
/** 注册界面组件 */
export function register(key: string, config: UIConfig) {
return function (ctor: any) {
ctor.oopsGuiKey = key;
setConfig(key, config);
//@ts-ignore
ctor[gui.internal.GUI_KEY] = key;
internal.setConfig(key, config);
};
}
/** 获取界面组件配置 */
export function getConfig(key: string) {
return configs[key];
}
/** 框架内部使用方法 */
export namespace internal {
/** 界面唯一标记变量名 */
export const GUI_KEY = "OOPS_GUI_KEY";
/** 获取界面组件配置 */
export function getConfig(key: string) {
return configs[key];
}
/** 获取界面组件配置 */
export function setConfig(key: string, config: UIConfig) {
configs[key] = config;
}
/** 获取界面组件配置 */
export function setConfig(key: string, config: UIConfig) {
let c = getConfig(key);
if (c == null) {
configs[key] = config;
}
else {
console.error(`界面${key}重复注册`);
}
}
/** 初始化界面组件配置 */
export function initConfigs(uicm: UIConfigMap) {
for (const key in uicm) {
configs[key] = uicm[key];
/** 初始化界面组件配置 */
export function initConfigs(uicm: UIConfigMap) {
for (const key in uicm) {
configs[key] = uicm[key];
}
}
}
}

View File

@@ -1,7 +1,7 @@
import { UIConfig } from "./UIConfig";
/** 界面编号 */
export type Uiid = number | string | UIConfig;
export type Uiid = number | string | UIConfig | Function;
/** 界面配置集合 */
export type UIConfigMap = { [key: string]: UIConfig }

View File

@@ -135,11 +135,9 @@ export class LayerManager {
/**
* 初始化所有UI的配置对象
* @param configs 配置对象
* @deprecated 后续将界面配置通过界面视图组件注册使用gui.register注册每一个界面
*/
init(configs: UIConfigMap): void {
// this.configs = configs;
gui.initConfigs(configs);
gui.internal.initConfigs(configs);
}
/**
@@ -177,19 +175,26 @@ export class LayerManager {
let key = "";
let config: UIConfig = null!;
// 确定 key 和 config
// 界面配置
if (typeof uiid === 'object') {
if (uiid.bundle == null) uiid.bundle = resLoader.defaultBundleName;
key = uiid.bundle + "_" + uiid.prefab;
config = gui.getConfig(key);
config = gui.internal.getConfig(key);
if (config == null) {
config = uiid;
gui.setConfig(key, uiid);
gui.internal.setConfig(key, uiid);
}
}
// 界面对象 - 配合gui.register使用
else if (uiid instanceof Function) {
//@ts-ignore
key = uiid[gui.internal.GUI_KEY];
config = gui.internal.getConfig(key);
}
// 界面唯一标记
else {
key = uiid.toString();
config = gui.getConfig(key);
config = gui.internal.getConfig(key);
if (config == null) {
console.error(`打开编号为【${uiid}】的界面失败,配置信息不存在`);
}
@@ -276,7 +281,7 @@ export class LayerManager {
if (comp && comp.params) {
// 释放显示的界面
if (node.parent) {
let uiid = gui.getConfig(comp.params.uiid);
let uiid = gui.internal.getConfig(comp.params.uiid);
this.remove(uiid, isDestroy);
}
// 释放缓存中的界面

View File

@@ -153,7 +153,7 @@ export namespace ecs {
ECSModel.compAddOrRemove.set(ctor.tid, []);
}
else {
throw new Error(`重复注册组件: ${name}.`);
throw new Error(`ECS 组件重复注册: ${name}.`);
}
}
}

View File

@@ -45,7 +45,12 @@ export abstract class CCComp extends GameComponent implements ecs.IComp {
/** 从父节点移除自己 */
remove(params?: UIRemove) {
const cct = ECSModel.compCtors[this.tid];
ModuleUtil.remove(this.ent, cct, params);
if (this.ent) {
ModuleUtil.remove(this.ent, cct, params);
}
else {
console.error(`组件 ${this.name} 移除失败,实体不存在`);
}
}
abstract reset(): void;

View File

@@ -57,7 +57,12 @@ export abstract class CCVMParentComp extends VMParent implements ecs.IComp {
/** 从父节点移除自己 */
remove(params?: UIRemove) {
const cct = ECSModel.compCtors[this.tid];
ModuleUtil.remove(this.ent, cct, params);
if (this.ent) {
ModuleUtil.remove(this.ent, cct, params);
}
else {
console.error(`组件 ${this.name} 移除失败,实体不存在`);
}
}
abstract reset(): void;

View File

@@ -1,6 +1,7 @@
import { Node, __private } from "cc";
import { oops } from "../../core/Oops";
import { resLoader } from "../../core/common/loader/ResLoader";
import { gui } from "../../core/gui/Gui";
import { Uiid } from "../../core/gui/layer/LayerEnum";
import { LayerUIElement, UICallbacks, UIRemove } from "../../core/gui/layer/LayerUIElement";
import { ViewUtil } from "../../core/utils/ViewUtil";
@@ -33,7 +34,7 @@ export class ModuleUtil {
};
//@ts-ignore
const key = ctor.oopsGuiKey;
const key = ctor[gui.internal.GUI_KEY];
if (key) {
oops.gui.open(key, uiArgs, uic);
}
@@ -59,7 +60,7 @@ export class ModuleUtil {
}
//@ts-ignore
const key = ctor.oopsGuiKey;
const key = ctor[gui.internal.GUI_KEY];
if (key) {
const node = oops.gui.get(key);
if (node == null) {