From a22c80e5bd060fd75fea7c3fff6eff2b774c348f Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 22 May 2020 18:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E9=94=AE=E6=8B=89=E6=A1=86=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=89=AA=E5=88=87=E7=B2=98=E8=B4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 2 +- _server/editor.js | 1 + _server/editor_mappanel.js | 78 ++++++++++++++++++++++++++++---------- _server/editor_ui.js | 18 +++++---- v2.x-final更新.txt | 4 +- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 4e88d5d6..81291140 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -523,7 +523,7 @@ return '{' + [ IdString_1 && ('"down": "' + IdString_1 +'"'), IdString_2 && ('"left": "' + IdString_2 +'"'), IdString_3 && ('"right": "' + IdString_3 +'"'), -].join(', ') + '}\n'; +].filter(function (x) { return x; }).join(', ') + '}\n'; */; diff --git a/_server/editor.js b/_server/editor.js index 2a6fc1b7..ac96b53b 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -70,6 +70,7 @@ function editor() { startPos:null, endPos:null, lastMoveE:{buttons:0,clientX:0,clientY:0}, + selectedArea: null, // 材料区拖动有关 lastMoveMaterE:null, tileSize: [1,1], diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index 2406177e..8cce7cc2 100644 --- a/_server/editor_mappanel.js +++ b/_server/editor_mappanel.js @@ -75,6 +75,7 @@ editor_mappanel_wrapper = function (editor) { * + 绘图时画个矩形在那个位置 */ editor.uifunctions.map_ondown = function (e) { + editor.uivalues.selectedArea = null; editor.uivalues.lastMoveE=e; var loc = editor.uifunctions.eToLoc(e); var pos = editor.uifunctions.locToPos(loc, true); @@ -211,16 +212,20 @@ editor_mappanel_wrapper = function (editor) { * + 绘图模式时, 根据画线/画矩形/画tileset 做对应的绘制 */ editor.uifunctions.map_onup = function (ee) { - console.log(1) + editor.uivalues.selectedArea = null; + ee.preventDefault(); + ee.stopPropagation(); var e=editor.uivalues.lastMoveE; if (!selectBox.isSelected()) { if (e.buttons == 2) { - if (editor.uivalues.endPos==null || editor.uivalues.startPos.x == editor.uivalues.endPos.x && editor.uivalues.startPos.y == editor.uivalues.endPos.y){ + if (editor.uivalues.endPos==null || (editor.uivalues.startPos.x == editor.uivalues.endPos.x && editor.uivalues.startPos.y == editor.uivalues.endPos.y)) { // 右键点击: 弹菜单 editor.uifunctions.showMidMenu(e.clientX, e.clientY); + editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); } else { // 右键拖拽: 选中区域 printf('已经选中该区域') + editor.uivalues.selectedArea = Object.assign({}, editor.uivalues.startPos, {x1: editor.uivalues.endPos.x, y1: editor.uivalues.endPos.y}); // 后续的处理 } } else { @@ -232,8 +237,8 @@ editor_mappanel_wrapper = function (editor) { else editor.exchangeBgFg(editor.uivalues.startPos, editor.uivalues.endPos, editor.layerMod); editor.uifunctions.unhighlightSaveFloorButton(); + editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); } - editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); editor.uivalues.startPos = editor.uivalues.endPos = null; return false; } @@ -876,30 +881,51 @@ editor_mappanel_wrapper = function (editor) { editor.constructor.prototype.copyFromPos = function (pos) { var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); pos = pos || editor.pos; - var map = core.clone(editor.map[pos.y][pos.x]); - var events = {}; - fields.forEach(function(v){ - events[v] = core.clone(editor.currentFloorData[v][pos.x+','+pos.y]); - }) - return {map: map, events: events}; + var x0 = pos.x, y0 = pos.y, x1 = pos.x1, y1 = pos.y1; + if (x1 == null) x1 = x0; + if (y1 == null) y1 = y0; + if (x0 > x1) { x0 ^= x1; x1 ^= x0; x0 ^= x1; }//swap + if (y0 > y1) { y0 ^= y1; y1 ^= y0; y0 ^= y1; }//swap + var result = {w: x1 - x0 + 1, h: y1 - y0 + 1, layer: editor.layerMod, data: []}; + for (var i = x0; i <= x1; ++i) { + for (var j = y0; j<= y1; ++j) { + var map = core.clone(editor[editor.layerMod][j][i]); + var events = {}; + fields.forEach(function(v){ + events[v] = core.clone(editor.currentFloorData[v][i+','+j]); + }) + result.data.push({map: map, events: events}); + } + } + return result; } editor.constructor.prototype.pasteToPos = function (info, pos) { if (info == null) return; var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); pos = pos || editor.pos; - editor.map[pos.y][pos.x] = core.clone(info.map); - fields.forEach(function(v){ - if (info.events[v] == null) delete editor.currentFloorData[v][pos.x+","+pos.y]; - else editor.currentFloorData[v][pos.x+","+pos.y] = core.clone(info.events[v]); - }); + var w = info.w || 1, h = info.h || 1, layer = info.layer || 'map'; + var data = core.clone(info.data || []); + for (var i = pos.x; i < pos.x+w; ++i) { + for (var j = pos.y; j < pos.y+h; ++j) { + var one = data.shift(); + if (j >= editor[editor.layerMod].length || i >= editor[editor.layerMod][0].length) continue; + editor[editor.layerMod][j][i] = core.clone(one.map); + if (layer == 'map' && editor.layerMod == 'map') { + fields.forEach(function(v){ + if (one.events[v] == null) delete editor.currentFloorData[v][i+","+j]; + else editor.currentFloorData[v][i+","+j] = core.clone(one.events[v]); + }); + } + } + } } editor.constructor.prototype.movePos = function (startPos, endPos, callback) { if (!startPos || !endPos) return; if (startPos.x == endPos.x && startPos.y == endPos.y) return; var copyed = editor.copyFromPos(startPos); - editor.pasteToPos({map:0, events: {}}, startPos); + editor.pasteToPos({w: 1, h: 1, layer: 'map', data: [{map:0, events: {}}]}, startPos); editor.pasteToPos(copyed, endPos); editor.updateMap(); editor.file.saveFloorFile(function (err) { @@ -986,16 +1012,28 @@ editor_mappanel_wrapper = function (editor) { editor.constructor.prototype.clearPos = function (clearPos, pos, callback) { var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); pos = pos || editor.pos; + var x0 = pos.x, y0 = pos.y, x1 = pos.x1, y1 = pos.y1; + if (x1 == null) x1 = x0; + if (y1 == null) y1 = y0; + if (x0 > x1) { x0 ^= x1; x1 ^= x0; x0 ^= x1; }//swap + if (y0 > y1) { y0 ^= y1; y1 ^= y0; y0 ^= y1; }//swap editor.uifunctions.hideMidMenu(); editor.savePreMap(); editor.info = 0; editor_mode.onmode(''); - if (clearPos) - editor.map[pos.y][pos.x]=editor.info; + for (var i = x0; i <= x1; ++i) { + for (var j = y0; j <= y1; ++j) { + if (j >= editor[editor.layerMod].length || i >= editor[editor.layerMod][0].length) continue; + if (clearPos) + editor[editor.layerMod][j][i] = 0; + if (editor.layerMod == 'map') { + fields.forEach(function(v){ + delete editor.currentFloorData[v][i+","+j]; + }); + } + } + } editor.updateMap(); - fields.forEach(function(v){ - delete editor.currentFloorData[v][pos.x+','+pos.y]; - }) editor.file.saveFloorFile(function (err) { if (err) { printe(err); diff --git a/_server/editor_ui.js b/_server/editor_ui.js index 3d528f20..fff57c1b 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -343,15 +343,15 @@ editor_ui_wrapper = function (editor) { // Ctrl+C, Ctrl+X, Ctrl+V if (e.ctrlKey && e.keyCode == 67 && !selectBox.isSelected()) { e.preventDefault(); - editor.uivalues.copyedInfo = editor.copyFromPos(); - printf('该点事件已复制'); + editor.uivalues.copyedInfo = editor.copyFromPos(editor.uivalues.selectedArea); + printf('该点事件已复制;请注意右键地图拉框可以复制一个区域;若有时复制失灵请多点几下空白处'); return; } if (e.ctrlKey && e.keyCode == 88 && !selectBox.isSelected()) { e.preventDefault(); - editor.uivalues.copyedInfo = editor.copyFromPos(); - editor.clearPos(true, null, function () { - printf('该点事件已剪切'); + editor.uivalues.copyedInfo = editor.copyFromPos(editor.uivalues.selectedArea); + editor.clearPos(true, editor.uivalues.selectedArea, function () { + printf('该点事件已剪切;请注意右键地图拉框可以剪切一个区域;若有时剪切失灵请多点几下空白处'); editor.uifunctions.unhighlightSaveFloorButton(); }) return; @@ -369,7 +369,7 @@ editor_ui_wrapper = function (editor) { printe(err); throw (err) } - ; printf('粘贴事件成功'); + ; printf('粘贴事件成功;若有时粘贴失灵请多点几下空白处'); editor.uifunctions.unhighlightSaveFloorButton(); editor.drawPosSelection(); }); @@ -377,8 +377,10 @@ editor_ui_wrapper = function (editor) { } // DELETE if (e.keyCode == 46 && !selectBox.isSelected()) { - editor.clearPos(true); - editor.uifunctions.unhighlightSaveFloorButton(); + editor.clearPos(true, editor.uivalues.selectedArea, function () { + printf('该点事件已删除;请注意右键地图拉框可以删除一个区域;;若有时删除失灵请多点几下空白处'); + editor.uifunctions.unhighlightSaveFloorButton(); + }) return; } // ESC diff --git a/v2.x-final更新.txt b/v2.x-final更新.txt index 13079805..aadfea45 100644 --- a/v2.x-final更新.txt +++ b/v2.x-final更新.txt @@ -65,8 +65,8 @@ (已完成!) showImage, drawImage,立绘等加上对称选项 (已完成!) 更多的图块blockly化 (已完成!) 勇士帧动画 -行走动画? - +(不处理;现在静止状态可以有帧动画了,所以不考虑行走过程动画) 行走动画 +\t[this], 勇士朝下,flag:arg清理,瞬移扣血 -------------