diff --git a/_server/css/editor.css b/_server/css/editor.css index 83b262bd..cc930a64 100644 --- a/_server/css/editor.css +++ b/_server/css/editor.css @@ -178,7 +178,12 @@ body { border: 1px solid #ccc; border-radius: 2px; font-size: 15px; - line-height: 14px; + line-height: 18px; +} + +#tip p { + margin-top: 10px; + margin-bottom: 10px; } .files { diff --git a/_server/css/editor_mobile.css b/_server/css/editor_mobile.css index 6dfaa651..a222d029 100644 --- a/_server/css/editor_mobile.css +++ b/_server/css/editor_mobile.css @@ -153,7 +153,7 @@ body { border: 1px solid #ccc; border-radius: 2px; font-size: 1rem; - line-height: 0.93rem; + line-height: 1.2rem; } #tip p{ diff --git a/_server/editor.js b/_server/editor.js index ac96b53b..620fa1a5 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -232,7 +232,6 @@ editor.prototype.init = function (callback) { if (Boolean(callback)) callback(); } - } @@ -410,6 +409,7 @@ editor.prototype.updateMap = function () { } // 绘制地图 end + editor.drawEventBlock(); this.updateLastUsedMap(); } @@ -691,7 +691,7 @@ editor.prototype.setSelectBoxFromInfo=function(thisevent, scrollTo){ editor.updateLastUsedMap(); }); editor.info = JSON.parse(JSON.stringify(thisevent)); - tip.infos(JSON.parse(JSON.stringify(thisevent))); + editor.uifunctions.showBlockInfo(JSON.parse(JSON.stringify(thisevent))); editor.pos=pos; editor_mode.onmode('nextChange'); editor_mode.onmode('enemyitem'); diff --git a/_server/editor_datapanel.js b/_server/editor_datapanel.js index 52ba9422..ac110b90 100644 --- a/_server/editor_datapanel.js +++ b/_server/editor_datapanel.js @@ -6,118 +6,18 @@ editor_datapanel_wrapper = function (editor) { //////////////////// 地图编辑 ////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// - // 由于历史遗留原因, 以下变量作为全局变量使用 - // pout exportMap mapEditArea mapEditArea copyMap clearMapButton deleteMap - window.pout = document.getElementById('pout') - window.exportMap = document.getElementById('exportMap') - exportMap.isExport=false - exportMap.onclick=function(){ - editor.updateMap(); - var sx=editor.map.length-1,sy=editor.map[0].length-1; + var pout = document.getElementById('pout'); + var exportMap = document.getElementById('exportMap'); + var importMap = document.getElementById('importMap'); + var clearMapButton=document.getElementById('clearMapButton') + var deleteMap=document.getElementById('deleteMap') - var filestr = ''; - for (var yy = 0; yy <= sy; yy++) { - filestr += '[' - for (var xx = 0; xx <= sx; xx++) { - var mapxy = editor.map[yy][xx]; - if (typeof(mapxy) == typeof({})) { - if ('idnum' in mapxy) mapxy = mapxy.idnum; - else { - // mapxy='!!?'; - tip.whichShow(3); - return; - } - } else if (typeof(mapxy) == 'undefined') { - tip.whichShow(3); - return; - } - mapxy = String(mapxy); - mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy; - filestr += mapxy + (xx == sx ? '' : ',') - } - - filestr += ']' + (yy == sy ? '' : ',\n'); - } - pout.value = filestr; - mapEditArea.mapArr(filestr); - exportMap.isExport = true; - mapEditArea.error(0); - tip.whichShow(2); - } - window.mapEditArea = document.getElementById('mapEditArea') - mapEditArea.errors=[ // 编号1,2 - "格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)", - "当前有未定义ID(在地图区域显示红块),请修改ID或者到icons.js和maps.js中进行定义!" - ] - mapEditArea.formatTimer=null - mapEditArea._mapArr='' - mapEditArea.mapArr=function(value){ - if(value!=null){ - var val=value - var oldval=mapEditArea._mapArr - if (val==oldval) return; - - if (exportMap.isExport) { - exportMap.isExport = false; - return; - } - if (mapEditArea.formatArr()) { - mapEditArea.error(0); - - setTimeout(function () { - if (mapEditArea.formatArr())mapEditArea.mapArr(mapEditArea.formatArr()); - mapEditArea.drawMap(); - tip.whichShow(8) - }, 1000); - clearTimeout(mapEditArea.formatTimer); - mapEditArea.formatTimer = setTimeout(function () { - pout.value = mapEditArea.formatArr(); - }, 5000); //5s后再格式化,不然光标跳到最后很烦 - } else { - mapEditArea.error(1); - } - - mapEditArea._mapArr=value - } - return mapEditArea._mapArr - } - pout.oninput=function(){ - mapEditArea.mapArr(pout.value) - } - mapEditArea._error=0 - mapEditArea.error=function(value){ - if(value!=null){ - mapEditArea._error=value - if (value>0) - printe(mapEditArea.errors[value-1]) - } - return mapEditArea._error - } - mapEditArea.drawMap= function () { - // var mapArray = mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' '); - var mapArray = JSON.parse('[' + mapEditArea.mapArr() + ']'); - var sy=editor.map.length,sx=editor.map[0].length; - for (var y = 0; y < sy; y++) - for (var x = 0; x < sx; x++) { - var num = mapArray[y][x]; - if (num == 0) - editor.map[y][x] = 0; - else if (typeof(editor.indexs[num][0]) == 'undefined') { - mapEditArea.error(2); - editor.map[y][x] = undefined; - } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; - } - - editor.updateMap(); - - } - mapEditArea.formatArr= function () { + var formatArr= function () { var formatArrStr = ''; - console.log(1) var si=editor.map.length,sk=editor.map[0].length; - if (mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; - var arr = mapEditArea.mapArr().replace(/\s+/g, '').split('],['); + if (pout.value.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; + var arr = pout.value.replace(/\s+/g, '').split('],['); if (arr.length != si) return; for (var i = 0; i < si; i++) { @@ -138,31 +38,71 @@ editor_datapanel_wrapper = function (editor) { } return formatArrStr; } - window.copyMap=document.getElementById('copyMap') - copyMap.err='' - copyMap.onclick=function(){ - tip.whichShow(0); - if (pout.value.trim() != '') { - if (mapEditArea.error()) { - copyMap.err = mapEditArea.errors[mapEditArea.error() - 1]; - tip.whichShow(5) - return; - } - try { - pout.focus(); - pout.setSelectionRange(0, pout.value.length); - document.execCommand("Copy"); - tip.whichShow(6); - } catch (e) { - copyMap.err = e; - tip.whichShow(5); + + exportMap.onclick=function(){ + editor.updateMap(); + var sx=editor.map.length-1,sy=editor.map[0].length-1; + + var filestr = ''; + for (var yy = 0; yy <= sy; yy++) { + filestr += '[' + for (var xx = 0; xx <= sx; xx++) { + var mapxy = editor.map[yy][xx]; + if (typeof(mapxy) == typeof({})) { + if ('idnum' in mapxy) mapxy = mapxy.idnum; + else { + printe("生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!"); + return; + } + } else if (typeof(mapxy) == 'undefined') { + printe("生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!"); + return; + } + mapxy = String(mapxy); + mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy; + filestr += mapxy + (xx == sx ? '' : ',') } + + filestr += ']' + (yy == sy ? '' : ',\n'); + } + pout.value = filestr; + if (formatArr()) { + pout.focus(); + pout.setSelectionRange(0, pout.value.length); + document.execCommand("Copy"); + printf("导出并复制成功!"); } else { - tip.whichShow(7); + printe("无法导出并复制此地图,可能有不合法块。") } } - window.clearMapButton=document.getElementById('clearMapButton') + importMap.onclick= function () { + var sy=editor.map.length,sx=editor.map[0].length; + var mapArray; + try { + mapArray = JSON.parse('[' + pout.value + ']'); + if (mapArray.length != sy || mapArray[0].length != sx) throw ''; + } catch (e) { + printe('格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)'); + return; + } + var hasError = false; + for (var y = 0; y < sy; y++) + for (var x = 0; x < sx; x++) { + var num = mapArray[y][x]; + if (num == 0) + editor.map[y][x] = 0; + else if (editor.indexs[num]==null || editor.indexs[num][0]==null) { + printe('当前有未定义ID(在地图区域显示红块),请用有效的图块进行覆盖!') + hasError = true; + editor.map[y][x] = {}; + } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; + } + editor.updateMap(); + if (!hasError) printf('地图导入成功!'); + } + clearMapButton.onclick=function () { + if (!confirm('你确定要清除地图上所有内容么?此过程不可逆!')) return; editor.mapInit(); editor_mode.onmode(''); editor.file.saveFloorFile(function (err) { @@ -173,15 +113,10 @@ editor_datapanel_wrapper = function (editor) { ;printf('地图清除成功'); }); editor.updateMap(); - clearTimeout(mapEditArea.formatTimer); - clearTimeout(tip.timer); - pout.value = ''; - mapEditArea.mapArr(''); - tip.whichShow(4); - mapEditArea.error(0); } - window.deleteMap=document.getElementById('deleteMap') + deleteMap.onclick=function () { + if (!confirm('你确定要删除此地图么?此过程不可逆!')) return; editor_mode.onmode(''); var index = core.floorIds.indexOf(editor.currentFloorId); if (index>=0) { @@ -197,7 +132,6 @@ editor_datapanel_wrapper = function (editor) { else printe('删除成功,请F5刷新编辑器生效'); } - editor.uifunctions.newMap_func = function () { var newMap = document.getElementById('newMap'); diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index 86a894c0..3be66b64 100644 --- a/_server/editor_mappanel.js +++ b/_server/editor_mappanel.js @@ -99,8 +99,7 @@ editor_mappanel_wrapper = function (editor) { editor_mode.onmode('nextChange'); editor_mode.onmode('loc'); //editor_mode.loc(); - //tip.whichShow(1); - tip.showHelp(6); + editor.uifunctions.showTips(6); editor.uivalues.startPos = pos; editor.dom.euiCtx.strokeStyle = '#FF0000'; editor.dom.euiCtx.lineWidth = 3; @@ -127,7 +126,6 @@ editor_mappanel_wrapper = function (editor) { editor.uivalues.lastMoveE=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); if (editor.uivalues.endPos != null && editor.uivalues.endPos.x == pos.x && editor.uivalues.endPos.y == pos.y) return; @@ -163,8 +161,6 @@ editor_mappanel_wrapper = function (editor) { // editor_mode.onmode('nextChange'); // editor_mode.onmode('loc'); //editor_mode.loc(); - //tip.whichShow(1); - // tip.showHelp(6); return false; } @@ -230,7 +226,6 @@ editor_mappanel_wrapper = function (editor) { // 后续的处理 } else { // 左键拖拽: 交换 - //tip.whichShow(1); // editor.movePos(editor.uivalues.startPos, editor.uivalues.endPos); editor.exchangePos(editor.uivalues.startPos, editor.uivalues.endPos); editor.uifunctions.unhighlightSaveFloorButton(); @@ -585,7 +580,6 @@ editor_mappanel_wrapper = function (editor) { editor_mode.onmode('nextChange'); editor_mode.onmode('loc'); //editor_mode.loc(); - //tip.whichShow(1); if (editor.isMobile) editor.showdataarea(false); return false; } @@ -679,8 +673,7 @@ editor_mappanel_wrapper = function (editor) { * 点击【】 */ editor.uifunctions.lockMode_onchange = function () { - tip.msgs[11] = String('锁定模式开启下将不再点击空白处自动保存,请谨慎操作。'); - tip.whichShow(12); + printf('锁定模式开启下将不再点击空白处自动保存,请谨慎操作。'); editor.uivalues.lockMode = editor.dom.lockMode.checked; } @@ -691,9 +684,7 @@ editor_mappanel_wrapper = function (editor) { editor.uifunctions.brushMod_onchange = function () { editor.brushMod = editor.dom.brushMod.value; if (editor.brushMod == 'fill') { - tip.isSelectedBlock(false); - tip.msgs[11] = String('填充模式下,将会用选中的素材替换所有和目标点联通的相同素材'); - tip.whichShow(12); + printf('填充模式下,将会用选中的素材替换所有和目标点联通的相同素材'); } } @@ -714,17 +705,12 @@ editor_mappanel_wrapper = function (editor) { !confirm("从V2.7开始,请直接素材区拖框进行绘制区域。\n\n点取消将不再显示此提示。")) { editor.config.set('alertTileModeV2.7', true); } - // tip.showHelp(5) - tip.isSelectedBlock(false) - tip.msgs[11] = String('tileset平铺模式下可以按选中tileset素材,并在地图上拖动来一次绘制一个区域'); - tip.whichShow(12); + printf('tileset平铺模式下可以按选中tileset素材,并在地图上拖动来一次绘制一个区域'); editor.brushMod = editor.dom.brushMod3.value; } editor.uifunctions.brushMod4_onchange = function () { - tip.isSelectedBlock(false); - tip.msgs[11] = String('填充模式下,将会用选中的素材替换所有和目标点联通的相同素材'); - tip.whichShow(12); + printf('填充模式下,将会用选中的素材替换所有和目标点联通的相同素材'); editor.brushMod = editor.dom.brushMod4.value; } diff --git a/_server/editor_materialpanel.js b/_server/editor_materialpanel.js index d7607b82..d524566e 100644 --- a/_server/editor_materialpanel.js +++ b/_server/editor_materialpanel.js @@ -8,9 +8,6 @@ editor_materialpanel_wrapper = function (editor) { selectBox.isSelected=function(value){ if(value!=null){ selectBox._isSelected=value; - tip.isSelectedBlock(value); - tip.whichShow(0); - clearTimeout(tip.timer); editor.dom.dataSelection.style.display=value?'':'none' } return selectBox._isSelected @@ -230,7 +227,7 @@ editor_materialpanel_wrapper = function (editor) { } } - tip.infos(JSON.parse(JSON.stringify(editor.info))); + editor.uifunctions.showBlockInfo(JSON.parse(JSON.stringify(editor.info))); editor_mode.onmode('nextChange'); editor_mode.onmode('enemyitem'); editor.updateLastUsedMap(); diff --git a/_server/editor_mode.js b/_server/editor_mode.js index 7ebc5b95..e072844a 100644 --- a/_server/editor_mode.js +++ b/_server/editor_mode.js @@ -128,7 +128,7 @@ editor_mode = function (editor) { editor.drawEventBlock(); if (editor_mode[mode]) editor_mode[mode](); editor.dom.editModeSelect.value = mode; - if (!selectBox.isSelected()) tip.showHelp(); + if (!selectBox.isSelected()) editor.uifunctions.showTips(); } editor_mode.prototype.change = function (value) { diff --git a/_server/editor_ui.js b/_server/editor_ui.js index 99f01747..89baaebf 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -1,29 +1,46 @@ editor_ui_wrapper = function (editor) { - // 由于历史遗留原因, 以下变量作为全局变量使用 - // printf printe tip - window.printf = function (str_, type) { - selectBox.isSelected(false); - if (!type) { - tip.whichShow(11); - } else { - tip.whichShow(12); + var tip=document.getElementById('tip'); + var print = function (msg, cls) { + if (msg == '') { + tip.innerHTML = ''; + return; } - setTimeout(function () { - if (!type) { - tip.msgs[11] = String(str_); - tip.whichShow(12); - } else { - tip.msgs[10] = String(str_); - tip.whichShow(11); - } - }, 1); + tip.innerHTML = '

' + msg + "

"; } - window.printe = function (str_) { - printf(str_, 'error') + + window.printf = function (msg) { + selectBox.isSelected(false); + print(msg, 'successText'); } - window.tip=document.getElementById('tip') - tip.showHelp = function(value) { + window.printe = function (msg) { + selectBox.isSelected(false); + print(msg, 'warnText'); + } + window.printi = function (msg) { + print(msg, 'infoText'); + } + + editor.uifunctions.showBlockInfo = function (value) { + if (value == 0) { + printi("当前选择为清除块,可擦除地图上块"); + return; + } + var hasId = 'id' in value; + if (hasId && value.idnum == 17) { + printi("当前选择为空气墙, 在编辑器中可视, 在游戏中隐藏的墙, 用来配合前景/背景的贴图"); + return; + } + var isAutotile = hasId && value.images == "autotile"; + tip.innerHTML = (hasId?`

图块编号:${ value['idnum'] }

+

图块ID:${ value['id'] }

`:` +

该图块无对应的数字或ID存在,请先前往icons.js和maps.js中进行定义!

`)+` +

图块所在素材:${ value['images'] + (isAutotile ? '( '+value['id']+' )' : '') } +

+

图块索引:${ value['y'] }

`; + } + + editor.uifunctions.showTips = function (value) { var tips = [ '表格的文本域可以双击进行编辑', '双击地图可以选中素材,右键可以弹出菜单', @@ -37,147 +54,6 @@ editor_ui_wrapper = function (editor) { if (value == null) value = Math.floor(Math.random() * tips.length); printf('tips: ' + tips[value]) } - tip._infos= {} - tip.infos=function(value){ - if(value!=null){ - var val=value - var oldval=tip._infos - - tip.isClearBlock(false); - tip.isAirwall(false); - if (typeof(val) != 'undefined') { - if (val == 0) { - tip.isClearBlock(true); - return; - } - if ('id' in val) { - if (val.idnum == 17) { - tip.isAirwall(true); - return; - } - tip.hasId = true; - } else { - tip.hasId = false; - } - tip.isAutotile = false; - if (val.images == "autotile" && tip.hasId) tip.isAutotile = true; - document.getElementById('isAirwall-else').innerHTML=(tip.hasId?`

图块编号:${ value['idnum'] }

-

图块ID:${ value['id'] }

`:` -

该图块无对应的数字或ID存在,请先前往icons.js和maps.js中进行定义!

`)+` -

图块所在素材:${ value['images'] + (tip.isAutotile ? '( '+value['id']+' )' : '') } -

-

图块索引:${ value['y'] }

` - } - - tip._infos=value - } - return tip._infos - } - tip.hasId= true - tip.isAutotile= false - tip._isSelectedBlock= false - tip.isSelectedBlock=function(value){ - if(value!=null){ - var dshow=document.getElementById('isSelectedBlock-if') - var dhide=document.getElementById('isSelectedBlock-else') - if(!value){ - var dtemp=dshow - dshow=dhide - dhide=dtemp - } - dshow.style.display='' - dhide.style.display='none' - tip._isSelectedBlock=value - } - return tip._isSelectedBlock - } - tip._isClearBlock= false - tip.isClearBlock=function(value){ - if(value!=null){ - var dshow=document.getElementById('isClearBlock-if') - var dhide=document.getElementById('isClearBlock-else') - if(!value){ - var dtemp=dshow - dshow=dhide - dhide=dtemp - } - dshow.style.display='' - dhide.style.display='none' - tip._isClearBlock=value - } - return tip._isClearBlock - } - tip._isAirwall= false - tip.isAirwall=function(value){ - if(value!=null){ - var dshow=document.getElementById('isAirwall-if') - var dhide=document.getElementById('isAirwall-else') - if(!value){ - var dtemp=dshow - dshow=dhide - dhide=dtemp - } - dshow.style.display='' - dhide.style.display='none' - tip._isAirwall=value - } - return tip._isAirwall - } - tip.geneMapSuccess= false - tip.timer= null - tip.msgs= [ //分别编号1,2,3,4,5,6,7,8,9,10;奇数警告,偶数成功 - "当前未选择任何图块,请先在右边选择要画的图块!", - "生成地图成功!可点击复制按钮复制地图数组到剪切板", - "生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!", - "地图清除成功!", - "复制失败!", - "复制成功!可直接粘贴到楼层文件的地图数组中。", - "复制失败!当前还没有数据", - "修改成功!可点击复制按钮复制地图数组到剪切板", - "选择背景图片失败!文件名格式错误或图片不存在!", - "更新背景图片成功!", - "11:警告", - "12:成功" - ] - tip._mapMsg= '' - tip.mapMsg=function(value){ - if(value!=null){ - document.getElementById('whichShow-if').innerText=value - tip._mapMsg=value - } - return tip._mapMsg - } - tip._whichShow= 0 - tip.whichShow=function(value){ - if(value!=null){ - - var dshow=document.getElementById('whichShow-if') - var dhide=null - if(!value){ - var dtemp=dshow - dshow=dhide - dhide=dtemp - } - if(dshow)dshow.style.display='' - if(dhide)dhide.style.display='none' - - if(dshow)dshow.setAttribute('class',(value%2) ? 'warnText' : 'successText') - - tip.mapMsg(''); - tip.msgs[4] = "复制失败!" + editTip.err; - clearTimeout(tip.timer); - if (value) { - tip.mapMsg(tip.msgs[value - 1]); - tip.timer = setTimeout(function () { - if (!(value % 2)) - value = 0; - }, 5000); //5秒后自动清除success,warn不清除 - } - tip._whichShow=value - } - return tip._whichShow - } - /** * 根据鼠标点击, 得到从元素向上到body的所有id diff --git a/editor-mobile.html b/editor-mobile.html index 60895ee4..e4e15e70 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -37,8 +37,8 @@
- - + +
@@ -325,19 +325,7 @@
-
- -
- -
-
- +
diff --git a/editor.html b/editor.html index 6e59f8c2..3919614e 100644 --- a/editor.html +++ b/editor.html @@ -35,8 +35,8 @@ 保留楼层属性
- - + +
@@ -301,20 +301,7 @@
-
- -
- -
-
- - +