From d74bca252d46cbef74eba52fd143335fe12cf5c9 Mon Sep 17 00:00:00 2001
From: liteng <930372551@qq.com>
Date: Sat, 6 Oct 2018 16:51:46 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=9C=BA=E6=99=AF=E5=90=8D?=
=?UTF-8?q?=E7=A7=B0=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/SceneController.cs | 50 +++++++++++++++++++
ShadowEditor.Server/Scene/EditSceneModel.cs | 24 +++++++++
.../ShadowEditor.Server.csproj | 1 +
.../src/editor/window/SceneEditWindow.js | 31 +++++++++++-
.../src/editor/window/SceneWindow.js | 3 +-
5 files changed, 106 insertions(+), 3 deletions(-)
create mode 100644 ShadowEditor.Server/Scene/EditSceneModel.cs
diff --git a/ShadowEditor.Server/Controllers/SceneController.cs b/ShadowEditor.Server/Controllers/SceneController.cs
index 3831a5b1..ea1840a8 100644
--- a/ShadowEditor.Server/Controllers/SceneController.cs
+++ b/ShadowEditor.Server/Controllers/SceneController.cs
@@ -99,6 +99,56 @@ namespace ShadowEditor.Server.Controllers
});
}
+ ///
+ /// 编辑场景信息
+ ///
+ ///
+ ///
+ [HttpPost]
+ public JsonResult Edit(EditSceneModel model)
+ {
+ var objectId = ObjectId.GenerateNewId();
+
+ if (!string.IsNullOrEmpty(model.ID) && !ObjectId.TryParse(model.ID, out objectId))
+ {
+ return Json(new
+ {
+ Code = 300,
+ Msg = "场景ID不合法。"
+ });
+ }
+
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return Json(new
+ {
+ Code = 300,
+ Msg = "场景名称不允许为空。"
+ });
+ }
+
+ if (model.Name.StartsWith("_"))
+ {
+ return Json(new
+ {
+ Code = 300,
+ Msg = "场景名称不允许以下划线开头。"
+ });
+ }
+
+ var mongo = new MongoHelper();
+
+ var filter = Builders.Filter.Eq("ID", objectId);
+ var update = Builders.Update.Set("Name", model.Name);
+ mongo.UpdateOne(Constant.SceneCollectionName, filter, update);
+
+ return Json(new
+ {
+ Code = 200,
+ Msg = "编辑场景成功!"
+ });
+ }
+
///
/// 保存场景
///
diff --git a/ShadowEditor.Server/Scene/EditSceneModel.cs b/ShadowEditor.Server/Scene/EditSceneModel.cs
new file mode 100644
index 00000000..2337a0e3
--- /dev/null
+++ b/ShadowEditor.Server/Scene/EditSceneModel.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShadowEditor.Server.Scene
+{
+ ///
+ /// 场景编辑数据模型
+ ///
+ public class EditSceneModel
+ {
+ ///
+ /// 场景ID
+ ///
+ public string ID { get; set; }
+
+ ///
+ /// 场景名称
+ ///
+ public string Name { get; set; }
+ }
+}
diff --git a/ShadowEditor.Server/ShadowEditor.Server.csproj b/ShadowEditor.Server/ShadowEditor.Server.csproj
index e3c71321..d570063b 100644
--- a/ShadowEditor.Server/ShadowEditor.Server.csproj
+++ b/ShadowEditor.Server/ShadowEditor.Server.csproj
@@ -125,6 +125,7 @@
+
diff --git a/ShadowEditor.Web/src/editor/window/SceneEditWindow.js b/ShadowEditor.Web/src/editor/window/SceneEditWindow.js
index 85c6c209..c2fb88fe 100644
--- a/ShadowEditor.Web/src/editor/window/SceneEditWindow.js
+++ b/ShadowEditor.Web/src/editor/window/SceneEditWindow.js
@@ -9,6 +9,7 @@ import Ajax from '../../utils/Ajax';
function SceneEditWindow(options) {
UI.Control.call(this, options);
this.app = options.app;
+ this.callback = options.callback || null;
}
SceneEditWindow.prototype = Object.create(UI.Control.prototype);
@@ -46,13 +47,15 @@ SceneEditWindow.prototype.render = function () {
text: '确定',
style: {
margin: '0 8px'
- }
+ },
+ onClick: this.save.bind(this)
}, {
xtype: 'button',
text: '取消',
style: {
margin: '0 8px'
- }
+ },
+ onClick: this.hide.bind(this)
}]
}]
});
@@ -81,4 +84,28 @@ SceneEditWindow.prototype.updateUI = function () {
name.setValue(this.data.Name);
};
+SceneEditWindow.prototype.save = function () {
+ var server = this.app.options.server;
+
+ if (this.data === undefined) {
+ return;
+ }
+
+ var name = UI.get('name', this.id);
+
+ Ajax.post(`${server}/api/Scene/Edit`, {
+ ID: this.data.ID,
+ Name: name.getValue()
+ }, json => {
+ var obj = JSON.parse(json);
+ UI.msg(obj.Msg);
+ if (obj.Code === 200) {
+ this.hide();
+ if (typeof (this.callback) === 'function') {
+ this.callback(obj);
+ }
+ }
+ });
+};
+
export default SceneEditWindow;
\ No newline at end of file
diff --git a/ShadowEditor.Web/src/editor/window/SceneWindow.js b/ShadowEditor.Web/src/editor/window/SceneWindow.js
index 5e675327..950baffa 100644
--- a/ShadowEditor.Web/src/editor/window/SceneWindow.js
+++ b/ShadowEditor.Web/src/editor/window/SceneWindow.js
@@ -181,7 +181,8 @@ SceneWindow.prototype.onEditScene = function (data) {
if (this.editWindow === undefined) {
this.editWindow = new SceneEditWindow({
app: this.app,
- parent: this.parent
+ parent: this.parent,
+ callback: this.update.bind(this)
});
this.editWindow.render();
}