From 934aa025f88e081bc989e9b2ba365563c454fae9 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 2 Jun 2020 16:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=96=87=E6=9C=AC=E7=AB=8B?= =?UTF-8?q?=E7=BB=98=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 79 +++++++++++++++++++++++++++++++++ _server/MotaActionParser.js | 35 ++++++++++++++- _server/editor_blocklyconfig.js | 1 + libs/ui.js | 8 ++-- 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index f2f20310..6aab1465 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -595,6 +595,7 @@ return JSON.stringify(code); action : text_0_s | text_1_s + | text_2_s | comment_s | autoText_s | scrollText_s @@ -754,6 +755,84 @@ var code = '"'+title+EvalString_2+EvalString_3+'",\n'; return code; */; +text_2_s + : '标题' EvalString? '图像' EvalString? '对话框效果' EvalString? ':' EvalString BGNL? Newline textDrawingList* Newline + + +/* text_2_s +tooltip : text:显示一段文字(剧情),选项较多请右键点击帮助 +helpUrl : https://h5mota.com/games/template/_docs/#/event?id=text%EF%BC%9A%E6%98%BE%E7%A4%BA%E4%B8%80%E6%AE%B5%E6%96%87%E5%AD%97%EF%BC%88%E5%89%A7%E6%83%85%EF%BC%89 +doubleclicktext : EvalString_3 +allIds : ['EvalString_1'] +default : ["小妖精","fairy","","欢迎使用事件编辑器(双击方块进入多行编辑)",null] +var title=''; +if (EvalString_0==''){ + if (EvalString_1=='' )title=''; + else title='\\t['+EvalString_1+']'; +} else { + if (EvalString_1=='')title='\\t['+EvalString_0+']'; + else title='\\t['+EvalString_0+','+EvalString_1+']'; +} +if(EvalString_2 && !(/^(up|center|down|hero|this)(,(hero|null|\d+,\d+|\d+))?$/.test(EvalString_2))) { + throw new Error('对话框效果的用法请右键点击帮助'); +} +EvalString_2 = EvalString_2 && ('\\b['+EvalString_2+']'); +var code = '"'+title+EvalString_2+textDrawingList_0.replace(/\s/g, '')+EvalString_3+'",\n'; +return code; +*/; + +textDrawingList + : textDrawing + | textDrawingEmpty; + + +textDrawing + : '立绘' EvalString '翻转' Reverse_List '绘制坐标' 'x' IntString 'y' IntString '宽' IntString? '高' IntString? BGNL? Newline + '裁剪坐标' 'x' IntString? 'y' IntString? '宽' IntString? '高' IntString? '不透明度' EvalString? '旋转角度' IntString? + +/* textDrawing +tooltip : 立绘 +helpUrl : https://h5mota.com/games/template/_docs/#/event?id=drawImage%ef%bc%9a%e7%bb%98%e5%88%b6%e5%9b%be%e7%89%87 +default : ["fairy.png","null","0","0","","","","","","","",""] +colour : this.subColor +allImages : ['EvalString_0'] +if (Reverse_List_0 && Reverse_List_0 != 'null') EvalString_0 += Reverse_List_0; +var list = [EvalString_0, IntString_0, IntString_1]; +if (IntString_2 || IntString_3) { + if (list.length != 3 || !IntString_2 || !IntString_3) { + throw "绘制的宽和高需同时设置"; + } + list.push(IntString_2); + list.push(IntString_3); +} +if (IntString_4 || IntString_5 || IntString_6 || IntString_7) { + if (list.length != 5) throw "如设置裁剪区域,请先设置绘制区域的宽高"; + if (!IntString_4 || !IntString_5 || !IntString_6 || !IntString_7) { + throw "如设置裁剪区域,请同时设置全部的裁剪坐标和宽高"; + } + list.splice(1, 0, IntString_4, IntString_5, IntString_6, IntString_7); +} +if (EvalString_1) { + if (list.length != 9) throw "如设置不透明度,需填满所有坐标和宽高"; + var opacity = parseFloat(EvalString_1); + if (isNaN(opacity) || opacity < 0 || opacity > 1) throw "不合法的不透明度,必须是0到1之间" + list.push(opacity); +} +if (IntString_8) { + if (list.length != 10) throw "如设置旋转角度,需填满所有坐标和宽高,以及不透明度"; + list.push(IntString_8); +} +return "\\f[" + list.join(",")+"]"; +*/; + +textDrawingEmpty + : Newline + +/* textDrawingEmpty +var code = ''; +return code; +*/; + comment_s : '添加注释' ':' EvalString Newline diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index ffa74fa7..7202bd61 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -210,7 +210,38 @@ ActionParser.prototype.parseAction = function() { return; case "text": // 文字/对话 var info = this.getTitleAndPosition(data.text); - if (info[0] || info[1] || info[2]) { + var textDrawing = []; + info[3] = (info[3] || "").replace(/(\f|\\f)\[(.*?)]/g, function (text, sympol, str) { + var ss = str.split(","); + if (ss.length == 3 || ss.length == 5 || ss.length >=9) { + var swap = function (i, j) { var x = ss[i]; ss[i] = ss[j]; ss[j] = x;} + if (ss.length >= 9) { + swap(1,5); swap(2,6); swap(3,7); swap(4,8); + } + textDrawing.push(ss); + } + return ''; + }); + if (textDrawing.length > 0) { + var buildTextDrawing = function (obj) { + if(!obj) obj=[]; + var text_choices = null; + for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { + var reverse = 'null'; + if (choice[0].endsWith(':o') || choice[0].endsWith(':x') || choice[0].endsWith(':y')) { + reverse = choice[0].substring(choice[0].length - 2); + choice[0] = choice[0].substring(0, choice[0].length - 2); + } + text_choices=MotaActionBlocks['textDrawing'].xmlText([ + choice[0], reverse, choice[1], choice[2], choice[3], choice[4], choice[5], choice[6], + choice[7], choice[8], choice[9], choice[10], text_choices]); + } + return text_choices; + } + this.next = MotaActionBlocks['text_2_s'].xmlText([ + info[0], info[1], info[2], info[3], buildTextDrawing(textDrawing), this.next + ]); + } else if (info[0] || info[1] || info[2]) { this.next = MotaActionBlocks['text_1_s'].xmlText([ info[0], info[1], info[2], info[3], this.next]); } @@ -1154,7 +1185,7 @@ MotaActionFunctions.JsonEvalString_pre = function (JsonEvalString) { } MotaActionFunctions.IntString_pre = function (IntString) { - if (!/^\d*$/.test(IntString)) throw new Error('此项必须是整数或不填'); + if (!/^[+-]?\d*$/.test(IntString)) throw new Error('此项必须是整数或不填'); return IntString; } diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 5961514a..179f0a56 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -87,6 +87,7 @@ editor_blocklyconfig=(function(){ '显示文字':[ MotaActionBlocks['text_0_s'].xmlText(), MotaActionBlocks['text_1_s'].xmlText(), + MotaActionFunctions.actionParser.parseList("\t[小妖精,fairy]\f[fairy.png,0,0]欢迎使用事件编辑器(双击方块进入多行编辑)"), MotaActionBlocks['comment_s'].xmlText(), MotaActionBlocks['autoText_s'].xmlText(), MotaActionBlocks['scrollText_s'].xmlText(), diff --git a/libs/ui.js b/libs/ui.js index 4825563a..771708f8 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1347,9 +1347,11 @@ ui.prototype._drawTextBox_drawImages = function (content) { core.drawImage('ui', ss[0], parseFloat(ss[1]), parseFloat(ss[2])); else if (ss.length==5) core.drawImage('ui', ss[0], parseFloat(ss[1]), parseFloat(ss[2]), parseFloat(ss[3]), parseFloat(ss[4])); - else if (ss.length==9 || ss.length==10) { - if (ss.length==10) core.setAlpha('ui', parseFloat(ss[9])); - core.drawImage('ui', ss[0], parseFloat(ss[1]), parseFloat(ss[2]), parseFloat(ss[3]), parseFloat(ss[4]), parseFloat(ss[5]), parseFloat(ss[6]), parseFloat(ss[7]), parseFloat(ss[8])); + else if (ss.length >= 9) { + if (ss.length >= 10) core.setAlpha('ui', parseFloat(ss[9])); + var angle = (parseFloat(ss[10]) || 0) * Math.PI / 180; + core.drawImage('ui', ss[0], parseFloat(ss[1]), parseFloat(ss[2]), parseFloat(ss[3]), parseFloat(ss[4]), + parseFloat(ss[5]), parseFloat(ss[6]), parseFloat(ss[7]), parseFloat(ss[8]), angle); core.setAlpha('ui', 1); } return "";