drawPaint

This commit is contained in:
ckcz123 2018-10-29 16:47:51 +08:00
parent b9dc593bd1
commit 2b1dd2ffe7
4 changed files with 87 additions and 61 deletions

View File

@ -362,10 +362,15 @@ actions.prototype.keyUp = function(keyCode, altKey) {
}
break;
case 33: case 34: // PAGEUP/PAGEDOWN
if (core.status.heroStop) {
core.ui.drawMaps();
}
break;
if (core.status.heroStop)
core.ui.drawMaps();
break;
case 77: // M
if (core.status.heroStop) {
core.ui.drawPaint();
core.drawTip("打开画图模式");
}
break;
case 37: // UP
break;
case 38: // DOWN
@ -1924,13 +1929,16 @@ actions.prototype.clickSettings = function (x,y) {
core.ui.drawQuickShop();
break;
case 2:
core.ui.drawMaps();
core.ui.drawPaint();
break;
case 3:
core.ui.drawMaps();
break;
case 4:
core.status.event.selection=0;
core.ui.drawSyncSave();
break;
case 4:
case 5:
core.status.event.selection=1;
core.ui.drawConfirmBox("你确定要返回标题页面吗?", function () {
core.ui.closePanel();
@ -1940,65 +1948,16 @@ actions.prototype.clickSettings = function (x,y) {
core.ui.drawSettings();
});
break;
case 5:
core.ui.drawStatistics();
/*
core.ui.drawWaiting("正在拉取统计信息,请稍后...");
var formData = new FormData();
formData.append('type', 'statistics');
formData.append('name', core.firstData.name);
formData.append('version', core.firstData.version);
var xhr = new XMLHttpRequest();
xhr.open("POST", "/games/upload.php");
xhr.onload = function(e) {
if (xhr.status==200) {
var response = JSON.parse(xhr.response);
if (response.code<0) {
core.drawText("出错啦!\n无法拉取统计信息。\n错误原因"+response.msg);
}
else {
var text="\t[本塔统计信息]";
var toAdd=false;
response.data.forEach(function (t) {
if (toAdd) text+="\n\n";
toAdd=true;
if (t.hard!='') text+=t.hard+"难度: "
text+="已有"+t.people+"人次游戏,"+t.score+"人次通关。";
t.info.forEach(function(ending) {
if (ending.ending!='') {
text+="\n"+ending.ending+" 已有"+ending.score+"人次通关。";
}
if (core.isset(ending.max) && ending.max>0) {
text+="\n当前MAX为"+ending.max+",最早由 "+(ending.username||"匿名")+" 于"+core.formatDate(new Date(1000*ending.timestamp))+"打出。";
}
})
})
core.drawText(text);
}
}
else {
core.drawText("出错啦!\n无法拉取统计信息。\n错误原因HTTP "+xhr.status);
}
};
xhr.ontimeout = function() {
core.drawText("出错啦!\n无法拉取统计信息。\n错误原因Timeout");
}
xhr.onerror = function() {
core.drawText("出错啦!\n无法拉取统计信息。\n错误原因XHR Error");
}
xhr.send(formData);
*/
break;
case 6:
core.ui.drawHelp();
core.ui.drawStatistics();
break;
case 7:
core.ui.drawAbout();
core.ui.drawHelp();
break;
case 8:
core.ui.drawAbout();
break;
case 9:
core.ui.closePanel();
break;
}

View File

@ -81,6 +81,7 @@ function core() {
height: 13,
tempCanvas: null, // A temp canvas for drawing
}
this.paint = {}
this.initStatus = {
'played': false,
'gameOver': false,

View File

@ -836,7 +836,7 @@ ui.prototype.drawSettings = function () {
core.status.event.id = 'settings';
this.drawChoices(null, [
"系统设置", "快捷商店", "浏览地图", "同步存档", "返回标题", "数据统计", "操作帮助", "关于本塔", "返回游戏"
"系统设置", "快捷商店", "浏览地图", "打开画板", "同步存档", "返回标题", "数据统计", "操作帮助", "关于本塔", "返回游戏"
]);
}
@ -2417,6 +2417,20 @@ ui.prototype.drawAbout = function () {
return this.uidata.drawAbout();
}
////// 绘制“画图”界面 //////
ui.prototype.drawPaint = function () {
core.lockControl();
core.status.event.id = 'paint';
core.clearMap('ui');
core.clearMap('route');
// 将已有的内容绘制到route上
core.utils.decodeCanvas(core.paint[core.status.floorId], 32*core.bigmap.width, 32*core.bigmap.height);
core.canvas.route.drawImage(core.bigmap.tempCanvas, 0, 0);
}
////// 绘制帮助页面 //////
ui.prototype.drawHelp = function () {
core.drawText([

View File

@ -726,6 +726,58 @@ utils.prototype.hide = function (obj, speed, callback) {
}, speed);
}
utils.prototype.encodeCanvas = function (ctx) {
var list = [];
var width = ctx.canvas.width, height = ctx.canvas.height;
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.msImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;
var imgData = ctx.getImageData(0, 0, width, height);
for (var i=0;i<imgData.data.length;i+=4) {
list.push(Math.sign(imgData.data[i+3]));
}
// compress 01 to array
var prev = 0, cnt = 0, arr = [];
for (var i=0;i<list.length;i++) {
if (list[i]!=prev) {
arr.push(cnt);
prev=list[i];
cnt=0;
}
cnt++;
}
arr.push(cnt);
return arr;
}
////// 解析arr数组并绘制到tempCanvas上 //////
utils.prototype.decodeCanvas = function (arr, width, height) {
if (!core.isset(arr)) return null;
// to byte array
var curr = 0, list = [];
arr.forEach(function (x) {
for (var i=0;i<x;i++) list.push(curr);
curr = 1-curr;
})
// 使用tempCanvas
var tempCanvas = core.bigmap.tempCanvas;
tempCanvas.canvas.width=width;
tempCanvas.canvas.height=height;
tempCanvas.clearRect(0, 0, width, height);
var imgData = tempCanvas.getImageData(0, 0, width, height);
for (var i=0;i<imgData.data.length;i+=4) {
var index = i/4;
if (list[index]) {
imgData.data[i]=255;
imgData.data[i+3]=255;
}
}
tempCanvas.putImageData(imgData, 0, 0);
}
utils.prototype.consoleOpened = function () {
var threshold = 160;
var widthThreshold = window.outerWidth - window.innerWidth > threshold;