From 1194e5e701e5adf89d3d651f97be3463900e9660 Mon Sep 17 00:00:00 2001 From: zhandouxiaojiji Date: Wed, 20 Jan 2021 21:37:59 +0800 Subject: [PATCH] add Tree describe v0.1.8 --- README.md | 1 + common/BehaviorTreeModel.ts | 1 + common/Utils.ts | 1 - render-process/Editor/TreePanel.tsx | 73 ++++++++++++++++++++++++++--- render-process/Editor/index.tsx | 24 ++++++++-- 5 files changed, 90 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ec3b72b..dba7f94 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ npm run dist # 编译exe可执行文件 + 面板拖拽新建节点 + 变量自动补全 + 设置面板 ++ 禁止动画选项 ## About 目前编辑器还处于非常简陋的阶段,有问题可以联系作者(QQ1013299930),本项目将长期维护,望前端大佬们多提点~ \ No newline at end of file diff --git a/common/BehaviorTreeModel.ts b/common/BehaviorTreeModel.ts index 026067b..56186cd 100644 --- a/common/BehaviorTreeModel.ts +++ b/common/BehaviorTreeModel.ts @@ -35,6 +35,7 @@ export interface BehaviorNodeModel { export interface BehaviorTreeModel { name: string; + desc?: string; root: BehaviorNodeModel; } diff --git a/common/Utils.ts b/common/Utils.ts index 6e81bbd..76d12e6 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -56,7 +56,6 @@ export const calcTreeNodeSize = (treeNode: GraphNodeModel) => { const updateHeight = (obj: any) => { if (Array.isArray(obj) || (obj && Object.keys(obj).length > 0)) { const { str, line } = toBreakWord(`参数:${JSON.stringify(obj)}`, 35); - console.log("line", str, line); height += 20 * line; } }; diff --git a/render-process/Editor/TreePanel.tsx b/render-process/Editor/TreePanel.tsx index 97e0d66..6120d2f 100644 --- a/render-process/Editor/TreePanel.tsx +++ b/render-process/Editor/TreePanel.tsx @@ -1,18 +1,44 @@ import React from "react"; -import { Card } from "antd"; -import { INode } from "@antv/g6/lib/interface/item"; +import { Button, Card, Form, Input } from "antd"; import { BehaviorTreeModel } from "../../common/BehaviorTreeModel"; +import { FormInstance } from "antd/lib/form"; + +const { Item } = Form; interface TreePanelProps { model?: BehaviorTreeModel; + onRenameTree: (name: string) => void; + onRemoveTree: () => void; + onChangeTreeDesc: (desc: string) => void; } -interface TreePanelState {} +interface TreePanelState { +} + +const inlineFormItemLayout = { + labelCol: { + sm: { span: 4 }, + }, + wrapperCol: { + sm: { span: 12 }, + }, +}; export default class TreePanel extends React.Component { - state: TreePanelState = {}; + name: string = ''; + desc: string = ''; + formRef = React.createRef(); - componentDidMount() {} + componentDidMount() { + const { model } = this.props; + this.name = model.name; + this.desc = model.desc; + this.formRef.current.resetFields(); + this.formRef.current.setFieldsValue({ + name: model.name, + desc: model.desc, + }) + } render() { const { model } = this.props; @@ -21,8 +47,43 @@ export default class TreePanel extends React.Component - 行为树:{model.name} +
+ + + + + + + {/* + + */} +
); } + + handleSubmit = () => { + const { model, onRenameTree, onChangeTreeDesc } = this.props; + const name = this.formRef.current.getFieldValue("name"); + const desc = this.formRef.current.getFieldValue("desc"); + if (name != this.name) { + console.log("change name", name); + this.name = name; + model.name = name; + onRenameTree(name); + } + if (desc != this.desc) { + console.log("change desc", desc); + this.desc = desc; + model.desc = desc; + onChangeTreeDesc(desc); + } + } + + handleRemoveTree = () => { + this.props.onRemoveTree(); + } } diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index 315c78a..a862d16 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -341,7 +341,7 @@ export default class Editor extends React.Component { } save() { - if(!this.unsave) { + if (!this.unsave) { return; } const { filepath } = this.props; @@ -351,7 +351,7 @@ export default class Editor extends React.Component { const treeModel = { name: path.basename(filepath).slice(0, -5), root, - desc: root.desc, + desc: this.treeModel.desc, } as BehaviorTreeModel; fs.writeFileSync( filepath, @@ -449,6 +449,13 @@ export default class Editor extends React.Component { this.useStackData(data); } + changeTreeDesc(desc: string) { + this.treeModel.desc = desc; + this.settings.setTreeDesc(this.props.filepath, desc); + this.unsave = true; + this.save(); + } + render() { const { curNodeId } = this.state; console.log("render tree", curNodeId); @@ -483,7 +490,18 @@ export default class Editor extends React.Component { }} /> ) : ( - + { + + }} + onRemoveTree={() => { + + }} + onChangeTreeDesc={(desc) => { + this.changeTreeDesc(desc); + }} + /> )}