update Explorer after TreeTabs
This commit is contained in:
1 parent
cdac600624
commit
909d643ea5
2 files changed
+27
-25
No files matched your search
@@ -25,7 +25,6 @@ export interface EditorProps {
|
|||||||
interface EditorState {
|
interface EditorState {
|
||||||
curNodeId?: string;
|
curNodeId?: string;
|
||||||
treeModel?: BehaviorTreeModel;
|
treeModel?: BehaviorTreeModel;
|
||||||
settings?: Settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Editor extends React.Component<EditorProps, EditorState> {
|
export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||||
@@ -38,10 +37,19 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
private autoId: number;
|
private autoId: number;
|
||||||
private undoStack: BehaviorNodeModel[] = [];
|
private undoStack: BehaviorNodeModel[] = [];
|
||||||
private redoStack: BehaviorNodeModel[] = [];
|
private redoStack: BehaviorNodeModel[] = [];
|
||||||
|
private treeModel: BehaviorTreeModel;
|
||||||
|
private settings: Settings;
|
||||||
|
private data: GraphNodeModel;
|
||||||
|
|
||||||
constructor(props: EditorProps) {
|
constructor(props: EditorProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.ref = React.createRef();
|
this.ref = React.createRef();
|
||||||
|
|
||||||
|
this.settings = Utils.getRemoteSettings();
|
||||||
|
const str = fs.readFileSync(this.props.filepath, "utf8");
|
||||||
|
let tree: BehaviorTreeModel = JSON.parse(str);
|
||||||
|
this.data = Utils.createTreeData(tree.root, this.settings);
|
||||||
|
this.autoId = Utils.refreshNodeId(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -255,20 +263,14 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
this.changeWithoutAnim();
|
this.changeWithoutAnim();
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings = Utils.getRemoteSettings();
|
graph.data(this.data);
|
||||||
|
|
||||||
const str = fs.readFileSync(this.props.filepath, "utf8");
|
|
||||||
let tree: BehaviorTreeModel = JSON.parse(str);
|
|
||||||
const data = Utils.createTreeData(tree.root, settings);
|
|
||||||
this.autoId = Utils.refreshNodeId(data);
|
|
||||||
graph.data(data);
|
|
||||||
graph.render();
|
graph.render();
|
||||||
graph.fitCenter();
|
graph.fitCenter();
|
||||||
graph.set("animate", true);
|
graph.set("animate", true);
|
||||||
|
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
|
||||||
this.setState({ treeModel: tree, settings });
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectNode(curNodeId: string | null) {
|
onSelectNode(curNodeId: string | null) {
|
||||||
@@ -286,7 +288,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
|
|
||||||
createNode(name: string) {
|
createNode(name: string) {
|
||||||
console.log("editor create node", name);
|
console.log("editor create node", name);
|
||||||
const { curNodeId, settings } = this.state;
|
const { curNodeId } = this.state;
|
||||||
if (!curNodeId) {
|
if (!curNodeId) {
|
||||||
message.warn("未选中节点");
|
message.warn("未选中节点");
|
||||||
return;
|
return;
|
||||||
@@ -300,7 +302,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
if (!curNodeData.children) {
|
if (!curNodeData.children) {
|
||||||
curNodeData.children = [];
|
curNodeData.children = [];
|
||||||
}
|
}
|
||||||
curNodeData.children.push(Utils.createTreeData(newNodeData, settings));
|
curNodeData.children.push(Utils.createTreeData(newNodeData, this.settings));
|
||||||
this.changeWithoutAnim();
|
this.changeWithoutAnim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +371,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.pushUndoStack();
|
this.pushUndoStack();
|
||||||
const data = Utils.createTreeData(JSON.parse(str), this.state.settings);
|
const data = Utils.createTreeData(JSON.parse(str), this.settings);
|
||||||
this.autoId = Utils.refreshNodeId(data, this.autoId);
|
this.autoId = Utils.refreshNodeId(data, this.autoId);
|
||||||
this.onSelectNode(null);
|
this.onSelectNode(null);
|
||||||
if (!curNodeData.children) {
|
if (!curNodeData.children) {
|
||||||
@@ -386,7 +388,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
|
|
||||||
useStackData(data: BehaviorNodeModel) {
|
useStackData(data: BehaviorNodeModel) {
|
||||||
this.graph.set("animate", false);
|
this.graph.set("animate", false);
|
||||||
this.graph.changeData(Utils.createTreeData(data, this.state.settings));
|
this.graph.changeData(Utils.createTreeData(data, this.settings));
|
||||||
this.graph.layout(true);
|
this.graph.layout(true);
|
||||||
this.graph.set("animate", true);
|
this.graph.set("animate", true);
|
||||||
}
|
}
|
||||||
@@ -423,7 +425,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { curNodeId, treeModel, settings } = this.state;
|
const { curNodeId, treeModel } = this.state;
|
||||||
var curNode: any;
|
var curNode: any;
|
||||||
if (curNodeId) {
|
if (curNodeId) {
|
||||||
curNode = this.graph.findDataById(curNodeId);
|
curNode = this.graph.findDataById(curNodeId);
|
||||||
@@ -437,11 +439,11 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
{curNode ? (
|
{curNode ? (
|
||||||
<NodePanel
|
<NodePanel
|
||||||
model={curNode}
|
model={curNode}
|
||||||
settings={settings}
|
settings={this.settings}
|
||||||
updateNode={(id, forceUpdate) => {
|
updateNode={(id, forceUpdate) => {
|
||||||
if (forceUpdate) {
|
if (forceUpdate) {
|
||||||
const data: any = this.graph.findDataById(id);
|
const data: any = this.graph.findDataById(id);
|
||||||
data.conf = settings.getNodeConf(data.name);
|
data.conf = this.settings.getNodeConf(data.name);
|
||||||
data.size = Utils.calcTreeNodeSize(data);
|
data.size = Utils.calcTreeNodeSize(data);
|
||||||
this.changeWithoutAnim();
|
this.changeWithoutAnim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.props.onTabSelected(this.state.curPath);
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
getOpenTreesModel() {
|
getOpenTreesModel() {
|
||||||
const trees: BehaviorTreeModel[] = []
|
const trees: BehaviorTreeModel[] = []
|
||||||
for (let k in this.editors) {
|
for (let k in this.editors) {
|
||||||
@@ -99,13 +105,9 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
if (this.state.filepaths.indexOf(path) < 0) {
|
if (this.state.filepaths.indexOf(path) < 0) {
|
||||||
const filepaths = this.state.filepaths;
|
const filepaths = this.state.filepaths;
|
||||||
filepaths.push(path);
|
filepaths.push(path);
|
||||||
this.setState({ filepaths, curPath: path },()=>{
|
this.setState({ filepaths, curPath: path });
|
||||||
this.props.onTabSelected(path);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.setState({ curPath: path },()=>{
|
this.setState({ curPath: path });
|
||||||
this.props.onTabSelected(path);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +136,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
defaultActiveKey={curPath}
|
defaultActiveKey={curPath}
|
||||||
activeKey={curPath}
|
activeKey={curPath}
|
||||||
onChange={(activeKey) => {
|
onChange={(activeKey) => {
|
||||||
this.setState({ curPath: activeKey },()=>{
|
this.setState({ curPath: activeKey });
|
||||||
this.props.onTabSelected(activeKey);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
onEdit={(targetKey, action) => {
|
onEdit={(targetKey, action) => {
|
||||||
if (action == "remove") {
|
if (action == "remove") {
|
||||||
|
|||||||
Reference in new issue
Block a user