Files
template/docs/render-guide/basics/ui-template.md
T

1.7 KiB

UI 通用模板

写 UI 时从这段模板开始。

import { defineComponent } from 'vue';
import { GameUI, SetupComponentOptions } from '@motajs/system';
import { DefaultProps } from '@motajs/render-vue';
import { IGameUIPropsBase } from '@user/client-base';
import { FULL_LOC } from '@/client';

// 这里填写自定义的 UI 参数
interface MyPanelProps extends IGameUIPropsBase, DefaultProps {}

const myPanelProps = {
    props: ['controller', 'instance', 'state']
} satisfies SetupComponentOptions<MyPanelProps>;

const MyPanel = defineComponent<MyPanelProps>(props => {
    return () => (
        <container loc={FULL_LOC}>{/* 在这里编写自己的 UI 内容 */}</container>
    );
}, myPanelProps);

export const MyPanelUI = new GameUI('my-panel', MyPanel);

前置知识

无——只要掌握基础 TS/JS,并按本指南的阅读路径阅读即可。

模板用法

  1. 复制到 src/client/ui/ 下新建的 .tsx 文件(例如 my-panel.tsx)。
  2. 把 MyPanel、myPanelProps、MyPanelUI 换成自己的名字。
  3. 在 <container> 里写 UI 内容。
  4. 在 src/client/ui/index.ts 中导出 MyPanelUI。

后续阅读