From 4c94ce4edb9352b03a4726c5e33b1c9d1d1f7d95 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Wed, 20 May 2020 14:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E4=B8=AD=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor.js | 7 ++-- _server/editor_mappanel.js | 64 ++++++++++++++++++++++++--------- _server/editor_materialpanel.js | 7 ++-- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index c2843696..bc64fe95 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -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, // 最近使用的图块 diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index f2f850ac..a397f535 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.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,9 +138,25 @@ 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) { - 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); + 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'); @@ -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()) { - //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; + 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.uifunctions.unhighlightSaveFloorButton(); + } editor.dom.euiCtx.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); - editor.uifunctions.unhighlightSaveFloorButton(); + editor.uivalues.startPos = editor.uivalues.endPos = null; return false; } editor.uivalues.holdingPath = 0; diff --git a/_server/editor_materialpanel.js b/_server/editor_materialpanel.js index 8a6704fa..d7607b82 100644 --- a/_server/editor_materialpanel.js +++ b/_server/editor_materialpanel.js @@ -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;