Virtual Keyboard

This commit is contained in:
ckcz123 2018-01-12 17:50:15 +08:00
parent 6b80afe9ee
commit 143a0afd1e
3 changed files with 159 additions and 13 deletions

View File

@ -78,6 +78,7 @@ function core() {
'stepPostfix': [], 'stepPostfix': [],
'mouseOutCheck': 1, 'mouseOutCheck': 1,
'moveStepBeforeStop': [], 'moveStepBeforeStop': [],
'downTime': null,
// 勇士状态;中心对称飞行器 // 勇士状态;中心对称飞行器
@ -713,6 +714,9 @@ core.prototype.keyUp = function(keyCode) {
if (core.status.heroStop) if (core.status.heroStop)
core.openBook(true); core.openBook(true);
break; break;
case 65: // A
core.doSL("autoSave", "load");
break;
case 83: // S case 83: // S
if (core.status.heroStop) if (core.status.heroStop)
core.save(true); core.save(true);
@ -792,9 +796,11 @@ core.prototype.ondown = function (x ,y) {
core.onclick(x, y, []); core.onclick(x, y, []);
return; return;
} }
core.status.downTime = new Date();
core.status.holdingPath=1; core.status.holdingPath=1;
core.status.mouseOutCheck =1; core.status.mouseOutCheck =1;
window.setTimeout(core.clearStepPostfix); // window.setTimeout(core.clearStepPostfix);
core.saveCanvas('ui'); core.saveCanvas('ui');
core.clearMap('ui', 0, 0, 416,416); core.clearMap('ui', 0, 0, 416,416);
var pos={'x':x,'y':y} var pos={'x':x,'y':y}
@ -842,8 +848,16 @@ core.prototype.onup = function () {
core.status.stepPostfix=[]; core.status.stepPostfix=[];
core.canvas.ui.clearRect(0, 0, 416,416); core.canvas.ui.clearRect(0, 0, 416,416);
core.canvas.ui.restore(); core.canvas.ui.restore();
core.onclick(posx,posy,stepPostfix);
//posx,posy是寻路的目标点,stepPostfix是后续的移动 // 长按
if (!core.status.lockControl && stepPostfix.length==0 && core.status.downTime!=null && new Date()-core.status.downTime>=1000) {
core.events.longClick();
}
else {
//posx,posy是寻路的目标点,stepPostfix是后续的移动
core.onclick(posx,posy,stepPostfix);
}
core.status.downTime=null;
} }
} }
@ -963,6 +977,11 @@ core.prototype.onclick = function (x, y, stepPostfix) {
return; return;
} }
if (core.status.event.id == 'keyBoard') {
core.events.clickKeyBoard(x,y);
return;
}
// 关于 // 关于
if (core.status.event.id == 'about') { if (core.status.event.id == 'about') {
core.events.clickAbout(x,y); core.events.clickAbout(x,y);
@ -1783,6 +1802,9 @@ core.prototype.trigger = function (x, y) {
////// 楼层切换 ////// ////// 楼层切换 //////
core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback) { core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback) {
var displayAnimate=!(time==0);
time = time || 800; time = time || 800;
time /= 20; time /= 20;
core.lockControl(); core.lockControl();
@ -1815,8 +1837,8 @@ core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback)
} }
window.setTimeout(function () { window.setTimeout(function () {
core.playSound('floor.mp3');
core.mapChangeAnimate('show', time/2, function () { var changing = function () {
// 根据文字判断是否斜体 // 根据文字判断是否斜体
var floorName = core.status.maps[floorId].name; var floorName = core.status.maps[floorId].name;
@ -1854,20 +1876,38 @@ core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback)
core.drawMap(floorId, function () { core.drawMap(floorId, function () {
setTimeout(function() { setTimeout(function() {
core.mapChangeAnimate('hide', time/4, function () {
core.unLockControl();
core.events.afterChangeFloor(floorId);
if (core.isset(callback)) callback();
});
if (core.isset(heroLoc.direction)) if (core.isset(heroLoc.direction))
core.setHeroLoc('direction', heroLoc.direction); core.setHeroLoc('direction', heroLoc.direction);
core.setHeroLoc('x', heroLoc.x); core.setHeroLoc('x', heroLoc.x);
core.setHeroLoc('y', heroLoc.y); core.setHeroLoc('y', heroLoc.y);
core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop'); core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop');
core.updateStatusBar(); core.updateStatusBar();
var changed = function () {
core.unLockControl();
core.events.afterChangeFloor(floorId);
if (core.isset(callback)) callback();
}
if (displayAnimate) {
core.mapChangeAnimate('hide', time/4, function () {
changed();
});
}
else {
changed();
}
}, 15) }, 15)
}); });
}); }
if (displayAnimate) {
core.playSound('floor.mp3');
core.mapChangeAnimate('show', time/2, function () {
changing();
});
}
else {
changing();
}
}, 50); }, 50);
} }
@ -3547,7 +3587,7 @@ core.prototype.loadData = function (data, callback) {
core.events.afterLoadData(data); core.events.afterLoadData(data);
core.changeFloor(data.floorId, null, data.hero.loc, null, function() { core.changeFloor(data.floorId, null, data.hero.loc, 0, function() {
core.setHeroMoveTriggerInterval(); core.setHeroMoveTriggerInterval();
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
}); });

View File

@ -706,6 +706,14 @@ events.prototype.afterLoadData = function(data) {
/********** 点击事件、键盘事件 ************/ /********** 点击事件、键盘事件 ************/
/****************************************/ /****************************************/
////// 长按 //////
events.prototype.longClick = function () {
core.waitHeroToStop(function () {
// 绘制快捷键
core.ui.drawKeyBoard();
});
}
////// 按下Ctrl键时快捷跳过对话 ////// ////// 按下Ctrl键时快捷跳过对话 //////
events.prototype.keyDownCtrl = function () { events.prototype.keyDownCtrl = function () {
if (core.status.event.id=='text') { if (core.status.event.id=='text') {
@ -1497,6 +1505,65 @@ events.prototype.keyUpSyncSave = function (keycode) {
} }
} }
////// “虚拟键盘”界面时的点击操作 //////
events.prototype.clickKeyBoard = function (x, y) {
if (y==3 && x>=1 && x<=11) {
core.ui.closePanel();
core.keyUp(112+x-1); // F1-F12: 112-122
}
if (y==4 && x>=1 && x<=10) {
core.ui.closePanel();
core.keyUp(x==10?48:48+x); // 1-9: 49-57; 0: 48
}
// 字母
var lines = [
["Q","W","E","R","T","Y","U","I","O","P"],
["A","S","D","F","G","H","J","K","L"],
["Z","X","C","V","B","N","M"],
];
if (y==5 && x>=1 && x<=10) {
core.ui.closePanel();
core.keyUp(lines[0][x-1].charCodeAt(0));
}
if (y==6 && x>=1 && x<=9) {
core.ui.closePanel();
core.keyUp(lines[1][x-1].charCodeAt(0));
}
if (y==7 && x>=1 && x<=7) {
core.ui.closePanel();
core.keyUp(lines[2][x-1].charCodeAt(0));
}
if (y==8 && x>=1 && x<=11) {
core.ui.closePanel();
if (x==1) core.keyUp(189); // -
if (x==2) core.keyUp(187); // =
if (x==3) core.keyUp(219); // [
if (x==4) core.keyUp(221); // ]
if (x==5) core.keyUp(220); // \
if (x==6) core.keyUp(186); // ;
if (x==7) core.keyUp(222); // '
if (x==8) core.keyUp(188); // ,
if (x==9) core.keyUp(190); // .
if (x==10) core.keyUp(191); // /
if (x==11) core.keyUp(192); // `
}
if (y==9 && x>=1 && x<=10) {
core.ui.closePanel();
if (x==1) core.keyUp(27); // ESC
if (x==2) core.keyUp(9); // TAB
if (x==3) core.keyUp(20); // CAPS
if (x==4) core.keyUp(16); // SHIFT
if (x==5) core.keyUp(17); // CTRL
if (x==6) core.keyUp(18); // ALT
if (x==7) core.keyUp(32); // SPACE
if (x==8) core.keyUp(8); // BACKSPACE
if (x==9) core.keyUp(13); // ENTER
if (x==10) core.keyUp(46); // DEL
}
if (y==10 && x>=9 && x<=11)
core.ui.closePanel();
}
////// “关于”界面时的点击操作 ////// ////// “关于”界面时的点击操作 //////
events.prototype.clickAbout = function () { events.prototype.clickAbout = function () {
if (core.isPlaying()) if (core.isPlaying())

View File

@ -1114,6 +1114,44 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, heroL
} }
} }
ui.prototype.drawKeyBoard = function () {
core.lockControl();
core.status.event.id = 'keyBoard';
core.clearMap('ui', 0, 0, 416, 416);
var left = 16, top = 48, right = 416 - 2 * left, bottom = 416 - 2 * top;
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
core.fillRect('ui', left, top, right, bottom, background);
core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2);
core.canvas.ui.textAlign = "center";
core.fillText('ui', "虚拟键盘", 208, top+35, "#FFD700", "bold 22px Verdana");
core.setFont('ui', '17px Verdana');
core.setFillStyle('ui', '#FFFFFF');
var offset = 128-9;
var lines = [
["F1","F2","F3","F4","F5","F6","F7","F8","F9","10","11"],
["1","2","3","4","5","6","7","8","9","0"],
["Q","W","E","R","T","Y","U","I","O","P"],
["A","S","D","F","G","H","J","K","L"],
["Z","X","C","V","B","N","M"],
["-","=","[","]","\\",";","'",",",".","/","`"],
["ES","TA","CA","SH","CT","AL","SP","BS","EN","DE"]
]
lines.forEach(function (line) {
for (var i=0;i<line.length;i++) {
core.fillText('ui', line[i], 48+32*i, offset);
}
offset+=32;
});
core.fillText("ui", "返回游戏", 416-80, offset-3, '#FFFFFF', 'bold 15px Verdana');
}
////// 绘制“关于”界面 ////// ////// 绘制“关于”界面 //////
ui.prototype.drawAbout = function() { ui.prototype.drawAbout = function() {
@ -1163,6 +1201,7 @@ ui.prototype.drawHelp = function () {
"点任意块: 寻路并移动\n"+ "点任意块: 寻路并移动\n"+
"点任意块并拖动: 指定寻路路线\n"+ "点任意块并拖动: 指定寻路路线\n"+
"单击勇士: 转向\n"+ "单击勇士: 转向\n"+
"双击勇士: 轻按(仅在轻按开关打开时有效)" "双击勇士: 轻按(仅在轻按开关打开时有效)\n",
"长按任意位置:打开虚拟键盘"
]); ]);
} }