refactor: UI 系统及其在渲染端的初始化

This commit is contained in:
AncTe committed 2026-10-08 19:02:04 +08:00
1 parent c466949ce0
commit acfb9c117d
7 files changed
+105 -20

No files matched your search

+12 -10
View File
@@ -30,16 +30,18 @@ export const UIContainer = defineComponent<IUIContainerProps>(props => {
);
}
return elements.concat(
data.stack.map((v, i) => (
<v.ui.component
{...v.vBind}
key={v.key}
controller={data}
instance={v}
hidden={v.hidden.value}
zIndex={i * 5}
></v.ui.component>
))
data.stack.map((v, i) => {
const pb = data.createPropsBase(v);
return (
<v.ui.component
{...v.vBind}
{...pb}
key={v.key}
hidden={v.hidden.value}
zIndex={i * 5}
></v.ui.component>
);
})
);
};
}, containerConfig);
+19 -1
View File
@@ -6,7 +6,8 @@ import {
UIComponent,
IUIDefaultPropsBase,
IUICustomStrategy,
UIRawProps
UIRawProps,
UIPropsBaseCreator
} from './types';
import { UIInstance } from './instance';
import {
@@ -20,6 +21,7 @@ import {
VNode
} from 'vue';
import { UIContainer } from './container';
import { logger } from '@motajs/common';
export class UIController<
PB extends IUIDefaultPropsBase<any>
@@ -34,6 +36,8 @@ export class UIController<
/** 当前的自定义 UI 控制策略 */
private strategy: IUICustomStrategy<PB>;
/** UI 基础参数的构造函数 */
private creator: UIPropsBaseCreator<PB> | null = null;
/** 是否维持背景 UI */
private keepBack: boolean = false;
@@ -52,6 +56,20 @@ export class UIController<
this.strategy = new UILastOnlyStrategy();
}
setPropsBaseCreator(creator: UIPropsBaseCreator<PB> | null): void {
this.creator = creator;
}
createPropsBase(instance: IUIInstance<UIComponent, PB>): PB {
if (!this.creator) {
logger.error(74);
// @ts-expect-error 不存在构造函数时的
return { instance, controller: this } as PB;
} else {
return this.creator(instance, this);
}
}
setBackground<C extends UIComponent>(
background: IGameUI<C> | null,
vBind: UIRawProps<C, PB>
+20
View File
@@ -112,6 +112,14 @@ export type UIRawProps<
PB extends IUIDefaultPropsBase<any>
> = Omit<Props<C>, keyof PB>;
/**
* UI 基础 Props 参数的构造函数
*/
export type UIPropsBaseCreator<PB extends IUIDefaultPropsBase<any>> = (
instance: IUIInstance<UIComponent, PB>,
controller: IUIController<PB>
) => PB;
export interface IUIController<PB extends IUIDefaultPropsBase<any>> {
/** 当前的 UI 栈 */
readonly stack: IUIInstance[];
@@ -125,6 +133,18 @@ export interface IUIController<PB extends IUIDefaultPropsBase<any>> {
/** 当前是否显示背景的响应式对象,用于容器响应式判断是否需要显示背景 */
readonly showBack: Ref<boolean>;
/**
* 设置基础参数的构造函数
* @param creator UI 基础 Props 参数的构造函数
*/
setPropsBaseCreator(creator: UIPropsBaseCreator<PB> | null): void;
/**
* 创建对应 UI 实例对象的基础参数
* @param instance UI 实例对象
*/
createPropsBase(instance: IUIInstance<UIComponent, PB>): PB;
/**
* 设置控制器的背景 UI
* @param background 背景 UI