add TreePanel

This commit is contained in:
zhandouxiaojiji committed 2020-10-27 21:31:22 +08:00
1 parent b4a48687d8
commit fd3b750007
3 files changed
+53 -11

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ interface NodePanelState {
} }
export default class Panel extends React.Component<NodePanelProps> { export default class NodePanel extends React.Component<NodePanelProps> {
componentDidMount() { componentDidMount() {
} }
+33
View File
@@ -0,0 +1,33 @@
import React from 'react';
import { Card } from 'antd';
import { INode } from '@antv/g6/lib/interface/item';
import { BehaviorTreeModel } from '../../common/BehaviorTreeModel';
interface TreePanelProps {
model?: BehaviorTreeModel;
}
interface TreePanelState {
}
export default class TreePanel extends React.Component<TreePanelProps, TreePanelState> {
state: TreePanelState = {};
componentDidMount() {
}
render() {
const { model } = this.props;
if(!model) {
return (<div/>)
}
return (
<Card title="概况" style={{ height: "100%" }}>
行为树:{model.name}
</Card>
)
}
}
+19 -10
View File
@@ -9,20 +9,20 @@ import { G6GraphEvent } from '@antv/g6/lib/interface/behavior';
import './Editor.css'; import './Editor.css';
import * as Utils from '../../common/Utils'; import * as Utils from '../../common/Utils';
import { BehaviorTreeModel, GraphNodeModel } from '../../common/BehaviorTreeModel'; import { BehaviorTreeModel, GraphNodeModel } from '../../common/BehaviorTreeModel';
import TreePanel from './TreePanel';
export interface EditorProps { export interface EditorProps {
filepath: string; filepath: string;
} }
interface EditorState { interface EditorState {
curNodeId: string | null; curNodeId?: string;
treeModel?: BehaviorTreeModel;
} }
export default class Editor extends React.Component<EditorProps, EditorState> { export default class Editor extends React.Component<EditorProps, EditorState> {
private ref: React.RefObject<any>; private ref: React.RefObject<any>;
state: EditorState = { state: EditorState = {}
curNodeId: null
}
private graph: TreeGraph; private graph: TreeGraph;
private dragSrcId: string; private dragSrcId: string;
@@ -33,9 +33,9 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.ref = React.createRef(); this.ref = React.createRef();
} }
shouldComponentUpdate() { // shouldComponentUpdate(nextProps: EditorProps, nextState: EditorState) {
return !this.graph; // return !this.graph || this.state.curNodeId != nextState.curNodeId;
} // }
componentDidMount() { componentDidMount() {
const graph = new TreeGraph({ const graph = new TreeGraph({
@@ -260,6 +260,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
graph.fitCenter(); graph.fitCenter();
this.graph = graph; this.graph = graph;
this.setState({treeModel: tree});
} }
onSelectNode(curNodeId: string | null) { onSelectNode(curNodeId: string | null) {
@@ -276,9 +278,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
} }
} }
createNode(name: string) {
}
render() { render() {
console.log("render editor") console.log("render editor")
const { curNodeId: curNode } = this.state; const { curNodeId, treeModel } = this.state;
var curNode;
if (curNodeId) {
curNode = this.graph.findDataById(curNodeId);
}
return ( return (
<div className="editor"> <div className="editor">
<Row className="editorBd"> <Row className="editorBd">
@@ -288,8 +298,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
ref={this.ref} ref={this.ref}
/> />
<Col span={6} className="editorSidebar"> <Col span={6} className="editorSidebar">
<NodePanel {curNode ? <NodePanel /> : <TreePanel model={treeModel}/>}
/>
</Col> </Col>
</Row> </Row>
</div> </div>