diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 61bbe2a0..db191884 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -235,6 +235,7 @@ action | break_s | continue_s | input_s + | input2_s | choices_s | function_s | pass_s @@ -1057,18 +1058,31 @@ return code; */; input_s - : '接受用户输入,提示' ':' EvalString Newline + : '接受用户输入数字,提示' ':' EvalString Newline /* input_s -tooltip : input:接受用户输入, 事件只能接受非负整数输入, 所有非法的输入将全部变成0 -helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%EF%BC%9A%E6%8E%A5%E5%8F%97%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5 +tooltip : input:接受用户输入数字, 事件只能接受非负整数输入, 所有非法的输入将全部变成0 +helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%95%b0%e5%ad%97 default : ["请输入一个数"] colour : this.dataColor var code = '{"type": "input", "text": "'+EvalString_0+'"},\n'; return code; */; +input2_s + : '接受用户输入文本,提示' ':' EvalString Newline + + +/* input2_s +tooltip : input2:接受用户输入文本, 允许用户输入任何形式的文本 +helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input2%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%96%87%e6%9c%ac +default : ["请输入文本"] +colour : this.dataColor +var code = '{"type": "input2", "text": "'+EvalString_0+'"},\n'; +return code; +*/; + if_s : '如果' ':' expression BGNL? Newline action+ '否则' ':' BGNL? Newline action+ BEND Newline @@ -1773,6 +1787,10 @@ ActionParser.prototype.parseAction = function() { this.next = MotaActionBlocks['input_s'].xmlText([ data.text,this.next]); break; + case "input2": + this.next = MotaActionBlocks['input2_s'].xmlText([ + data.text,this.next]); + break; case "if": // 条件判断 this.next = MotaActionBlocks['if_s'].xmlText([ MotaActionBlocks['evalString_e'].xmlText([data.condition]), diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index d9017a64..7be006de 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -88,6 +88,7 @@ editor_blockly = function () { MotaActionBlocks['idString_1_e'].xmlText(['status','hp']) ]), MotaActionBlocks['input_s'].xmlText(), + MotaActionBlocks['input2_s'].xmlText(), MotaActionBlocks['update_s'].xmlText(), MotaActionBlocks['updateEnemys_s'].xmlText(), MotaActionBlocks['moveHero_s'].xmlText(), diff --git a/docs/event.md b/docs/event.md index 29b55dfa..d16497d3 100644 --- a/docs/event.md +++ b/docs/event.md @@ -995,13 +995,13 @@ value为音量大小,在0到100之间,默认为100。设置后,BGM和SE都 该事件会显示失败页面,并重新开始游戏。 -### input:接受用户输入 +### input:接受用户输入数字 -使用`{"type": "input"}`可以接受用户的输入。 +使用`{"type": "input"}`可以接受用户的输入的数字。 ``` js "x,y": [ // 实际执行的事件列表 - {"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入内容 + {"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入数字 "你刚刚输入的数是${flag:input}" // 输入结果将被赋值为flag:input ] ``` @@ -1014,6 +1014,25 @@ text为提示文字,可以在这里给输入提示文字。这里同样可以 输入得到的结果将被赋值给flag:input,可以供后续if来进行判断。 +### input2:接受用户输入文本 + +类似于input事件,使用`{"type": "input2"}`可以接受用户的输入的文本。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "input2", "text": "请输入你的ID"}, // 显示一个弹窗让用户输入文本 + "你好,${flag:input},欢迎来到本塔" // 输入结果将被赋值为flag:input +] +``` + +text为提示文字,可以在这里给输入提示文字。这里同样可以使用${ }来计算表达式的值。 + +当执行input2事件时,将显示一个弹窗,并提示用户输入一个内容。 + +该事件可以接收任何形式的文本输入,包括中文,空格,标点符号等等。如果用户点击取消按钮,则视为空字符串。 + +输入得到的结果也将被赋值给flag:input,可以供后续使用。 + ### if:条件判断 使用`{"type": "if"}`可以对条件进行判断,根据判断结果将会选择不同的分支执行。 diff --git a/libs/events.js b/libs/events.js index 1318c8d9..01cba1fa 100644 --- a/libs/events.js +++ b/libs/events.js @@ -750,6 +750,32 @@ events.prototype.doAction = function() { this.doAction(); } break; + case "input2": + { + var value; + if (core.status.replay.replaying) { + var action = core.status.replay.toReplay.shift(); + try { + if (action.indexOf("input2:")!=0) throw new Error("Input2 Error. Current action: "+action); + value = core.decodeBase64(action.substring(7)); + } + catch (e) { + console.log(e); + core.stopReplay(); + core.drawTip("录像文件出错"); + return; + } + } + else { + core.interval.onDownInterval = 'tmp'; + value = prompt(core.replaceText(data.text)); + if (!core.isset(value)) value=""; + } + core.status.route.push("input2:"+core.encodeBase64(value)); + core.setFlag("input", value); + this.doAction(); + } + break; case "if": // 条件判断 if (core.calValue(data.condition)) core.events.insertAction(data["true"]) diff --git a/libs/utils.js b/libs/utils.js index fe4be893..b8ed902c 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -336,6 +336,8 @@ utils.prototype.encodeRoute = function (route) { ans+='G'; else if (t.indexOf('input:')==0) ans+="P"+t.substring(6); + else if (t.indexOf('input2:')==0) + ans+="Q"+t.substring(7)+":"; else if (t=='no') ans+='N'; else if (t.indexOf('move:')==0) @@ -370,7 +372,7 @@ utils.prototype.decodeRoute = function (route) { } var getString = function () { var str=""; - while (index