From 6707e7eca0caaf547f315b102da24c279c74ef19 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Wed, 28 Feb 2018 20:02:40 +0800 Subject: [PATCH] Long Press --- docs/event.md | 2 +- libs/core.js | 32 ++++++++++++++++++++++++++++++-- libs/events.js | 13 +++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/docs/event.md b/docs/event.md index 24803034..879ac5d1 100644 --- a/docs/event.md +++ b/docs/event.md @@ -303,7 +303,7 @@ position为可选项,表示设置文字显示位置。只能为up(上),c bold为可选项,如果设置则为true或false,表示正文是否使用粗体。 默认值:`false` -time为可选项,表示文字滚动的速度。若此项设置为0将直接全部显示,若大于0则会设置为相邻字符依次显示的时间间隔。 默认值:`50` +time为可选项,表示文字添加的速度。若此项设置为0将直接全部显示,若大于0则会设置为相邻字符依次显示的时间间隔。 默认值:`0` ### tip:显示一段提示文字 diff --git a/libs/core.js b/libs/core.js index 1769e9cc..e81ba5df 100644 --- a/libs/core.js +++ b/libs/core.js @@ -17,12 +17,14 @@ function core() { this.timeout = { 'getItemTipTimeout': null, 'turnHeroTimeout': null, + 'onDownTimeout': null, } this.interval = { 'heroMoveInterval': null, "tipAnimate": null, 'openDoorAnimate': null, 'animateInterval': null, + 'onDownInterval': null, } this.animateFrame = { 'background': null, @@ -132,7 +134,7 @@ function core() { "background": [0,0,0,0.85], "text": [255,255,255,1], "bold": false, - "time": 50, + "time": 0, }, 'curtainColor': null, 'usingCenterFly':false, @@ -772,8 +774,13 @@ core.prototype.clearStatus = function() { core.prototype.resetStatus = function(hero, hard, floorId, route, maps) { // 停止各个Timeout和Interval + for (var i in core.timeout) { + clearTimeout(core.timeout[i]); + core.timeout[i] = null; + } for (var i in core.interval) { clearInterval(core.interval[i]); + core.interval[i] = null; } // 初始化status @@ -1226,6 +1233,18 @@ core.prototype.ondown = function (x ,y) { if (core.isset(core.status.replay)&&core.status.replay.replaying) return; if (!core.status.played || core.status.lockControl) { core.onclick(x, y, []); + if (core.timeout.onDownTimeout==null) { + core.timeout.onDownTimeout = setTimeout(function () { + if (core.interval.onDownInterval == null) { + core.interval.onDownInterval = setInterval(function () { + if (!core.events.longClick()) { + clearInterval(core.interval.onDownInterval); + core.interval.onDownInterval = null; + } + }, 40) + } + }, 500); + } return; } @@ -1268,6 +1287,12 @@ core.prototype.onmove = function (x ,y) { ////// 当点击(触摸)事件放开时 ////// core.prototype.onup = function () { if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + + clearTimeout(core.timeout.onDownTimeout); + core.timeout.onDownTimeout = null; + clearInterval(core.interval.onDownInterval); + core.interval.onDownInterval = null; + // core.status.holdingPath=0; if(core.status.stepPostfix.length>0){ var stepPostfix = []; @@ -1287,7 +1312,10 @@ core.prototype.onup = function () { // 长按 if (!core.status.lockControl && stepPostfix.length==0 && core.status.downTime!=null && new Date()-core.status.downTime>=1000) { - core.events.longClick(); + core.waitHeroToStop(function () { + // 绘制快捷键 + core.ui.drawKeyBoard(); + }); } else { //posx,posy是寻路的目标点,stepPostfix是后续的移动 diff --git a/libs/events.js b/libs/events.js index d1ef7e54..461f18b5 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1095,10 +1095,15 @@ events.prototype.afterLoadData = function(data) { ////// 长按 ////// events.prototype.longClick = function () { - core.waitHeroToStop(function () { - // 绘制快捷键 - core.ui.drawKeyBoard(); - }); + if (core.status.event.id=='text') { + core.drawText(); + return true; + } + if (core.status.event.id=='action' && core.status.event.data.type=='text') { + this.doAction(); + return true; + } + return false; } ////// 按下Ctrl键时(快捷跳过对话) //////