右键拉框复制剪切粘贴

This commit is contained in:
ckcz123 2020-05-22 18:38:10 +08:00
parent c6d2bbeea5
commit a22c80e5bd
5 changed files with 72 additions and 31 deletions

View File

@ -523,7 +523,7 @@ return '{' + [
IdString_1 && ('"down": "' + IdString_1 +'"'), IdString_1 && ('"down": "' + IdString_1 +'"'),
IdString_2 && ('"left": "' + IdString_2 +'"'), IdString_2 && ('"left": "' + IdString_2 +'"'),
IdString_3 && ('"right": "' + IdString_3 +'"'), IdString_3 && ('"right": "' + IdString_3 +'"'),
].join(', ') + '}\n'; ].filter(function (x) { return x; }).join(', ') + '}\n';
*/; */;

View File

@ -70,6 +70,7 @@ function editor() {
startPos:null, startPos:null,
endPos:null, endPos:null,
lastMoveE:{buttons:0,clientX:0,clientY:0}, lastMoveE:{buttons:0,clientX:0,clientY:0},
selectedArea: null,
// 材料区拖动有关 // 材料区拖动有关
lastMoveMaterE:null, lastMoveMaterE:null,
tileSize: [1,1], tileSize: [1,1],

View File

@ -75,6 +75,7 @@ editor_mappanel_wrapper = function (editor) {
* + 绘图时画个矩形在那个位置 * + 绘图时画个矩形在那个位置
*/ */
editor.uifunctions.map_ondown = function (e) { editor.uifunctions.map_ondown = function (e) {
editor.uivalues.selectedArea = null;
editor.uivalues.lastMoveE=e; editor.uivalues.lastMoveE=e;
var loc = editor.uifunctions.eToLoc(e); var loc = editor.uifunctions.eToLoc(e);
var pos = editor.uifunctions.locToPos(loc, true); var pos = editor.uifunctions.locToPos(loc, true);
@ -211,16 +212,20 @@ editor_mappanel_wrapper = function (editor) {
* + 绘图模式时, 根据画线/画矩形/画tileset 做对应的绘制 * + 绘图模式时, 根据画线/画矩形/画tileset 做对应的绘制
*/ */
editor.uifunctions.map_onup = function (ee) { editor.uifunctions.map_onup = function (ee) {
console.log(1) editor.uivalues.selectedArea = null;
ee.preventDefault();
ee.stopPropagation();
var e=editor.uivalues.lastMoveE; var e=editor.uivalues.lastMoveE;
if (!selectBox.isSelected()) { if (!selectBox.isSelected()) {
if (e.buttons == 2) { 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.uifunctions.showMidMenu(e.clientX, e.clientY);
editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__);
} else { } else {
// 右键拖拽: 选中区域 // 右键拖拽: 选中区域
printf('已经选中该区域') printf('已经选中该区域')
editor.uivalues.selectedArea = Object.assign({}, editor.uivalues.startPos, {x1: editor.uivalues.endPos.x, y1: editor.uivalues.endPos.y});
// 后续的处理 // 后续的处理
} }
} else { } else {
@ -232,8 +237,8 @@ editor_mappanel_wrapper = function (editor) {
else else
editor.exchangeBgFg(editor.uivalues.startPos, editor.uivalues.endPos, editor.layerMod); editor.exchangeBgFg(editor.uivalues.startPos, editor.uivalues.endPos, editor.layerMod);
editor.uifunctions.unhighlightSaveFloorButton(); 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; editor.uivalues.startPos = editor.uivalues.endPos = null;
return false; return false;
} }
@ -876,30 +881,51 @@ editor_mappanel_wrapper = function (editor) {
editor.constructor.prototype.copyFromPos = function (pos) { editor.constructor.prototype.copyFromPos = function (pos) {
var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); var fields = Object.keys(editor.file.comment._data.floors._data.loc._data);
pos = pos || editor.pos; pos = pos || editor.pos;
var map = core.clone(editor.map[pos.y][pos.x]); 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 = {}; var events = {};
fields.forEach(function(v){ fields.forEach(function(v){
events[v] = core.clone(editor.currentFloorData[v][pos.x+','+pos.y]); events[v] = core.clone(editor.currentFloorData[v][i+','+j]);
}) })
return {map: map, events: events}; result.data.push({map: map, events: events});
}
}
return result;
} }
editor.constructor.prototype.pasteToPos = function (info, pos) { editor.constructor.prototype.pasteToPos = function (info, pos) {
if (info == null) return; if (info == null) return;
var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); var fields = Object.keys(editor.file.comment._data.floors._data.loc._data);
pos = pos || editor.pos; pos = pos || editor.pos;
editor.map[pos.y][pos.x] = core.clone(info.map); 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){ fields.forEach(function(v){
if (info.events[v] == null) delete editor.currentFloorData[v][pos.x+","+pos.y]; if (one.events[v] == null) delete editor.currentFloorData[v][i+","+j];
else editor.currentFloorData[v][pos.x+","+pos.y] = core.clone(info.events[v]); else editor.currentFloorData[v][i+","+j] = core.clone(one.events[v]);
}); });
} }
}
}
}
editor.constructor.prototype.movePos = function (startPos, endPos, callback) { editor.constructor.prototype.movePos = function (startPos, endPos, callback) {
if (!startPos || !endPos) return; if (!startPos || !endPos) return;
if (startPos.x == endPos.x && startPos.y == endPos.y) return; if (startPos.x == endPos.x && startPos.y == endPos.y) return;
var copyed = editor.copyFromPos(startPos); 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.pasteToPos(copyed, endPos);
editor.updateMap(); editor.updateMap();
editor.file.saveFloorFile(function (err) { editor.file.saveFloorFile(function (err) {
@ -986,16 +1012,28 @@ editor_mappanel_wrapper = function (editor) {
editor.constructor.prototype.clearPos = function (clearPos, pos, callback) { editor.constructor.prototype.clearPos = function (clearPos, pos, callback) {
var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); var fields = Object.keys(editor.file.comment._data.floors._data.loc._data);
pos = pos || editor.pos; 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.uifunctions.hideMidMenu();
editor.savePreMap(); editor.savePreMap();
editor.info = 0; editor.info = 0;
editor_mode.onmode(''); editor_mode.onmode('');
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) if (clearPos)
editor.map[pos.y][pos.x]=editor.info; editor[editor.layerMod][j][i] = 0;
editor.updateMap(); if (editor.layerMod == 'map') {
fields.forEach(function(v){ fields.forEach(function(v){
delete editor.currentFloorData[v][pos.x+','+pos.y]; delete editor.currentFloorData[v][i+","+j];
}) });
}
}
}
editor.updateMap();
editor.file.saveFloorFile(function (err) { editor.file.saveFloorFile(function (err) {
if (err) { if (err) {
printe(err); printe(err);

View File

@ -343,15 +343,15 @@ editor_ui_wrapper = function (editor) {
// Ctrl+C, Ctrl+X, Ctrl+V // Ctrl+C, Ctrl+X, Ctrl+V
if (e.ctrlKey && e.keyCode == 67 && !selectBox.isSelected()) { if (e.ctrlKey && e.keyCode == 67 && !selectBox.isSelected()) {
e.preventDefault(); e.preventDefault();
editor.uivalues.copyedInfo = editor.copyFromPos(); editor.uivalues.copyedInfo = editor.copyFromPos(editor.uivalues.selectedArea);
printf('该点事件已复制'); printf('该点事件已复制;请注意右键地图拉框可以复制一个区域;若有时复制失灵请多点几下空白处');
return; return;
} }
if (e.ctrlKey && e.keyCode == 88 && !selectBox.isSelected()) { if (e.ctrlKey && e.keyCode == 88 && !selectBox.isSelected()) {
e.preventDefault(); e.preventDefault();
editor.uivalues.copyedInfo = editor.copyFromPos(); editor.uivalues.copyedInfo = editor.copyFromPos(editor.uivalues.selectedArea);
editor.clearPos(true, null, function () { editor.clearPos(true, editor.uivalues.selectedArea, function () {
printf('该点事件已剪切'); printf('该点事件已剪切;请注意右键地图拉框可以剪切一个区域;若有时剪切失灵请多点几下空白处');
editor.uifunctions.unhighlightSaveFloorButton(); editor.uifunctions.unhighlightSaveFloorButton();
}) })
return; return;
@ -369,7 +369,7 @@ editor_ui_wrapper = function (editor) {
printe(err); printe(err);
throw (err) throw (err)
} }
; printf('粘贴事件成功'); ; printf('粘贴事件成功;若有时粘贴失灵请多点几下空白处');
editor.uifunctions.unhighlightSaveFloorButton(); editor.uifunctions.unhighlightSaveFloorButton();
editor.drawPosSelection(); editor.drawPosSelection();
}); });
@ -377,8 +377,10 @@ editor_ui_wrapper = function (editor) {
} }
// DELETE // DELETE
if (e.keyCode == 46 && !selectBox.isSelected()) { if (e.keyCode == 46 && !selectBox.isSelected()) {
editor.clearPos(true); editor.clearPos(true, editor.uivalues.selectedArea, function () {
printf('该点事件已删除;请注意右键地图拉框可以删除一个区域;;若有时删除失灵请多点几下空白处');
editor.uifunctions.unhighlightSaveFloorButton(); editor.uifunctions.unhighlightSaveFloorButton();
})
return; return;
} }
// ESC // ESC

View File

@ -65,8 +65,8 @@
(已完成!) showImage, drawImage立绘等加上对称选项 (已完成!) showImage, drawImage立绘等加上对称选项
(已完成!) 更多的图块blockly化 (已完成!) 更多的图块blockly化
(已完成!) 勇士帧动画 (已完成!) 勇士帧动画
行走动画? (不处理;现在静止状态可以有帧动画了,所以不考虑行走过程动画) 行走动画
\t[this], 勇士朝下flag:arg清理瞬移扣血
------------- -------------