显示选择项设置宽度

This commit is contained in:
ckcz123 2021-08-12 16:53:43 +08:00
parent 1e5b7b443d
commit 2ffa315acb
10 changed files with 27 additions and 21 deletions

View File

@ -1869,7 +1869,7 @@ drawBackground: fn(left: string, top: string, right: string, bottom: string, pos
drawBook: fn(index?: ?) 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()) drawConfirmBox: fn(text: string, yesCallback?: fn(), noCallback?: fn())

View File

@ -3585,7 +3585,7 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
}, },
"drawChoices": { "drawChoices": {
"!doc": "绘制一个选项界面", "!doc": "绘制一个选项界面",
"!type": "fn(content?: string, choices?: [?])" "!type": "fn(content?: string, choices?: [?], width?: number, ctx?: string|CanvasRenderingContext2D)"
}, },
"setFontForMaxWidth": { "setFontForMaxWidth": {
"!doc": "根据最大宽度自动缩小字体", "!doc": "根据最大宽度自动缩小字体",

View File

@ -2715,14 +2715,14 @@ return code;
*/; */;
choices_s 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 /* choices_s
tooltip : choices: 给用户提供选项 tooltip : choices: 给用户提供选项
helpUrl : /_docs/#/instruction helpUrl : /_docs/#/instruction
previewBlock : true previewBlock : true
default : ["","流浪者","trader",0] default : ["","流浪者","trader",0,0,'']
allIds : ['IdString_0'] allIds : ['IdString_0']
var title=''; var title='';
if (EvalString_0==''){ if (EvalString_0==''){
@ -2734,8 +2734,10 @@ if (EvalString_0==''){
} }
EvalString_Multi_0 = title+EvalString_Multi_0; EvalString_Multi_0 = title+EvalString_Multi_0;
EvalString_Multi_0 = EvalString_Multi_0 ?(', "text": "'+EvalString_Multi_0+'"'):''; EvalString_Multi_0 = EvalString_Multi_0 ?(', "text": "'+EvalString_Multi_0+'"'):'';
Int_0 = Int_0 ? (', "timeout": '+Int_0) : ''; Int_0 = Int_0 ? (', "selected": '+Int_0) : '';
var code = ['{"type": "choices"',EvalString_Multi_0,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.isCollapsed()?', "_collapsed": true':'',
block.isEnabled()?'':', "_disabled": true', block.isEnabled()?'':', "_disabled": true',
', "choices": [\n', ', "choices": [\n',

View File

@ -845,7 +845,7 @@ ActionParser.prototype.parseAction = function() {
if (!this.isset(data.text)) data.text = ''; if (!this.isset(data.text)) data.text = '';
var info = this.getTitleAndPosition(data.text); var info = this.getTitleAndPosition(data.text);
this.next = MotaActionFunctions.xmlText('choices_s', [ 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; break;
case "for": // 循环遍历 case "for": // 循环遍历
this.next = MotaActionFunctions.xmlText('for_s',[ this.next = MotaActionFunctions.xmlText('for_s',[

View File

@ -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; if (one.type == 'waitAsync') hasAsync = false;
} }
return hasAsync; return hasAsync;

View File

@ -115,7 +115,7 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['restart_s'].xmlText(), MotaActionBlocks['restart_s'].xmlText(),
MotaActionBlocks['confirm_s'].xmlText(), MotaActionBlocks['confirm_s'].xmlText(),
MotaActionBlocks['choices_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]}]), '剑','','',null,'','',MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]),
]) ])
]), ]),

View File

@ -408,7 +408,9 @@ editor_ui_wrapper = function (editor) {
data.choices[i].text = core.replaceText(data.choices[i].text); data.choices[i].text = core.replaceText(data.choices[i].text);
} }
core.saveCanvas('uievent'); 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'); core.loadCanvas('uievent');
return; return;
} else if (type == "confirm") { } else if (type == "confirm") {

View File

@ -906,12 +906,12 @@ actions.prototype._keyDownChoices = function (keycode) {
if (keycode == 38) { if (keycode == 38) {
core.status.event.selection--; core.status.event.selection--;
core.playSound('光标移动'); 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) { if (keycode == 40) {
core.status.event.selection++; core.status.event.selection++;
core.playSound('光标移动'); 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; if (selection == core.status.event.selection) return;
core.status.event.selection = selection; core.status.event.selection = selection;
core.playSound('光标移动'); 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);
} }
} }

View File

@ -2020,6 +2020,7 @@ events.prototype._action_choices = function (data, x, y, prefix) {
try { return core.calValue(x.condition, prefix); } catch (e) { return true; } try { return core.calValue(x.condition, prefix); } catch (e) { return true; }
}) })
if (data.choices.length == 0) return this.doAction(); if (data.choices.length == 0) return this.doAction();
var selected = data.selected || 0;
if (core.isReplaying()) { if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift(); var action = core.status.replay.toReplay.shift();
if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) { 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 (main.replayChecking) {
// 录像验证系统中选择第一项 // 录像验证系统中选择第一项
if (action != 'choices:none') core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作 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 { } else {
// 正常游戏中弹窗选择 // 正常游戏中弹窗选择
core.myprompt('录像回放出错!当前需要执行选择项但录像中未记录。\n如需修复请输入您要选的项从0起点击取消将不会修复。', 0, function (value) { 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": data.choices[i]};
data.choices[i].text = core.replaceText(data.choices[i].text, prefix); 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) { events.prototype.__action_choices_replaying = function (data, index) {

View File

@ -1522,7 +1522,7 @@ ui.prototype._drawTextBox_getHorizontalPosition = function (content, titleInfo,
} else left = null; } else left = null;
if (posInfo.pos && posInfo.pos[2] != null) { if (posInfo.pos && posInfo.pos[2] != null) {
width = core.calValue(posInfo.pos[2]) || 0; width = core.calValue(posInfo.pos[2]) || 0;
validWidth = width - paddingLeft - paddingRight; min_width = validWidth = width - paddingLeft - paddingRight;
} else validWidth = 0; } else validWidth = 0;
if (validWidth < min_width) { if (validWidth < min_width) {
validWidth = this._calTextBoxWidth('ui', realContent, min_width, max_width, this._buildFont()); 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 || []); choices = core.clone(choices || []);
core.status.event.ui = {"text": content, "choices": choices}; core.status.event.ui = {"text": content, "choices": choices, "width": width};
this.clearUI(); this.clearUI();
content = core.replaceText(content || ""); content = core.replaceText(content || "");
var titleInfo = this._getTitleAndIcon(content); var titleInfo = this._getTitleAndIcon(content);
titleInfo.content = this._drawTextBox_drawImages(titleInfo.content, ctx); 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); var vPos = this._drawChoices_getVerticalPosition(titleInfo, choices, hPos);
core.status.event.ui.offset = vPos.offset; 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); 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'; ctx = ctx || 'ui';
// 宽度计算:考虑提示文字和选项的长度 // 宽度计算:考虑提示文字和选项的长度
core.setFont(ctx, this._buildFont(17, true)); 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++) { for (var i = 0; i < choices.length; i++) {
if (typeof choices[i] === 'string') if (typeof choices[i] === 'string')
choices[i] = {"text": choices[i]}; choices[i] = {"text": choices[i]};