Merge pull request #16 from i2Echo/master

update gui
This commit is contained in:
Zhang Chen 2017-12-22 00:35:17 +08:00 committed by GitHub
commit e7047d641b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 262 additions and 156 deletions

6
_server/vendor/vue.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -22,29 +22,10 @@
position: absolute; position: absolute;
left: 5px; left: 5px;
top: 10px; top: 10px;
width: 430px; width: 435px;
height: 400px; height: 400px;
/* border: 1px solid rgb(238, 13, 13); */
} }
#left span{
display: block;
position: absolute;
color: red;
}
#left .col{
top: 2px;
left: 20px;
font-size: 13px;
color: blue;
}
#left .row{
width: 10px;
left: 0px;
top: 25px;
font-size: 13px;
text-align: right;
}
#editArea{ #editArea{
position: absolute; position: absolute;
width: 100%; width: 100%;
@ -56,44 +37,54 @@
} }
#pout{ #pout{
display: block; display: block;
width: 408px; width: 410px;
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
margin-left: 15px; margin-left: 22px;
margin-top: 20px; margin-top: 21px;
line-height: 20px;
} }
#editTip{ #editTip{
position: absolute; position: absolute;
width: 50%; width: 100%;
height: 80px; height: 80px;
bottom:10px; bottom:10px;
right: 10px; left: 10px;
} }
#editTip p{ #editArea p{
margin: 10px 0; margin: 10px;
/* display: block; */ display: block;
line-height: 30px; width: 70%;
text-align: right; line-height: 20px;
text-align: left;
font-size: 14px; font-size: 14px;
} }
#editTip .btn{ #editTip .btn{
margin-left: 60%; float: right;
margin-top: 0; margin-right: 20px;
margin-top: 5px;
} }
#mid{ #mid{
position: absolute; position: absolute;
left: 448px; left: 448px;
top: 0; top: 10px;
width: 440px;
height: 630px;
}
.map {
position: absolute;
left: 20px;
top: 21px;
width: 416px; width: 416px;
height: 620px; height: 416px;
/* border: 1px solid rgb(238, 13, 13); */
} }
#mid .tools{ #mid .tools{
position: absolute; position: absolute;
width: 400px; width: 425px;
height: 195px; height: 180px;
left: 0; left: 0;
top: 425px; bottom: 0;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
padding: 10px 5px; padding: 10px 5px;
margin-left: 8px;; margin-left: 8px;;
@ -103,8 +94,8 @@
float: right; float: right;
width: 50%; width: 50%;
height: 95%; height: 95%;
padding: 10px; padding: 5px 10px 10px 10px;
margin-right: 5px; margin-right: 0;
box-sizing: border-box; box-sizing: border-box;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 2px; border-radius: 2px;
@ -143,9 +134,9 @@
padding: 0 5px; padding: 0 5px;
display: inline-block; display: inline-block;
font-size: 11px; font-size: 14px;
font-weight: 400; font-weight: 400;
text-transform: uppercase; /* text-transform: uppercase; */
letter-spacing: 0; letter-spacing: 0;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: pointer;
@ -164,11 +155,18 @@
} }
#right{ #right{
position: absolute; position: absolute;
left: 896px; left: 900px;
top: 0; top: 10px;
width: 450px; width: 440px;
height: 620px; height: 630px;
/* border: 1px solid rgb(238, 13, 13); */ /* border: 1px solid rgb(238, 13, 13); */
}
#iconLib{
position: absolute;
width: 435px;
height: 620px;
left: 5px;
top: 5px;
overflow:auto; overflow:auto;
} }
.gameCanvas { .gameCanvas {
@ -176,8 +174,8 @@
} }
#dataSelection{ #dataSelection{
position: absolute; position: absolute;
top:0; /* top:0;
left:320px; left:320px; */
z-index:75; z-index:75;
width:32px;height:32px; width:32px;height:32px;
@ -192,6 +190,7 @@
.warnText{ .warnText{
color: #D50000; color: #D50000;
font-weight: 700; font-weight: 700;
font-size: 14px;
} }
.infoText{ .infoText{
color: #2196F3; color: #2196F3;
@ -200,6 +199,65 @@
color: #00897B color: #00897B
} }
table, td {
border: 1px solid #fff;
color: #fff;
}
table.col{
position: relative;
text-align: center;
border-collapse: collapse;
}
table.col td{
background-color: #4DB6AC;
}
#arrColMark td{
width: 16px;
}
#arrColMark {
top: 2px;
left: 36px;
width: 385px;
height: 16px;
font-size: 13px;
}
#mapColMark {
top: 2px;
left: 19px;
width: 418px;
height: 16px;
font-size: 13px;
}
#mapColMark td{
width: 29px;
}
table.row{
position: relative;
text-align: right;
vertical-align:middle;
border-collapse: collapse;
}
table.row td{
background-color: #795548;
}
#arrRowMark{
top: 5px;
left: 2px;
width: 16px;
height: 262px;
font-size: 12px;
}
#mapRowMark{
top: 1px;
left: 2px;
width: 16px;
height: 416px;
font-size: 12px;
}
#mapRowMark td{
height: 29px;
}
/* for vue dom */ /* for vue dom */
[v-cloak] { [v-cloak] {
display: none !important; display: none !important;
@ -209,25 +267,24 @@
<body> <body>
<div class="main"> <div class="main">
<div id="left"> <div id="left">
<div id="editArea"> <table class="col" id='arrColMark'></table>
<span class="col" id='numMark'></span> <table class="row" id='arrRowMark'></table>
<span class="row">0 1 2 3 4 5 6 7 8 9 10 11 12</span> <div id="editArea" v-cloak>
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea>
<p class="warnText" v-cloak>{{ errormsg }}</p> <p class="warnText" v-if="error">{{ errors[error-1] }}</p>
</div> </div>
<div id="editTip" v-cloak> <div id="editTip" v-cloak>
<input class='btn' type="button" value="copyMap" v-on:click="copyMap"/> <input class='btn' type="button" value="复制地图" v-on:click="copyMap"/>
<!-- <p v-bind:class="[ hasError ? 'warnText' : 'infoText']" v-show="isShow">{{ message }}</p> -->
</div> </div>
</div> </div>
<div id="mid"> <div id="mid">
<div class="map"> <table class="col" id='mapColMark'></table>
<table class="row" id='mapRowMark'></table>
<div class="map" id="mapEdit">
<canvas class='gameCanvas' id='bg' width='416' height='416' style='z-index:1'></canvas> <canvas class='gameCanvas' id='bg' width='416' height='416' style='z-index:1'></canvas>
<canvas class='gameCanvas' id='eventLayer' width='416' height='416' style='z-index:2'></canvas> <canvas class='gameCanvas' id='eventLayer' width='416' height='416' style='z-index:2'></canvas>
<canvas class='gameCanvas' id='ui' width='416' height='416' style='z-index:100'></canvas> <canvas class='gameCanvas' id='ui' width='416' height='416' style='z-index:100'></canvas>
</div> </div>
<div class="tools"> <div class="tools">
<div id="tip" v-cloak > <div id="tip" v-cloak >
@ -242,8 +299,8 @@
<p v-if="whichShow" v-bind:class="[ (whichShow%2) ? 'warnText' : 'successText']" >{{ mapMsg }}</p> <p v-if="whichShow" v-bind:class="[ (whichShow%2) ? 'warnText' : 'successText']" >{{ mapMsg }}</p>
</div> </div>
</div> </div>
<input class='btn' id='clear' type="button" value="clearMap" v-on:click="clearMap"/> <input class='btn' id='clear' type="button" value="清除地图" v-on:click="clearMap"/>
<input class='btn' type="button" value="exportMap" id="exportM" v-on:click="exportMap"/> <input class='btn' type="button" value="导出地图" id="exportM" v-on:click="exportMap"/>
<div class="files"> <div class="files">
<input class='btn' type="button" value="read" onclick="readUTF8file(pin.value)" /> <input class='btn' type="button" value="read" onclick="readUTF8file(pin.value)" />
@ -255,7 +312,9 @@
</div> </div>
</div> </div>
<div id="right"> <div id="right">
<canvas class='gameCanvas' id='data' width='416' height='416' style='z-index:0'></canvas> <div id="iconLib">
<canvas class='gameCanvas' id='data' width='416' height='416' style='z-index:0'></canvas>
</div>
<div id="selectBox"> <div id="selectBox">
<div id='dataSelection' v-show="isSelected"></div> <div id='dataSelection' v-show="isSelected"></div>
</div> </div>
@ -267,8 +326,8 @@
<script>main={'instance':{}}</script> <script>main={'instance':{}}</script>
<script src='libs/icons.js'></script> <script src='libs/icons.js'></script>
<script src='libs/maps.js'></script> <script src='libs/maps.js'></script>
<!-- <script src='ibs/vendor/vue.min.js'></script> --> <script src='_server/vendor/vue.min.js'></script>
<script src="https://unpkg.com/vue"></script> <!-- <script src="https://unpkg.com/vue"></script> -->
<script> <script>
main.instance.icons.init();//不知道为什么,需要手动init,明明maps是正常的 main.instance.icons.init();//不知道为什么,需要手动init,明明maps是正常的
icons=main.instance.icons.getIcons(); icons=main.instance.icons.getIcons();
@ -301,14 +360,21 @@
} }
} }
// 生成数组定位编号 // 生成定位编号
var str = ' '; var colNum = ' ';
for(var i=0; i<13; i++){ for(var i=0; i<13; i++){
var strNum = String(i); var tpl = '<td>'+i+'</td>';
str += Array(8-strNum.length).join('&nbsp;') + strNum; colNum += tpl;
} }
numMark.innerHTML = str; arrColMark.innerHTML = '<tr>'+colNum+'</tr>';
mapColMark.innerHTML = '<tr>'+colNum+'</tr>';
var rowNum = ' ';
for(var i=0; i<13; i++){
var tpl = '<tr><td>'+i+'</td></tr>';
rowNum += tpl;
}
arrRowMark.innerHTML = rowNum;
mapRowMark.innerHTML = rowNum;
</script> </script>
@ -506,7 +572,10 @@
for (var yy = 0; yy <= fullY; yy++) { for (var yy = 0; yy <= fullY; yy++) {
if (isGrass(xx, yy)) continue; if (isGrass(xx, yy)) continue;
var mapxy=map[m(xx,yy)]; var mapxy=map[m(xx,yy)];
if (typeof(mapxy) == typeof(-1))continue; if (typeof(mapxy) == typeof(-1)){
if(mapxy == 0) cxt.clearRect(xx*32, yy*32, 32, 32);
continue;
}
else if(typeof(mapxy) == typeof([][0])) {//未定义块画红块 else if(typeof(mapxy) == typeof([][0])) {//未定义块画红块
cxt.fillStyle = 'red'; cxt.fillStyle = 'red';
cxt.fillRect(xx*32, yy*32, 32, 32); cxt.fillRect(xx*32, yy*32, 32, 32);
@ -587,14 +656,15 @@
function eToLoc(e) { function eToLoc(e) {
var loc = { var loc = {
'x': document.documentElement.scrollLeft+e.clientX - mid.offsetLeft, 'x': document.documentElement.scrollLeft+e.clientX - mid.offsetLeft-mapEdit.offsetLeft,
'y': document.documentElement.scrollTop+e.clientY - mid.offsetTop, 'y': document.documentElement.scrollTop+e.clientY - mid.offsetTop-mapEdit.offsetTop,
'size': 32 'size': 32
}; };
return loc; }//返回可用的组件内坐标 return loc; }//返回可用的组件内坐标
function locToPos(loc) { function locToPos(loc) {
pos = { 'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.size) } pos = { 'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.size) }
console.log(pos)
return pos; return pos;
} }
@ -669,6 +739,10 @@
e.stopPropagation(); e.stopPropagation();
var loc = eToLoc(e); var loc = eToLoc(e);
if (stepPostfix.length) { if (stepPostfix.length) {
preMapData = JSON.parse(JSON.stringify(map));
currDrawData.pos = JSON.parse(JSON.stringify(stepPostfix));
currDrawData.info = JSON.parse(JSON.stringify(info));
reDo = null;
// console.log(stepPostfix); // console.log(stepPostfix);
for (var ii = 0; ii < stepPostfix.length; ii++) for (var ii = 0; ii < stepPostfix.length; ii++)
map[m(stepPostfix[ii].x, stepPostfix[ii].y)] = info; map[m(stepPostfix[ii].x, stepPostfix[ii].y)] = info;
@ -681,16 +755,46 @@
} }
} }
var preMapData = {};
var currDrawData = {
pos: [],
info: {}
};
var reDo = null;
document.body.onkeydown = function(e) {
// 禁止快捷键的默认行为
if( e.ctrlKey && ( e.keyCode == 90 || e.keyCode == 89 ) )
e.preventDefault();
//Ctrl+z 撤销上一步undo
if(e.keyCode == 90 && e.ctrlKey && preMapData && currDrawData.pos.length){
map = JSON.parse(JSON.stringify(preMapData));
updateMap();
reDo = JSON.parse(JSON.stringify(currDrawData));
currDrawData = {pos: [],info: {}};
preMapData = null;
}
//Ctrl+y 重做一步redo
if(e.keyCode == 89 && e.ctrlKey && reDo && reDo.pos.length){
preMapData = JSON.parse(JSON.stringify(map));
for(var j=0; j<reDo.pos.length;j++)
map[m(reDo.pos[j].x, reDo.pos[j].y)] = JSON.parse(JSON.stringify(reDo.info));
map[fullX + 1 + fullY * (fullX + 1)] = -2;
updateMap();
currDrawData = JSON.parse(JSON.stringify(reDo));
reDo = null;
}
}
// info=ids[indexs[20][0]];//autotile // info=ids[indexs[20][0]];//autotile
data.onmousedown = function (e) { data.onmousedown = function (e) {
e.stopPropagation(); e.stopPropagation();
var loc = { var loc = {
'x': document.documentElement.scrollLeft + e.clientX - right.offsetLeft, 'x': document.documentElement.scrollLeft + e.clientX - right.offsetLeft-iconLib.offsetLeft,
'y': document.documentElement.scrollTop + right.scrollTop+e.clientY - right.offsetTop, 'y': document.documentElement.scrollTop + e.clientY + iconLib.scrollTop - right.offsetTop-iconLib.offsetTop,
'size': 32 'size': 32
}; };
pos = locToPos(loc); pos = locToPos(loc);
// console.log(pos);
for (var spriter in widthsX){ for (var spriter in widthsX){
if(pos.x>=widthsX[spriter][1] && pos.x<widthsX[spriter][2]){ if(pos.x>=widthsX[spriter][1] && pos.x<widthsX[spriter][2]){
pos.x=widthsX[spriter][1]; pos.x=widthsX[spriter][1];
@ -702,14 +806,14 @@
selectBox.isSelected = true; selectBox.isSelected = true;
// console.log(pos,core.material.images[pos.images].height) // console.log(pos,core.material.images[pos.images].height)
dataSelection.style.left=pos.x*32+'px'; dataSelection.style.left = (iconLib.offsetLeft+pos.x*32) +'px';
dataSelection.style.top=pos.y*32+'px'; dataSelection.style.top = (iconLib.offsetTop + pos.y*32) +'px';
info={'images':pos.images,'y':pos.y}; info={'images':pos.images,'y':pos.y};
for (var ii=0;ii<ids.length;ii++){ for (var ii=0;ii<ids.length;ii++){
if(pos.images==ids[ii].images && pos.y==ids[ii].y) if(pos.images==ids[ii].images && pos.y==ids[ii].y)
info = JSON.parse(JSON.stringify(ids[ii])); info = ids[ii];
} }
tip.infos = info; tip.infos = JSON.parse(JSON.stringify(info));
} }
} }
} }
@ -791,7 +895,10 @@
methods: { methods: {
exportMap: function(){ exportMap: function(){
if(editArea.error) {
tip.whichShow = 3;
return;
}
var filestr=''; var filestr='';
for (var yy = 0; yy < 13; yy++){ for (var yy = 0; yy < 13; yy++){
filestr+='[' filestr+='['
@ -813,7 +920,7 @@
filestr+=mapxy+(xx==12?'':',') filestr+=mapxy+(xx==12?'':',')
} }
filestr+=(']'+(yy==12?'':',')+'\n') filestr += ']'+(yy==12?'':',\n');
} }
pout.value = filestr; pout.value = filestr;
@ -825,115 +932,106 @@
el: '#editArea', el: '#editArea',
data: { data: {
mapArr: '', mapArr: '',
errormsg: '',
errors: [ // 编号1,2,3,4 errors: [ // 编号1,2,3,4
"格式错误,请使用正确格式", "格式错误!请使用正确格式(13*13数组如不清楚可先点击生成地图查看正确格式)",
"当前ID未定义在地图区域显示红块请修改ID或者到icons.js和maps.js中进行定义", "当前有未定义ID在地图区域显示红块请修改ID或者到icons.js和maps.js中进行定义",
"编号错误当前编辑器暂时支持编号小于400请修改编号" "ID越界在地图区域显示红块当前编辑器暂时支持编号小于400请修改编号",
// "发生错误!",
], ],
error: 0, error: 0,
timer: null, formatTimer: null,
}, },
watch: { watch: {
mapArr: function () { mapArr: function () {
var self = this; var that = this;
setTimeout(function(){ if(that.formatArr()){
self.drawMap(); that.error = 0;
tip.whichShow = 8 clearTimeout(that.formatTimer);
}, 1000); setTimeout(function(){
that.drawMap();
tip.whichShow = 8
}, 1000);
that.formatTimer = setTimeout(function(){
pout.value = that.formatArr();
}, 5000); //5s后再格式化不然光标跳到最后很烦
}else{
that.error = 1;
}
}, },
error: function(){ error: function(){
var that = this;
that.errormsg = '';
if(that.error)
that.errormsg = that.errors[that.error-1];
clearTimeout(that.timer);
that.timer = setTimeout(function() {
tip.error = 0;
}, 5000); //5秒后自动清除
} }
}, },
methods: { methods: {
drawMap: function(){ drawMap: function(){
var that = this; var that = this;
if(that.formatArr){
var mapArray;
var arr = that.mapArr.replace(/\s/g, '');
var mapJson = '{"mapArr":['+arr+']}';
try{
mapArray = JSON.parse(mapJson).mapArr;
}catch (e) {
that.errors[3] = '发生错误!'+e;
that.error = 4;
return;
}
for(var y=0; y<mapArray.length; y++)
for(var x=0; x<mapArray[y].length; x++){
var num = mapArray[y][x];
if(num == 0 )
map[m(x, y)] = 0;
else if(num >= 400){
that.error = 3;
map[m(x, y)] = 'undefined';
}else if(indexs[num][0] == ''){
that.error = 2;
map[m(x, y)] = 'undefined';
}else map[m(x, y)] = ids[[indexs[num][0]]];
}
updateMap(); var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' ')
}else{ for(var i=0; i<mapArray.length; i++){
that.error = 1; var num = parseInt(mapArray[i]);
if(num == 0 )
map[i] = 0;
else if(num >= 400){
that.error = 3;
map[i] = undefined;
}else if(indexs[num][0] == undefined){
that.error = 2;
map[i] = undefined;
}else map[i] = ids[[indexs[num][0]]];
} }
updateMap();
}, },
formatArr: function(){ formatArr: function(){
var formatArr = ''; var formatArrStr = '';
var arr = this.mapArr.replace(/\s/g, '').split('],[');
if(arr.length != 13) return false; if(this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != 169) return false;
else { var arr = this.mapArr.replace(/\s+/g, '').split('],[');
for(var i =0; i<13; i++){
var a = []; if(arr.length != 13) return ;
formatArr +='['; for(var i =0; i<13; i++){
if(i==0||i==12) a = arr[i].split(/\D/).join(' ').trim().split(' '); var a = [];
else a = arr[i].split(/\D/); formatArrStr +='[';
if(a.length != 13){ if(i==0||i==12) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
formatArr = ''; else a = arr[i].split(/\D+/);
return false; if(a.length != 13){
} formatArrStr = '';
else { return ;
for(var k=0; k<13; k++){
formatArr = Array(Math.max(4-mapxy.length,0)).join(' ')+a[k];
filestr+=a[k]+(k==12?'':',')
}
}
formatArr += (']'+(i==12?'':',')+'\n');
} }
this.mapArr = formatArr; for(var k=0; k<13; k++){
return true; formatArrStr += Array(Math.max(4-a[k].length,0)).join(' ')+parseInt(a[k])+(k==12?'':',');
}
formatArrStr += ']'+(i==12?'':',\n');
} }
return formatArrStr;
} }
} }
}); });
var editTip = new Vue({ var editTip = new Vue({
el: '#editTip', el: '#editTip',
data: { data: {
err: ''
// message: ''
}, },
methods: { methods: {
copyMap: function(){ copyMap: function(){
this.message = '';
tip.whichShow = 0; tip.whichShow = 0;
if(pout.value.trim() != ''){ if(pout.value.trim() != ''){
if(editArea.error) {
this.err = editArea.errors[editArea.error-1];
tip.whichShow = 5
return;
}
try{ try{
pout.select(); pout.select();
document.execCommand("Copy"); document.execCommand("Copy");
tip.whichShow = 6; tip.whichShow = 6;
}catch(e){ }catch(e){
this.error= e; this.err= e;
tip.whichShow = 5; tip.whichShow = 5;
} }
}else{ }else{
@ -953,6 +1051,7 @@
ec.clearRect(0, 0, 416, 416); ec.clearRect(0, 0, 416, 416);
pout.value = ''; pout.value = '';
tip.whichShow = 4; tip.whichShow = 4;
editArea.error = 0;
} }
} }
}) })
@ -964,12 +1063,12 @@
isSelectedBlock: false, isSelectedBlock: false,
geneMapSuccess: false, geneMapSuccess: false,
timer: null, timer: null,
msgs: [ //分别编号1,2,3,4,5,6奇数警告偶数成功 msgs: [ //分别编号1,2,3,4,5,6,7,8;奇数警告,偶数成功
"当前未选择任何图块,请先在右边选择要画的图块!", "当前未选择任何图块,请先在右边选择要画的图块!",
"生成地图成功!可点击复制按钮复制地图数组到剪切板", "生成地图成功!可点击复制按钮复制地图数组到剪切板",
"生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!", "生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!",
"地图清除成功!", "地图清除成功!",
"复制失败!"+editTip.error, "复制失败!",
"复制成功!可直接粘贴到楼层文件的地图数组中。", "复制成功!可直接粘贴到楼层文件的地图数组中。",
"复制失败!当前还没有数据", "复制失败!当前还没有数据",
"修改成功!可点击复制按钮复制地图数组到剪切板" "修改成功!可点击复制按钮复制地图数组到剪切板"
@ -995,6 +1094,7 @@
whichShow: function(){ whichShow: function(){
var that = this; var that = this;
that.mapMsg = ''; that.mapMsg = '';
that.msgs[4] = "复制失败!"+editTip.err;
if(that.whichShow) if(that.whichShow)
that.mapMsg = that.msgs[that.whichShow-1]; that.mapMsg = that.msgs[that.whichShow-1];