显示选择项设置宽度
This commit is contained in:
parent
1e5b7b443d
commit
2ffa315acb
@ -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())
|
||||
|
||||
@ -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": "根据最大宽度自动缩小字体",
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',[
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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]}]),
|
||||
])
|
||||
]),
|
||||
|
||||
@ -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") {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
12
libs/ui.js
12
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]};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user