From f1eb680b5607581371bede00fd852038d849029a Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Mon, 12 Aug 2019 21:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=9A=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E7=BB=93=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor2/component/MaterialComponent.jsx | 2 ++ .../src/editor2/sidebar/ScriptPanel.jsx | 15 ++++++++++++++- .../editor2/sidebar/window/ScriptWindow.jsx | 15 ++++++++++++++- .../src/editor2/viewport/ScriptEditorPanel.jsx | 18 ++++++++---------- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ShadowEditor.Web/src/editor2/component/MaterialComponent.jsx b/ShadowEditor.Web/src/editor2/component/MaterialComponent.jsx index d7872d44..a69fe887 100644 --- a/ShadowEditor.Web/src/editor2/component/MaterialComponent.jsx +++ b/ShadowEditor.Web/src/editor2/component/MaterialComponent.jsx @@ -699,6 +699,8 @@ class MaterialComponent extends React.Component { attributes: material.attributes }; + app.call(`editScript`, this, uuid, script.name, script.type, script.source); + app.script.open(material.uuid, this.selected.name + '-ProgramInfo', 'json', JSON.stringify(obj), this.selected.name + `-${L_SHADER_INFO}`, source => { try { obj = JSON.parse(source); diff --git a/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx b/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx index 6a0dd3c0..5bc5a018 100644 --- a/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx +++ b/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx @@ -16,6 +16,7 @@ class ScriptPanel extends React.Component { this.handleAddScript = this.handleAddScript.bind(this); this.handleEditScript = this.handleEditScript.bind(this); + this.handleSaveScript = this.handleSaveScript.bind(this); this.handleRemoveScript = this.handleRemoveScript.bind(this); this.update = this.update.bind(this); } @@ -78,10 +79,22 @@ class ScriptPanel extends React.Component { handleEditScript(uuid) { var script = app.editor.scripts[uuid]; if (script) { - app.call(`editScript`, this, uuid, script.name, script.type, script.source); + app.call(`editScript`, this, uuid, script.name, script.type, script.source, this.handleSaveScript); } } + handleSaveScript(uuid, name, type, source) { + app.editor.scripts[uuid] = { + id: null, + uuid, + name, + type, + source, + }; + + app.call(`scriptChanged`, this); + } + handleRemoveScript(uuid) { const script = app.editor.scripts[uuid]; diff --git a/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx b/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx index 0da5360b..8e414362 100644 --- a/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx +++ b/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx @@ -29,6 +29,7 @@ class ScriptWindow extends React.Component { this.handleTypeChange = this.handleTypeChange.bind(this); this.handleOK = this.handleOK.bind(this); this.handleClose = this.handleClose.bind(this); + this.handleSaveScript = this.handleSaveScript.bind(this); } render() { @@ -117,7 +118,19 @@ class ScriptWindow extends React.Component { source: '', }); - app.call(`editScript`, this, uuid, name, type, source); + app.call(`editScript`, this, uuid, name, type, source, this.handleSaveScript); + } + + handleSaveScript(uuid, name, type, source) { + app.editor.scripts[uuid] = { + id: null, + uuid, + name, + type, + source, + }; + + app.call(`scriptChanged`, this); } handleClose() { diff --git a/ShadowEditor.Web/src/editor2/viewport/ScriptEditorPanel.jsx b/ShadowEditor.Web/src/editor2/viewport/ScriptEditorPanel.jsx index cbec26f6..6061d9c0 100644 --- a/ShadowEditor.Web/src/editor2/viewport/ScriptEditorPanel.jsx +++ b/ShadowEditor.Web/src/editor2/viewport/ScriptEditorPanel.jsx @@ -18,6 +18,8 @@ class ScriptEditorPanel extends React.Component { source: '', }; + this.callback = null; + this.ref = React.createRef(); this.handleEditScript = this.handleEditScript.bind(this); @@ -59,7 +61,9 @@ class ScriptEditorPanel extends React.Component { app.on(`editScript.ScriptPanel`, this.handleEditScript); } - handleEditScript(uuid, name, type, source) { + handleEditScript(uuid, name, type, source, callback) { + this.callback = callback; + this.setState({ show: true, uuid, @@ -76,13 +80,9 @@ class ScriptEditorPanel extends React.Component { const source = app.scriptEditor.getValue(); - app.editor.scripts[uuid] = { - id: null, - name, - type, - source, - uuid, - }; + this.callback && this.callback(uuid, name, type, source); + + this.callback = null; this.setState({ show: false, @@ -91,8 +91,6 @@ class ScriptEditorPanel extends React.Component { type: 'javascript', source: '', }); - - app.call(`scriptChanged`, this); } }