选中区域

This commit is contained in:
YouWei Zhao 2020-05-20 14:49:05 +08:00
parent d1edf27dde
commit 4c94ce4edb
3 changed files with 56 additions and 22 deletions

View File

@ -69,6 +69,11 @@ function editor() {
mouseOutCheck : 2,
startPos:null,
endPos:null,
lastMoveE:{buttons:0,clientX:0,clientY:0},
// 材料区拖动有关
lastMoveMaterE:null,
tileSize: [1,1],
startLoc: null,
// 撤销/恢复
preMapData : [],
preMapMax: 10,
@ -104,8 +109,6 @@ function editor() {
},
// tile
tileSize: [1,1],
startLoc: null,
lockMode: false,
// 最近使用的图块

View File

@ -75,6 +75,7 @@ editor_mappanel_wrapper = function (editor) {
* + 绘图时画个矩形在那个位置
*/
editor.uifunctions.map_ondown = function (e) {
editor.uivalues.lastMoveE=e;
var loc = editor.uifunctions.eToLoc(e);
var pos = editor.uifunctions.locToPos(loc, true);
if (editor.uivalues.bindSpecialDoor.loc != null) {
@ -89,10 +90,10 @@ editor_mappanel_wrapper = function (editor) {
}
return false;
}
if (e.button == 2) {
editor.uifunctions.showMidMenu(e.clientX, e.clientY);
return false;
}
// if (e.buttons == 2) { // 挪到onup
// editor.uifunctions.showMidMenu(e.clientX, e.clientY);
// return false;
// }
if (!selectBox.isSelected()) {
editor_mode.onmode('nextChange');
editor_mode.onmode('loc');
@ -122,6 +123,7 @@ editor_mappanel_wrapper = function (editor) {
* + 绘图模式时找到与队列尾相邻的鼠标方向的点画个矩形
*/
editor.uifunctions.map_onmove = function (e) {
editor.uivalues.lastMoveE=e;
if (!selectBox.isSelected()) {
if (editor.uivalues.startPos == null) return;
//tip.whichShow(1);
@ -136,11 +138,27 @@ editor_mappanel_wrapper = function (editor) {
editor.uivalues.endPos = pos;
if (editor.uivalues.startPos != null) {
if (editor.uivalues.startPos.x != editor.uivalues.endPos.x || editor.uivalues.startPos.y != editor.uivalues.endPos.y) {
if (e.buttons == 2) {
// 右键拖拽: 画选的区域
var x0 = editor.uivalues.startPos.x;
var y0 = editor.uivalues.startPos.y;
var x1 = editor.uivalues.endPos.x;
var y1 = editor.uivalues.endPos.y;
if (x0 > x1) { x0 ^= x1; x1 ^= x0; x0 ^= x1; }//swap
if (y0 > y1) { y0 ^= y1; y1 ^= y0; y0 ^= y1; }//swap
// draw rect
editor.dom.euiCtx.clearRect(0, 0, editor.dom.euiCtx.canvas.width, editor.dom.euiCtx.canvas.height);
editor.dom.euiCtx.fillStyle = 'rgba(0, 127, 255, 0.4)';
editor.dom.euiCtx.fillRect(32 * x0 - core.bigmap.offsetX, 32 * y0 - core.bigmap.offsetY,
32 * (x1 - x0) + 32, 32 * (y1 - y0) + 32);
}else{
// 左键拖拽: 画箭头
core.drawArrow('eui',
32 * editor.uivalues.startPos.x + 16 - core.bigmap.offsetX, 32 * editor.uivalues.startPos.y + 16 - core.bigmap.offsetY,
32 * editor.uivalues.endPos.x + 16 - core.bigmap.offsetX, 32 * editor.uivalues.endPos.y + 16 - core.bigmap.offsetY);
}
}
}
// editor_mode.onmode('nextChange');
// editor_mode.onmode('loc');
//editor_mode.loc();
@ -192,17 +210,31 @@ editor_mappanel_wrapper = function (editor) {
* + 非绘图模式时, 交换首末点的内容
* + 绘图模式时, 根据画线/画矩形/画tileset 做对应的绘制
*/
editor.uifunctions.map_onup = function (e) {
editor.uifunctions.map_onup = function (ee) {
console.log(1)
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){
// 右键点击: 弹菜单
editor.uifunctions.showMidMenu(e.clientX, e.clientY);
} else {
// 右键拖拽: 选中区域
printf('已经选中该区域')
// 后续的处理
}
} else {
// 左键拖拽: 交换
//tip.whichShow(1);
// editor.movePos(editor.uivalues.startPos, editor.uivalues.endPos);
if (editor.layerMod == 'map')
editor.exchangePos(editor.uivalues.startPos, editor.uivalues.endPos);
else
editor.exchangeBgFg(editor.uivalues.startPos, editor.uivalues.endPos, editor.layerMod);
editor.uivalues.startPos = editor.uivalues.endPos = null;
editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__);
editor.uifunctions.unhighlightSaveFloorButton();
}
editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__);
editor.uivalues.startPos = editor.uivalues.endPos = null;
return false;
}
editor.uivalues.holdingPath = 0;

View File

@ -62,7 +62,6 @@ editor_materialpanel_wrapper = function (editor) {
}
}
var lastmoveE=null;
/**
* editor.dom.iconLib.onmousedown
* 素材区的单击/拖拽事件
@ -70,7 +69,7 @@ editor_materialpanel_wrapper = function (editor) {
editor.uifunctions.material_ondown = function (e) {
e.stopPropagation();
e.preventDefault();
lastmoveE=e;
editor.uivalues.lastMoveMaterE=e;
if (!editor.isMobile && e.clientY >= editor.dom.iconLib.offsetHeight - editor.uivalues.scrollBarHeight) return;
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
@ -90,7 +89,7 @@ editor_materialpanel_wrapper = function (editor) {
editor.uifunctions.material_onmove = function (e) {
e.stopPropagation();
e.preventDefault();
lastmoveE=e;
editor.uivalues.lastMoveMaterE=e;
if (!editor.uivalues.startLoc) return;
var pos0 = editor.uifunctions.locToPos(editor.uivalues.startLoc);
@ -109,7 +108,7 @@ editor_materialpanel_wrapper = function (editor) {
var startLoc = editor.uivalues.startLoc;
editor.uivalues.startLoc = null;
var e=lastmoveE;
var e=editor.uivalues.lastMoveMaterE;
if (!editor.isMobile && e.clientY >= editor.dom.iconLib.offsetHeight - editor.uivalues.scrollBarHeight) return;
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;