diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index d87bd35e..a6bd22a7 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -1528,13 +1528,13 @@ return code; */; choicesContext - : '子选项' EvalString '颜色' EvalString? Colour BGNL? Newline action+ + : '子选项' EvalString '图标' IdString? '颜色' EvalString? Colour BGNL? Newline action+ /* choicesContext tooltip : 选项的选择 helpUrl : https://h5mota.com/games/template/docs/#/event?id=choices%EF%BC%9A%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E9%80%89%E9%A1%B9 -default : ["提示文字:红钥匙",""] +default : ["提示文字:红钥匙","",""] colour : this.subColor if (EvalString_1) { var colorRe = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/; @@ -1543,7 +1543,8 @@ if (EvalString_1) { else EvalString_1 = ', "color": "'+EvalString_1+'"'; } -var code = '{"text": "'+EvalString_0+'"'+EvalString_1+', "action": [\n'+action_0+']},\n'; +IdString_0 = IdString_0?(', "icon": "'+IdString_0+'"'):''; +var code = '{"text": "'+EvalString_0+'"'+IdString_0+EvalString_1+', "action": [\n'+action_0+']},\n'; return code; */; @@ -2411,7 +2412,7 @@ ActionParser.prototype.parseAction = function() { var text_choices = null; for(var ii=data.choices.length-1,choice;choice=data.choices[ii];ii--) { text_choices=MotaActionBlocks['choicesContext'].xmlText([ - choice.text,choice.color,'rgba('+choice.color+')',this.insertActionList(choice.action),text_choices]); + choice.text,choice.icon,choice.color,'rgba('+choice.color+')',this.insertActionList(choice.action),text_choices]); } this.next = MotaActionBlocks['choices_s'].xmlText([ this.isset(data.text)?this.EvalString(data.text):null,'','',text_choices,this.next]); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index fe97347d..b42c9dac 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -64,9 +64,9 @@ editor_blockly = function () { MotaActionBlocks['lose_s'].xmlText(), MotaActionBlocks['choices_s'].xmlText([ '选择剑或者盾','流浪者','man',MotaActionBlocks['choicesContext'].xmlText([ - '剑','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), + '剑','','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]), MotaActionBlocks['choicesContext'].xmlText([ - '盾','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [9,3]}]), + '盾','','',null,MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [9,3]}]), ]) ]) ]), diff --git a/libs/ui.js b/libs/ui.js index 87ae0017..41290945 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -503,6 +503,23 @@ ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width) } } +ui.prototype.__getIconInfo = function (id) { + var image = null, icon = null; + ["terrains","animates","items","npcs","enemys"].forEach(function (v) { + if (core.isset(core.material.icons[v][id])) { + image = core.material.images[v]; + icon = core.material.icons[v][id]; + } + }); + if (image == null) { + if (id in core.statusBar.icons) { + image = core.statusBar.icons[id]; + icon = 0; + } + } + return [image,icon]; +} + ui.prototype.__drawText = function (canvas, content, content_left, content_top, valid_width, color, per_height, text_font, time) { core.setTextAlign(canvas, 'left'); @@ -550,19 +567,7 @@ ui.prototype.__drawText = function (canvas, content, content_left, content_top, if (content.charAt(index+1) == '[' && ((index2=content.indexOf(']', index+1))>=0)) { var str = content.substring(index+2, index2); // --- 获得图标 - var image = null, icon = null; - ["terrains","animates","items","npcs","enemys"].forEach(function (v) { - if (core.isset(core.material.icons[v][str])) { - image = core.material.images[v]; - icon = core.material.icons[v][str]; - } - }); - if (image == null) { - if (str in core.statusBar.icons) { - image = core.statusBar.icons[str]; - icon = 0; - } - } + var iconInfo = core.ui.__getIconInfo(str), image = iconInfo[0], icon = iconInfo[1]; if (image != null) { if (core.isset(valid_width) && offsetx + text_font + 6 > content_left + valid_width) { index --; @@ -889,8 +894,7 @@ ui.prototype.drawScrollText = function (content, time, callback) { ////// 绘制一个选项界面 ////// ui.prototype.drawChoices = function(content, choices) { - - choices = choices || []; + choices = core.clone(choices || []); var background = core.status.textAttribute.background; var isWindowSkin = false; @@ -914,7 +918,12 @@ ui.prototype.drawChoices = function(content, choices) { var globalFont = core.status.globalAttribute.font; core.setFont('ui', "bold 17px "+globalFont); for (var i = 0; i < choices.length; i++) { - width = Math.max(width, core.calWidth('ui', core.replaceText(choices[i].text || choices[i]))+30); + if (typeof choices[i] === 'string') + choices[i] = {"text": choices[i]}; + choices[i].text = core.replaceText(choices[i].text); + choices[i].width = core.calWidth('ui', core.replaceText(choices[i].text)); + if (core.isset(choices[i].icon)) choices[i].width += 28; + width = Math.max(width, choices[i].width+30); } var left=parseInt((416 - width) / 2); // 左边界 @@ -1011,14 +1020,23 @@ ui.prototype.drawChoices = function(content, choices) { var color = choices[i].color || textColor; if (color instanceof Array) color = core.arrayToRGBA(color); core.setFillStyle('ui', color); - core.fillText('ui', core.replaceText(choices[i].text || choices[i]), 208, choice_top + 32 * i, null, "bold 17px "+globalFont); + var offset = 208; + if (core.isset(choices[i].icon)) { + var iconInfo = this.__getIconInfo(choices[i].icon), image = iconInfo[0], icon = iconInfo[1]; + if (image != null) { + core.drawImage('ui', image, 0, 32*icon, 32, 32, + 208 - choices[i].width/2, choice_top + 32*i - 17, 22, 22); + offset += 14; + } + } + core.fillText('ui', choices[i].text, offset, choice_top + 32 * i, null, "bold 17px "+globalFont); } if (choices.length>0) { if (!core.isset(core.status.event.selection)) core.status.event.selection=0; while (core.status.event.selection<0) core.status.event.selection+=choices.length; while (core.status.event.selection>=choices.length) core.status.event.selection-=choices.length; - var len = core.calWidth('ui', core.replaceText(choices[core.status.event.selection].text || choices[core.status.event.selection])); + var len = choices[core.status.event.selection].width; if (isWindowSkin) this.drawWindowSelector(background, 208-len/2-5, choice_top + 32 * core.status.event.selection - 20, len+10, 28); else