keyUpKeyBoard

This commit is contained in:
ckcz123 2018-12-20 17:04:59 +08:00
parent d2e3710f28
commit d0e3b48147
4 changed files with 64 additions and 46 deletions

View File

@ -467,25 +467,24 @@ core.maps.removeBlockByIds(floorId, ids)
ui.js主要用来进行UI窗口的绘制比如对话框、怪物手册、楼传器、存读档界面等等。 ui.js主要用来进行UI窗口的绘制比如对话框、怪物手册、楼传器、存读档界面等等。
core.ui.getContextByName(name) core.ui.getContextByName(canvas)
根据画布名找到一个画布的context支持系统画布和自定义画布。如果不存在画布返回null。 根据画布名找到一个画布的context支持系统画布和自定义画布。如果不存在画布返回null。
也可以传画布的context自身则返回自己。
core.clearMap(name) core.clearMap(name)
清空某个画布图层。 清空某个画布图层。
name为画布名可以是系统画布之一也可以是任意自定义动态创建的画布名。 name为画布名可以是系统画布之一也可以是任意自定义动态创建的画布名还可以直接传画布的context本身(下同)
如果name也可以是'all'若为all则为清空所有系统画布。 如果name也可以是'all'若为all则为清空所有系统画布。
core.ui.fillText(name, text, x, y, style, font) core.ui.fillText(name, text, x, y, style, font)
在某个画布上绘制一段文字。 在某个画布上绘制一段文字。
name为画布名可以是系统画布之一也可以是任意自定义动态创建的画布名。下同 text为要绘制的文本x,y为要绘制的坐标style可选为绘制的样式font可选为绘制的字体。下同
text为要绘制的文本x,y为要绘制的坐标style可选为绘制的样式font可选为绘制的字体。
core.ui.fillBoldText(canvas, text, style, x, y, font) core.ui.fillBoldText(name, text, style, x, y, font)
在某个画布上绘制一个描黑边的文字。 在某个画布上绘制一个描黑边的文字。
canvas为要绘制的画布的contexttext为文本style为颜色样式x,y坐标font可选为要绘制的字体。
core.ui.fillRect(name, x, y, width, height, style) core.ui.fillRect(name, x, y, width, height, style)
@ -531,7 +530,7 @@ font可选如果存在则会先设置该画布上的字体。
core.ui.drawImage(name, image, x, y, w, h, x1, y1, w1, h1) core.ui.drawImage(name, image, x, y, w, h, x1, y1, w1, h1)
在一个画布上绘制图片。 在一个画布上绘制图片。
name为画布名可以是系统画布之一也可以是任意自定义动态创建的画布名。 name为画布名可以是系统画布之一也可以是任意自定义动态创建的画布名还可以直接传画布的context本身
image为要绘制的图片可以是一个全塔属性中定义的图片名会从images中去获取图片本身或者一个画布。 image为要绘制的图片可以是一个全塔属性中定义的图片名会从images中去获取图片本身或者一个画布。
后面的8个坐标参数与canvas的drawImage的八个参数完全相同。 后面的8个坐标参数与canvas的drawImage的八个参数完全相同。
请查看 http://www.w3school.com.cn/html5/canvas_drawimage.asp 了解更多。 请查看 http://www.w3school.com.cn/html5/canvas_drawimage.asp 了解更多。

View File

@ -251,6 +251,10 @@ actions.prototype.keyUp = function(keyCode, altKey, fromReplay) {
this.keyUpSL(keyCode); this.keyUpSL(keyCode);
return; return;
} }
if (core.status.event.id == 'keyBoard') {
this.keyUpKeyBoard(keyCode);
return;
}
if (core.status.event.id=='switchs') { if (core.status.event.id=='switchs') {
this.keyUpSwitchs(keyCode); this.keyUpSwitchs(keyCode);
return; return;
@ -2546,6 +2550,14 @@ actions.prototype.clickKeyBoard = function (x, y) {
core.ui.closePanel(); core.ui.closePanel();
} }
////// “虚拟键盘”界面时的点击操作 //////
actions.prototype.keyUpKeyBoard = function (keycode) {
if (keycode==27 || keycode==88 || keycode==13 || keycode==32 || keycode==67) {
core.ui.closePanel();
return;
}
}
////// 光标界面时的点击操作 ////// ////// 光标界面时的点击操作 //////
actions.prototype.clickCursor = function (x,y) { actions.prototype.clickCursor = function (x,y) {

View File

@ -630,8 +630,8 @@ core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback,
} }
////// 从名字获得画布 ////// ////// 从名字获得画布 //////
core.prototype.getContextByName = function (name) { core.prototype.getContextByName = function (canvas) {
return core.ui.getContextByName(name); return core.ui.getContextByName(canvas);
} }
////// 清除地图 ////// ////// 清除地图 //////
@ -645,8 +645,8 @@ core.prototype.fillText = function (name, text, x, y, style, font) {
} }
////// 在某个canvas上绘制一段描边文字 ////// ////// 在某个canvas上绘制一段描边文字 //////
core.prototype.fillBoldText = function (canvas, text, style, x, y, font) { core.prototype.fillBoldText = function (name, text, style, x, y, font) {
core.ui.fillBoldText(canvas, text, style , x, y, font); core.ui.fillBoldText(name, text, style , x, y, font);
} }
////// 在某个canvas上绘制一个矩形 ////// ////// 在某个canvas上绘制一个矩形 //////

View File

@ -17,11 +17,16 @@ ui.prototype.init = function () {
////////////////// 地图设置 ////////////////// 地图设置
ui.prototype.getContextByName = function (name) { ui.prototype.getContextByName = function (canvas) {
if (core.isset(core.canvas[name])) if (typeof canvas == 'string') {
return core.canvas[name]; if (core.isset(core.canvas[canvas]))
if (core.isset(core.dymCanvas[name])) canvas = core.canvas[canvas];
return core.dymCanvas[name]; else if (core.isset(core.dymCanvas[canvas]))
canvas = core.dymCanvas[canvas];
}
if (core.isset(canvas) && core.isset(canvas.canvas)) {
return canvas;
}
return null; return null;
} }
@ -53,18 +58,17 @@ ui.prototype.fillText = function (name, text, x, y, style, font) {
} }
////// 在某个canvas上绘制粗体 ////// ////// 在某个canvas上绘制粗体 //////
ui.prototype.fillBoldText = function (canvas, text, style, x, y, font) { ui.prototype.fillBoldText = function (name, text, style, x, y, font) {
if (typeof canvas == "string") var ctx = this.getContextByName(name);
canvas = this.getContextByName(canvas); if (!ctx) return;
if (!core.isset(canvas)) return; if (core.isset(font)) ctx.font = font;
if (core.isset(font)) canvas.font = font; ctx.fillStyle = '#000000';
canvas.fillStyle = '#000000'; ctx.fillText(text, x-1, y-1);
canvas.fillText(text, x-1, y-1); ctx.fillText(text, x-1, y+1);
canvas.fillText(text, x-1, y+1); ctx.fillText(text, x+1, y-1);
canvas.fillText(text, x+1, y-1); ctx.fillText(text, x+1, y+1);
canvas.fillText(text, x+1, y+1); ctx.fillStyle = style;
canvas.fillStyle = style; ctx.fillText(text, x, y);
canvas.fillText(text, x, y);
} }
////// 在某个canvas上绘制一个矩形 ////// ////// 在某个canvas上绘制一个矩形 //////
@ -97,12 +101,11 @@ ui.prototype.drawLine = function (name, x1, y1, x2, y2, style, lineWidth) {
core.setLineWidth(name, lineWidth); core.setLineWidth(name, lineWidth);
} }
var ctx = this.getContextByName(name); var ctx = this.getContextByName(name);
if (ctx) { if (!ctx) return;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(x1, y1); ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2); ctx.lineTo(x2, y2);
ctx.stroke(); ctx.stroke();
}
} }
////// 在某个canvas上绘制一个箭头 ////// ////// 在某个canvas上绘制一个箭头 //////
@ -115,18 +118,17 @@ ui.prototype.drawArrow = function (name, x1, y1, x2, y2, style, lineWidth) {
core.setLineWidth(name, lineWidth); core.setLineWidth(name, lineWidth);
} }
var ctx = this.getContextByName(name); var ctx = this.getContextByName(name);
if (ctx) { if (!ctx) return;
var head = 10; var head = 10;
var dx = x2-x1, dy=y2-y1; var dx = x2-x1, dy=y2-y1;
var angle = Math.atan2(dy,dx); var angle = Math.atan2(dy,dx);
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(x1,y1); ctx.moveTo(x1,y1);
ctx.lineTo(x2, y2); ctx.lineTo(x2, y2);
ctx.lineTo(x2-head*Math.cos(angle-Math.PI/6),y2-head*Math.sin(angle-Math.PI/6)); ctx.lineTo(x2-head*Math.cos(angle-Math.PI/6),y2-head*Math.sin(angle-Math.PI/6));
ctx.moveTo(x2, y2); ctx.moveTo(x2, y2);
ctx.lineTo(x2-head*Math.cos(angle+Math.PI/6),y2-head*Math.sin(angle+Math.PI/6)); ctx.lineTo(x2-head*Math.cos(angle+Math.PI/6),y2-head*Math.sin(angle+Math.PI/6));
ctx.stroke(); ctx.stroke();
}
} }
////// 设置某个canvas的文字字体 ////// ////// 设置某个canvas的文字字体 //////
@ -2555,6 +2557,11 @@ ui.prototype.drawKeyBoard = function () {
}); });
core.fillText("ui", "返回游戏", 416-80, offset-3, '#FFFFFF', 'bold 15px '+globalFont); core.fillText("ui", "返回游戏", 416-80, offset-3, '#FFFFFF', 'bold 15px '+globalFont);
if (isWindowSkin)
this.drawWindowSelector(background, 300, offset - 22, 72, 27);
else
core.strokeRect('ui', 300, offset - 22, 72, 27, "#FFD700", 2);
} }
////// 绘制状态栏 ///// ////// 绘制状态栏 /////