From bd008a2d4847e3e962d6016cd04c77ca00e476d9 Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 27 Feb 2019 00:37:46 +0800 Subject: [PATCH 1/5] autoFormat & clearPoint --- _server/editor.js | 21 ++++++++++++++++----- _server/editor_multi.js | 18 +++++++++++++----- editor-mobile.html | 1 + editor.html | 1 + 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index 006a4df2..5a9f3539 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -1230,16 +1230,15 @@ editor.prototype.listen = function () { }); } - var clearLoc = document.getElementById('clearLoc'); - clearLoc.onmousedown = function(e){ + var _clearPoint = function (clearPoint) { editor.hideMidMenu(); - e.stopPropagation(); editor.preMapData = null; reDo = null; editor.info = 0; editor_mode.onmode(''); var now = editor.pos; - editor.map[now.y][now.x]=editor.info; + if (clearPoint) + editor.map[now.y][now.x]=editor.info; editor.updateMap(); fields.forEach(function(v){ delete editor.currentFloorData[v][now.x+','+now.y]; @@ -1249,11 +1248,23 @@ editor.prototype.listen = function () { printe(err); throw(err) } - ;printf('清空此点及事件成功'); + ;printf(clearPoint?'清空该点和事件成功':'只清空该点事件成功'); editor.drawPosSelection(); }); } + var clearEvent = document.getElementById('clearEvent'); + clearEvent.onmousedown = function (e) { + e.stopPropagation(); + _clearPoint(false); + } + + var clearLoc = document.getElementById('clearLoc'); + clearLoc.onmousedown = function(e){ + e.stopPropagation(); + _clearPoint(true); + } + var brushMod=document.getElementById('brushMod'); brushMod.onchange=function(){ editor.brushMod=brushMod.value; diff --git a/_server/editor_multi.js b/_server/editor_multi.js index 856fa59b..705f0ab4 100644 --- a/_server/editor_multi.js +++ b/_server/editor_multi.js @@ -64,11 +64,8 @@ editor_multi = function () { return '\t'; } - editor_multi.format = function () { - if (!editor_multi.lintAutocomplete) { - alert("只有代码才能进行格式化操作!"); - return; - } + var _format = function () { + if (!editor_multi.lintAutocomplete) return; codeEditor.setValue(js_beautify(codeEditor.getValue(), { brace_style: "collapse-preserve-inline", indent_with_tabs: true, @@ -76,6 +73,15 @@ editor_multi = function () { })); } + editor_multi.format = function () { + if (!editor_multi.lintAutocomplete) { + alert("只有代码才能进行格式化操作!"); + return; + } + _format(); + } + + editor_multi.import = function (id_, args) { var thisTr = document.getElementById(id_); if (!thisTr) return false; @@ -122,6 +128,8 @@ editor_multi = function () { editor_multi.id = ''; return; } + // ----- 自动格式化 + _format(); if (editor_multi.id === 'callFromBlockly') { editor_multi.id = ''; editor_multi.multiLineDone(); diff --git a/editor-mobile.html b/editor-mobile.html index 85c3791d..681feb8f 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -316,6 +316,7 @@ + diff --git a/editor.html b/editor.html index 10a6a405..4584bff7 100644 --- a/editor.html +++ b/editor.html @@ -336,6 +336,7 @@ + From 4372981cb3ce1d6371118179ec923369749ab96a Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 27 Feb 2019 04:53:26 +0800 Subject: [PATCH 2/5] draw icons in toolbox --- _docs/element.md | 3 +++ _docs/event.md | 15 ++++++++++++ _server/editor_blockly.js | 6 +++-- libs/ui.js | 49 +++++++++++++++++++++++++++++++++------ 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/_docs/element.md b/_docs/element.md index 3e123c60..c5fcc4be 100644 --- a/_docs/element.md +++ b/_docs/element.md @@ -326,9 +326,12 @@ floorId指定的是目标楼层的唯一标识符(ID)。 - 使用`\r[...]`来动态修改局部文本的颜色,如`\r[red]`。 - 使用`${}`来计算一个表达式的值,如`${status:atk+status:def}`。 - 使用`\f[...]`来同时插入一张立绘图,如`\f[1.png,100,200]`。 +- 使用`\\i[...]`来在对话框中绘制一个图标,如`\\i[fly]`。 从V2.5.2开始,也允许绘制一张头像图在对话框中,只要通过`\t[1.png]`或`\t[标题,1.png]`的写法。 +**使用`\\i[...]`绘制图标请注意:在事件块中,允许只写一个反斜杠`\i`,系统会自动转义成`\\i`;但是在脚本中必须两个反斜杠都写上!** + 详细信息请参见[剧情文本控制](event#text:显示一段文字(剧情))中的说明。 从V2.5.2开始,可以用一张WindowSkin图片作为对话框的背景皮肤。 diff --git a/_docs/event.md b/_docs/event.md index 01c0f726..9d591c36 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -267,6 +267,21 @@ ] ``` +从V2.5.5以后,也可以使用`\\i[...]`来在对话框中绘制一个图标。 + +这里可以使用一个合法ID(32x48图块除外),或使用一个系统图标(`core.statusBar.icons`中的内容)。 + +``` js +"x,y": [ // 实际执行的事件列表 + "\t[勇士]\b[up,hero]这是一个飞行器\\i[fly],这是一个破墙镐\\i[pickaxe]", + "\t[hero]也可以使用系统图标,比如这是存档\\i[save],这是工具栏\\i[toolbox]", +] +``` + +**可以在控制台中输入`core.statusBar.icons`以查看所有的系统图标定义。** + +!> 注意,在事件块中,允许只写一个反斜杠`\i`,系统会自动转义成`\\i`;但是在脚本中必须两个反斜杠都写上! + 另外值得一提的是,我们是可以在文字中计算一个表达式的值的。只需要将表达式用 `${ }`整个括起来就可以。 ``` js diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index b624e7c4..fe97347d 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -339,7 +339,7 @@ function omitedcheckUpdateFunction(event) { } } try { - var code = Blockly.JavaScript.workspaceToCode(workspace); + var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\i/g, '\\\\i'); codeAreaHL.setValue(code); } catch (error) { codeAreaHL.setValue(String(error)); @@ -481,7 +481,8 @@ function omitedcheckUpdateFunction(event) { MotaActionFunctions.parse( eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g, function (c) { return {'<': '<', '>': '>', '&': '&'}[c]; - }).replace(/\\r/g, '\\\\r').replace(/\\f/g, '\\\\f')), + }).replace(/\\r/g, '\\\\r').replace(/\\f/g, '\\\\f') + .replace(/\\i/,'\\\\i')), document.getElementById('entryType').value ); } @@ -555,6 +556,7 @@ function omitedcheckUpdateFunction(event) { return; } var code = Blockly.JavaScript.workspaceToCode(editor_blockly.workspace); + code = code.replace(/\\i/g, '\\\\i'); eval('var obj=' + code); setvalue(JSON.stringify(obj)); } diff --git a/libs/ui.js b/libs/ui.js index 9d11eefa..87ae0017 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -504,7 +504,7 @@ ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width) } ui.prototype.__drawText = function (canvas, content, content_left, content_top, valid_width, - color, per_height, time) { + color, per_height, text_font, time) { core.setTextAlign(canvas, 'left'); var offsetx = content_left, offsety = content_top; @@ -543,6 +543,41 @@ ui.prototype.__drawText = function (canvas, content, content_left, content_top, else currcolor = color; return drawNext(); } + // \\i 绘制图标 + if (ch == '\\' && content.charAt(index)=='i') { + // 绘制图标 + var index2; + 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; + } + } + if (image != null) { + if (core.isset(valid_width) && offsetx + text_font + 6 > content_left + valid_width) { + index --; + offsetx = content_left; + offsety += per_height; + return drawNext(); + } + // --- 绘制 + core.drawImage(canvas, image, 0, 32*icon, 32, 32, offsetx + 2, offsety - text_font + 1, text_font+2, text_font+2); + offsetx += text_font + 6; + index = index2+1; + return true; + } + } + } // 检查是不是自动换行 var charwidth = core.calWidth(canvas, ch); if (core.isset(valid_width) && offsetx + charwidth > content_left + valid_width) { @@ -663,7 +698,7 @@ ui.prototype.drawTextBox = function(content, showAll) { var globalFont = core.status.globalAttribute.font; var font = textfont + 'px '+globalFont; if (textAttribute.bold) font = "bold "+font; - var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, ""); + var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1"); var leftSpace = 25, rightSpace = 12; if (core.isset(px) && core.isset(py)) leftSpace = 20; @@ -797,7 +832,7 @@ ui.prototype.drawTextBox = function(content, showAll) { core.setFont('ui', font); - this.__drawText('ui', content, content_left, content_top, validWidth, textColor, textfont + 5, + this.__drawText('ui', content, content_left, content_top, validWidth, textColor, textfont + 5, textfont, (showAll || textAttribute.time<=0 || core.status.event.id!='action')?0:textAttribute.time); } @@ -819,7 +854,7 @@ ui.prototype.drawScrollText = function (content, time, callback) { var font = textfont+"px "+core.status.globalAttribute.font; if (textAttribute.bold) font = "bold "+font; - var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, ""); + var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1"); var contents = core.splitLines('ui', realContent), lines = contents.length; // 计算总高度,按1.4倍行距计算 @@ -830,7 +865,7 @@ ui.prototype.drawScrollText = function (content, time, callback) { tempCanvas.clearRect(0, 0, width, height); tempCanvas.font = font; - this.__drawText(tempCanvas, content, offset, textfont, null, textColor, 1.4*textfont, 0); + this.__drawText(tempCanvas, content, offset, textfont, null, textColor, 1.4*textfont, textfont, 0); // 开始绘制到UI上 core.clearMap('ui'); @@ -898,7 +933,7 @@ ui.prototype.drawChoices = function(content, choices) { // 获得name, image, icon var info = this.getTitleAndIcon(content); content = core.replaceText(info.content); - var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, ""); + var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1"); id=info.id; name=info.name; image=info.image; icon=info.icon; iconHeight=info.iconHeight; animate=info.animate; if (id=='hero' || core.isset(icon)) @@ -967,7 +1002,7 @@ ui.prototype.drawChoices = function(content, choices) { } core.setFont('ui', 'bold 15px '+globalFont); - this.__drawText('ui', content, content_left, content_top, validWidth, textColor, 20, 0); + this.__drawText('ui', content, content_left, content_top, validWidth, textColor, 20, 15, 0); } // 选项 From bd0e8e2f10ab6a2906fbac554138a8615a7fdc77 Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 27 Feb 2019 05:06:46 +0800 Subject: [PATCH 3/5] editor strict check range --- _server/data.comment.js | 16 ++++++++++++++++ _server/editor_mode.js | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/_server/data.comment.js b/_server/data.comment.js index 8f157bcf..76c87a1f 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -16,26 +16,31 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "images": { "_leaf": true, "_type": "textarea", + "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放所有可能使用的图片(tilesets除外) \n图片可以被作为背景图(的一部分),也可以直接用自定义事件进行显示。 \n 图片名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好 \n 建议对于较大的图片,在网上使用在线的“图片压缩工具(http://compresspng.com/zh/)”来进行压缩,以节省流量 \n 依次向后添加" }, "tilesets": { "_leaf": true, "_type": "textarea", + "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放额外素材的图片名, \n可以自定导入任意张素材图片,无需PS,无需注册,即可直接在游戏中使用 \n 形式如[\"1.png\", \"2.png\"] ,将需要的素材图片放在images目录下 \n 素材的宽高必须都是32的倍数,且图片上的总图块数不超过1000(即最多有1000个32*32的图块在该图片上)" }, "animates": { "_leaf": true, "_type": "textarea", + "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放所有可能使用的动画,必须是animate格式,在这里不写后缀名 \n动画必须放在animates目录下;文件名不能使用中文,不能带空格或特殊字符 \n \"jianji\", \"thunder\" \n 根据需求自行添加" }, "bgms": { "_leaf": true, "_type": "textarea", + "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放所有的bgm,和文件名一致。 \n音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好" }, "sounds": { "_leaf": true, "_type": "textarea", + "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放所有的SE,和文件名一致 \n音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好" }, "startBackground": { @@ -131,17 +136,20 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "title": { "_leaf": true, "_type": "textarea", + "_string": true, "_data": "游戏名,将显示在标题页面以及切换楼层的界面中" }, "name": { "_leaf": true, "_type": "textarea", + "_string": true, "_range": "/^[a-zA-Z0-9_]{1,30}$/.test(thiseval)", "_data": "游戏的唯一英文标识符。由英文、数字、下划线组成,不能超过30个字符。\n此项必须修改,其将直接影响到存档的定位!" }, "version": { "_leaf": true, "_type": "textarea", + "_string": true, "_data": "当前游戏版本;版本不一致的存档不能通用。" }, "floorId": { @@ -160,6 +168,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "name": { "_leaf": true, "_type": "textarea", + "_string": true, "_data": "勇士名;可以改成喜欢的" }, "lv": { @@ -211,6 +220,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "equipment": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Array", "_data": "初始装上的装备,此处建议请直接留空数组" }, "items": { @@ -220,21 +230,25 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "keys": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Object && !(thiseval instanceof Array)", "_data": "初始三种钥匙个数" }, "constants": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Object && !(thiseval instanceof Array)", "_data": "初始永久道具个数,例如初始送手册可以写 {\"book\": 1}" }, "tools": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Object && !(thiseval instanceof Array)", "_data": "初始消耗道具个数,例如初始有两破可以写 {\"pickaxe\": 2}" }, "equips": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Object && !(thiseval instanceof Array)", "_data": "初始装备个数,例如初始送铁剑可以写 {\"sword1\": 1}" } } @@ -242,6 +256,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "flyRange": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Array", "_data": "初始可飞的楼层;一般留空数组即可" }, "loc": { @@ -276,6 +291,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "flags": { "_leaf": true, "_type": "textarea", + "_range": "thiseval instanceof Object && !(thiseval instanceof Array)", "_data": "游戏过程中的变量或flags" }, "steps": { diff --git a/_server/editor_mode.js b/_server/editor_mode.js index 40ad2801..15950e8e 100644 --- a/_server/editor_mode.js +++ b/_server/editor_mode.js @@ -1166,7 +1166,21 @@ editor_mode = function (editor) { if(editor.isMobile)editor.showdataarea(false); } + editor_mode.checkUnique = function (thiseval) { + if (!(thiseval instanceof Array)) return false; + var map = {}; + for (var i = 0; i Date: Wed, 27 Feb 2019 21:04:25 +0800 Subject: [PATCH 4/5] icon in choices --- _server/blockly/MotaAction.g4 | 9 +++--- _server/editor_blockly.js | 4 +-- libs/ui.js | 54 +++++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 24 deletions(-) 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 From 42e04f58bea6261757ebe8c2790f6726f8a33cd9 Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 27 Feb 2019 21:19:43 +0800 Subject: [PATCH 5/5] setValue2 --- _docs/event.md | 17 +++++++++++++++++ _server/blockly/MotaAction.g4 | 20 ++++++++++++++++++++ _server/editor_blockly.js | 14 ++++++++++---- libs/events.js | 3 +++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/_docs/event.md b/_docs/event.md index 9d591c36..a84cc3d8 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -440,6 +440,23 @@ value是一个表达式,将通过这个表达式计算出的结果赋值给nam 另外注意一点的是,如果hp被设置成了0或以下,将触发lose事件,直接死亡。 +### setValue2:增减勇士的某个属性、道具个数,或某个变量/Flag的值 + +和`{"type": "setValue"}`的写法完全相同,不过此项是可以直接将值加减到原始数值上。 + +即下面的写法是等价的: + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "setValue", "name": "status:atk", "value": "status:atk+10" } // 攻击提高10点 + {"type": "setValue2", "name": "status:atk", "value": "10" } // 和上面写法等价 + {"type": "setValue", "name": "item:yellowKey", "value": "item:yellowKey-3" } // 黄钥匙个数-3 + {"type": "setValue2", "name": "item:yellowKey", "value": "-3" } // 和上面写法等价 + {"type": "setValue", "name": "flag:door2", "value": "flag:door2+1" } // 将变量door值+1 + {"type": "setValue2", "name": "flag:door2", "value": "01" } // 和上面写法等价 +] +``` + ### setFloor:设置楼层属性 使用`{"type":"setFloor"}`可以设置某层楼的楼层属性。 diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index a6bd22a7..fafa1bb7 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -229,6 +229,7 @@ action | setText_s | tip_s | setValue_s + | setValue2_s | setFloor_s | setGlobalAttribute_s | setGlobalValue_s @@ -465,6 +466,18 @@ var code = '{"type": "setValue", "name": "'+idString_e_0+'", "value": "'+express return code; */; +setValue2_s + : '数值增减' ':' '名称' idString_e '+=' expression Newline + + +/* setValue2_s +tooltip : setValue2:增减勇士的某个属性、道具个数, 或某个变量/Flag的值 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=setValue2%ef%bc%9a%e5%a2%9e%e5%87%8f%e5%8b%87%e5%a3%ab%e7%9a%84%e6%9f%90%e4%b8%aa%e5%b1%9e%e6%80%a7%e3%80%81%e9%81%93%e5%85%b7%e4%b8%aa%e6%95%b0%ef%bc%8c%e6%88%96%e6%9f%90%e4%b8%aa%e5%8f%98%e9%87%8f%2fFlag%e7%9a%84%e5%80%bc +colour : this.dataColor +var code = '{"type": "setValue2", "name": "'+idString_e_0+'", "value": "'+expression_0+'"},\n'; +return code; +*/; + setFloor_s : '设置楼层属性' ':' Floor_Meta_List '楼层名' IdString? '值' EvalString Newline @@ -2365,6 +2378,13 @@ ActionParser.prototype.parseAction = function() { MotaActionBlocks['evalString_e'].xmlText([data.value]), this.next]); break; + case "setValue2": + this.next = MotaActionBlocks['setValue2_s'].xmlText([ + // MotaActionBlocks['idString_e'].xmlText([data.name]), + this.tryToUseEvFlag_e('idString_e', [data.name]), + MotaActionBlocks['evalString_e'].xmlText([data.value]), + this.next]); + break; case "setFloor": this.next = MotaActionBlocks['setFloor_s'].xmlText([ data.name, data.floorId||null, data.value, this.next]); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index b42c9dac..e1db7827 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -75,6 +75,9 @@ editor_blockly = function () { MotaActionBlocks['setValue_s'].xmlText([ MotaActionBlocks['idString_1_e'].xmlText(['status','hp']) ]), + MotaActionBlocks['setValue2_s'].xmlText([ + MotaActionBlocks['idString_1_e'].xmlText(['status','hp']) + ]), MotaActionBlocks['setFloor_s'].xmlText(), MotaActionBlocks['setGlobalAttribute_s'].xmlText(), MotaActionBlocks['setGlobalValue_s'].xmlText(), @@ -154,6 +157,9 @@ editor_blockly = function () { MotaActionBlocks['setValue_s'].xmlText([ MotaActionBlocks['idString_1_e'].xmlText(['status','hp']) ]), + MotaActionBlocks['setValue2_s'].xmlText([ + MotaActionBlocks['idString_1_e'].xmlText(['status','hp']) + ]), MotaActionBlocks['expression_arithmetic_0'].xmlText(), MotaActionBlocks['evFlag_e'].xmlText(), MotaActionBlocks['negate_e'].xmlText(), @@ -178,8 +184,8 @@ editor_blockly = function () { {"text": "黄钥匙(\${9+flag:shop_times}金币)", "color": [255,255,0,1], "action": [ {"type": "if", "condition": "status:money>=9+flag:shop_times", "true": [ - {"type": "setValue", "name": "status:money", "value": "status:money-(9+flag:shop_times)"}, - {"type": "setValue", "name": "item:yellowKey", "value": "item:yellowKey+1"}, + {"type": "setValue2", "name": "status:money", "value": "-(9+flag:shop_times)"}, + {"type": "setValue2", "name": "item:yellowKey", "value": "1"}, ], "false": [ "\t[老人,man]你的金钱不足!", @@ -194,7 +200,7 @@ editor_blockly = function () { ]} ] }, - {"type": "setValue", "name": "flag:shop_times", "value": "flag:shop_times+1"}, + {"type": "setValue2", "name": "flag:shop_times", "value": "1"}, {"type": "revisit"} ], 'event'), '', @@ -217,7 +223,7 @@ editor_blockly = function () { ],'afterBattle'), '', MotaActionFunctions.actionParser.parse([ - {"type": "setValue", "name": "flag:__door__", "value": "flag:__door__+1"}, + {"type": "setValue2", "name": "flag:__door__", "value": "1"}, {"type": "if", "condition": "flag:__door__==2", "true": [ {"type": "openDoor", "loc": [10,5]} diff --git a/libs/events.js b/libs/events.js index 55a10979..d9be042a 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1001,8 +1001,11 @@ events.prototype.doAction = function() { } break; case "setValue": + case "setValue2": try { var value=core.calValue(data.value, prefix); + if (data.type == 'setValue2') + value += core.calValue(data.name, prefix); // 属性 if (data.name.indexOf("status:")==0) { core.setStatus(data.name.substring(7), value);