Merge remote-tracking branch 'refs/remotes/origin/dev-2.0-blockly-20180214' into dev-2.0-appendPic-20180218

This commit is contained in:
YouWei Zhao 2018-02-21 18:09:39 +08:00
commit bb6a9e3266
5 changed files with 57 additions and 14 deletions

View File

@ -230,13 +230,13 @@ return code;
*/ */
setText_s setText_s
: '设置剧情文本的属性' '位置' SetTextPosition_List BGNL? '标题颜色' EvalString? '正文颜色' EvalString? '背景色' EvalString? Newline : '设置剧情文本的属性' '位置' SetTextPosition_List BGNL? '标题颜色' EvalString? '正文颜色' EvalString? '背景色' EvalString? '粗体' B_List Newline
; ;
/* setText_s /* setText_s
tooltip : setText设置剧情文本的属性,颜色为RGB三元组或RGBA四元组 tooltip : setText设置剧情文本的属性,颜色为RGB三元组或RGBA四元组
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=settext%ef%bc%9a%e8%ae%be%e7%bd%ae%e5%89%a7%e6%83%85%e6%96%87%e6%9c%ac%e7%9a%84%e5%b1%9e%e6%80%a7 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=settext%ef%bc%9a%e8%ae%be%e7%bd%ae%e5%89%a7%e6%83%85%e6%96%87%e6%9c%ac%e7%9a%84%e5%b1%9e%e6%80%a7
default : [null,"255,215,0,1","255,255,255,1","0,0,0,0.85"] default : [null,"255,215,0,1","255,255,255,1","0,0,0,0.85",[['不改变','null'],['设为粗体','true'],['取消粗体','false']]]
SetTextPosition_List_0 = ', "position": "'+SetTextPosition_List_0+'"'; SetTextPosition_List_0 = ', "position": "'+SetTextPosition_List_0+'"';
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)?$/; 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)?$/;
if (EvalString_0) { if (EvalString_0) {
@ -251,7 +251,8 @@ if (EvalString_2) {
if (!colorRe.test(EvalString_2))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1'); if (!colorRe.test(EvalString_2))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1');
EvalString_2 = ', "background": ['+EvalString_2+']'; EvalString_2 = ', "background": ['+EvalString_2+']';
} }
var code = '{"type": "setText"'+SetTextPosition_List_0+EvalString_0+EvalString_1+EvalString_2+'},\n'; B_List_0 = ', "bold": '+B_List_0;
var code = '{"type": "setText"'+SetTextPosition_List_0+EvalString_0+EvalString_1+EvalString_2+B_List_0+'},\n';
return code; return code;
*/ */
@ -922,6 +923,12 @@ Weather_List
: '无'|'rain'|'snow' : '无'|'rain'|'snow'
; ;
B_List
: 'null'
| 'true'
| 'false'
;
Bool: 'TRUE' Bool: 'TRUE'
| 'FALSE' | 'FALSE'
; ;
@ -1127,7 +1134,7 @@ ActionParser.prototype.parseAction = function() {
data.text=setTextfunc(data.text); data.text=setTextfunc(data.text);
data.background=setTextfunc(data.background); data.background=setTextfunc(data.background);
this.next = MotaActionBlocks['setText_s'].xmlText([ this.next = MotaActionBlocks['setText_s'].xmlText([
data.position,data.title,data.text,data.background,this.next]); data.position,data.title,data.text,data.background,data.bold,this.next]);
break; break;
case "tip": case "tip":
this.next = MotaActionBlocks['tip_s'].xmlText([ this.next = MotaActionBlocks['tip_s'].xmlText([

View File

@ -267,8 +267,8 @@
``` js ``` js
"x,y": [ // 实际执行的事件列表 "x,y": [ // 实际执行的事件列表
{"type": "setText", "position": "up", "title": [255,0,0], "text": [255,255,0], "background": [0,0,255,0.3]}, {"type": "setText", "position": "up", "title": [255,0,0], "text": [255,255,0], "background": [0,0,255,0.3], "bold": true},
"这段话将显示在上方标题为红色正文为黄色背景为透明度0.3的蓝色" "这段话将显示在上方,标题为红色,正文为黄色粗体背景为透明度0.3的蓝色"
] ]
``` ```
@ -280,6 +280,8 @@ text为可选项如果设置则为一个RGB三元组或RGBA四元组表示
background为可选项如果设置则为一个RGB三元组或RGBA四元组表示背景色。 background为可选项如果设置则为一个RGB三元组或RGBA四元组表示背景色。
bold为可选项如果设置则为true或false表示正文是否使用粗体。
### tip显示一段提示文字 ### tip显示一段提示文字
`{"type": "tip"}`可以在左上角显示一段提示文字。 `{"type": "tip"}`可以在左上角显示一段提示文字。
@ -1324,7 +1326,7 @@ events.prototype.afterPushBox = function () {
- 如果`effect`为字符串则和上面的全局商店的写法完全相同。可由分号分开每一项为X+=Y的形式X为你要修改的勇士属性/道具个数Y为一个表达式。 - 如果`effect`为字符串则和上面的全局商店的写法完全相同。可由分号分开每一项为X+=Y的形式X为你要修改的勇士属性/道具个数Y为一个表达式。
- 如果`effect`为函数,则也允许写一个`function`,来代表本次升级将会执行的操作。 - 如果`effect`为函数,则也允许写一个`function`,来代表本次升级将会执行的操作。
## 开始,难度分歧,获胜与失败 ## 开始,难度分歧,获胜与失败,多结局
游戏开始时将调用`events.js`中的`startGame`函数。 游戏开始时将调用`events.js`中的`startGame`函数。
@ -1362,13 +1364,16 @@ events.prototype.setInitData = function (hard) {
``` js ``` js
////// 游戏获胜事件 ////// ////// 游戏获胜事件 //////
events.prototype.win = function(reason) { events.prototype.win = function(reason) {
core.ui.closePanel();
var replaying = core.status.replay.replaying;
core.stopReplay();
core.waitHeroToStop(function() { core.waitHeroToStop(function() {
core.removeGlobalAnimate(0,0,true); core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图 core.clearMap('all'); // 清空全地图
core.drawText([ core.drawText([
"\t[结局2]恭喜通关!你的分数是${status:hp}。" "\t[恭喜通关]你的分数是${status:hp}。"
], function () { ], function () {
core.restart(); core.events.gameOver('', replaying);
}) })
}); });
} }
@ -1381,11 +1386,14 @@ events.prototype.win = function(reason) {
``` js ``` js
////// 游戏失败事件 ////// ////// 游戏失败事件 //////
events.prototype.lose = function(reason) { events.prototype.lose = function(reason) {
core.ui.closePanel();
var replaying = core.status.replay.replaying;
core.stopReplay();
core.waitHeroToStop(function() { core.waitHeroToStop(function() {
core.drawText([ core.drawText([
"\t[结局1]你死了。\n如题。" "\t[结局1]你死了。\n如题。"
], function () { ], function () {
core.restart(); core.events.gameOver(null, replaying);
}); });
}) })
} }
@ -1393,6 +1401,26 @@ events.prototype.lose = function(reason) {
其参数reason为失败原因。你可以在这里修改失败界面时显示的文字。 其参数reason为失败原因。你可以在这里修改失败界面时显示的文字。
如果要设置多种不同的结局只需要在win的传参中把`core.events.gameOver('', replaying);`的空字符串改成具体的结局名。
例如:
``` js
events.prototype.win = function(reason) { // 传入参数"reason"为结局名
// ... 上略
], function () {
core.events.gameOver(reason, replaying); // 使用reason作为结局名
})
});
}
// 然后在事件可以调用
{"type": "win", "reason": "TRUE END"}, // TE结局
{"type": "win", "reason": "NORMAL END"} // NE结局
```
上面这个例子中我们直接把reason作为结局名的参数传入gameOver函数这样的话就可以直接在{"type": "win"}中加上"reason"代表具体的结局。
========================================================================================== ==========================================================================================
[继续阅读下一章:个性化](personalization) [继续阅读下一章:个性化](personalization)

View File

@ -130,6 +130,7 @@ function core() {
"title": [255,215,0,1], "title": [255,215,0,1],
"background": [0,0,0,0.85], "background": [0,0,0,0.85],
"text": [255,255,255,1], "text": [255,255,255,1],
"bold": false,
}, },
'curtainColor': null, 'curtainColor': null,
'usingCenterFly':false, 'usingCenterFly':false,
@ -4788,8 +4789,10 @@ core.prototype.loadData = function (data, callback) {
// load shop times // load shop times
for (var shop in core.status.shops) { for (var shop in core.status.shops) {
core.status.shops[shop].times = data.shops[shop].times; if (core.isset(data.shops[shop])) {
core.status.shops[shop].visited = data.shops[shop].visited; core.status.shops[shop].times = data.shops[shop].times;
core.status.shops[shop].visited = data.shops[shop].visited;
}
} }
core.events.afterLoadData(data); core.events.afterLoadData(data);

View File

@ -313,6 +313,9 @@ events.prototype.doAction = function() {
core.status.textAttribute[t]=data[t]; core.status.textAttribute[t]=data[t];
} }
}) })
if (core.isset(data.bold)) {
core.status.textAttribute.bold=data.bold;
}
core.events.doAction(); core.events.doAction();
break; break;
case "tip": case "tip":

View File

@ -120,7 +120,9 @@ ui.prototype.drawTextBox = function(content) {
if (id=='hero' || core.isset(icon)) content_left=left+63; if (id=='hero' || core.isset(icon)) content_left=left+63;
var validWidth = right-(content_left-left)-13; var validWidth = right-(content_left-left)-13;
var contents = core.splitLines("ui", content, validWidth, '16px Verdana'); var font = '16px Verdana';
if (textAttribute.bold) font = "bold "+font;
var contents = core.splitLines("ui", content, validWidth, font);
var height = 20 + 21*(contents.length+1) + (id=='hero'?core.material.icons.hero.height-10:core.isset(name)?32-10:0); var height = 20 + 21*(contents.length+1) + (id=='hero'?core.material.icons.hero.height-10:core.isset(name)?32-10:0);
@ -229,7 +231,7 @@ ui.prototype.drawTextBox = function(content) {
core.setFillStyle('ui', core.arrayToRGB(textAttribute.text)); core.setFillStyle('ui', core.arrayToRGB(textAttribute.text));
for (var i=0;i<contents.length;i++) { for (var i=0;i<contents.length;i++) {
core.fillText('ui', contents[i], content_left, content_top, null, '16px Verdana'); core.fillText('ui', contents[i], content_left, content_top, null, font);
content_top+=21; content_top+=21;
} }