From 1c7ef5903deb2df7539481f91338220e5fff0f67 Mon Sep 17 00:00:00 2001 From: zhandouxiaojiji Date: Fri, 23 Oct 2020 18:04:54 +0800 Subject: [PATCH] node add desc --- common/Utils.ts | 1 + main-process/Settings.ts | 10 ++++---- render-process/Editor/index.tsx | 6 +++++ render-process/index.tsx | 45 +++++++++++++++++---------------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/common/Utils.ts b/common/Utils.ts index a4011fb..4ce9198 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -29,6 +29,7 @@ export const createTreeData = (bNode: BehaviorNodeModel) => { const treeData: any = { id: bNode.id.toString(), name: bNode.name, + desc: bNode.desc, } if (bNode.children) { treeData.children = []; diff --git a/main-process/Settings.ts b/main-process/Settings.ts index 997f7bc..0a95ba5 100644 --- a/main-process/Settings.ts +++ b/main-process/Settings.ts @@ -24,7 +24,7 @@ const sampleNodeClassify: BehaviorNodeClassify[] = [ export default class Settings { private settings: SettingsModel; - private name2classify: { [name: string]: string } = {}; + private name2conf: { [name: string]: BehaviorNodeTypeModel } = {}; constructor() { this.load(); } @@ -41,9 +41,9 @@ export default class Settings { get nodeConfig() { const str = fs.readFileSync(this.nodeConfigPath, 'utf8'); const types: BehaviorNodeTypeModel[] = JSON.parse(str); - this.name2classify = {}; + this.name2conf = {}; types.forEach(t => { - this.name2classify[t.name] = t.type; + this.name2conf[t.name] = t; }) return types; } @@ -78,7 +78,7 @@ export default class Settings { fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2)); } - getClassify(name: string) { - return this.name2classify[name]; + getNodeConf(name: string) { + return this.name2conf[name]; } } \ No newline at end of file diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index b98ce13..d66b33f 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -80,11 +80,17 @@ export default class Editor extends React.Component { graph.on('node:mouseenter', (e: G6GraphEvent) => { const { item } = e; + if(item.hasState('selected')) { + return; + } graph.setItemState(item, 'hover', true); }); graph.on('node:mouseleave', (e: G6GraphEvent) => { const { item } = e; + if(item.hasState('selected')) { + return; + } graph.setItemState(item, 'hover', false); }); diff --git a/render-process/index.tsx b/render-process/index.tsx index 2db969e..6ad7b6e 100644 --- a/render-process/index.tsx +++ b/render-process/index.tsx @@ -20,12 +20,12 @@ const { Header, Sider, Content, Footer } = Layout; const { TabPane } = Tabs; const NODE_COLORS: any = { - ['Composite'] : 'rgb(91,237,32)', - ['Decorator'] : 'rgb(218,167,16)', - ['Condition'] : 'rgb(228,20,139)', - ['Action'] : 'rgb(91,143,249)', - ['Other'] : 'rgb(112,112,112)', -} + ['Composite']: 'rgb(91,237,32)', + ['Decorator']: 'rgb(218,167,16)', + ['Condition']: 'rgb(228,20,139)', + ['Action']: 'rgb(91,143,249)', + ['Other']: 'rgb(112,112,112)', +} interface MainState { workspace: string; @@ -60,17 +60,17 @@ export default class Main extends Component { width: 150, }, stateStyles: { - hover: { - 'main-box': { - fill: 'gray', - } - }, selected: { 'main-box': { stroke: 'black', lineWidth: 3, }, }, + hover: { + 'name-text': { + stroke: 'white', + } + }, dragSrc: { fill: 'gray', }, @@ -92,8 +92,9 @@ export default class Main extends Component { }, }, draw(cfg, group) { - const classfiy = settings.getClassify(cfg.name as string) || 'Other'; - const color = NODE_COLORS[classfiy]; + const nodeConf = settings.getNodeConf(cfg.name as string); + const classify = nodeConf.type || 'Other'; + const color = NODE_COLORS[classify] || 'Other'; var size = cfg.size ? cfg.size as number[] : [150, 40]; const w = size[0]; const h = size[1]; @@ -118,9 +119,9 @@ export default class Main extends Component { // name bg group.addShape('rect', { attrs: { - x: x0+1.5, - y: y0+1.5, - width: w-3, + x: x0 + 1.5, + y: y0 + 1.5, + width: w - 3, height: 16, fill: color, // radius: r, @@ -144,8 +145,8 @@ export default class Main extends Component { }); // icon - var img = `./static/icons/${classfiy}.svg`; - console.log(cfg.type, classfiy); + var img = `./static/icons/${classify}.svg`; + console.log(cfg.type, classify); group.addShape('image', { attrs: { x: x0 + 15, @@ -173,20 +174,20 @@ export default class Main extends Component { var x = x0 + 2; var y = y0 + 20; // desc text - if(cfg.desc) { + const desc = cfg.desc || nodeConf.desc; + if (desc) { group.addShape('text', { attrs: { textBaseline: 'top', x, y, lineHeight: 20, - text: cfg.name, + text: `备注:${desc}`, fill: 'black', }, - name: 'name-text', + name: 'desc-text', }); } - group.addShape('rect', { name: 'drag-up',