From 35e8784da5ab1abce84144ad68c230e2678948bc Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 2 Jun 2020 18:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E7=AB=8B=E7=BB=98=E5=92=8C?= =?UTF-8?q?=E5=9B=BE=E7=89=87;=E9=80=89=E6=8B=A9bgm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 8 +++ _server/editor_blockly.js | 101 ++++++++++++++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 10 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 6aab1465..c316dfcc 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -795,6 +795,7 @@ 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 +previewBlock : true allImages : ['EvalString_0'] if (Reverse_List_0 && Reverse_List_0 != 'null') EvalString_0 += Reverse_List_0; var list = [EvalString_0, IntString_0, IntString_1]; @@ -1815,6 +1816,7 @@ helpUrl : https://h5mota.com/games/template/_docs/#/event?id=showImage%ef%bc%9a% default : [1,"bg.jpg","null","0","0",1,0,false] allImages : ['EvalString_0'] colour : this.printColor +previewBlock : true if(Int_0<=0 || Int_0>50) throw new Error('图片编号在1~50之间'); if (Reverse_List_0 && Reverse_List_0 != 'null') { Reverse_List_0 = ', "reverse": "' + Reverse_List_0 + '"'; @@ -1836,6 +1838,7 @@ helpUrl : https://h5mota.com/games/template/_docs/#/event?id=showImage%ef%bc%9a% default : [1,"bg.jpg","null","0","0","","",1,"0","0","","",0,false] allImages : ['EvalString_0'] colour : this.printColor +previewBlock : true if(Int_0<=0 || Int_0>50) throw new Error('图片编号在1~50之间'); if (Reverse_List_0 && Reverse_List_0 != 'null') { Reverse_List_0 = ', "reverse": "' + Reverse_List_0 + '"'; @@ -1893,6 +1896,7 @@ helpUrl : https://h5mota.com/games/template/_docs/#/event?id=showgif%EF%BC%9A%E6 default : ["","",""] allImages : ['EvalString_0'] colour : this.printColor +previewBlock : true EvalString_0 = EvalString_0 ? (', "name": "'+EvalString_0+'"') : ''; var loc = (PosString_0 && PosString_1) ? (', "loc": ['+PosString_0+','+PosString_1+']') : ''; var code = '{"type": "showGif"'+EvalString_0+loc+'},\n'; @@ -1928,6 +1932,7 @@ tooltip : setCurtain: 更改画面色调,动画时间可不填 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=setcurtain%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83 default : ["255,255,255,1",'rgba(255,255,255,1)',500,true,false] colour : this.soundColor +previewBlock : true IntString_0 = IntString_0 ?(', "time": '+IntString_0):''; Bool_0 = Bool_0 ? ', "keep": true' : ''; var async = Bool_1?', "async": true':''; @@ -2085,6 +2090,7 @@ tooltip : playBgm: 播放背景音乐 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=playbgm%EF%BC%9A%E6%92%AD%E6%94%BE%E8%83%8C%E6%99%AF%E9%9F%B3%E4%B9%90 default : ["bgm.mp3", 0, true] allBgms : ['EvalString_0'] +material : ["./project/bgms/", "EvalString_0"] colour : this.soundColor Int_0 = Int_0 ? (', "startTime": '+Int_0) : ''; Bool_0 = Bool_0 ? ', "keep": true' : ''; @@ -2126,6 +2132,7 @@ tooltip : loadBgm: 预加载某个背景音乐,之后可以直接播放 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=loadBgm%ef%bc%9a%e9%a2%84%e5%8a%a0%e8%bd%bd%e4%b8%80%e4%b8%aa%e8%83%8c%e6%99%af%e9%9f%b3%e4%b9%90 default : ["bgm.mp3"] allBgms : ['EvalString_0'] +material : ["./project/bgms/", "EvalString_0"] colour : this.soundColor var code = '{"type": "loadBgm", "name": "'+EvalString_0+'"},\n'; return code; @@ -2155,6 +2162,7 @@ helpUrl : https://h5mota.com/games/template/_docs/#/event?id=playsound%EF%BC%9A% default : ["item.mp3",false] colour : this.soundColor allSounds : ['EvalString_0'] +material : ["./project/sounds/", "EvalString_0"] Bool_0 = Bool_0 ? ', "stop": true' : ''; var code = '{"type": "playSound", "name": "'+EvalString_0+'"'+Bool_0+'},\n'; return code; diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 2924cb28..6f8e1843 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -234,18 +234,86 @@ editor_blockly = function () { if (b && MotaActionBlocks[b.type].previewBlock) { try { + // 特殊处理立绘 + if (b.type == 'textDrawing') { + var str = Blockly.JavaScript.blockToCode(b); + var list = str.substring(str.indexOf('[')+1, str.lastIndexOf(']')).split(","); + if (list.length == 3 || list.length == 5 || list.length >= 9) { + var arr = []; + var name = list[0]; + var obj = {"type": "drawImage"}; + if (name.endsWith(":o") || name.endsWith(":x") || name.endsWith(":y")) { + obj.reverse = name.substring(name.length-2); + name = name.substring(0, name.length - 2); + } + obj.image = name; + obj.x = parseFloat(list[1]); + obj.y = parseFloat(list[2]); + if (list.length >= 5) { + obj.w = parseFloat(list[3]); + obj.h = parseFloat(list[4]); + } + if (list.length >= 9) { + obj.x1 = parseFloat(list[5]); + obj.y1 = parseFloat(list[6]); + obj.w1 = parseFloat(list[7]); + obj.h1 = parseFloat(list[8]); + } + if (list.length >= 10) { + arr.push({"type": "setAttribute", "alpha": parseFloat(list[9])}); + } + if (list.length >= 11) { + obj.angle = parseFloat(list[10]); + } + arr.push(obj); + console.log(arr); + editor.uievent.previewUI(arr); + } + return true; + } + var code = "[" + Blockly.JavaScript.blockToCode(b).replace(/\\(i|c|d|e|z)/g, '\\\\$1') + "]"; eval("var obj="+code); - if (obj.length > 0 && b.type == 'waitContext_2') { - var dt = obj[0]; - editor.uievent.previewUI([{"type": "fillRect", "x": dt.px[0], "y": dt.py[0], - "width": "(" + dt.px[1] + ")-(" + dt.px[0] + ")", "height": "(" + dt.py[1] + ")-(" + dt.py[0] + ")", - "style": "rgba(255,0,0,0.5)"}]) - } - else if (obj.length > 0 && b.type.startsWith(obj[0].type)) { - if (b.type == 'previewUI_s') - editor.uievent.previewUI(obj[0].action); - else editor.uievent.previewUI([obj[0]]); + if (obj.length == 0) return true; + obj = obj[0]; + switch (b.type) { + case 'waitContext_2': // 等待用户操作坐标预览 + editor.uievent.previewUI([{"type": "fillRect", "x": obj.px[0], "y": obj.py[0], + "width": "(" + obj.px[1] + ")-(" + obj.px[0] + ")", "height": "(" + obj.py[1] + ")-(" + obj.py[0] + ")", + "style": "rgba(255,0,0,0.5)"}]); + break; + case 'showImage_s': // 显示图片 + case 'showImage_1_s': + if (obj.sloc) { + editor.uievent.previewUI([ + {type: "setAttribute", alpha: obj.opacity}, + {type: "drawImage", image: obj.image, x: obj.sloc[0], y: obj.sloc[1], w: obj.sloc[2], h: obj.sloc[3], + x1: obj.loc[0], y1: obj.loc[1], w1: obj.loc[2], h1: obj.loc[3], reverse: obj.reverse} + ]); + } else { + editor.uievent.previewUI([ + {type: "setAttribute", alpha: obj.opacity}, + {type: "drawImage", image: obj.image, x: obj.loc[0], y: obj.loc[1], w: obj.loc[2], h: obj.loc[3], reverse: obj.reverse} + ]); + } + break; + case 'showGif_s': // 显示动图 + if (obj.name && obj.loc) { + editor.uievent.previewUI([{type: "drawImage", image: obj.name, x: obj.loc[0], y: obj.loc[1]}]); + } + break; + case 'setCurtain_0_s': // 更改色调 + if (obj.color) { + editor.uievent.previewUI([{type: "fillRect", x: 0, y: 0, width: core.__PIXELS__, height: core.__PIXELS__, style: obj.color}]); + } + break; + case 'previewUI_s': // 预览 + editor.uievent.previewUI(obj.action); + break; + default: + if (b.type.startsWith(obj.type)) { + editor.uievent.previewUI([obj]); + } } } catch (e) {main.log(e);} return true; @@ -263,6 +331,19 @@ editor_blockly = function () { return; } + if (b && MotaActionBlocks[b.type].material) { + var material = JSON.parse(MotaActionBlocks[b.type].material); + console.log(material); + editor.uievent.selectMaterial([b.getFieldValue(material[1])], '请选择素材', material[0], function (one) { + return /^[-A-Za-z0-9_.]+$/.test(one) ? one : null; + }, function (value) { + if (value instanceof Array && value.length > 0) { + b.setFieldValue(value[0], material[1]); + } + }); + return; + } + var f = b ? MotaActionBlocks[b.type].doubleclicktext : null; if (f) { var value = b.getFieldValue(f);