From 2ffa315acb87d62fd28a016e5d6cdae686f9d78d Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Thu, 12 Aug 2021 16:53:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=80=89=E6=8B=A9=E9=A1=B9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _docs/api.md | 2 +- _server/CodeMirror/defs.js | 2 +- _server/MotaAction.g4 | 10 ++++++---- _server/MotaActionParser.js | 2 +- _server/editor_blockly.js | 2 +- _server/editor_blocklyconfig.js | 2 +- _server/editor_ui.js | 4 +++- libs/actions.js | 6 +++--- libs/events.js | 6 ++++-- libs/ui.js | 12 ++++++------ 10 files changed, 27 insertions(+), 21 deletions(-) diff --git a/_docs/api.md b/_docs/api.md index 3f67bd85..58ee76f4 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -1869,7 +1869,7 @@ drawBackground: fn(left: string, top: string, right: string, bottom: string, pos drawBook: fn(index?: ?) 绘制怪物手册 -drawChoices: fn(content?: string, choices?: [?]) +drawChoices: fn(content?: string, choices?: [?], width?: number, ctx?: string|CanvasRenderingContext2D) 绘制一个选项界面 drawConfirmBox: fn(text: string, yesCallback?: fn(), noCallback?: fn()) diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js index 58d33de5..c48a8388 100644 --- a/_server/CodeMirror/defs.js +++ b/_server/CodeMirror/defs.js @@ -3585,7 +3585,7 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [ }, "drawChoices": { "!doc": "绘制一个选项界面", - "!type": "fn(content?: string, choices?: [?])" + "!type": "fn(content?: string, choices?: [?], width?: number, ctx?: string|CanvasRenderingContext2D)" }, "setFontForMaxWidth": { "!doc": "根据最大宽度自动缩小字体", diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 10a37142..8ec17bb5 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2715,14 +2715,14 @@ return code; */; choices_s - : '选项' ':' EvalString_Multi? BGNL? '标题' EvalString? '图像' IdString? '超时毫秒数' Int BGNL? Newline choicesContext+ BEND Newline + : '选项' ':' EvalString_Multi? BGNL? '标题' EvalString? '图像' IdString? '默认选中项' Int '超时毫秒数' Int '宽度' IntString? BGNL? Newline choicesContext+ BEND Newline /* choices_s tooltip : choices: 给用户提供选项 helpUrl : /_docs/#/instruction previewBlock : true -default : ["","流浪者","trader",0] +default : ["","流浪者","trader",0,0,''] allIds : ['IdString_0'] var title=''; if (EvalString_0==''){ @@ -2734,8 +2734,10 @@ if (EvalString_0==''){ } EvalString_Multi_0 = title+EvalString_Multi_0; EvalString_Multi_0 = EvalString_Multi_0 ?(', "text": "'+EvalString_Multi_0+'"'):''; -Int_0 = Int_0 ? (', "timeout": '+Int_0) : ''; -var code = ['{"type": "choices"',EvalString_Multi_0,Int_0, +Int_0 = Int_0 ? (', "selected": '+Int_0) : ''; +Int_1 = Int_1 ? (', "timeout": '+Int_1) : ''; +IntString_0 = IntString_0 ? (', "width": ' + IntString_0) : ''; +var code = ['{"type": "choices"',EvalString_Multi_0,Int_0,Int_1,IntString_0, block.isCollapsed()?', "_collapsed": true':'', block.isEnabled()?'':', "_disabled": true', ', "choices": [\n', diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index af322813..e86b7131 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -845,7 +845,7 @@ ActionParser.prototype.parseAction = function() { if (!this.isset(data.text)) data.text = ''; var info = this.getTitleAndPosition(data.text); this.next = MotaActionFunctions.xmlText('choices_s', [ - info[3],info[0],info[1],data.timeout||0,text_choices,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); + info[3],info[0],info[1],data.selected||0,data.timeout||0,data.width,text_choices,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "for": // 循环遍历 this.next = MotaActionFunctions.xmlText('for_s',[ diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index cfcf7b5e..651ebc13 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -235,7 +235,7 @@ editor_blockly = function () { } } } - if (one.async && one.type != 'animate' && one.type != 'function') hasAsync = true; + if (one.async && one.type != 'animate' && one.type != 'function' && one.type != 'playSound') hasAsync = true; if (one.type == 'waitAsync') hasAsync = false; } return hasAsync; diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 51ecdd02..718bbbef 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -115,7 +115,7 @@ editor_blocklyconfig=(function(){ MotaActionBlocks['restart_s'].xmlText(), MotaActionBlocks['confirm_s'].xmlText(), MotaActionBlocks['choices_s'].xmlText([ - '选择剑或者盾','流浪者','man',0,MotaActionBlocks['choicesContext'].xmlText([ + '选择剑或者盾','流浪者','man',0,0,'',MotaActionBlocks['choicesContext'].xmlText([ '剑','','',null,'','',MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), ]) ]), diff --git a/_server/editor_ui.js b/_server/editor_ui.js index d284c214..090af052 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -408,7 +408,9 @@ editor_ui_wrapper = function (editor) { data.choices[i].text = core.replaceText(data.choices[i].text); } core.saveCanvas('uievent'); - core.drawChoices(core.replaceText(data.text), data.choices, 'uievent'); + core.status.event.selection = data.selected || 0; + core.drawChoices(core.replaceText(data.text), data.choices, data.width, 'uievent'); + core.status.event.selection = null; core.loadCanvas('uievent'); return; } else if (type == "confirm") { diff --git a/libs/actions.js b/libs/actions.js index dae45741..b8762467 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -906,12 +906,12 @@ actions.prototype._keyDownChoices = function (keycode) { if (keycode == 38) { core.status.event.selection--; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); } if (keycode == 40) { core.status.event.selection++; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); } } @@ -925,7 +925,7 @@ actions.prototype._onMoveChoices = function (x, y) { if (selection == core.status.event.selection) return; core.status.event.selection = selection; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); } } diff --git a/libs/events.js b/libs/events.js index 391c1f34..d9e3e6c3 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2020,6 +2020,7 @@ events.prototype._action_choices = function (data, x, y, prefix) { try { return core.calValue(x.condition, prefix); } catch (e) { return true; } }) if (data.choices.length == 0) return this.doAction(); + var selected = data.selected || 0; if (core.isReplaying()) { var action = core.status.replay.toReplay.shift(); if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) { @@ -2035,7 +2036,7 @@ events.prototype._action_choices = function (data, x, y, prefix) { if (main.replayChecking) { // 录像验证系统中选择第一项 if (action != 'choices:none') core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作 - core.events.__action_choices_replaying(data, 0) + core.events.__action_choices_replaying(data, selected) } else { // 正常游戏中弹窗选择 core.myprompt('录像回放出错!当前需要执行选择项但录像中未记录。\n如需修复请输入您要选的项(从0起),点击取消将不会修复。', 0, function (value) { @@ -2063,7 +2064,8 @@ events.prototype._action_choices = function (data, x, y, prefix) { data.choices[i] = {"text": data.choices[i]}; data.choices[i].text = core.replaceText(data.choices[i].text, prefix); } - core.ui.drawChoices(core.replaceText(data.text, prefix), data.choices); + core.status.event.selection = selected; + core.ui.drawChoices(core.replaceText(data.text, prefix), data.choices, data.width); } events.prototype.__action_choices_replaying = function (data, index) { diff --git a/libs/ui.js b/libs/ui.js index f8fd231f..0d0b70e0 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1522,7 +1522,7 @@ ui.prototype._drawTextBox_getHorizontalPosition = function (content, titleInfo, } else left = null; if (posInfo.pos && posInfo.pos[2] != null) { width = core.calValue(posInfo.pos[2]) || 0; - validWidth = width - paddingLeft - paddingRight; + min_width = validWidth = width - paddingLeft - paddingRight; } else validWidth = 0; if (validWidth < min_width) { validWidth = this._calTextBoxWidth('ui', realContent, min_width, max_width, this._buildFont()); @@ -1697,16 +1697,16 @@ ui.prototype.textImage = function (content, lineHeight) { } ////// 绘制一个选项界面 ////// -ui.prototype.drawChoices = function(content, choices, ctx) { +ui.prototype.drawChoices = function(content, choices, width, ctx) { choices = core.clone(choices || []); - core.status.event.ui = {"text": content, "choices": choices}; + core.status.event.ui = {"text": content, "choices": choices, "width": width}; this.clearUI(); content = core.replaceText(content || ""); var titleInfo = this._getTitleAndIcon(content); titleInfo.content = this._drawTextBox_drawImages(titleInfo.content, ctx); - var hPos = this._drawChoices_getHorizontalPosition(titleInfo, choices, ctx); + var hPos = this._drawChoices_getHorizontalPosition(titleInfo, choices, width, ctx); var vPos = this._drawChoices_getVerticalPosition(titleInfo, choices, hPos); core.status.event.ui.offset = vPos.offset; @@ -1715,11 +1715,11 @@ ui.prototype.drawChoices = function(content, choices, ctx) { this._drawChoices_drawChoices(choices, isWindowSkin, hPos, vPos, ctx); } -ui.prototype._drawChoices_getHorizontalPosition = function (titleInfo, choices, ctx) { +ui.prototype._drawChoices_getHorizontalPosition = function (titleInfo, choices, width, ctx) { ctx = ctx || 'ui'; // 宽度计算:考虑提示文字和选项的长度 core.setFont(ctx, this._buildFont(17, true)); - var width = this._calTextBoxWidth(ctx, titleInfo.content || "", 246, this.PIXEL - 20); + var width = this._calTextBoxWidth(ctx, titleInfo.content || "", width || 246, this.PIXEL - 20); for (var i = 0; i < choices.length; i++) { if (typeof choices[i] === 'string') choices[i] = {"text": choices[i]};