From c727cd78f128bc77cc3010b8735b26729a7e4136 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 10 Aug 2021 15:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=A1=AE=E8=AE=A4=E6=A1=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 2 +- _server/editor_blockly.js | 1 + _server/editor_ui.js | 4 +++ libs/events.js | 3 +- libs/ui.js | 58 +++++++++++++++++++++++---------------- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index ae25dcec..44414c27 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2771,7 +2771,7 @@ confirm_s tooltip : 弹出确认框 helpUrl : /_docs/#/instruction default : ["确认要xxx吗?",0,false] -doubleclicktext : EvalString_Multi_0 +previewBlock : true Bool_0 = Bool_0?', "default": true':'' Int_0 = Int_0 ? (', "timeout": '+Int_0) : ''; var code = ['{"type": "confirm"'+Int_0+Bool_0+', "text": "',EvalString_Multi_0,'",', diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 7d189e55..c6db59e4 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -299,6 +299,7 @@ editor_blockly = function () { case 'text_1_s': case 'text_2_s': case 'choices_s': + case 'confirm_s': if (!_isTextAttributeSet) { alert('警告!你尚未设置用于预览的剧情文本的属性,将采用默认属性进行预览。\n你可以双击“设置剧情文本的属性”事件来设置用于预览的属性。'); core.status.textAttribute = core.clone(core.initStatus.textAttribute); diff --git a/_server/editor_ui.js b/_server/editor_ui.js index 580a627d..1057115c 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -411,6 +411,10 @@ editor_ui_wrapper = function (editor) { core.drawChoices(core.replaceText(data.text), data.choices, 'uievent'); core.loadCanvas('uievent'); return; + } else if (type == "confirm") { + core.saveCanvas('uievent'); + core.drawConfirmBox(data.text, null, null, 'uievent'); + core.loadCanvas('uievent'); } else if (core.ui["_uievent_" + type]) core.ui["_uievent_" + type](data); }) diff --git a/libs/events.js b/libs/events.js index a63c887e..17b065ff 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2100,7 +2100,8 @@ events.prototype._precompile_choices = function (data) { } events.prototype._action_confirm = function (data, x, y, prefix) { - core.status.event.ui = {"text": core.replaceText(data.text, prefix), "yes": data.yes, "no": data.no}; + data.text = core.replaceText(data.text, prefix); + core.status.event.ui = {"text": data.text, "yes": data.yes, "no": data.no}; if (core.isReplaying()) { var action = core.status.replay.toReplay.shift(); if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) { diff --git a/libs/ui.js b/libs/ui.js index 2324800a..acb69b84 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1780,13 +1780,14 @@ ui.prototype._drawChoices_drawTitle = function (titleInfo, hPos, vPos, ctx) { } ui.prototype._drawChoices_drawChoices = function (choices, isWindowSkin, hPos, vPos, ctx) { + var hasCtx = ctx != null; ctx = ctx || 'ui'; // 选项 core.setTextAlign(ctx, 'center'); core.setFont(ctx, this._buildFont(17, true)); for (var i = 0; i < choices.length; i++) { var color = core.arrayToRGBA(choices[i].color || core.status.textAttribute.text); - if (choices[i].need != null && choices[i].need != '' && !core.calValue(choices[i].need)) color = '#999999'; + if (main.mode == 'play' && choices[i].need != null && choices[i].need != '' && !core.calValue(choices[i].need)) color = '#999999'; core.setFillStyle(ctx, color); var offset = this.HPIXEL; if (choices[i].icon) { @@ -1806,7 +1807,7 @@ ui.prototype._drawChoices_drawChoices = function (choices, isWindowSkin, hPos, v while (core.status.event.selection >= choices.length) core.status.event.selection -= choices.length; var len = choices[core.status.event.selection].width; if (isWindowSkin) { - if (ctx) { + if (hasCtx) { this._drawSelector(ctx, core.status.textAttribute.background, len + 10, 28, this.HPIXEL - len/2 - 5, vPos.choice_top + 32 * core.status.event.selection - 20); } else { @@ -1821,47 +1822,58 @@ ui.prototype._drawChoices_drawChoices = function (choices, isWindowSkin, hPos, v } ////// 绘制一个确认/取消的警告页面 ////// -ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback) { - core.lockControl(); +ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback, ctx) { + var hasCtx = ctx != null; + ctx = ctx || 'ui'; text = core.replaceText(text || ""); - // 处理自定义事件 - if (core.status.event.id != 'action') { - core.status.event.id = 'confirmBox'; - core.status.event.ui = text; - core.status.event.data = {'yes': yesCallback, 'no': noCallback}; + if (main.mode == 'play') { + core.lockControl(); + + // 处理自定义事件 + if (core.status.event.id != 'action') { + core.status.event.id = 'confirmBox'; + core.status.event.ui = text; + core.status.event.data = {'yes': yesCallback, 'no': noCallback}; + } } if (core.status.event.selection != 0 && core.status.event.selection != 'none') core.status.event.selection = 1; this.clearUI(); - core.setFont('ui', this._buildFont(19, true)); + core.setFont(ctx, this._buildFont(19, true)); var contents = text.split("\n"); - var rect = this._drawConfirmBox_getRect(contents); - var isWindowSkin = this.drawBackground(rect.left, rect.top, rect.right, rect.bottom); + var rect = this._drawConfirmBox_getRect(contents, ctx); + var isWindowSkin = this.drawBackground(rect.left, rect.top, rect.right, rect.bottom, {ctx: ctx}); - core.setTextAlign('ui', 'center'); - core.setFillStyle('ui', core.arrayToRGBA(core.status.textAttribute.text)) + core.setTextAlign(ctx, 'center'); + core.setFillStyle(ctx, core.arrayToRGBA(core.status.textAttribute.text)) for (var i in contents) { - core.fillText('ui', contents[i], this.HPIXEL, rect.top + 50 + i*30); + core.fillText(ctx, contents[i], this.HPIXEL, rect.top + 50 + i*30); } - core.fillText('ui', "确定", this.HPIXEL - 38, rect.bottom - 35, null, this._buildFont(17, true)); - core.fillText('ui', "取消", this.HPIXEL + 38, rect.bottom - 35); + core.fillText(ctx, "确定", this.HPIXEL - 38, rect.bottom - 35, null, this._buildFont(17, true)); + core.fillText(ctx, "取消", this.HPIXEL + 38, rect.bottom - 35); if (core.status.event.selection != 'none') { - var len=core.calWidth('ui', "确定"); + var len=core.calWidth(ctx, "确定"); var strokeLeft = this.HPIXEL + (76*core.status.event.selection-38) - parseInt(len/2) - 5; - if (isWindowSkin) - this._drawWindowSelector(core.status.textAttribute.background, strokeLeft, rect.bottom-35-20, len+10, 28); + if (isWindowSkin) { + if (hasCtx) { + this._drawSelector(ctx, core.status.textAttribute.background, + len + 10, 28, strokeLeft, rect.bottom-35-20); + } else { + this._drawWindowSelector(core.status.textAttribute.background, strokeLeft, rect.bottom-35-20, len+10, 28); + } + } else - core.strokeRoundRect('ui', strokeLeft, rect.bottom-35-20, len+10, 28, 6, core.status.globalAttribute.selectColor, 2); + core.strokeRoundRect(ctx, strokeLeft, rect.bottom-35-20, len+10, 28, 6, core.status.globalAttribute.selectColor, 2); } } -ui.prototype._drawConfirmBox_getRect = function (contents) { +ui.prototype._drawConfirmBox_getRect = function (contents, ctx) { var max_width = contents.reduce(function (pre, curr) { - return Math.max(pre, core.calWidth('ui', curr)); + return Math.max(pre, core.calWidth(ctx, curr)); }, 0); var left = Math.min(this.HPIXEL - 40 - parseInt(max_width / 2), 100), right = this.PIXEL - left; var top = this.HPIXEL - 68 - (contents.length-1)*30, bottom = this.HPIXEL + 68;