diff --git a/_docs/event.md b/_docs/event.md index e91d34f6..e7e67b94 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -1964,6 +1964,31 @@ yes和no均为必填项,即用户点击确认或取消后执行的事件。 ![](img/events/52.jpg) +从V2.6.6开始,也允许直接在`type:wait`中增加`data`项判定按键或点击坐标。 + +```js +[ + {"type": "wait", "data": [ + {"case": "keyboard", "keycode": 13, "action": [ + {"type": "comment", "text": "当按下回车(keycode=13)时执行此事件"}, + ]}, + {"case": "mouse", "px": [0,32], "py": [0,32], "action": [ + {"type": "comment", "text": "当点击地图左上角时执行此事件"}, + ]}, + ]}, +] +``` + +![](img/events/52.png) + +`data`是一个数组,每一项中,case只能为`keyboard`和`mouse`二选一,分别对应键盘和鼠标(即`type=0`和`type=1`)。 + +如果是键盘,则可以指定`keycode`为键盘的按键内容;否则指定`px`和`py`为点击的像素区间。 + +action为如果满足该条件时应该执行的事件列表。 + + + ### waitAsync:等待所有异步事件执行完毕 上面有很多很多的异步事件(也就是执行时不等待执行完毕)。 diff --git a/_docs/img/events/52.png b/_docs/img/events/52.png new file mode 100644 index 00000000..3c0c13c8 Binary files /dev/null and b/_docs/img/events/52.png differ diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 5059405e..e436f5d6 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2020,14 +2020,14 @@ return code; waitContext_2 - : '点击的场合' '像素x范围' Int '~' Int '; y范围' Int '~' Int BGNL? Newline action+ BEND Newline + : '点击的场合' '像素x范围' PosString '~' PosString '; y范围' PosString '~' PosString BGNL? Newline action+ BEND Newline /* waitContext_2 tooltip : wait: 等待用户操作并获得按键或点击信息 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=wait%EF%BC%9A%E7%AD%89%E5%BE%85%E7%94%A8%E6%88%B7%E6%93%8D%E4%BD%9C default : [0,32,0,32] colour : this.subColor -var code = '{"case": "mouse", "px": [' + Int_0 + ',' + Int_1 + '], "py": [' + Int_2 + ',' + Int_3 + '], "action": [\n' + action_0 + ']},\n'; +var code = '{"case": "mouse", "px": [' + PosString_0 + ',' + PosString_1 + '], "py": [' + PosString_2 + ',' + PosString_3 + '], "action": [\n' + action_0 + ']},\n'; return code; */; diff --git a/_server/editor.js b/_server/editor.js index 716b27a0..84b3f424 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -159,7 +159,7 @@ editor.prototype.init = function (callback) { editor.mode = editor_mode; core.resetGame(core.firstData.hero, null, core.firstData.floorId, core.clone(core.initStatus.maps)); var lastFloorId = core.getLocalStorage('editorLastFloorId', core.status.floorId); - if (core.floors.indexOf(lastFloorId) < 0) lastFloorId = core.status.floorId; + if (core.floorIds.indexOf(lastFloorId) < 0) lastFloorId = core.status.floorId; core.changeFloor(lastFloorId, null, core.firstData.hero.loc, null, function () { afterCoreReset(); }, true); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index c1f0562a..91599d24 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -692,14 +692,20 @@ function omitedcheckUpdateFunction(event) { "previewUI_s", "clearMap_s", "clearMap_1_s", "setAttribute_s", "fillText_s", "fillBoldText_s", "fillRect_s", "strokeRect_s", "drawLine_s", "drawArrow_s", "fillPolygon_s", "strokePolygon_s", "fillCircle_s", "strokeCircle_s", - "drawImage_s", "drawImage_1_s", "drawIcon_s", "drawBackground_s", "drawSelector_s", "drawSelector_1_s" + "drawImage_s", "drawImage_1_s", "drawIcon_s", "drawBackground_s", "drawSelector_s", "drawSelector_1_s", + "waitContext_2" ]; if (b && types.indexOf(b.type)>=0) { try { var code = "[" + Blockly.JavaScript.blockToCode(b).replace(/\\(i|c|d|e)/g, '\\\\$1') + "]"; eval("var obj="+code); - // console.log(obj); - if (obj.length > 0 && b.type.startsWith(obj[0].type)) { + if (obj.length > 0 && b.type == 'waitContext_2') { + var dt = obj[0]; + editor.uievent.previewUI([{"type": "fillRect", "x": dt.px[0], "y": dt.py[0], + "width": "(" + dt.px[1] + ")-(" + dt.px[0] + ")", "height": "(" + dt.py[1] + ")-(" + dt.py[0] + ")", + "style": "#FF0000"}]) + } + else if (obj.length > 0 && b.type.startsWith(obj[0].type)) { if (b.type == 'previewUI_s') editor.uievent.previewUI(obj[0].action); else editor.uievent.previewUI([obj[0]]); diff --git a/libs/events.js b/libs/events.js index 8a50cc5f..628d5548 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1970,6 +1970,17 @@ events.prototype.__action_wait_afterGet = function (data) { core.insertAction(todo); } +events.prototype._precompile_wait = function (data) { + if (data.data) { + data.data.forEach(function (v) { + if (v.px) v.px = this.__precompile_array(v.px); + if (v.py) v.py = this.__precompile_array(v.py); + v.action = this.precompile(v.action); + }, this); + } + return data; +} + events.prototype._action_waitAsync = function (data, x, y, prefix) { var test = window.setInterval(function () { if (!core.hasAsync()) {