From 2e34fd267fd0e161b528253fd279b4b48c4c673f Mon Sep 17 00:00:00 2001 From: oc Date: Fri, 12 Apr 2019 23:59:39 +0800 Subject: [PATCH 1/4] drawChoices offset --- _docs/api.md | 2 +- _server/editor_blockly.js | 2 +- libs/actions.js | 25 ++++++++++++------------- libs/ui.js | 26 ++++++++++++++------------ 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/_docs/api.md b/_docs/api.md index 7ad94388..2f167244 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -199,7 +199,7 @@ core.onkeyDown(e) core.onkeyUp(e) 当放开某个键时的操作,e为KeyboardEvent。 -请勿直接覆盖或调用此函数,如有需要请注册一个"onkeyDown"的交互函数。 +请勿直接覆盖或调用此函数,如有需要请注册一个"onkeyUp"的交互函数。 core.pressKey(keyCode) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 4a705f37..90bf5962 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -68,6 +68,7 @@ editor_blockly = function () { MotaActionBlocks['tip_s'].xmlText(), MotaActionBlocks['win_s'].xmlText(), MotaActionBlocks['lose_s'].xmlText(), + MotaActionBlocks['confirm_s'].xmlText(), MotaActionBlocks['choices_s'].xmlText([ '选择剑或者盾','流浪者','man',MotaActionBlocks['choicesContext'].xmlText([ '剑','','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), @@ -76,7 +77,6 @@ editor_blockly = function () { ]) ]) ]), - MotaActionBlocks['confirm_s'].xmlText(), ], '数据相关':[ MotaActionBlocks['setValue_s'].xmlText([ diff --git a/libs/actions.js b/libs/actions.js index 989c7978..e64fb01e 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -777,9 +777,8 @@ actions.prototype._sys_longClick = function (x, y, fromEvent) { // 数字键快速选择选项 actions.prototype._selectChoices = function (length, keycode, callback) { - var topIndex = this.HSIZE - parseInt((length - 1) / 2); + var topIndex = this.HSIZE - parseInt((length - 1) / 2) + (core.status.event.ui.offset || 0); if (keycode == 13 || keycode == 32 || keycode == 67) { - core.status.event.ui.sep = 0; callback.apply(this, [this.HSIZE, topIndex + core.status.event.selection]); } if (keycode >= 49 && keycode <= 57) { @@ -884,7 +883,7 @@ actions.prototype._clickAction = function (x, y) { var choices = data.choices; if (choices.length == 0) return; if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) { - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.sep || 0); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { // 选择 core.status.route.push("choices:" + (y - topIndex)); @@ -1208,7 +1207,7 @@ actions.prototype._clickShop = function (x, y) { var shop = core.status.event.data.shop; var choices = shop.choices; if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) { - var topIndex = this.HSIZE - parseInt(choices.length / 2); + var topIndex = this.HSIZE - parseInt(choices.length / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { return core.events._useShop(shop, y - topIndex); } @@ -1238,7 +1237,7 @@ actions.prototype._clickQuickShop = function (x, y) { }); if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) { - var topIndex = this.HSIZE - parseInt(keys.length / 2); + var topIndex = this.HSIZE - parseInt(keys.length / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + keys.length) { var reason = core.events.canUseQuickShop(keys[y - topIndex]); if (!core.flags.enableDisabledShop && reason) { @@ -1831,7 +1830,7 @@ actions.prototype._keyUpSL = function (keycode) { actions.prototype._clickSwitchs = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; core.status.event.selection = selection; @@ -1928,7 +1927,7 @@ actions.prototype._keyUpSwitchs = function (keycode) { actions.prototype._clickSettings = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; core.status.event.selection = selection; @@ -1979,7 +1978,7 @@ actions.prototype._keyUpSettings = function (keycode) { actions.prototype._clickSyncSave = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; core.status.event.selection = selection; @@ -2062,7 +2061,7 @@ actions.prototype._clickSyncSelect = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; core.status.event.selection = selection; @@ -2096,7 +2095,7 @@ actions.prototype._clickLocalSaveSelect = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; @@ -2136,7 +2135,7 @@ actions.prototype._clickStorageRemove = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; @@ -2225,7 +2224,7 @@ actions.prototype._clickReplay = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; @@ -2279,7 +2278,7 @@ actions.prototype._clickGameInfo = function (x, y) { if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; - var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2); + var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; diff --git a/libs/ui.js b/libs/ui.js index 9b4dfbc0..5425c2ad 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -555,9 +555,8 @@ ui.prototype._calTextBoxWidth = function (ctx, content, min_width, max_width, fo ////// 处理 \i[xxx] 的问题 ui.prototype._getDrawableIconInfo = function (id) { - var splt = id.split(':'); - if (splt[0] == 'flag' && splt.length > 1) { // 使用变量表示图标 - id = core.getFlag(splt[1], id); + if (id && id.indexOf('flag:') === 0) { + id = core.getFlag(id.substring(5), id); } var image = null, icon = null; ["terrains","animates","items","npcs","enemys"].forEach(function (v) { @@ -974,6 +973,7 @@ ui.prototype.drawChoices = function(content, choices) { var titleInfo = this._getTitleAndIcon(content); var hPos = this._drawChoices_getHorizontalPosition(titleInfo, choices); var vPos = this._drawChoices_getVerticalPosition(titleInfo, choices, hPos); + core.status.event.ui.offset = vPos.offset; var isWindowSkin = this.drawBackground(hPos.left, vPos.top, hPos.right, vPos.bottom); this._drawChoices_drawTitle(titleInfo, hPos, vPos); @@ -1002,20 +1002,22 @@ ui.prototype._drawChoices_getVerticalPosition = function (titleInfo, choices, hP var length = choices.length; var height = 32 * (length + 2), bottom = this.HPIXEL + height / 2; if (length % 2 == 0) bottom += 16; + var offset = 0; var choice_top = bottom - height + 56; if (titleInfo.content) { + var headHeight = 0; var realContent = this._getRealContent(titleInfo.content); var lines = core.splitLines('ui', realContent, hPos.validWidth, this._buildFont(15, true)); - if (titleInfo.title) height += 25; - height += lines.length * 20; + if (titleInfo.title) headHeight += 25; + headHeight += lines.length * 20; + height += headHeight; + if (bottom - height <= 32) { + offset = Math.floor(headHeight / 64); + bottom += 32 * offset; + choice_top += 32 * offset; + } } - if(bottom-height<0){ - var sep = Math.ceil((height-bottom)/32); - choice_top += sep * 32; - bottom += sep*32; - core.status.event.ui.sep = sep; - } - return {top: bottom - height, height: height, bottom: bottom, choice_top: choice_top }; + return {top: bottom - height, height: height, bottom: bottom, choice_top: choice_top, offset: offset }; } ui.prototype._drawChoices_drawTitle = function (titleInfo, hPos, vPos) { From f8c95e57aac5f83bf1bc3d2910208276cd2adc3d Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 13 Apr 2019 00:09:40 +0800 Subject: [PATCH 2/4] V2.6 --- README.md | 18 ++++++++++++++++++ 更新说明.txt | 22 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b81aa04b..da2183a4 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,24 @@ HTML5 canvas制作的魔塔样板,支持全平台游戏! ## 更新说明 +### 2019.4.13 V2.6 + +* [x] 拆分整个项目,大幅重构代码,新增大量API +* [x] 重写文档,尤其是脚本和API列表 +* [x] 现在可以对编辑器的表格的结构进行配置 +* [x] 可以收藏和高亮存档 +* [x] 独立出来的插件编写 +* [x] 新增事件:关门、显示确认框、后置循环处理 +* [x] 剧情文本的绘制可以设置居中选项 +* [x] 选项框的绘制可以增加图标 +* [x] 增加公共事件版的全局商店 +* [x] 公共事件现在可以传入参数 +* [x] 重写滑冰事件,现在滑冰在背景层了 +* [x] 将输入框改成自定义实现,避免部分设备不支持 +* [x] 状态栏文字可以自动放缩 +* [x] 显示图片和对话框立绘可以裁剪图片 +* [x] 修复所有已知bug,大量细节优化 + ### 2019.2.19 V2.5.5 * [x] 现在编辑器修改地图后可以直接读档生效,无需再重置地图或回放录像 diff --git a/更新说明.txt b/更新说明.txt index 4bf78891..ec9833e3 100644 --- a/更新说明.txt +++ b/更新说明.txt @@ -1,4 +1,24 @@ -HTML5魔塔样板V2.5.5 +HTML5魔塔样板V2.6 + +拆分整个项目,大幅重构代码,新增大量API +重写文档,尤其是脚本和API列表 +现在可以对编辑器的表格的结构进行配置 +可以收藏和高亮存档 +独立出来的插件编写 +新增事件:关门、显示确认框、后置循环处理 +剧情文本的绘制可以设置居中选项 +选项框的绘制可以增加图标 +增加公共事件版的全局商店 +公共事件现在可以传入参数 +重写滑冰事件,现在滑冰在背景层了 +将输入框改成自定义实现,避免部分设备不支持 +状态栏文字可以自动放缩 +显示图片和对话框立绘可以裁剪图片 +修复所有已知bug,大量细节优化 + +----------------------------------------------------------------------- + +HTML5魔塔样板V2.5.5 现在编辑器修改地图后可以直接读档生效,无需再重置地图或回放录像 存档方式优化,大幅降低单个存档的占用空间 From 8ec4b13afc9371527c18bad74379e0e02ae47b3a Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 13 Apr 2019 00:52:41 +0800 Subject: [PATCH 3/4] Fix hatred decrease --- project/functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/functions.js b/project/functions.js index 4e4c0762..8ce11fa8 100644 --- a/project/functions.js +++ b/project/functions.js @@ -1205,7 +1205,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var leftHp = core.status.hero.hp - (damage[x + "," + y] || 0); if (leftHp > 1) { // 上整/下整 - var value = Math.floor((leftHp + (core.flags.betweenAttackCeil ? 0 : 1)) / 2); + var value = Math.floor((leftHp + (core.flags.betweenAttackCeil ? 1 : 0)) / 2); damage[loc] = (damage[loc] || 0) + value; type[loc] = "夹击伤害"; } From 822a0deb5bec0bdecf9a48bf9e7f28a5097c5d13 Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 13 Apr 2019 22:11:08 +0800 Subject: [PATCH 4/4] changefloor current position --- _server/MotaAction.g4 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 4f38fe1e..98f8cdca 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -228,7 +228,8 @@ default : [null,"MT1",null,0,0,null,500,null] var toFloorId = IdString_0; if (Floor_List_0!='floorId') toFloorId = Floor_List_0; var loc = ', "loc": ['+Number_0+', '+Number_1+']'; -if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"'; +if (Stair_List_0==='now')loc = ''; +else if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"'; DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"'); Int_0 = (Int_0!=='') ?(', "time": '+Int_0):''; Bool_0 = Bool_0 ?'':(', "ignoreChangeFloor": false'); @@ -1982,8 +1983,8 @@ Floor_List /*Floor_List ['floorId',':before',':next']*/; Stair_List - : '坐标'|'上楼梯'|'下楼梯' - /*Stair_List ['loc','upFloor','downFloor']*/; + : '坐标'|'上楼梯'|'下楼梯'|'保持不变' + /*Stair_List ['loc','upFloor','downFloor','now']*/; SetTextPosition_List : '不改变'|'距离顶部'|'居中'|'距离底部' @@ -2167,7 +2168,10 @@ ActionParser.prototype.parse = function (obj,type) { case 'changeFloor': if(!obj)obj={}; - if(!this.isset(obj.loc))obj.loc=[0,0]; + if(!this.isset(obj.loc)) { + obj.loc=[0,0]; + if (!this.isset(obj.stair)) obj.stair='now'; + } if (obj.floorId==':before'||obj.floorId==':next') { obj.floorType=obj.floorId; delete obj.floorId;