From a6a8b91863e2eab86a99a558962e08417ff610d5 Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 1 Dec 2018 14:48:52 +0800 Subject: [PATCH] show/hide status bar --- README.md | 2 ++ _server/blockly/MotaAction.g4 | 38 ++++++++++++++++++++++++++++++-- _server/editor_blockly.js | 2 ++ docs/event.md | 41 +++++++++++++++++++++++++++++++++++ libs/control.js | 23 ++++++++++++++++++++ libs/events.js | 10 +++++++-- 更新说明.txt | 2 ++ 7 files changed, 114 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40c46a5b..8721c47f 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ HTML5 canvas制作的魔塔样板,支持全平台游戏! * [x] 升级事件改用事件编辑器完成 * [x] 每层楼都增添该层的并行事件处理 * [x] 新增快捷键:N返回标题;P查看评论;O打开工程 +* [x] 新增事件:设置全局属性或全局数值 +* [x] 新增事件:隐藏/显示状态栏 * [x] 道具可以设置是否在回放时绘制道具栏或直接使用 * [x] 可以同时异步移动/跳跃勇士和多个NPC * [x] 可以同时异步移动两张或以上的图片了 diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 1fedbba2..6fecc669 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -230,6 +230,8 @@ action | setBgFgBlock_s | setHeroIcon_s | update_s + | showStatusBar_s + | hideStatusBar_s | updateEnemys_s | sleep_s | wait_s @@ -445,7 +447,7 @@ setGlobalAttribute_s /* setGlobalAttribute_s tooltip : setGlobalAttribute:设置全局属性 -helpUrl : https://h5mota.com/games/template/docs/#/event?id=setFloor%ef%bc%9a%e8%ae%be%e7%bd%ae%e6%a5%bc%e5%b1%82%e5%b1%9e%e6%80%a7 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=setGlobalAttribute%ef%bc%9a%e8%ae%be%e7%bd%ae%e4%b8%80%e4%b8%aa%e5%85%a8%e5%b1%80%e5%b1%9e%e6%80%a7 default : ["font","Verdana"] colour : this.dataColor var code = '{"type": "setGlobalAttribute", "name": "'+Global_Attribute_List_0+'", "value": "'+EvalString_0+'"},\n'; @@ -459,7 +461,7 @@ setGlobalValue_s /* setGlobalValue_s tooltip : setGlobalValue:设置全局属性 -helpUrl : https://h5mota.com/games/template/docs/#/event?id=setFloor%ef%bc%9a%e8%ae%be%e7%bd%ae%e6%a5%bc%e5%b1%82%e5%b1%9e%e6%80%a7 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=setGlobalValue%ef%bc%9a%e8%ae%be%e7%bd%ae%e4%b8%80%e4%b8%aa%e5%85%a8%e5%b1%80%e6%95%b0%e5%80%bc default : ["lavaDamage","100"] colour : this.dataColor var code = '{"type": "setGlobalValue", "name": "'+Global_Value_List_0+'", "value": '+EvalString_0+'},\n'; @@ -768,6 +770,30 @@ var code = '{"type": "update"},\n'; return code; */; +showStatusBar_s + : '显示状态栏' Newline + + +/* showStatusBar_s +tooltip : showStatusBar: 显示状态栏 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=showStatusBar%ef%bc%9a%e6%98%be%e7%a4%ba%e7%8a%b6%e6%80%81%e6%a0%8f +colour : this.soundColor +var code = '{"type": "showStatusBar"},\n'; +return code; +*/; + +hideStatusBar_s + : '隐藏状态栏' Newline + + +/* hideStatusBar_s +tooltip : hideStatusBar: 隐藏状态栏 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=hideStatusBar%ef%bc%9a%e9%9a%90%e8%97%8f%e7%8a%b6%e6%80%81%e6%a0%8f +colour : this.soundColor +var code = '{"type": "hideStatusBar"},\n'; +return code; +*/; + updateEnemys_s : '更新怪物数据' Newline @@ -2175,6 +2201,14 @@ ActionParser.prototype.parseAction = function() { this.next = MotaActionBlocks['update_s'].xmlText([ this.next]); break; + case "showStatusBar": + this.next = MotaActionBlocks['showStatusBar_s'].xmlText([ + this.next]); + break; + case "hideStatusBar": + this.next = MotaActionBlocks['hideStatusBar_s'].xmlText([ + this.next]); + break; case "updateEnemys": this.next = MotaActionBlocks['updateEnemys_s'].xmlText([ this.next]); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 4b0212e4..f36cb09e 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -133,6 +133,8 @@ editor_blockly = function () { MotaActionBlocks['wait_s'].xmlText(), MotaActionBlocks['viberate_s'].xmlText(), MotaActionBlocks['animate_s'].xmlText(), + MotaActionBlocks['showStatusBar_s'].xmlText(), + MotaActionBlocks['hideStatusBar_s'].xmlText(), MotaActionBlocks['setFg_0_s'].xmlText(), MotaActionBlocks['setFg_1_s'].xmlText(), MotaActionBlocks['setWeather_s'].xmlText(), diff --git a/docs/event.md b/docs/event.md index 8b1c6622..041d9547 100644 --- a/docs/event.md +++ b/docs/event.md @@ -414,6 +414,37 @@ value为必填项,代表要修改到的数值。其应该和楼层属性中的 !> 如果修改到的是字符串类型,比如楼层中文名、状态栏名称、地面素材ID、背景音乐等,必须加引号,否则会报错。 +### setGlobalAttribute:设置一个全局属性 + +使用`{"type":"setGlobalAttribute"}`可以设置一个全局属性。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "setGlobalAttribute", "name": "font", "value": "Verdana"}, // 设置字体为Verdana +] +``` + +name必填项,代表要修改的全局属性。目前只能为`"font", "statusLeftBackground", "statusTopBackground", "toolsBackground", +"borderColor", "statusBarColor", "hardLabelColor", "floorChangingBackground", "floorChangingTextColor"`。 + +value为必填项,代表要修改到的结果。此项无需再手动加单引号。 + +### setGlobalValue:设置一个全局数值 + +使用`{"type":"setGlobalValue"}`可以设置一个全局数值。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "setGlobalValue", "name": "lavaDamage", "value": 200}, // 设置血网伤害为200 +] +``` + +name必填项,代表要修改的全局数值,其和全塔属性中的values一一对应。目前只能为`"lavaDamage", "poisonDamage", "weakValue", "redJewel", +"blueJewel", "greenJewel", "redPotion", "bluePotion", "yellowPotion", "greenPotion", "breakArmor", "counterAttack", +"purify", "hatred", "maxValidHp", "animateSpeed"`。 + +value为必填项,代表要修改到的结果。该项必须是个数值。 + ### show:将一个禁用事件启用 我们上面提到了,所有事件都必须靠其他事件驱动来完成,不存在当某个flag为true时自动执行的说法。那么,我们自然要有启用事件的写法。 @@ -676,6 +707,16 @@ name是可选的,代表目标行走图的文件名。 如果你需要刷新状态栏和地图显伤,只需要简单地调用 `{"type": "update"}` 即可。 +### hideStatusBar:隐藏状态栏 + +使用`{"type": "hideStatusBar"}`可以隐藏状态栏。读档或重新开始游戏时,状态栏会重新显示。 + +隐藏状态栏的状态下,将无法点击工具栏里面的按钮(如存读档怪物手册等)。建议仅在事件中使用,事件结束前显示。 + +### showStatusBar:显示状态栏 + +使用`{"type": "showStatusBar"}`会重新显示状态栏。 + ### updateEnemys:更新怪物数据 使用 `{"type": "updateEnemys"}` 可以动态修改怪物数据。 diff --git a/libs/control.js b/libs/control.js index 2ded4a97..1f040ec4 100644 --- a/libs/control.js +++ b/libs/control.js @@ -293,6 +293,9 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value // 清除游戏数据 core.clearStatus(); + // 显示状态栏 + core.control.triggerStatusBar("show"); + // 初始化status core.status = core.clone(core.initStatus); // 初始化maps @@ -2732,6 +2735,26 @@ control.prototype.updateStatusBar = function () { } } +control.prototype.triggerStatusBar = function (name) { + if (name!='hide') name='show'; + var statusItems = core.dom.status; + var toolItems = core.dom.tools; + if (name == 'hide') { + for (var i = 0; i < statusItems.length; ++i) + statusItems[i].style.opacity = 0; + for (var i = 0; i < toolItems.length; ++i) + toolItems[i].style.display = 'none'; + } + else { + for (var i = 0; i < statusItems.length; ++i) + statusItems[i].style.opacity = 1; + for (var i = 0; i < toolItems.length; ++i) + toolItems[i].style.display = 'block'; + if (core.domStyle.screenMode != 'vertical') + core.statusBar.image.shop.style.display = 'none'; + } +} + control.prototype.updateHeroIcon = function (name) { name = name || "hero.png"; if (core.statusBar.icons.name == name) return; diff --git a/libs/events.js b/libs/events.js index 942631ee..0e66a335 100644 --- a/libs/events.js +++ b/libs/events.js @@ -98,8 +98,6 @@ events.prototype.startGame = function (hard, seed, route, callback) { console.log('开始游戏'); core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps); - core.status.isStarting = true; - if (core.isset(seed)) { core.setFlag('__seed__', seed); core.setFlag('__rand__', seed); @@ -1046,6 +1044,14 @@ events.prototype.doAction = function() { core.updateStatusBar(); this.doAction(); break; + case "showStatusBar": + core.control.triggerStatusBar("show"); + this.doAction(); + break; + case "hideStatusBar": + core.control.triggerStatusBar("hide"); + this.doAction(); + break; case "updateEnemys": core.enemys.updateEnemys(); core.updateStatusBar(); diff --git a/更新说明.txt b/更新说明.txt index 82f7e95f..443b2ae6 100644 --- a/更新说明.txt +++ b/更新说明.txt @@ -8,6 +8,8 @@ 升级事件改用事件编辑器完成 每层楼都增添该层的并行事件处理 新增快捷键:N返回标题;P查看评论;O打开工程 +新增事件:设置全局属性或全局数值 +新增事件:隐藏/显示状态栏 道具可以设置是否在回放时绘制道具栏或直接使用 可以同时异步移动/跳跃勇士和多个NPC 可以同时异步移动两张或以上的图片了