From 983c645d8eb1d8d43fd5d29ea5a1a6d16f0d2ff2 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Mon, 19 Aug 2019 21:36:51 +0800 Subject: [PATCH] reoeder unsorted1 --- _server/editor.js | 59 ++-- _server/editor_datapanel.js | 5 +- _server/editor_listen.js | 130 +++++++++ _server/editor_mappanel.js | 408 ++++++++++++++++++++++++---- _server/editor_materialpanel.js | 128 ++++++++- _server/editor_ui.js | 92 +++---- _server/editor_unsorted_1.js | 468 -------------------------------- _server/editor_unsorted_3.js | 3 +- _server/editor_util.js | 4 +- editor-mobile.html | 2 +- editor.html | 2 +- 11 files changed, 711 insertions(+), 590 deletions(-) create mode 100644 _server/editor_listen.js delete mode 100644 _server/editor_unsorted_1.js diff --git a/_server/editor.js b/_server/editor.js index f28237eb..0942c892 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -12,9 +12,29 @@ function editor() { mapEdit:document.getElementById('mapEdit'), selectFloor:document.getElementById('selectFloor'), iconExpandBtn :document.getElementById('iconExpandBtn'), + dataSelection : document.getElementById('dataSelection'), + iconLib:document.getElementById('iconLib'), + midMenu:document.getElementById('midMenu'), + addFloorEvent :document.getElementById('addFloorEvent'), + chooseThis : document.getElementById('chooseThis'), + chooseInRight : document.getElementById('chooseInRight'), + copyLoc : document.getElementById('copyLoc'), + moveLoc : document.getElementById('moveLoc'), + clearEvent : document.getElementById('clearEvent'), + clearLoc : document.getElementById('clearLoc'), + brushMod:document.getElementById('brushMod'), + brushMod2:document.getElementById('brushMod2'), + brushMod3:document.getElementById('brushMod3'), + bgc : document.getElementById('bg'), + fgc : document.getElementById('fg'), + evc : document.getElementById('event'), + ev2c : document.getElementById('event2'), + layerMod:document.getElementById('layerMod'), + layerMod2:document.getElementById('layerMod2'), + layerMod3:document.getElementById('layerMod3'), + viewportButtons:document.getElementById('viewportButtons'), }; - this.uifunctions={}; this.uivalues={ // 绘制区拖动有关 holdingPath : 0, @@ -32,8 +52,14 @@ function editor() { // shortcut:{}, copyedInfo : null, + // 折叠素材 scrollBarHeight :0, folded:false, + foldPerCol: 50, + // 画图区菜单 + lastRightButtonPos:[{x:0,y:0},{x:0,y:0}], + lastCopyedInfo : [null, null], + // }; @@ -63,6 +89,8 @@ function editor() { }; } +editor.prototype.uifunctions={}; + /* editor.loc editor.pos @@ -89,7 +117,7 @@ editor.prototype.init = function (callback) { editor_mappanel_wrapper(editor); editor_datapanel_wrapper(editor); editor_materialpanel_wrapper(editor); - editor_unsorted_1_wrapper(editor); + editor_listen_wrapper(editor); editor.printe=printe; afterMainInit(); }); @@ -323,7 +351,7 @@ editor.prototype.drawInitData = function (icons) { editor.widthsX = {}; editor.uivalues.folded = core.getLocalStorage('folded', false); // editor.uivalues.folded = true; - editor.foldPerCol = 50; + editor.uivalues.foldPerCol = 50; // var imgNames = Object.keys(images); //还是固定顺序吧; var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"]; @@ -343,8 +371,8 @@ editor.prototype.drawInitData = function (icons) { var width = images[img].width, height = images[img].height, mh = height; if (editor.uivalues.folded) { var per_height = (img == 'enemy48' || img == 'npc48' ? 48 : 32); - width = Math.ceil(height / per_height / editor.foldPerCol) * 32; - if (width > 32) mh = per_height * editor.foldPerCol; + width = Math.ceil(height / per_height / editor.uivalues.foldPerCol) * 32; + if (width > 32) mh = per_height * editor.uivalues.foldPerCol; } editor.widthsX[img] = [img, sumWidth / 32, (sumWidth + width) / 32, height]; sumWidth += width; @@ -392,7 +420,7 @@ editor.prototype.drawInitData = function (icons) { })(editor.airwallImg,nowx); if (editor.uivalues.folded) { // --- 单列 & 折行 - var subimgs = core.splitImage(images[img], 32, editor.foldPerCol * 32); + var subimgs = core.splitImage(images[img], 32, editor.uivalues.foldPerCol * 32); var frames = images[img].width / 32; for (var i = 0; i < subimgs.length; i+=frames) { drawImage(subimgs[i], nowx, i==0?2*32:0); @@ -419,7 +447,7 @@ editor.prototype.drawInitData = function (icons) { if (editor.uivalues.folded) { // --- 单列 & 折行 var per_height = img.endsWith('48') ? 48 : 32; - var subimgs = core.splitImage(images[img], 32, editor.foldPerCol * per_height); + var subimgs = core.splitImage(images[img], 32, editor.uivalues.foldPerCol * per_height); var frames = images[img].width / 32; for (var i = 0; i < subimgs.length; i+=frames) { drawImage(subimgs[i], nowx, 0); @@ -509,15 +537,14 @@ editor.prototype.setSelectBoxFromInfo=function(thisevent){ if(thisevent.x)pos.x+=thisevent.x; ysize = thisevent.images.endsWith('48') ? 48 : 32; if (editor.uivalues.folded && core.tilesets.indexOf(thisevent.images)==-1) { - pos.x += Math.floor(pos.y / editor.foldPerCol); - pos.y %= editor.foldPerCol; + pos.x += Math.floor(pos.y / editor.uivalues.foldPerCol); + pos.y %= editor.uivalues.foldPerCol; } if(pos.x == 0) pos.y+=2; } - var dataSelection = document.getElementById('dataSelection'); - dataSelection.style.left = pos.x * 32 + 'px'; - dataSelection.style.top = pos.y * ysize + 'px'; - dataSelection.style.height = ysize - 6 + 'px'; + editor.dom.dataSelection.style.left = pos.x * 32 + 'px'; + editor.dom.dataSelection.style.top = pos.y * ysize + 'px'; + editor.dom.dataSelection.style.height = ysize - 6 + 'px'; setTimeout(function(){selectBox.isSelected(true);}); editor.info = JSON.parse(JSON.stringify(thisevent)); tip.infos(JSON.parse(JSON.stringify(thisevent))); @@ -527,11 +554,11 @@ editor.prototype.setSelectBoxFromInfo=function(thisevent){ } editor.prototype.listen = function () { - // 移动至 editor_unsorted_1.js + // 移动至 editor_listen.js }//绑定事件 editor.prototype.mobile_listen=function(){ - // 移动至 editor_unsorted_1.js + // 移动至 editor_listen.js } editor.prototype.copyFromPos = function (pos) { @@ -632,7 +659,7 @@ editor.prototype.exchangeBgFg = function (startPos, endPos, name, callback) { editor.prototype.clearPos = function (clearPos, pos, callback) { var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); pos = pos || editor.pos; - editor.hideMidMenu(); + editor.uifunctions.hideMidMenu(); editor.uivalues.preMapData = null; editor.info = 0; editor_mode.onmode(''); diff --git a/_server/editor_datapanel.js b/_server/editor_datapanel.js index f6a73d4a..bc14f729 100644 --- a/_server/editor_datapanel.js +++ b/_server/editor_datapanel.js @@ -1 +1,4 @@ -editor_datapanel_wrapper = function (editor) {} \ No newline at end of file +editor_datapanel_wrapper = function (editor) { + + +} \ No newline at end of file diff --git a/_server/editor_listen.js b/_server/editor_listen.js new file mode 100644 index 00000000..93dc5a68 --- /dev/null +++ b/_server/editor_listen.js @@ -0,0 +1,130 @@ +editor_listen_wrapper = function (editor) { + + editor.constructor.prototype.listen = function () { + + editor.dom.body.onmousedown = editor.uifunctions.body_click; + + editor.dom.eui.oncontextmenu = function (e) { e.preventDefault() } // 自定义了右键菜单, 阻止默认行为 + editor.dom.midMenu.oncontextmenu = function (e) { e.preventDefault() } + + editor.dom.eui.ondblclick = editor.uifunctions.map_doubleClick + + editor.dom.eui.onmousedown = editor.uifunctions.map_ondown + editor.dom.eui.onmousemove = editor.uifunctions.map_onmove + editor.dom.eui.onmouseup = editor.uifunctions.map_onup + + editor.dom.mid.onmousewheel = editor.uifunctions.map_mousewheel + + editor.uivalues.shortcut = core.getLocalStorage('shortcut', { 48: 0, 49: 0, 50: 0, 51: 0, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0 }); + editor.dom.body.onkeydown = editor.uifunctions.body_shortcut + + editor.uivalues.scrollBarHeight = editor.uifunctions.getScrollBarHeight(); + editor.dom.iconExpandBtn.style.display = 'block'; + editor.dom.iconExpandBtn.innerText = editor.uivalues.folded ? "展开" : "折叠"; + editor.dom.iconExpandBtn.onclick = editor.uifunctions.fold_material_click + + editor.dom.iconLib.onmousedown = editor.uifunctions.material_ondown + + editor.dom.addFloorEvent.onmousedown = editor.addFloorEvent_click + editor.dom.chooseThis.onmousedown = editor.uifunctions.chooseThis_click + editor.dom.chooseInRight.onmousedown = editor.uifunctions.chooseInRight_click + editor.dom.copyLoc.onmousedown = editor.uifunctions.copyLoc_click + editor.dom.moveLoc.onmousedown = editor.uifunctions.moveLoc_click + editor.dom.clearEvent.onmousedown = editor.uifunctions.clearEvent_click + editor.dom.clearLoc.onmousedown = editor.uifunctions.clearLoc_click + + editor.dom.brushMod.onchange = editor.uifunctions.brushMod_onchange + if (editor.dom.brushMod2) editor.dom.brushMod2.onchange = editor.uifunctions.brushMod2_onchange; + if (editor.dom.brushMod3) editor.dom.brushMod3.onchange = editor.uifunctions.brushMod3_onchange; + + editor.dom.layerMod.onchange = editor.uifunctions.layerMod_onchange + if (editor.dom.layerMod2) editor.dom.layerMod2.onchange = editor.uifunctions.layerMod2_onchange; + if (editor.dom.layerMod3) editor.dom.layerMod3.onchange = editor.uifunctions.layerMod3_onchange; + + editor.uifunctions.viewportButtons_clickBinding() + } + + editor.constructor.prototype.mobile_listen = function () { + if (!editor.isMobile) return; + + var mobileview = document.getElementById('mobileview'); + var editModeSelect = document.getElementById('editModeSelect'); + var mid = document.getElementById('mid'); + var right = document.getElementById('right'); + var mobileeditdata = document.getElementById('mobileeditdata'); + + + editor.showdataarea = function (callShowMode) { + mid.style = 'z-index:-1;opacity: 0;'; + right.style = 'z-index:-1;opacity: 0;'; + mobileeditdata.style = ''; + if (callShowMode) editor.mode.showMode(editModeSelect.value); + editor.uifunctions.hideMidMenu(); + } + mobileview.children[0].onclick = function () { + editor.showdataarea(true) + } + mobileview.children[1].onclick = function () { + mid.style = ''; + right.style = 'z-index:-1;opacity: 0;'; + mobileeditdata.style = 'z-index:-1;opacity: 0;'; + editor.lastClickId = ''; + } + mobileview.children[3].onclick = function () { + mid.style = 'z-index:-1;opacity: 0;'; + right.style = ''; + mobileeditdata.style = 'z-index:-1;opacity: 0;'; + editor.lastClickId = ''; + } + + + var gettrbyid = function () { + if (!editor.lastClickId) return false; + thisTr = document.getElementById(editor.lastClickId); + input = thisTr.children[2].children[0].children[0]; + field = thisTr.children[0].getAttribute('title'); + cobj = JSON.parse(thisTr.children[1].getAttribute('cobj')); + return [thisTr, input, field, cobj]; + } + mobileeditdata.children[0].onclick = function () { + var info = gettrbyid() + if (!info) return; + info[1].ondblclick() + } + mobileeditdata.children[1].onclick = function () { + var info = gettrbyid() + if (!info) return; + printf(info[2]) + } + mobileeditdata.children[2].onclick = function () { + var info = gettrbyid() + if (!info) return; + printf(info[0].children[1].getAttribute('title')) + } + + //===== + + document.body.ontouchstart = document.body.onmousedown; + document.body.onmousedown = null; + + editor.dom.eui.ontouchstart = editor.dom.eui.onmousedown + editor.dom.eui.onmousedown = null + editor.dom.eui.ontouchmove = editor.dom.eui.onmousemove + editor.dom.eui.onmousemove = null + editor.dom.eui.ontouchend = editor.dom.eui.onmouseup + editor.dom.eui.onmouseup = null + + + editor.dom.chooseThis.ontouchstart = editor.dom.chooseThis.onmousedown + editor.dom.chooseThis.onmousedown = null + editor.dom.chooseInRight.ontouchstart = editor.dom.chooseInRight.onmousedown + editor.dom.chooseInRight.onmousedown = null + editor.dom.copyLoc.ontouchstart = editor.dom.copyLoc.onmousedown + editor.dom.copyLoc.onmousedown = null + editor.dom.moveLoc.ontouchstart = editor.dom.moveLoc.onmousedown + editor.dom.moveLoc.onmousedown = null + editor.dom.clearLoc.ontouchstart = editor.dom.clearLoc.onmousedown + editor.dom.clearLoc.onmousedown = null + } + +} \ No newline at end of file diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index 6e74fca5..320baf35 100644 --- a/_server/editor_mappanel.js +++ b/_server/editor_mappanel.js @@ -5,7 +5,7 @@ editor_mappanel_wrapper = function (editor) { /** * 在绘图区格子内画一个随机色块 */ - editor.uifunctions.fillPos=function(pos) { + editor.uifunctions.fillPos = function (pos) { editor.dom.euiCtx.fillStyle = '#' + ~~(Math.random() * 8) + ~~(Math.random() * 8) + ~~(Math.random() * 8); editor.dom.euiCtx.fillRect(pos.x * 32 + 12 - core.bigmap.offsetX, pos.y * 32 + 12 - core.bigmap.offsetY, 8, 8); } @@ -13,15 +13,15 @@ editor_mappanel_wrapper = function (editor) { /** * 从鼠标点击返回可用的组件内坐标 */ - editor.uifunctions.eToLoc=function (e) { + editor.uifunctions.eToLoc = function (e) { var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft var scrollTop = document.documentElement.scrollTop || document.body.scrollTop - var xx=e.clientX,yy=e.clientY - if(editor.isMobile){xx=e.touches[0].clientX,yy=e.touches[0].clientY} + var xx = e.clientX, yy = e.clientY + if (editor.isMobile) { xx = e.touches[0].clientX, yy = e.touches[0].clientY } editor.loc = { 'x': scrollLeft + xx - editor.dom.mid.offsetLeft - editor.dom.mapEdit.offsetLeft, 'y': scrollTop + yy - editor.dom.mid.offsetTop - editor.dom.mapEdit.offsetTop, - 'size': editor.isMobile?(32*innerWidth*0.96/core.__PIXELS__):32 + 'size': editor.isMobile ? (32 * innerWidth * 0.96 / core.__PIXELS__) : 32 }; return editor.loc; } @@ -30,13 +30,13 @@ editor_mappanel_wrapper = function (editor) { * 组件内坐标转地图位置 * @param {Boolean} addViewportOffset 是否加上大地图的偏置 */ - editor.uifunctions.locToPos= function(loc, addViewportOffset) { - var offsetX=0, offsetY=0; - if (addViewportOffset){ - offsetX=core.bigmap.offsetX/32; - offsetY=core.bigmap.offsetY/32; + editor.uifunctions.locToPos = function (loc, addViewportOffset) { + var offsetX = 0, offsetY = 0; + if (addViewportOffset) { + offsetX = core.bigmap.offsetX / 32; + offsetY = core.bigmap.offsetY / 32; } - editor.pos = {'x': ~~(loc.x / loc.size)+offsetX, 'y': ~~(loc.y / loc.size)+offsetY} + editor.pos = { 'x': ~~(loc.x / loc.size) + offsetX, 'y': ~~(loc.y / loc.size) + offsetY } return editor.pos; } @@ -44,9 +44,9 @@ editor_mappanel_wrapper = function (editor) { * editor.dom.eui.ondblclick * 双击地图可以选中素材 */ - editor.uifunctions.map_doubleClick= function(e) { + editor.uifunctions.map_doubleClick = function (e) { var loc = editor.uifunctions.eToLoc(e); - var pos = editor.uifunctions.locToPos(loc,true); + var pos = editor.uifunctions.locToPos(loc, true); editor.setSelectBoxFromInfo(editor[editor.layerMod][pos.y][pos.x]); return; } @@ -54,7 +54,7 @@ editor_mappanel_wrapper = function (editor) { /** * 用于鼠标移出map后清除状态 */ - editor.uifunctions.clearMapStepStatus=function() { + editor.uifunctions.clearMapStepStatus = function () { if (editor.uivalues.mouseOutCheck > 1) { editor.uivalues.mouseOutCheck--; setTimeout(editor.uifunctions.clearMapStepStatus, 1000); @@ -72,11 +72,11 @@ editor_mappanel_wrapper = function (editor) { * + 非绘图时选中 * + 绘图时画个矩形在那个位置 */ - editor.uifunctions.map_ondown= function (e) { + editor.uifunctions.map_ondown = function (e) { var loc = editor.uifunctions.eToLoc(e); - var pos = editor.uifunctions.locToPos(loc,true); - if (e.button==2){ - editor.showMidMenu(e.clientX,e.clientY); + var pos = editor.uifunctions.locToPos(loc, true); + if (e.button == 2) { + editor.uifunctions.showMidMenu(e.clientX, e.clientY); return false; } if (!selectBox.isSelected()) { @@ -88,7 +88,7 @@ editor_mappanel_wrapper = function (editor) { editor.uivalues.startPos = pos; editor.dom.euiCtx.strokeStyle = '#FF0000'; editor.dom.euiCtx.lineWidth = 3; - if(editor.isMobile)editor.showMidMenu(e.clientX,e.clientY); + if (editor.isMobile) editor.uifunctions.showMidMenu(e.clientX, e.clientY); return false; } @@ -107,12 +107,12 @@ editor_mappanel_wrapper = function (editor) { * + 非绘图模式时维护起止位置并画箭头 * + 绘图模式时找到与队列尾相邻的鼠标方向的点画个矩形 */ - editor.uifunctions.map_onmove= function (e) { + editor.uifunctions.map_onmove = function (e) { if (!selectBox.isSelected()) { if (editor.uivalues.startPos == null) return; //tip.whichShow(1); var loc = editor.uifunctions.eToLoc(e); - var pos = editor.uifunctions.locToPos(loc,true); + var pos = editor.uifunctions.locToPos(loc, true); if (editor.uivalues.endPos != null && editor.uivalues.endPos.x == pos.x && editor.uivalues.endPos.y == pos.y) return; if (editor.uivalues.endPos != null) { editor.dom.euiCtx.clearRect(Math.min(32 * editor.uivalues.startPos.x - core.bigmap.offsetX, 32 * editor.uivalues.endPos.x - core.bigmap.offsetX), @@ -140,7 +140,7 @@ editor_mappanel_wrapper = function (editor) { } editor.uivalues.mouseOutCheck = 2; var loc = editor.uifunctions.eToLoc(e); - var pos = editor.uifunctions.locToPos(loc,true); + var pos = editor.uifunctions.locToPos(loc, true); var pos0 = editor.uivalues.stepPostfix[editor.uivalues.stepPostfix.length - 1] var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x] var max = 0, index = 4; @@ -150,7 +150,7 @@ editor_mappanel_wrapper = function (editor) { max = directionDistance[i]; } } - var pos = [{'x': 0, 'y': 1}, {'x': -1, 'y': 0}, {'x': 0, 'y': -1}, {'x': 1, 'y': 0}, false][index] + var pos = [{ 'x': 0, 'y': 1 }, { 'x': -1, 'y': 0 }, { 'x': 0, 'y': -1 }, { 'x': 1, 'y': 0 }, false][index] if (pos) { pos.x += pos0.x; pos.y += pos0.y; @@ -165,7 +165,7 @@ editor_mappanel_wrapper = function (editor) { * + 非绘图模式时, 交换首末点的内容 * + 绘图模式时, 根据画线/画矩形/画tileset 做对应的绘制 */ - editor.uifunctions.map_onup=function (e) { + editor.uifunctions.map_onup = function (e) { if (!selectBox.isSelected()) { //tip.whichShow(1); // editor.movePos(editor.uivalues.startPos, editor.uivalues.endPos); @@ -179,18 +179,18 @@ editor_mappanel_wrapper = function (editor) { } editor.uivalues.holdingPath = 0; if (editor.uivalues.stepPostfix && editor.uivalues.stepPostfix.length) { - editor.uivalues.preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); - if(editor.brushMod!=='line'){ - var x0=editor.uivalues.stepPostfix[0].x; - var y0=editor.uivalues.stepPostfix[0].y; - var x1=editor.uivalues.stepPostfix[editor.uivalues.stepPostfix.length-1].x; - var y1=editor.uivalues.stepPostfix[editor.uivalues.stepPostfix.length-1].y; - if(x0>x1){x0^=x1;x1^=x0;x0^=x1;}//swap - if(y0>y1){y0^=y1;y1^=y0;y0^=y1;}//swap - editor.uivalues.stepPostfix=[]; - for(var jj=y0;jj<=y1;jj++){ - for(var ii=x0;ii<=x1;ii++){ - editor.uivalues.stepPostfix.push({x:ii,y:jj}) + editor.uivalues.preMapData = JSON.parse(JSON.stringify({ map: editor.map, fgmap: editor.fgmap, bgmap: editor.bgmap })); + if (editor.brushMod !== 'line') { + var x0 = editor.uivalues.stepPostfix[0].x; + var y0 = editor.uivalues.stepPostfix[0].y; + var x1 = editor.uivalues.stepPostfix[editor.uivalues.stepPostfix.length - 1].x; + var y1 = editor.uivalues.stepPostfix[editor.uivalues.stepPostfix.length - 1].y; + if (x0 > x1) { x0 ^= x1; x1 ^= x0; x0 ^= x1; }//swap + if (y0 > y1) { y0 ^= y1; y1 ^= y0; y0 ^= y1; }//swap + editor.uivalues.stepPostfix = []; + for (var jj = y0; jj <= y1; jj++) { + for (var ii = x0; ii <= x1; ii++) { + editor.uivalues.stepPostfix.push({ x: ii, y: jj }) } } } @@ -198,21 +198,21 @@ editor_mappanel_wrapper = function (editor) { editor.uivalues.currDrawData.info = JSON.parse(JSON.stringify(editor.info)); editor.uivalues.reDo = null; // console.log(editor.uivalues.stepPostfix); - if(editor.brushMod==='tileset' && core.tilesets.indexOf(editor.info.images)!==-1){ - var imgWidth=~~(core.material.images.tilesets[editor.info.images].width/32); - var x0=editor.uivalues.stepPostfix[0].x; - var y0=editor.uivalues.stepPostfix[0].y; - var idnum=editor.info.idnum; - for (var ii = 0; ii < editor.uivalues.stepPostfix.length; ii++){ - if(editor.uivalues.stepPostfix[ii].y!=y0){ + if (editor.brushMod === 'tileset' && core.tilesets.indexOf(editor.info.images) !== -1) { + var imgWidth = ~~(core.material.images.tilesets[editor.info.images].width / 32); + var x0 = editor.uivalues.stepPostfix[0].x; + var y0 = editor.uivalues.stepPostfix[0].y; + var idnum = editor.info.idnum; + for (var ii = 0; ii < editor.uivalues.stepPostfix.length; ii++) { + if (editor.uivalues.stepPostfix[ii].y != y0) { y0++; - idnum+=imgWidth; + idnum += imgWidth; } - editor[editor.layerMod][editor.uivalues.stepPostfix[ii].y][editor.uivalues.stepPostfix[ii].x] = editor.ids[editor.indexs[idnum+editor.uivalues.stepPostfix[ii].x-x0]]; + editor[editor.layerMod][editor.uivalues.stepPostfix[ii].y][editor.uivalues.stepPostfix[ii].x] = editor.ids[editor.indexs[idnum + editor.uivalues.stepPostfix[ii].x - x0]]; } } else { for (var ii = 0; ii < editor.uivalues.stepPostfix.length; ii++) - editor[editor.layerMod][editor.uivalues.stepPostfix[ii].y][editor.uivalues.stepPostfix[ii].x] = editor.info; + editor[editor.layerMod][editor.uivalues.stepPostfix[ii].y][editor.uivalues.stepPostfix[ii].x] = editor.info; } // console.log(editor.map); editor.updateMap(); @@ -227,15 +227,15 @@ editor_mappanel_wrapper = function (editor) { * editor.dom.mid.onmousewheel * 在地图编辑区域滚轮切换楼层 */ - editor.uifunctions.map_mousewheel=function (e) { + editor.uifunctions.map_mousewheel = function (e) { var wheel = function (direct) { - var index=editor.core.floorIds.indexOf(editor.currentFloorId); + var index = editor.core.floorIds.indexOf(editor.currentFloorId); var toId = editor.currentFloorId; - if (direct>0 && index0) - toId = editor.core.floorIds[index-1]; + if (direct > 0 && index < editor.core.floorIds.length - 1) + toId = editor.core.floorIds[index + 1]; + else if (direct < 0 && index > 0) + toId = editor.core.floorIds[index - 1]; else return; editor_mode.onmode('nextChange'); @@ -255,4 +255,308 @@ editor_mappanel_wrapper = function (editor) { } return false; } + + /** + * 显示右键菜单 + */ + editor.uifunctions.showMidMenu = function (x, y) { + editor.uivalues.lastRightButtonPos = JSON.parse(JSON.stringify( + [editor.pos, editor.uivalues.lastRightButtonPos[0]] + )); + // --- copy + editor.uivalues.lastCopyedInfo = [editor.copyFromPos(), editor.uivalues.lastCopyedInfo[0]]; + var locStr = '(' + editor.uivalues.lastRightButtonPos[1].x + ',' + editor.uivalues.lastRightButtonPos[1].y + ')'; + var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; + var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; + + // 检测是否是上下楼 + var thisevent = editor.map[editor.pos.y][editor.pos.x]; + if (thisevent.id == 'upFloor') { + editor.dom.addFloorEvent.style.display = 'block'; + editor.dom.addFloorEvent.children[0].innerHTML = '绑定上楼事件'; + } + else if (thisevent.id == 'downFloor') { + editor.dom.addFloorEvent.style.display = 'block'; + editor.dom.addFloorEvent.children[0].innerHTML = '绑定下楼事件'; + } + else if (['leftPortal', 'rightPortal', 'downPortal', 'upPortal'].indexOf(thisevent.id) >= 0) { + editor.dom.addFloorEvent.style.display = 'block'; + editor.dom.addFloorEvent.children[0].innerHTML = '绑定楼传事件'; + } + else editor.dom.addFloorEvent.style.display = 'none'; + + editor.dom.chooseThis.children[0].innerHTML = '选中此点' + '(' + editor.pos.x + ',' + editor.pos.y + ')' + editor.dom.copyLoc.children[0].innerHTML = '复制事件' + locStr + '到此处'; + editor.dom.moveLoc.children[0].innerHTML = '交换事件' + locStr + '与此事件的位置'; + editor.dom.midMenu.style = 'top:' + (y + scrollTop) + 'px;left:' + (x + scrollLeft) + 'px;'; + } + + /** + * 隐藏右键菜单 + */ + editor.uifunctions.hideMidMenu = function () { + if (editor.isMobile) { + setTimeout(function () { + editor.dom.midMenu.style = 'display:none'; + }, 200) + } else { + editor.dom.midMenu.style = 'display:none'; + } + } + + /** + * editor.dom.addFloorEvent.onmousedown + * 菜单 添加上下楼事件 + */ + editor.addFloorEvent_click = function (e) { + editor.uifunctions.hideMidMenu(); + e.stopPropagation(); + var thisevent = editor.map[editor.pos.y][editor.pos.x]; + var loc = editor.pos.x + "," + editor.pos.y; + if (thisevent.id == 'upFloor') { + editor.currentFloorData.changeFloor[loc] = { "floorId": ":next", "stair": "downFloor" }; + } + else if (thisevent.id == 'downFloor') { + editor.currentFloorData.changeFloor[loc] = { "floorId": ":before", "stair": "upFloor" }; + } + else if (thisevent.id == 'leftPortal' || thisevent.id == 'rightPortal') { + editor.currentFloorData.changeFloor[loc] = { "floorId": ":next", "stair": ":symmetry_x" } + } + else if (thisevent.id == 'upPortal' || thisevent.id == 'downPortal') { + editor.currentFloorData.changeFloor[loc] = { "floorId": ":next", "stair": ":symmetry_y" } + } + editor.file.saveFloorFile(function (err) { + if (err) { + printe(err); + throw (err) + } + editor.drawPosSelection(); + editor_mode.showMode('loc'); + printf('添加楼梯事件成功'); + }); + } + + /** + * editor.dom.chooseThis.onmousedown + * 菜单 选中此点 + */ + editor.uifunctions.chooseThis_click = function (e) { + editor.uifunctions.hideMidMenu(); + e.stopPropagation(); + selectBox.isSelected(false); + + editor_mode.onmode('nextChange'); + editor_mode.onmode('loc'); + //editor_mode.loc(); + //tip.whichShow(1); + if (editor.isMobile) editor.showdataarea(false); + } + + /** + * editor.dom.chooseInRight.onmousedown + * 菜单 在素材区选中此图块 + */ + editor.uifunctions.chooseInRight_click = function (e) { + editor.uifunctions.hideMidMenu(); + e.stopPropagation(); + var thisevent = editor[editor.layerMod][editor.pos.y][editor.pos.x]; + editor.setSelectBoxFromInfo(thisevent); + } + + /** + * editor.dom.copyLoc.onmousedown + * 菜单 复制此事件 + */ + editor.uifunctions.copyLoc_click = function (e) { + editor.uifunctions.hideMidMenu(); + e.stopPropagation(); + editor.uivalues.preMapData = null; + editor.uivalues.reDo = null; + editor_mode.onmode(''); + var now = editor.pos, last = editor.uivalues.lastRightButtonPos[1]; + if (now.x == last.x && now.y == last.y) return; + editor.pasteToPos(editor.uivalues.lastCopyedInfo[1]); + editor.updateMap(); + editor.file.saveFloorFile(function (err) { + if (err) { + printe(err); + throw (err) + } + ; printf('复制事件成功'); + editor.drawPosSelection(); + }); + } + + /** + * editor.dom.moveLoc.onmousedown + * 菜单 移动此事件 + */ + editor.uifunctions.moveLoc_click = function (e) { + editor.uifunctions.hideMidMenu(); + e.stopPropagation(); + editor.uivalues.preMapData = null; + editor.uivalues.reDo = null; + editor_mode.onmode(''); + editor.exchangePos(editor.pos, editor.uivalues.lastRightButtonPos[1]); + } + + /** + * editor.dom.clearEvent.onmousedown + * 菜单 仅清空此点事件 + */ + editor.uifunctions.clearEvent_click = function (e) { + e.stopPropagation(); + editor.uivalues.reDo = null; + editor.clearPos(false); + } + + /** + * editor.dom.clearLoc.onmousedown + * 菜单 清空此点及事件 + */ + editor.uifunctions.clearLoc_click = function (e) { + e.stopPropagation(); + editor.uivalues.reDo = null; + editor.clearPos(true); + } + + /** + * editor.dom.brushMod.onchange + * 切换画笔模式 + */ + editor.uifunctions.brushMod_onchange = function () { + editor.brushMod = editor.dom.brushMod.value; + } + + /** + * editor.dom.brushMod2.onchange + * 切换画笔模式 + */ + editor.uifunctions.brushMod2_onchange = function () { + editor.brushMod = editor.dom.brushMod2.value; + } + + /** + * editor.dom.brushMod3.onchange + * 切换画笔模式 + */ + editor.uifunctions.brushMod3_onchange = function () { + // tip.showHelp(5) + tip.isSelectedBlock(false) + tip.msgs[11] = String('tileset贴图模式下可以按选中tileset素材,并在地图上拖动来一次绘制一个区域'); + tip.whichShow(12); + editor.brushMod = editor.dom.brushMod3.value; + } + + /** + * editor.dom.layerMod.onchange + * 切换编辑的层 + */ + editor.uifunctions.layerMod_onchange = function () { + editor.layerMod = editor.dom.layerMod.value; + [editor.dom.bgc, editor.dom.fgc, editor.dom.evc, editor.dom.ev2c].forEach(function (x) { + x.style.opacity = 1; + }); + + // 手机端.... + if (editor.isMobile) { + if (editor.dom.layerMod.value == 'bgmap') { + [editor.dom.fgc, editor.dom.evc, editor.dom.ev2c].forEach(function (x) { + x.style.opacity = 0.3; + }); + } + if (editor.dom.layerMod.value == 'fgmap') { + [editor.dom.bgc, editor.dom.evc, editor.dom.ev2c].forEach(function (x) { + x.style.opacity = 0.3; + }); + } + } + } + + /** + * editor.dom.layerMod2.onchange + * 切换编辑的层 + */ + editor.uifunctions.layerMod2_onchange = function () { + editor.layerMod = editor.dom.layerMod2.value; + [editor.dom.fgc, editor.dom.evc, editor.dom.ev2c].forEach(function (x) { + x.style.opacity = 0.3; + }); + editor.dom.bgc.style.opacity = 1; + } + + /** + * editor.dom.layerMod3.onchange + * 切换编辑的层 + */ + editor.uifunctions.layerMod3_onchange = function () { + editor.layerMod = editor.dom.layerMod3.value; + [editor.dom.bgc, editor.dom.evc, editor.dom.ev2c].forEach(function (x) { + x.style.opacity = 0.3; + }); + editor.dom.fgc.style.opacity = 1; + } + + /** + * 移动大地图可视窗口的绑定 + */ + editor.uifunctions.viewportButtons_clickBinding = function () { + var pressTimer = null; + for (var ii = 0, node; node = editor.dom.viewportButtons.children[ii]; ii++) { + (function (x, y) { + var move = function () { + editor.moveViewport(x, y); + } + node.onmousedown = function () { + clearTimeout(pressTimer); + pressTimer = setTimeout(function () { + pressTimer = -1; + var f = function () { + if (pressTimer != null) { + move(); + setTimeout(f, 150); + } + } + f(); + }, 500); + }; + node.onmouseup = function () { + if (pressTimer > 0) { + clearTimeout(pressTimer); + move(); + } + pressTimer = null; + } + })([-1, 0, 0, 1][ii], [0, -1, 1, 0][ii]); + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } \ No newline at end of file diff --git a/_server/editor_materialpanel.js b/_server/editor_materialpanel.js index 531714be..2ba50d82 100644 --- a/_server/editor_materialpanel.js +++ b/_server/editor_materialpanel.js @@ -1,4 +1,130 @@ editor_materialpanel_wrapper = function (editor) { - + editor.uifunctions.getScrollBarHeight = function () { + var outer = document.createElement("div"); + outer.style.visibility = "hidden"; + outer.style.width = "100px"; + outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps + + document.body.appendChild(outer); + + var widthNoScroll = outer.offsetWidth; + // force scrollbars + outer.style.overflow = "scroll"; + + // add innerdiv + var inner = document.createElement("div"); + inner.style.width = "100%"; + outer.appendChild(inner); + + var widthWithScroll = inner.offsetWidth; + + // remove divs + outer.parentNode.removeChild(outer); + + return widthNoScroll - widthWithScroll; + } + + /** + * editor.dom.iconExpandBtn.onclick + */ + editor.uifunctions.fold_material_click = function () { + if (confirm(editor.uivalues.folded ? "你想要展开素材吗?\n展开模式下将显示全素材内容。" + : ("你想要折叠素材吗?\n折叠模式下每个素材将仅显示单列,并且每" + editor.uivalues.foldPerCol + "个自动换列。"))) { + core.setLocalStorage('folded', !editor.uivalues.folded); + window.location.reload(); + } + } + + /** + * editor.dom.iconLib.onmousedown + * 素材区的单击事件 + */ + editor.uifunctions.material_ondown = function (e) { + e.stopPropagation(); + 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; + var loc = { + 'x': scrollLeft + e.clientX + editor.dom.iconLib.scrollLeft - right.offsetLeft - editor.dom.iconLib.offsetLeft, + 'y': scrollTop + e.clientY + editor.dom.iconLib.scrollTop - right.offsetTop - editor.dom.iconLib.offsetTop, + 'size': 32 + }; + editor.loc = loc; + var pos = editor.uifunctions.locToPos(loc); + for (var spriter in editor.widthsX) { + if (pos.x >= editor.widthsX[spriter][1] && pos.x < editor.widthsX[spriter][2]) { + var ysize = spriter.endsWith('48') ? 48 : 32; + loc.ysize = ysize; + pos.images = editor.widthsX[spriter][0]; + pos.y = ~~(loc.y / loc.ysize); + if (!editor.uivalues.folded && core.tilesets.indexOf(pos.images) == -1) pos.x = editor.widthsX[spriter][1]; + var autotiles = core.material.images['autotile']; + if (pos.images == 'autotile') { + var imNames = Object.keys(autotiles); + if ((pos.y + 1) * ysize > editor.widthsX[spriter][3]) + pos.y = ~~(editor.widthsX[spriter][3] / ysize) - 4; + else { + for (var i = 0; i < imNames.length; i++) { + if (pos.y >= 4 * i && pos.y < 4 * (i + 1)) { + pos.images = imNames[i]; + pos.y = 4 * i; + } + } + } + } + else { + var height = editor.widthsX[spriter][3], col = height / ysize; + if (editor.uivalues.folded && core.tilesets.indexOf(pos.images) == -1) { + col = (pos.x == editor.widthsX[spriter][2] - 1) ? ((col - 1) % editor.uivalues.foldPerCol + 1) : editor.uivalues.foldPerCol; + } + if (spriter == 'terrains' && pos.x == editor.widthsX[spriter][1]) col += 2; + pos.y = Math.min(pos.y, col - 1); + } + + selectBox.isSelected(true); + // console.log(pos,core.material.images[pos.images].height) + editor.dom.dataSelection.style.left = pos.x * 32 + 'px'; + editor.dom.dataSelection.style.top = pos.y * ysize + 'px'; + editor.dom.dataSelection.style.height = ysize - 6 + 'px'; + + if (pos.x == 0 && pos.y == 0) { + // editor.info={idnum:0, id:'empty','images':'清除块', 'y':0}; + editor.info = 0; + } else if (pos.x == 0 && pos.y == 1) { + editor.info = editor.ids[editor.indexs[17]]; + } else { + if (autotiles[pos.images]) editor.info = { 'images': pos.images, 'y': 0 }; + else if (core.tilesets.indexOf(pos.images) != -1) editor.info = { 'images': pos.images, 'y': pos.y, 'x': pos.x - editor.widthsX[spriter][1] }; + else { + var y = pos.y; + if (editor.uivalues.folded) { + y += editor.uivalues.foldPerCol * (pos.x - editor.widthsX[spriter][1]); + } + if (pos.images == 'terrains' && pos.x == 0) y -= 2; + editor.info = { 'images': pos.images, 'y': y } + } + + for (var ii = 0; ii < editor.ids.length; ii++) { + if ((core.tilesets.indexOf(pos.images) != -1 && editor.info.images == editor.ids[ii].images + && editor.info.y == editor.ids[ii].y && editor.info.x == editor.ids[ii].x) + || (Object.prototype.hasOwnProperty.call(autotiles, pos.images) && editor.info.images == editor.ids[ii].id + && editor.info.y == editor.ids[ii].y) + || (core.tilesets.indexOf(pos.images) == -1 && editor.info.images == editor.ids[ii].images + && editor.info.y == editor.ids[ii].y) + ) { + + editor.info = editor.ids[ii]; + break; + } + } + } + tip.infos(JSON.parse(JSON.stringify(editor.info))); + editor_mode.onmode('nextChange'); + editor_mode.onmode('enemyitem'); + //editor_mode.enemyitem(); + } + } + } + } \ No newline at end of file diff --git a/_server/editor_ui.js b/_server/editor_ui.js index 936a791c..98a88073 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -1,13 +1,13 @@ editor_ui_wrapper = function (editor) { - + /** * 根据鼠标点击, 得到从元素向上到body的所有id */ - editor.uifunctions.getClickpath=function(e){ + editor.uifunctions.getClickpath = function (e) { //console.log(e); var clickpath = []; - var getpath=function(e) { + var getpath = function (e) { var path = []; var currentElem = e.target; while (currentElem) { @@ -38,13 +38,13 @@ editor_ui_wrapper = function (editor) { * + 维护绘图区的菜单的隐藏 * + 记录最后一次点击的id(主要为了数据区服务) */ - editor.uifunctions.body_click=function (e) { - var clickpath=editor.uifunctions.getClickpath(e); - - var unselect=true; - for(var ii=0,thisId;thisId=['edit','tip','brushMod','brushMod2','brushMod3','layerMod','layerMod2','layerMod3','viewportButtons'][ii];ii++){ - if (clickpath.indexOf(thisId) !== -1){ - unselect=false; + editor.uifunctions.body_click = function (e) { + var clickpath = editor.uifunctions.getClickpath(e); + + var unselect = true; + for (var ii = 0, thisId; thisId = ['edit', 'tip', 'brushMod', 'brushMod2', 'brushMod3', 'layerMod', 'layerMod2', 'layerMod3', 'viewportButtons'][ii]; ii++) { + if (clickpath.indexOf(thisId) !== -1) { + unselect = false; break; } } @@ -55,9 +55,9 @@ editor_ui_wrapper = function (editor) { editor.file.saveFloorFile(function (err) { if (err) { printe(err); - throw(err) + throw (err) } - ;printf('地图保存成功'); + ; printf('地图保存成功'); }); } selectBox.isSelected(false); @@ -65,30 +65,30 @@ editor_ui_wrapper = function (editor) { } } //editor.mode.onmode(''); - if (e.button!=2 && !editor.isMobile){ - editor.hideMidMenu(); + if (e.button != 2 && !editor.isMobile) { + editor.uifunctions.hideMidMenu(); } - if (clickpath.indexOf('down') !== -1 && editor.isMobile && clickpath.indexOf('midMenu') === -1){ - editor.hideMidMenu(); + if (clickpath.indexOf('down') !== -1 && editor.isMobile && clickpath.indexOf('midMenu') === -1) { + editor.uifunctions.hideMidMenu(); } - if(clickpath.length>=2 && clickpath[0].indexOf('id_')===0){editor.lastClickId=clickpath[0]} + if (clickpath.length >= 2 && clickpath[0].indexOf('id_') === 0) { editor.lastClickId = clickpath[0] } } /** * editor.dom.body.onkeydown * 绑定快捷键 */ - editor.uifunctions.body_shortcut=function (e) { + editor.uifunctions.body_shortcut = function (e) { // UI预览 & 地图选点 if (uievent && uievent.isOpen) { e.preventDefault(); if (e.keyCode == 27) uievent.close(); else if (e.keyCode == 13) uievent.confirm(); - else if (e.keyCode==87) uievent.move(0,-1) - else if (e.keyCode==65) uievent.move(-1,0) - else if (e.keyCode==83) uievent.move(0,1); - else if (e.keyCode==68) uievent.move(1,0); + else if (e.keyCode == 87) uievent.move(0, -1) + else if (e.keyCode == 65) uievent.move(-1, 0) + else if (e.keyCode == 83) uievent.move(0, 1); + else if (e.keyCode == 68) uievent.move(1, 0); return; } @@ -108,7 +108,7 @@ editor_ui_wrapper = function (editor) { } // 如果是开启事件/脚本编辑器状态,则忽略 - if (editor_multi.id!="" || editor_blockly.id!="") + if (editor_multi.id != "" || editor_blockly.id != "") return; // 禁止快捷键的默认行为 @@ -123,13 +123,13 @@ editor_ui_wrapper = function (editor) { editor.bgmap = JSON.parse(JSON.stringify(editor.uivalues.preMapData.bgmap)); editor.updateMap(); editor.uivalues.reDo = JSON.parse(JSON.stringify(editor.uivalues.currDrawData)); - editor.uivalues.currDrawData = {pos: [], info: {}}; + editor.uivalues.currDrawData = { pos: [], info: {} }; editor.uivalues.preMapData = null; return; } //Ctrl+y 重做一步redo if (e.keyCode == 89 && e.ctrlKey && editor.uivalues.reDo && editor.uivalues.reDo.pos.length && selectBox.isSelected()) { - editor.uivalues.preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); + editor.uivalues.preMapData = JSON.parse(JSON.stringify({ map: editor.map, fgmap: editor.fgmap, bgmap: editor.bgmap })); for (var j = 0; j < editor.uivalues.reDo.pos.length; j++) editor.map[editor.uivalues.reDo.pos[j].y][editor.uivalues.reDo.pos[j].x] = JSON.parse(JSON.stringify(editor.uivalues.reDo.info)); @@ -140,11 +140,11 @@ editor_ui_wrapper = function (editor) { } // PGUP和PGDOWN切换楼层 - if (e.keyCode==33 || e.keyCode==34) { + if (e.keyCode == 33 || e.keyCode == 34) { e.preventDefault(); - var index=editor.core.floorIds.indexOf(editor.currentFloorId); - var nextIndex = index + (e.keyCode==33?1:-1); - if (nextIndex>=0 && nextIndex= 0 && nextIndex < editor.core.floorIds.length) { var toId = editor.core.floorIds[nextIndex]; editor_mode.onmode('nextChange'); editor_mode.onmode('floor'); @@ -154,21 +154,21 @@ editor_ui_wrapper = function (editor) { return; } //ctrl + 0~9 切换到快捷图块 - if (e.ctrlKey && [48, 49, 50, 51, 52, 53, 54, 55, 56, 57].indexOf(e.keyCode) !== -1){ - editor.setSelectBoxFromInfo(JSON.parse(JSON.stringify(editor.uivalues.shortcut[e.keyCode]||0))); + if (e.ctrlKey && [48, 49, 50, 51, 52, 53, 54, 55, 56, 57].indexOf(e.keyCode) !== -1) { + editor.setSelectBoxFromInfo(JSON.parse(JSON.stringify(editor.uivalues.shortcut[e.keyCode] || 0))); return; } //alt + 0~9 改变快捷图块 - if (e.altKey && [48, 49, 50, 51, 52, 53, 54, 55, 56, 57].indexOf(e.keyCode) !== -1){ - var infoToSave = JSON.stringify(editor.info||0); - if(infoToSave==JSON.stringify({}))return; - editor.uivalues.shortcut[e.keyCode]=JSON.parse(infoToSave); - printf('已保存该快捷图块, ctrl + '+(e.keyCode-48)+' 使用.') - core.setLocalStorage('shortcut',editor.uivalues.shortcut); + if (e.altKey && [48, 49, 50, 51, 52, 53, 54, 55, 56, 57].indexOf(e.keyCode) !== -1) { + var infoToSave = JSON.stringify(editor.info || 0); + if (infoToSave == JSON.stringify({})) return; + editor.uivalues.shortcut[e.keyCode] = JSON.parse(infoToSave); + printf('已保存该快捷图块, ctrl + ' + (e.keyCode - 48) + ' 使用.') + core.setLocalStorage('shortcut', editor.uivalues.shortcut); return; } var focusElement = document.activeElement; - if (!focusElement || focusElement.tagName.toLowerCase()=='body') { + if (!focusElement || focusElement.tagName.toLowerCase() == 'body') { // Ctrl+C, Ctrl+X, Ctrl+V if (e.ctrlKey && e.keyCode == 67 && !selectBox.isSelected()) { e.preventDefault(); @@ -195,9 +195,9 @@ editor_ui_wrapper = function (editor) { editor.file.saveFloorFile(function (err) { if (err) { printe(err); - throw(err) + throw (err) } - ;printf('粘贴事件成功'); + ; printf('粘贴事件成功'); editor.drawPosSelection(); }); return; @@ -214,9 +214,9 @@ editor_ui_wrapper = function (editor) { editor.file.saveFloorFile(function (err) { if (err) { printe(err); - throw(err) + throw (err) } - ;printf('地图保存成功'); + ; printf('地图保存成功'); }); } selectBox.isSelected(false); @@ -225,10 +225,10 @@ editor_ui_wrapper = function (editor) { } switch (e.keyCode) { // WASD - case 87: editor.moveViewport(0,-1); break; - case 65: editor.moveViewport(-1,0); break; - case 83: editor.moveViewport(0,1); break; - case 68: editor.moveViewport(1,0); break; + case 87: editor.moveViewport(0, -1); break; + case 65: editor.moveViewport(-1, 0); break; + case 83: editor.moveViewport(0, 1); break; + case 68: editor.moveViewport(1, 0); break; // Z~. case 90: editor_mode.change('map'); break; // Z case 88: editor_mode.change('loc'); break; // X diff --git a/_server/editor_unsorted_1.js b/_server/editor_unsorted_1.js deleted file mode 100644 index 59ecbc01..00000000 --- a/_server/editor_unsorted_1.js +++ /dev/null @@ -1,468 +0,0 @@ -editor_unsorted_1_wrapper=function(editor){ - -editor.constructor.prototype.listen=function () { - editor.dom.body.onmousedown = editor.uifunctions.body_click; - // 自定义了右键菜单, 阻止默认行为 - editor.dom.eui.oncontextmenu=function(e){e.preventDefault()} - editor.dom.eui.ondblclick = editor.uifunctions.map_doubleClick - - editor.dom.eui.onmousedown = editor.uifunctions.map_ondown - editor.dom.eui.onmousemove = editor.uifunctions.map_onmove - editor.dom.eui.onmouseup = editor.uifunctions.map_onup - - editor.dom.mid.onmousewheel = editor.uifunctions.map_mousewheel - - - editor.uivalues.shortcut = core.getLocalStorage('shortcut',{48: 0, 49: 0, 50: 0, 51: 0, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0}); - - editor.dom.body.onkeydown = editor.uifunctions.body_shortcut - - editor.uifunctions.getScrollBarHeight = function () { - var outer = document.createElement("div"); - outer.style.visibility = "hidden"; - outer.style.width = "100px"; - outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps - - document.body.appendChild(outer); - - var widthNoScroll = outer.offsetWidth; - // force scrollbars - outer.style.overflow = "scroll"; - - // add innerdiv - var inner = document.createElement("div"); - inner.style.width = "100%"; - outer.appendChild(inner); - - var widthWithScroll = inner.offsetWidth; - - // remove divs - outer.parentNode.removeChild(outer); - - return widthNoScroll - widthWithScroll; - } - editor.uivalues.scrollBarHeight = editor.uifunctions.getScrollBarHeight(); - - editor.dom.iconExpandBtn.style.display = 'block'; - editor.dom.iconExpandBtn.innerText = editor.uivalues.folded ? "展开" : "折叠"; - editor.dom.iconExpandBtn.onclick = function () { - if (confirm(editor.uivalues.folded ? "你想要展开素材吗?\n展开模式下将显示全素材内容。" - : ("你想要折叠素材吗?\n折叠模式下每个素材将仅显示单列,并且每"+editor.foldPerCol+"个自动换列。"))) { - core.setLocalStorage('folded', !editor.uivalues.folded); - window.location.reload(); - } - } - - var dataSelection = document.getElementById('dataSelection'); - var iconLib=document.getElementById('iconLib'); - iconLib.onmousedown = function (e) { - e.stopPropagation(); - if (!editor.isMobile && e.clientY>=iconLib.offsetHeight - editor.uivalues.scrollBarHeight) return; - var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; - var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; - var loc = { - 'x': scrollLeft + e.clientX + iconLib.scrollLeft - right.offsetLeft - iconLib.offsetLeft, - 'y': scrollTop + e.clientY + iconLib.scrollTop - right.offsetTop - iconLib.offsetTop, - 'size': 32 - }; - editor.loc = loc; - var pos = editor.uifunctions.locToPos(loc); - for (var spriter in editor.widthsX) { - if (pos.x >= editor.widthsX[spriter][1] && pos.x < editor.widthsX[spriter][2]) { - var ysize = spriter.endsWith('48') ? 48 : 32; - loc.ysize = ysize; - pos.images = editor.widthsX[spriter][0]; - pos.y = ~~(loc.y / loc.ysize); - if(!editor.uivalues.folded && core.tilesets.indexOf(pos.images)==-1) pos.x = editor.widthsX[spriter][1]; - var autotiles = core.material.images['autotile']; - if (pos.images == 'autotile') { - var imNames = Object.keys(autotiles); - if ((pos.y + 1) * ysize > editor.widthsX[spriter][3]) - pos.y = ~~(editor.widthsX[spriter][3] / ysize) - 4; - else { - for (var i = 0; i < imNames.length; i++) { - if (pos.y >= 4 * i && pos.y < 4 * (i + 1)) { - pos.images = imNames[i]; - pos.y = 4 * i; - } - } - } - } - else { - var height = editor.widthsX[spriter][3], col = height / ysize; - if (editor.uivalues.folded && core.tilesets.indexOf(pos.images)==-1) { - col = (pos.x == editor.widthsX[spriter][2] - 1) ? ((col - 1) % editor.foldPerCol + 1) : editor.foldPerCol; - } - if (spriter == 'terrains' && pos.x == editor.widthsX[spriter][1]) col += 2; - pos.y = Math.min(pos.y, col - 1); - } - - selectBox.isSelected(true); - // console.log(pos,core.material.images[pos.images].height) - dataSelection.style.left = pos.x * 32 + 'px'; - dataSelection.style.top = pos.y * ysize + 'px'; - dataSelection.style.height = ysize - 6 + 'px'; - - if (pos.x == 0 && pos.y == 0) { - // editor.info={idnum:0, id:'empty','images':'清除块', 'y':0}; - editor.info = 0; - } else if(pos.x == 0 && pos.y == 1){ - editor.info = editor.ids[editor.indexs[17]]; - } else { - if (autotiles[pos.images]) editor.info = {'images': pos.images, 'y': 0}; - else if (core.tilesets.indexOf(pos.images)!=-1) editor.info = {'images': pos.images, 'y': pos.y, 'x': pos.x-editor.widthsX[spriter][1]}; - else { - var y = pos.y; - if (editor.uivalues.folded) { - y += editor.foldPerCol * (pos.x-editor.widthsX[spriter][1]); - } - if (pos.images == 'terrains' && pos.x == 0) y -= 2; - editor.info = {'images': pos.images, 'y': y} - } - - for (var ii = 0; ii < editor.ids.length; ii++) { - if ((core.tilesets.indexOf(pos.images)!=-1 && editor.info.images == editor.ids[ii].images - && editor.info.y == editor.ids[ii].y && editor.info.x == editor.ids[ii].x) - || (Object.prototype.hasOwnProperty.call(autotiles, pos.images) && editor.info.images == editor.ids[ii].id - && editor.info.y == editor.ids[ii].y) - || (core.tilesets.indexOf(pos.images)==-1 && editor.info.images == editor.ids[ii].images - && editor.info.y == editor.ids[ii].y ) - ) { - - editor.info = editor.ids[ii]; - break; - } - } - } - tip.infos(JSON.parse(JSON.stringify(editor.info))); - editor_mode.onmode('nextChange'); - editor_mode.onmode('enemyitem'); - //editor_mode.enemyitem(); - } - } - } - - var midMenu=document.getElementById('midMenu'); - midMenu.oncontextmenu=function(e){e.preventDefault()} - editor.lastRightButtonPos=[{x:0,y:0},{x:0,y:0}]; - editor.lastCopyedInfo = [null, null]; - editor.showMidMenu=function(x,y){ - editor.lastRightButtonPos=JSON.parse(JSON.stringify( - [editor.pos,editor.lastRightButtonPos[0]] - )); - // --- copy - editor.lastCopyedInfo = [editor.copyFromPos(), editor.lastCopyedInfo[0]]; - var locStr='('+editor.lastRightButtonPos[1].x+','+editor.lastRightButtonPos[1].y+')'; - var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; - var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; - - // 检测是否是上下楼 - var thisevent = editor.map[editor.pos.y][editor.pos.x]; - if (thisevent.id=='upFloor') { - addFloorEvent.style.display='block'; - addFloorEvent.children[0].innerHTML='绑定上楼事件'; - } - else if (thisevent.id=='downFloor') { - addFloorEvent.style.display='block'; - addFloorEvent.children[0].innerHTML='绑定下楼事件'; - } - else if (['leftPortal','rightPortal','downPortal','upPortal'].indexOf(thisevent.id)>=0) { - addFloorEvent.style.display='block'; - addFloorEvent.children[0].innerHTML='绑定楼传事件'; - } - else addFloorEvent.style.display='none'; - - chooseThis.children[0].innerHTML='选中此点'+'('+editor.pos.x+','+editor.pos.y+')' - copyLoc.children[0].innerHTML='复制事件'+locStr+'到此处'; - moveLoc.children[0].innerHTML='交换事件'+locStr+'与此事件的位置'; - midMenu.style='top:'+(y+scrollTop)+'px;left:'+(x+scrollLeft)+'px;'; - } - editor.hideMidMenu=function(){ - if(editor.isMobile){ - setTimeout(function(){ - midMenu.style='display:none'; - },200) - } else { - midMenu.style='display:none'; - } - } - - var addFloorEvent = document.getElementById('addFloorEvent'); - addFloorEvent.onmousedown = function(e) { - editor.hideMidMenu(); - e.stopPropagation(); - var thisevent = editor.map[editor.pos.y][editor.pos.x]; - var loc = editor.pos.x+","+editor.pos.y; - if (thisevent.id=='upFloor') { - editor.currentFloorData.changeFloor[loc] = {"floorId": ":next", "stair": "downFloor"}; - } - else if (thisevent.id=='downFloor') { - editor.currentFloorData.changeFloor[loc] = {"floorId": ":before", "stair": "upFloor"}; - } - else if (thisevent.id=='leftPortal' || thisevent.id=='rightPortal') { - editor.currentFloorData.changeFloor[loc] = {"floorId": ":next", "stair": ":symmetry_x"} - } - else if (thisevent.id=='upPortal' || thisevent.id=='downPortal') { - editor.currentFloorData.changeFloor[loc] = {"floorId": ":next", "stair": ":symmetry_y"} - } - editor.file.saveFloorFile(function (err) { - if (err) { - printe(err); - throw(err) - } - editor.drawPosSelection(); - editor_mode.showMode('loc'); - printf('添加楼梯事件成功'); - }); - } - - var chooseThis = document.getElementById('chooseThis'); - chooseThis.onmousedown = function(e){ - editor.hideMidMenu(); - e.stopPropagation(); - selectBox.isSelected(false); - - editor_mode.onmode('nextChange'); - editor_mode.onmode('loc'); - //editor_mode.loc(); - //tip.whichShow(1); - if(editor.isMobile)editor.showdataarea(false); - } - - var chooseInRight = document.getElementById('chooseInRight'); - chooseInRight.onmousedown = function(e){ - editor.hideMidMenu(); - e.stopPropagation(); - var thisevent = editor[editor.layerMod][editor.pos.y][editor.pos.x]; - editor.setSelectBoxFromInfo(thisevent); - } - - var copyLoc = document.getElementById('copyLoc'); - copyLoc.onmousedown = function(e){ - editor.hideMidMenu(); - e.stopPropagation(); - editor.uivalues.preMapData = null; - editor.uivalues.reDo = null; - editor_mode.onmode(''); - var now = editor.pos, last = editor.lastRightButtonPos[1]; - if (now.x == last.x && now.y == last.y) return; - editor.pasteToPos(editor.lastCopyedInfo[1]); - editor.updateMap(); - editor.file.saveFloorFile(function (err) { - if (err) { - printe(err); - throw(err) - } - ;printf('复制事件成功'); - editor.drawPosSelection(); - }); - } - - var moveLoc = document.getElementById('moveLoc'); - moveLoc.onmousedown = function(e){ - editor.hideMidMenu(); - e.stopPropagation(); - editor.uivalues.preMapData = null; - editor.uivalues.reDo = null; - editor_mode.onmode(''); - editor.exchangePos(editor.pos, editor.lastRightButtonPos[1]); - } - - var clearEvent = document.getElementById('clearEvent'); - clearEvent.onmousedown = function (e) { - e.stopPropagation(); - editor.uivalues.reDo = null; - editor.clearPos(false); - } - - var clearLoc = document.getElementById('clearLoc'); - clearLoc.onmousedown = function(e){ - e.stopPropagation(); - editor.uivalues.reDo = null; - editor.clearPos(true); - } - - var brushMod=document.getElementById('brushMod'); - brushMod.onchange=function(){ - editor.brushMod=brushMod.value; - } - - var brushMod2=document.getElementById('brushMod2'); - if(brushMod2)brushMod2.onchange=function(){ - editor.brushMod=brushMod2.value; - } - - var brushMod3=document.getElementById('brushMod3'); - if(brushMod3) { - brushMod3.onchange=function(){ - // tip.showHelp(5) - tip.isSelectedBlock(false) - tip.msgs[11] = String('tileset贴图模式下可以按选中tileset素材,并在地图上拖动来一次绘制一个区域'); - tip.whichShow(12); - editor.brushMod=brushMod3.value; - } - } - - var bgc = document.getElementById('bg'), fgc = document.getElementById('fg'), - evc = document.getElementById('event'), ev2c = document.getElementById('event2'); - - var layerMod=document.getElementById('layerMod'); - layerMod.onchange=function(){ - editor.layerMod=layerMod.value; - [bgc,fgc,evc,ev2c].forEach(function (x) { - x.style.opacity = 1; - }); - - // 手机端.... - if (editor.isMobile) { - if (layerMod.value == 'bgmap') { - [fgc,evc,ev2c].forEach(function (x) { - x.style.opacity = 0.3; - }); - } - if (layerMod.value == 'fgmap') { - [bgc,evc,ev2c].forEach(function (x) { - x.style.opacity = 0.3; - }); - } - } - } - - var layerMod2=document.getElementById('layerMod2'); - if(layerMod2)layerMod2.onchange=function(){ - editor.layerMod=layerMod2.value; - [fgc,evc,ev2c].forEach(function (x) { - x.style.opacity = 0.3; - }); - bgc.style.opacity = 1; - } - - var layerMod3=document.getElementById('layerMod3'); - if(layerMod3)layerMod3.onchange=function(){ - editor.layerMod=layerMod3.value; - [bgc,evc,ev2c].forEach(function (x) { - x.style.opacity = 0.3; - }); - fgc.style.opacity = 1; - } - - var viewportButtons=document.getElementById('viewportButtons'); - var pressTimer = null; - for(var ii=0,node;node=viewportButtons.children[ii];ii++){ - (function(x,y){ - var move = function () { - editor.moveViewport(x, y); - } - node.onmousedown = function () { - clearTimeout(pressTimer); - pressTimer = setTimeout(function () { - pressTimer = -1; - var f = function () { - if (pressTimer != null) { - move(); - setTimeout(f, 150); - } - } - f(); - }, 500); - }; - node.onmouseup = function () { - if (pressTimer > 0) { - clearTimeout(pressTimer); - move(); - } - pressTimer = null; - } - })([-1,0,0,1][ii],[0,-1,1,0][ii]); - } -} - -editor.constructor.prototype.mobile_listen=function () { - if(!editor.isMobile)return; - - var mobileview=document.getElementById('mobileview'); - var editModeSelect=document.getElementById('editModeSelect'); - var mid=document.getElementById('mid'); - var right=document.getElementById('right'); - var mobileeditdata=document.getElementById('mobileeditdata'); - - - editor.showdataarea=function(callShowMode){ - mid.style='z-index:-1;opacity: 0;'; - right.style='z-index:-1;opacity: 0;'; - mobileeditdata.style=''; - if(callShowMode)editor.mode.showMode(editModeSelect.value); - editor.hideMidMenu(); - } - mobileview.children[0].onclick=function(){ - editor.showdataarea(true) - } - mobileview.children[1].onclick=function(){ - mid.style=''; - right.style='z-index:-1;opacity: 0;'; - mobileeditdata.style='z-index:-1;opacity: 0;'; - editor.lastClickId=''; - } - mobileview.children[3].onclick=function(){ - mid.style='z-index:-1;opacity: 0;'; - right.style=''; - mobileeditdata.style='z-index:-1;opacity: 0;'; - editor.lastClickId=''; - } - - - var gettrbyid=function(){ - if(!editor.lastClickId)return false; - thisTr = document.getElementById(editor.lastClickId); - input = thisTr.children[2].children[0].children[0]; - field = thisTr.children[0].getAttribute('title'); - cobj = JSON.parse(thisTr.children[1].getAttribute('cobj')); - return [thisTr,input,field,cobj]; - } - mobileeditdata.children[0].onclick=function(){ - var info = gettrbyid() - if(!info)return; - info[1].ondblclick() - } - mobileeditdata.children[1].onclick=function(){ - var info = gettrbyid() - if(!info)return; - printf(info[2]) - } - mobileeditdata.children[2].onclick=function(){ - var info = gettrbyid() - if(!info)return; - printf(info[0].children[1].getAttribute('title')) - } - - //===== - - document.body.ontouchstart=document.body.onmousedown; - document.body.onmousedown=null; - - editor.dom.eui.ontouchstart=editor.dom.eui.onmousedown - editor.dom.eui.onmousedown=null - editor.dom.eui.ontouchmove=editor.dom.eui.onmousemove - editor.dom.eui.onmousemove=null - editor.dom.eui.ontouchend=editor.dom.eui.onmouseup - editor.dom.eui.onmouseup=null - - - var chooseThis = document.getElementById('chooseThis'); - chooseThis.ontouchstart=chooseThis.onmousedown - chooseThis.onmousedown=null - var chooseInRight = document.getElementById('chooseInRight'); - chooseInRight.ontouchstart=chooseInRight.onmousedown - chooseInRight.onmousedown=null - var copyLoc = document.getElementById('copyLoc'); - copyLoc.ontouchstart=copyLoc.onmousedown - copyLoc.onmousedown=null - var moveLoc = document.getElementById('moveLoc'); - moveLoc.ontouchstart=moveLoc.onmousedown - moveLoc.onmousedown=null - var clearLoc = document.getElementById('clearLoc'); - clearLoc.ontouchstart=clearLoc.onmousedown - clearLoc.onmousedown=null -} - -} \ No newline at end of file diff --git a/_server/editor_unsorted_3.js b/_server/editor_unsorted_3.js index 7f1d0edc..32cdcf20 100644 --- a/_server/editor_unsorted_3.js +++ b/_server/editor_unsorted_3.js @@ -361,7 +361,6 @@ tip.whichShow=function(value){ return tip._whichShow } selectBox=document.getElementById('selectBox') -dataSelection=document.getElementById('dataSelection') selectBox._isSelected=false selectBox.isSelected=function(value){ if(value!=null){ @@ -369,7 +368,7 @@ selectBox.isSelected=function(value){ tip.isSelectedBlock(value); tip.whichShow(0); clearTimeout(tip.timer); - dataSelection.style.display=value?'':'none' + editor.dom.dataSelection.style.display=value?'':'none' } return selectBox._isSelected } diff --git a/_server/editor_util.js b/_server/editor_util.js index 6f81a8c1..beb437db 100644 --- a/_server/editor_util.js +++ b/_server/editor_util.js @@ -161,10 +161,10 @@ editor_util_wrapper = function (editor) { return val != null && !(typeof val == 'number' && isNaN(val)); } - editor_util.prototype.checkCallback=function(callback){ + editor_util.prototype.checkCallback = function (callback) { if (!editor.util.isset(callback)) { editor.printe('未设置callback'); - throw('未设置callback') + throw ('未设置callback') } } diff --git a/editor-mobile.html b/editor-mobile.html index acbe0d1b..f849cb7e 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -573,7 +573,7 @@ - + diff --git a/editor.html b/editor.html index adc23948..119fc2af 100644 --- a/editor.html +++ b/editor.html @@ -558,7 +558,7 @@ - +