From 2e34fd267fd0e161b528253fd279b4b48c4c673f Mon Sep 17 00:00:00 2001 From: oc Date: Fri, 12 Apr 2019 23:59:39 +0800 Subject: [PATCH] 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) {