From ee025ad7b043496eb89ba413ffb539f56038ac91 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Mon, 13 Jan 2020 10:52:28 +0800 Subject: [PATCH] onStatusBarClick --- _server/table/functions.comment.js | 6 ++++++ libs/actions.js | 19 ++++++++++++++++++- main.js | 9 +++++++++ project/functions.js | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/_server/table/functions.comment.js b/_server/table/functions.comment.js index 6f30fa75..81e18e7c 100644 --- a/_server/table/functions.comment.js +++ b/_server/table/functions.comment.js @@ -139,6 +139,12 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_type": "textarea", "_lint": true, "_data": "按键处理" + }, + "onStatusBarClick": { + "_leaf": true, + "_type": "textarea", + "_lint": true, + "_data": "状态栏点击事件,仅在开启自绘状态栏时生效" } } }, diff --git a/libs/actions.js b/libs/actions.js index 9f63d0bd..c04140fd 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -59,6 +59,8 @@ actions.prototype._init = function () { // --- longClick注册 this.registerAction('longClick', '_sys_longClick_lockControl', this._sys_longClick_lockControl, 50); this.registerAction('longClick', '_sys_longClick', this._sys_longClick, 0); + // --- onStatusBarClick注册 + this.registerAction('onStatusBarClick', '_sys_onStatusBarClick', this._sys_onStatusBarClick, 0); } @@ -612,7 +614,7 @@ actions.prototype._getClickLoc = function (x, y) { ////// 具体点击屏幕上(x,y)点时,执行的操作 ////// actions.prototype.onclick = function (x, y, stepPostfix) { // console.log("Click: (" + x + "," + y + ")"); - this.doRegisteredAction('onclick', x, y, stepPostfix || []); + return this.doRegisteredAction('onclick', x, y, stepPostfix || []); } actions.prototype._sys_onclick_lockControl = function (x, y) { @@ -844,6 +846,21 @@ actions.prototype._sys_longClick = function (x, y, fromEvent) { return false; } +actions.prototype.onStatusBarClick = function (e) { + if (!core.isPlaying()) return false; + var left = core.dom.gameGroup.offsetLeft + 3; + var top = core.dom.gameGroup.offsetTop + 3; + var px = parseInt((e.clientX - left) / core.domStyle.scale), py = parseInt((e.clientY - top) / core.domStyle.scale); + return this.doRegisteredAction('onStatusBarClick', px, py); +} + +actions.prototype._sys_onStatusBarClick = function (px, py) { + if (!core.status.played) return true; + if (this.actionsdata.onStatusBarClick) { + this.actionsdata.onStatusBarClick(px, py); + } +} + /////////////////// 在某个界面时的按键点击效果 /////////////////// // 数字键快速选择选项 diff --git a/main.js b/main.js index 8f581d72..d9e3534a 100644 --- a/main.js +++ b/main.js @@ -518,6 +518,15 @@ main.dom.data.ontouchend = function (e) { } } +main.dom.statusCanvas.onclick = function (e) { + try { + e.preventDefault(); + main.core.onStatusBarClick(e); + } catch (e) { + main.log(e); + } +} + ////// 点击状态栏中的怪物手册时 ////// main.statusBar.image.book.onclick = function (e) { e.stopPropagation(); diff --git a/project/functions.js b/project/functions.js index e094e708..243f226d 100644 --- a/project/functions.js +++ b/project/functions.js @@ -933,6 +933,23 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = */ } +}, + "onStatusBarClick": function (px, py) { + // 点击状态栏时触发的事件,仅在自绘状态栏开启时生效 + // px和py为点击的像素坐标 + // + // 横屏模式下状态栏的画布大小是 129*416 + // 竖屏模式下状态栏的画布大小是 416*(32*rows+9) 其中rows为状态栏行数,即全塔属性中statusCanvasRowsOnMobile值 + // 可以使用 core.domStyle.isVertical 来判定当前是否是竖屏模式 + + // 如果正在执行事件,则忽略 + if (core.status.event.id != null) return; + // 如果当前正在行走,则忽略;也可以使用 core.waitHeroToStop(callback) 来停止行走再回调执行脚本 + if (core.isMoving()) return; + + // 判定px和py来执行自己的脚本内容.... 注意横竖屏 + // 这里是直接打出点击坐标的例子。 + // console.log("onStatusBarClick:", px, py); } }, "control": {