diff --git a/images/forward.png b/images/forward.png new file mode 100644 index 00000000..6701f077 Binary files /dev/null and b/images/forward.png differ diff --git a/images/pause.png b/images/pause.png new file mode 100644 index 00000000..db4f3aea Binary files /dev/null and b/images/pause.png differ diff --git a/images/play.png b/images/play.png new file mode 100644 index 00000000..34cfd72f Binary files /dev/null and b/images/play.png differ diff --git a/images/rewind.png b/images/rewind.png new file mode 100644 index 00000000..bafb4ee1 Binary files /dev/null and b/images/rewind.png differ diff --git a/images/stop.png b/images/stop.png new file mode 100644 index 00000000..8a2a1219 Binary files /dev/null and b/images/stop.png differ diff --git a/libs/core.js b/libs/core.js index e5a4cafe..b5d3efeb 100644 --- a/libs/core.js +++ b/libs/core.js @@ -102,7 +102,8 @@ function core() { 'pausing': false, 'animate': false, // 正在某段动画中 'toReplay': [], - 'totalList': [] + 'totalList': [], + 'speed': 1.0 }, // event事件 @@ -603,7 +604,18 @@ core.prototype.onkeyDown = function(e) { ////// 放开某个键时 ////// core.prototype.onkeyUp = function(e) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (core.isset(core.status.replay)&&core.status.replay.replaying) { + if (e.keyCode==27) // ESCAPE + core.stopReplay(); + else if (e.keyCode==90) // Z + core.rewindReplay(); + else if (e.keyCode==88) // X + core.forwardReplay(); + else if (e.keyCode==32) // SPACE + core.triggerReplay(); + return; + } + var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] if(isArrow && !core.status.lockControl){ for(var ii =0;ii= core.values.animateSpeed * 2 / animateValue) { animateCurrent++; animateTime = 0; @@ -2502,7 +2514,7 @@ core.prototype.moveBlock = function(x,y,steps,time,immediateHide,callback) { moveSteps.shift(); } } - }, time/16); + }, time / 16 / core.status.replay.speed); } ////// 显示/隐藏某个块时的动画效果 ////// @@ -2547,7 +2559,7 @@ core.prototype.animateBlock = function (x,y,type,time,callback) { core.status.replay.animate=false; if (core.isset(callback)) callback(); } - }, time/10); + }, time / 10 / core.status.replay.speed); } ////// 将某个块从禁用变成启用状态 ////// @@ -3493,22 +3505,79 @@ core.prototype.debug = function() { core.drawTip("作弊成功"); } -////// 回放 ////// -core.prototype.replay = function (list) { +////// 开始播放 ////// +core.prototype.startReplay = function (list) { + core.status.replay.replaying=true; + core.status.replay.pausing=false; + core.status.replay.speed=1.0; + core.status.replay.toReplay = core.clone(list); + core.status.replay.totalList = core.clone(list); + core.updateStatusBar(); + core.drawTip("开始播放"); + this.replay(); + return; +} - if (core.isset(list) && (list instanceof Array)) { - core.status.replay.replaying=true; - core.status.replay.toReplay = core.clone(list); - this.replay(); - return; - } +////// 更改播放状态 ////// +core.prototype.triggerReplay = function () { + if (core.status.replay.pausing) this.resumeReplay(); + else this.pauseReplay(); +} + +////// 暂停播放 ////// +core.prototype.pauseReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.pausing = true; + core.updateStatusBar(); + core.drawTip("暂停播放"); +} + +////// 恢复播放 ////// +core.prototype.resumeReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.pausing = false; + core.updateStatusBar(); + core.drawTip("恢复播放"); + core.replay(); +} + +////// 加速播放 ////// +core.prototype.forwardReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.speed = parseInt(10*core.status.replay.speed + 1)/10; + if (core.status.replay.speed>2.5) core.status.replay.speed=2.5; + core.drawTip("x"+core.status.replay.speed+"倍"); +} + +////// 减速播放 ////// +core.prototype.rewindReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.speed = parseInt(10*core.status.replay.speed - 1)/10; + if (core.status.replay.speed<0.3) core.status.replay.speed=0.3; + core.drawTip("x"+core.status.replay.speed+"倍"); +} + +////// 停止播放 ////// +core.prototype.stopReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.toReplay = []; + core.status.replay.totalList = []; + core.status.replay.replaying=false; + core.status.replay.pausing=false; + core.status.replay.speed=1.0; + core.updateStatusBar(); + core.drawTip("停止播放并恢复游戏"); +} + +////// 回放 ////// +core.prototype.replay = function () { if (!core.status.replay.replaying) return; // 没有回放 if (core.status.replay.pausing) return; // 暂停状态 if (core.status.replay.animate) return; // 正在某段动画中 if (core.status.replay.toReplay.length==0) { // 回放完毕 - core.status.replay.replaying=false; + core.stopReplay(); core.insertAction("录像回放完毕!"); return; } @@ -3576,7 +3645,7 @@ core.prototype.replay = function (list) { var selection = parseInt(selections.shift()); if (isNaN(selection) || selection<0 || selection>=choices.length || !core.events.clickShop(6, topIndex+selection)) { clearInterval(shopInterval); - core.status.replay.replaying=false; + core.stopReplay(); core.drawTip("录像文件出错"); return; } @@ -3603,7 +3672,7 @@ core.prototype.replay = function (list) { } } - core.status.replay.replaying=false; + core.stopReplay(); core.insertAction("录像文件出错"); } @@ -4111,6 +4180,7 @@ core.prototype.readFile = function (success, error) { return; } core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); + core.platform.fileInput.value = ''; } } @@ -4407,16 +4477,52 @@ core.prototype.updateStatusBar = function () { } core.statusBar.hard.innerHTML = core.status.hard; - if (core.hasItem('book')) { + + + // 回放 + if (core.status.replay.replaying) { + core.statusBar.image.book.src = core.status.replay.pausing?core.statusBar.icons.play.src:core.statusBar.icons.pause.src; core.statusBar.image.book.style.opacity = 1; - } else { - core.statusBar.image.book.style.opacity = 0.3; - } - if (core.hasItem('fly')) { + + core.statusBar.image.fly.src = core.statusBar.icons.stop.src; core.statusBar.image.fly.style.opacity = 1; - } else { - core.statusBar.image.fly.style.opacity = 0.3; + + //core.statusBar.image.toolbox.src = core.statusBar.icons.forward.src; + core.statusBar.image.toolbox.style.opacity = 0; + + core.statusBar.image.shop.style.opacity = 0; + + core.statusBar.image.save.src = core.statusBar.icons.rewind.src; + core.statusBar.image.save.style.opacity = 1; + + core.statusBar.image.load.src = core.statusBar.icons.forward.src; + core.statusBar.image.load.style.opacity = 1; + + core.statusBar.image.settings.style.opacity = 0; + } + else { + core.statusBar.image.book.src = core.statusBar.icons.book.src; + core.statusBar.image.book.style.opacity = core.hasItem('book')?1:0.3; + + core.statusBar.image.fly.src = core.statusBar.icons.fly.src; + core.statusBar.image.fly.style.opacity = core.hasItem('fly')?1:0.3; + + core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src; + core.statusBar.image.toolbox.style.opacity = 1; + + core.statusBar.image.shop.style.opacity = 1; + + core.statusBar.image.save.src = core.statusBar.icons.save.src; + core.statusBar.image.save.style.opacity = 1; + + core.statusBar.image.load.src = core.statusBar.icons.load.src; + core.statusBar.image.load.style.opacity = 1; + + core.statusBar.image.settings.src = core.statusBar.icons.settings.src; + core.statusBar.image.settings.style.opacity = 1; + } + core.updateFg(); } diff --git a/libs/events.js b/libs/events.js index 369ab144..a0e30a13 100644 --- a/libs/events.js +++ b/libs/events.js @@ -115,7 +115,7 @@ events.prototype.setInitData = function (hard) { events.prototype.win = function(reason) { core.ui.closePanel(); var replaying = core.status.replay.replaying; - core.status.replay.replaying=false; + core.stopReplay(); core.waitHeroToStop(function() { core.removeGlobalAnimate(0,0,true); core.clearMap('all'); // 清空全地图 @@ -131,9 +131,8 @@ events.prototype.win = function(reason) { events.prototype.lose = function(reason) { core.ui.closePanel(); var replaying = core.status.replay.replaying; - core.status.replay.replaying=false; + core.stopReplay(); core.waitHeroToStop(function() { - core.status.replay.replaying=false; core.drawText([ "\t[结局1]你死了。\n如题。" ], function () { @@ -481,7 +480,7 @@ events.prototype.doAction = function() { }, 500) } else { - core.status.replay.replaying=false; + core.stopReplay(); core.drawTip("录像文件出错"); } } @@ -1047,9 +1046,10 @@ events.prototype.clickFly = function(x,y) { var index=core.status.hero.flyRange.indexOf(core.status.floorId); var stair=core.status.event.data