From 4a41c62e8a57737da181995eabfc0bbdbb6fb65b Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Sun, 14 Jul 2019 08:28:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=84=9A=E6=9C=AC=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/editor2/sidebar/ScriptPanel.jsx | 112 +++++++----------- .../editor2/sidebar/window/ScriptWindow.jsx | 28 ++++- 2 files changed, 64 insertions(+), 76 deletions(-) diff --git a/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx b/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx index 52340eca..1b3cd675 100644 --- a/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx +++ b/ShadowEditor.Web/src/editor2/sidebar/ScriptPanel.jsx @@ -1,5 +1,5 @@ import './css/ScriptPanel.css'; -import { classNames, PropTypes, Button } from '../../third_party'; +import { classNames, PropTypes, Button, IconButton, Icon } from '../../third_party'; import ScriptWindow from './window/ScriptWindow.jsx'; /** @@ -10,6 +10,10 @@ class ScriptPanel extends React.Component { constructor(props) { super(props); + this.state = { + scripts: {}, + }; + this.handleAddScript = this.handleAddScript.bind(this); this.handleEditScript = this.handleEditScript.bind(this); this.handleRemoveScript = this.handleRemoveScript.bind(this); @@ -17,91 +21,57 @@ class ScriptPanel extends React.Component { } render() { + const scripts = this.state.scripts; + return
-
-
+
; } + getExtension(type) { + let extension = ''; + + switch (type) { + case 'javascript': + extension = 'js'; + break; + case 'vertexShader': + extension = 'glsl'; + break; + case 'fragmentShader': + extension = 'glsl'; + break; + case 'json': + extension = 'json'; + break; + } + + return extension; + } + componentDidMount() { - // app.on(`scriptChanged.${this.id}`, this.update); + app.on(`scriptChanged.ScriptPanel`, this.update); } update() { - var container = UI.get('scriptsContainer'); - container.dom.innerHTML = ''; - container.dom.style.display = 'none'; - - var scripts = app.editor.scripts; - - if (Object.keys(scripts).length === 0) { - return; - } - - container.dom.style.display = 'block'; - - Object.keys(scripts).forEach(n => { - var script = scripts[n]; - var uuid = script.uuid; - var name = script.name; - var extension; - - switch (script.type) { - case 'javascript': - extension = '.js'; - break; - case 'vertexShader': - case 'fragmentShader': - extension = '.glsl'; - break; - case 'json': - extension = '.json'; - break; - } - - var data = { - xtype: 'control', - parent: container.dom, - children: [{ - xtype: 'text', - text: name + extension, - style: { - width: '100px', - fontSize: '12px' - } - }, { - xtype: 'button', - text: L_EDIT, - style: { - marginLeft: '4px' - }, - onClick: () => { - this.editScript(uuid); - } - }, { - xtype: 'button', - text: L_DELETE, - style: { - marginLeft: '4px' - }, - onClick: () => { - this.deleteScript(uuid); - } - }, { - xtype: 'br' - }] - }; - - UI.create(data).render(); + this.setState({ + scripts: app.editor.scripts, }); } handleAddScript() { const window = app.createElement(ScriptWindow); - app.addElement(window); } @@ -117,7 +87,7 @@ class ScriptPanel extends React.Component { handleRemoveScript(uuid) { var script = app.editor.scripts[uuid]; - UI.confirm(L_CONFIRM, `${L_DELETE} ${script.name}?`, (event, btn) => { + app.confirm(L_CONFIRM, `${L_DELETE} ${script.name}?`, (event, btn) => { if (btn === 'ok') { delete app.editor.scripts[uuid]; app.call('scriptChanged', this); diff --git a/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx b/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx index 267b87a8..0da5360b 100644 --- a/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx +++ b/ShadowEditor.Web/src/editor2/sidebar/window/ScriptWindow.jsx @@ -28,7 +28,7 @@ class ScriptWindow extends React.Component { this.handleNameChange = this.handleNameChange.bind(this); this.handleTypeChange = this.handleTypeChange.bind(this); this.handleOK = this.handleOK.bind(this); - this.handleCancel = this.handleCancel.bind(this); + this.handleClose = this.handleClose.bind(this); } render() { @@ -37,7 +37,7 @@ class ScriptWindow extends React.Component { return + onClose={this.handleClose}>
@@ -56,7 +56,7 @@ class ScriptWindow extends React.Component { - + ; } @@ -97,12 +97,30 @@ class ScriptWindow extends React.Component { source = JavaScriptStarter(); } - this.handleCancel(); + app.editor.scripts[uuid] = { + id: null, + name, + type, + source, + uuid, + }; + + app.call(`scriptChanged`, this); + + this.handleClose(); + + this.setState({ + show: false, + uuid: null, + name: '', + type: 'javascript', + source: '', + }); app.call(`editScript`, this, uuid, name, type, source); } - handleCancel() { + handleClose() { app.removeElement(this); } }