paint on route

This commit is contained in:
ckcz123 2018-10-29 20:23:10 +08:00
parent 2b1dd2ffe7
commit 6488b355e8
4 changed files with 95 additions and 28 deletions

View File

@ -368,7 +368,6 @@ actions.prototype.keyUp = function(keyCode, altKey) {
case 77: // M
if (core.status.heroStop) {
core.ui.drawPaint();
core.drawTip("打开画图模式");
}
break;
case 37: // UP
@ -443,9 +442,18 @@ actions.prototype.keyUp = function(keyCode, altKey) {
}
////// 点击(触摸)事件按下时 //////
actions.prototype.ondown = function (x ,y) {
actions.prototype.ondown = function (loc) {
if (core.isset(core.status.replay)&&core.status.replay.replaying
&&core.status.event.id!='save'&&(core.status.event.id||"").indexOf('book')!=0&&core.status.event.id!='viewMaps') return;
// 画板
if (core.status.played && (core.status.event||{}).id=='paint') {
this.ondownPaint(loc.x, loc.y);
return;
}
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
if (!core.status.played || core.status.lockControl) {
this.onclick(x, y, []);
if (core.timeout.onDownTimeout==null) {
@ -472,11 +480,18 @@ actions.prototype.ondown = function (x ,y) {
}
////// 当在触摸屏上滑动时 //////
actions.prototype.onmove = function (x ,y) {
actions.prototype.onmove = function (loc) {
if (core.isset(core.status.replay)&&core.status.replay.replaying
&&core.status.event.id!='save'&&(core.status.event.id||"").indexOf('book')!=0&&core.status.event.id!='viewMaps') return;
// if (core.status.holdingPath==0){return;}
//core.status.mouseOutCheck =1;
// 画板
if (core.status.played && (core.status.event||{}).id=='paint') {
this.onmovePaint(loc.x, loc.y)
return;
}
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
var pos={'x':x,'y':y};
var pos0=core.status.stepPostfix[core.status.stepPostfix.length-1];
var directionDistance=[pos.y-pos0.y,pos0.x-pos.x,pos0.y-pos.y,pos.x-pos0.x];
@ -497,10 +512,18 @@ actions.prototype.onmove = function (x ,y) {
}
////// 当点击(触摸)事件放开时 //////
actions.prototype.onup = function () {
actions.prototype.onup = function (loc) {
if (core.isset(core.status.replay)&&core.status.replay.replaying
&&core.status.event.id!='save'&&(core.status.event.id||"").indexOf('book')!=0&&core.status.event.id!='viewMaps') return;
// 画板
if (core.status.played && (core.status.event||{}).id=='paint') {
this.onupPaint(loc.x, loc.y)
return;
}
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
clearTimeout(core.timeout.onDownTimeout);
core.timeout.onDownTimeout = null;
clearInterval(core.interval.onDownInterval);
@ -1929,10 +1952,10 @@ actions.prototype.clickSettings = function (x,y) {
core.ui.drawQuickShop();
break;
case 2:
core.ui.drawPaint();
core.ui.drawMaps();
break;
case 3:
core.ui.drawMaps();
core.ui.drawPaint();
break;
case 4:
core.status.event.selection=0;
@ -2507,3 +2530,33 @@ actions.prototype.clickAbout = function () {
else
core.restart();
}
actions.prototype.ondownPaint = function (x, y) {
console.log("ondown: ("+x+","+y+")");
core.canvas.route.beginPath();
core.canvas.route.moveTo(x+core.bigmap.offsetX, y+core.bigmap.offsetY);
core.status.event.data.x = x;
core.status.event.data.y = y;
}
actions.prototype.onmovePaint = function (x, y) {
if (core.status.event.data.x==null) return;
var midx = (core.status.event.data.x+x)/2, midy = (core.status.event.data.y+y)/2;
core.canvas.route.quadraticCurveTo(midx, midy, x, y);
core.canvas.route.stroke();
core.status.event.data.x = x;
core.status.event.data.y = y;
}
actions.prototype.onupPaint = function (x,y) {
console.log("onup: ("+x+","+y+")");
var midx = (core.status.event.data.x+x)/2, midy = (core.status.event.data.y+y)/2;
core.canvas.route.quadraticCurveTo(midx, midy, x, y);
core.canvas.route.stroke();
core.status.event.data.x = null;
core.status.event.data.y = null;
// 保存
core.paint[core.status.floorId] = LZString.compress(core.utils.encodeCanvas(core.canvas.route).join(","));
}

View File

@ -396,18 +396,18 @@ core.prototype.keyUp = function(keyCode, altKey) {
}
////// 点击(触摸)事件按下时 //////
core.prototype.ondown = function (x ,y) {
return core.actions.ondown(x,y);
core.prototype.ondown = function (loc) {
return core.actions.ondown(loc);
}
////// 当在触摸屏上滑动时 //////
core.prototype.onmove = function (x ,y) {
return core.actions.onmove(x,y);
core.prototype.onmove = function (loc) {
return core.actions.onmove(loc);
}
////// 当点击(触摸)事件放开时 //////
core.prototype.onup = function () {
return core.actions.onup();
core.prototype.onup = function (loc) {
return core.actions.onup(loc);
}
////// 获得点击事件相对左上角的坐标0到12之间 //////

View File

@ -2420,15 +2420,28 @@ ui.prototype.drawAbout = function () {
////// 绘制“画图”界面 //////
ui.prototype.drawPaint = function () {
console.log("drawPaint");
core.drawTip("打开绘图模式,现在可以任意在界面上绘图标记");
core.lockControl();
core.status.event.id = 'paint';
core.status.event.data = {"x": null, "y": null, "erase": false};
core.clearMap('ui');
core.clearMap('route');
core.setAlpha('route', 1);
core.setOpacity('route', 1);
// 将已有的内容绘制到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);
var value = core.paint[core.status.floorId];
if (core.isset(value) && typeof value == 'string') value = LZString.decompress(value).split(",");
core.utils.decodeCanvas(value, 32*core.bigmap.width, 32*core.bigmap.height);
core.canvas.route.drawImage(core.bigmap.tempCanvas.canvas, 0, 0);
core.setLineWidth('route', 3);
core.setStrokeStyle('route', '#FF0000');
}
////// 绘制帮助页面 //////

25
main.js
View File

@ -317,8 +317,7 @@ main.dom.data.onmousedown = function (e) {
}
var loc = main.core.getClickLoc(e.clientX, e.clientY);
if (loc == null) return;
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
main.core.ondown(x, y);
main.core.ondown(loc);
} catch (ee) {}
}
@ -328,15 +327,17 @@ main.dom.data.onmousemove = function (e) {
e.stopPropagation();
var loc = main.core.getClickLoc(e.clientX, e.clientY);
if (loc == null) return;
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
main.core.onmove(x, y);
main.core.onmove(loc);
}catch (ee) {}
}
////// 鼠标放开时 //////
main.dom.data.onmouseup = function () {
main.dom.data.onmouseup = function (e) {
try {
main.core.onup();
e.stopPropagation();
var loc = main.core.getClickLoc(e.clientX, e.clientY);
if (loc == null) return;
main.core.onup(loc);
}catch (e) {}
}
@ -356,9 +357,7 @@ main.dom.data.ontouchstart = function (e) {
e.preventDefault();
var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
if (loc == null) return;
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
//main.core.onclick(x, y, []);
main.core.ondown(x, y);
main.core.ondown(loc);
}catch (ee) {}
}
@ -368,15 +367,17 @@ main.dom.data.ontouchmove = function (e) {
e.preventDefault();
var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
if (loc == null) return;
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
main.core.onmove(x, y);
main.core.onmove(loc);
}catch (ee) {}
}
////// 手指离开触摸屏时 //////
main.dom.data.ontouchend = function () {
try {
main.core.onup();
e.preventDefault();
var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
if (loc == null) return;
main.core.onup(loc);
} catch (e) {
}
}