diff --git a/source/Context/Status.tsx b/source/Context/Status.tsx index 90d0ead..0e51c25 100644 --- a/source/Context/Status.tsx +++ b/source/Context/Status.tsx @@ -3,12 +3,25 @@ import { Emitter } from "@Model/Emitter"; import { Model } from "@Model/Model"; import { Archive } from "@Model/Archive"; import { AbstractRenderer } from "@Model/Renderer"; -import ClassicRenderer, { MouseMod } from "@GLRender/ClassicRenderer"; +import { ClassicRenderer, MouseMod } from "@GLRender/ClassicRenderer"; +import { Setting } from "./Setting"; +import { I18N } from "@Component/Localization/Localization"; + +function randomColor() { + return [Math.random(), Math.random(), Math.random(), 1] +} class Status extends Emitter<{ mouseModChange: MouseMod }> { + public setting: Setting = undefined as any; + + /** + * 对象命名 + */ + public objectNameIndex = 1; + /** * 渲染器 */ @@ -29,6 +42,26 @@ class Status extends Emitter<{ */ public mouseMod: MouseMod = MouseMod.Drag; + public newGroup() { + const group = this.model.addGroup(); + group.color = randomColor(); + group.displayName = I18N(this.setting.language, "Object.List.New.Group", { + id: this.objectNameIndex.toString() + }); + this.objectNameIndex ++; + return group; + } + + public newRange() { + const range = this.model.addRange(); + range.color = randomColor(); + range.displayName = I18N(this.setting.language, "Object.List.New.Range", { + id: this.objectNameIndex.toString() + }); + this.objectNameIndex ++; + return range; + } + public setMouseMod(mod: MouseMod) { this.mouseMod = mod; if (this.renderer instanceof ClassicRenderer) { diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index 5966d8e..1ec0799 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -19,6 +19,9 @@ const EN_US = { "Command.Bar.Add.Tag.Info": "Add label object", "Command.Bar.Camera.Info": "Renderer settings", "Command.Bar.Setting.Info": "Global Settings", + "Object.List.New.Group": "Group object {id}", + "Object.List.New.Range": "Range object {id}", + "Object.List.No.Data": "There are no objects in the model, click the button to create it", "Panel.Title.Notfound": "{id}", "Panel.Info.Notfound": "This panel with id {id} can not found!", "Panel.Title.Render.View": "Live preview", diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index 214f9a9..c9ef69d 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -19,6 +19,9 @@ const ZH_CN = { "Command.Bar.Add.Tag.Info": "添加标签对象", "Command.Bar.Camera.Info": "渲染器设置", "Command.Bar.Setting.Info": "全局设置", + "Object.List.New.Group": "组对象 {id}", + "Object.List.New.Range": "范围对象 {id}", + "Object.List.No.Data": "模型中没有任何对象,点击按钮以创建", "Panel.Title.Notfound": "找不到面板: {id}", "Panel.Info.Notfound": "这个编号为 {id} 的面板无法找到!", "Panel.Title.Render.View": "实时预览", diff --git a/source/Model/CtrlObject.ts b/source/Model/CtrlObject.ts index 638cf7e..47857dc 100644 --- a/source/Model/CtrlObject.ts +++ b/source/Model/CtrlObject.ts @@ -7,6 +7,11 @@ import type { ObjectID } from "./Renderer"; */ class CtrlObject extends LabelObject { + /** + * 显示名称 + */ + public displayName: string = ""; + /** * 颜色 */ diff --git a/source/Page/SimulatorWeb/SimulatorWeb.tsx b/source/Page/SimulatorWeb/SimulatorWeb.tsx index 05f4e99..72fae27 100644 --- a/source/Page/SimulatorWeb/SimulatorWeb.tsx +++ b/source/Page/SimulatorWeb/SimulatorWeb.tsx @@ -36,11 +36,12 @@ class SimulatorWeb extends Component { this.status = new Status(); this.status.renderer = new ClassicRenderer({ className: "canvas" }).onLoad(); this.status.model.bindRenderer(this.status.renderer); + this.status.setting = this.setting; // 测试代码 if (true) { - let group = this.status.model.addGroup(); - let range = this.status.model.addRange(); + let group = this.status.newGroup(); + let range = this.status.newRange(); range.color = [.1, .5, .9]; group.new(100); group.color = [.8, .1, .6]; diff --git a/source/Panel/ObjectList/ObjectList.tsx b/source/Panel/ObjectList/ObjectList.tsx index beb8365..761950d 100644 --- a/source/Panel/ObjectList/ObjectList.tsx +++ b/source/Panel/ObjectList/ObjectList.tsx @@ -1,30 +1,65 @@ import { Component, ReactNode } from "react"; import { DetailsList } from "@Component/DetailsList/DetailsList"; +import { useStatus, IMixinStatusProps } from "@Context/Status"; +import { Localization } from "@Component/Localization/Localization"; + +@useStatus +class ObjectList extends Component { + + private handelChange = () => { + this.forceUpdate(); + } + + public componentDidMount(){ + if (this.props.status) { + this.props.status.model.on("objectChange", this.handelChange); + } + } + + public componentWillUnmount(){ + if (this.props.status) { + this.props.status.model.off("objectChange", this.handelChange); + } + } + + private renderList() { + const objList = this.props.status?.model.objectPool ?? []; + + if (objList.length <= 0) { + return + } -class ObjectList extends Component { - public render(): ReactNode { return { + return { + key: object.id.toString(), + name: object.displayName, + color: object.color, + display: object.display, + update: object.update + } + }))} columns={[ { key: "name", render: (name) => {name} - }, { - key: "behaviors", - render: (behaviors) => {(behaviors as Record<"name", string>[]).map(r => r.name).join(", ")} - }, { - key: "label", - render: (label) => {(label as Record<"name", string>[]).map(r => r.name).join(", ")} + // }, { + // key: "behaviors", + // render: (behaviors) => {(behaviors as Record<"name", string>[]).map(r => r.name).join(", ")} + // }, { + // key: "label", + // render: (label) => {(label as Record<"name", string>[]).map(r => r.name).join(", ")} } ]} /> } + + public render(): ReactNode { + return this.renderList(); + } } export { ObjectList }; \ No newline at end of file