drawTextBox position

This commit is contained in:
oc 2018-10-29 01:31:37 +08:00
parent 6bcba464f7
commit 2dad906e7e
4 changed files with 24 additions and 21 deletions

View File

@ -306,41 +306,45 @@ return code;
*/; */;
setText_s setText_s
: '设置剧情文本的属性' '位置' SetTextPosition_List BGNL? '标题颜色' EvalString? '正文颜色' EvalString? '背景色' EvalString? '粗体' B_1_List BGNL? '标题字体大小' EvalString? '正文字体大小' EvalString? '打字间隔' EvalString? Newline : '设置剧情文本的属性' '位置' SetTextPosition_List '偏移像素' EvalString? BGNL? '标题颜色' EvalString? '正文颜色' EvalString? '背景色' EvalString? '粗体' B_1_List BGNL? '标题字体大小' EvalString? '正文字体大小' EvalString? '打字间隔' EvalString? 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,"","","",null,"","",''] default : [null,"","","","",null,"","",""]
SetTextPosition_List_0 =SetTextPosition_List_0==='null'?'': ', "position": "'+SetTextPosition_List_0+'"'; SetTextPosition_List_0 =SetTextPosition_List_0==='null'?'': ', "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) {
if (!colorRe.test(EvalString_0))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1'); if (!/^\d+$/.test(EvalString_0))throw new Error('像素偏移量必须是整数或不填');
EvalString_0 = ', "title": ['+EvalString_0+']'; EvalString_0 = ', "offset": '+EvalString_0;
} }
if (EvalString_1) { if (EvalString_1) {
if (!colorRe.test(EvalString_1))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1'); if (!colorRe.test(EvalString_1))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1');
EvalString_1 = ', "text": ['+EvalString_1+']'; EvalString_1 = ', "title": ['+EvalString_1+']';
} }
if (EvalString_2) { 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 = ', "text": ['+EvalString_2+']';
} }
if (EvalString_3) { if (EvalString_3) {
if (!/^\d+$/.test(EvalString_3))throw new Error('字体大小必须是整数或不填'); if (!colorRe.test(EvalString_3))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1');
EvalString_3 = ', "titlefont": '+EvalString_3; EvalString_3 = ', "background": ['+EvalString_3+']';
} }
if (EvalString_4) { if (EvalString_4) {
if (!/^\d+$/.test(EvalString_4))throw new Error('字体大小必须是整数或不填'); if (!/^\d+$/.test(EvalString_4))throw new Error('字体大小必须是整数或不填');
EvalString_4 = ', "textfont": '+EvalString_4; EvalString_4 = ', "titlefont": '+EvalString_4;
} }
if (EvalString_5) { if (EvalString_5) {
if (!/^\d+$/.test(EvalString_5))throw new Error('打字时间间隔必须是整数或不填'); if (!/^\d+$/.test(EvalString_5))throw new Error('字体大小必须是整数或不填');
EvalString_5 = ', "time": '+EvalString_5; EvalString_5 = ', "textfont": '+EvalString_5;
} }
B_1_List_0 = ', "bold": '+B_1_List_0; if (EvalString_6) {
var code = '{"type": "setText"'+SetTextPosition_List_0+EvalString_0+EvalString_1+EvalString_2+B_1_List_0+EvalString_3+EvalString_4+EvalString_5+'},\n'; if (!/^\d+$/.test(EvalString_6))throw new Error('打字时间间隔必须是整数或不填');
EvalString_6 = ', "time": '+EvalString_6;
}
B_1_List_0 = B_1_List_0==='null'?'':', "bold": '+B_1_List_0;
var code = '{"type": "setText"'+SetTextPosition_List_0+EvalString_0+EvalString_1+EvalString_2+B_1_List_0+EvalString_3+EvalString_4+EvalString_5+EvalString_6+'},\n';
return code; return code;
*/; */;
@ -1450,7 +1454,7 @@ Stair_List
/*Stair_List ['loc','upFloor','downFloor']*/; /*Stair_List ['loc','upFloor','downFloor']*/;
SetTextPosition_List SetTextPosition_List
: '不改变'|'上'|'中'|'下' : '不改变'|'距离顶部'|'居中'|'距离底部'
/*SetTextPosition_List ['null','up','center','down']*/; /*SetTextPosition_List ['null','up','center','down']*/;
ShopUse_List ShopUse_List
@ -1705,7 +1709,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,data.bold,data.titlefont,data.textfont,data.time,this.next]); data.position,data.offset,data.title,data.text,data.background,data.bold,data.titlefont,data.textfont,data.time,this.next]);
break; break;
case "tip": case "tip":
this.next = MotaActionBlocks['tip_s'].xmlText([ this.next = MotaActionBlocks['tip_s'].xmlText([

View File

@ -145,6 +145,7 @@ function core() {
}, },
'textAttribute': { 'textAttribute': {
'position': "center", 'position': "center",
"offset": 20,
"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],

View File

@ -348,10 +348,7 @@ events.prototype.doAction = function() {
} }
break; break;
case "setText": // 设置文本状态 case "setText": // 设置文本状态
if (data.position=='up'||data.position=='down'||data.position=='center') { ["position", "offset", "bold", "titlefont", "textfont", "time"].forEach(function (t) {
core.status.textAttribute.position=data.position;
}
["bold", "titlefont", "textfont", "time"].forEach(function (t) {
if (core.isset(data[t])) core.status.textAttribute[t]=data[t]; if (core.isset(data[t])) core.status.textAttribute[t]=data[t];
}); });
["background", "title", "text"].forEach(function (t) { ["background", "title", "text"].forEach(function (t) {

View File

@ -373,6 +373,7 @@ ui.prototype.drawTextBox = function(content, showAll) {
var titlefont = textAttribute.titlefont || 22; var titlefont = textAttribute.titlefont || 22;
var textfont = textAttribute.textfont || 16; var textfont = textAttribute.textfont || 16;
var offset = textAttribute.offset || 0;
var position = textAttribute.position, px=null, py=null, ydelta=iconHeight-32; var position = textAttribute.position, px=null, py=null, ydelta=iconHeight-32;
if (content.indexOf("\b[")==0 || content.indexOf("\\b[")==0) { if (content.indexOf("\b[")==0 || content.indexOf("\\b[")==0) {
@ -434,7 +435,7 @@ ui.prototype.drawTextBox = function(content, showAll) {
} }
else if (position=='up') { else if (position=='up') {
if (px==null || py==null) { if (px==null || py==null) {
top = 5; top = 5 + offset;
} }
else { else {
top = 32 * py - height - ydelta - yoffset; top = 32 * py - height - ydelta - yoffset;
@ -442,7 +443,7 @@ ui.prototype.drawTextBox = function(content, showAll) {
} }
else if (position=='down') { else if (position=='down') {
if (px==null || py==null) { if (px==null || py==null) {
top = 416 - height - 5; top = 416 - height - 5 - offset;
} }
else { else {
top = 32 * py + 32 + yoffset; top = 32 * py + 32 + yoffset;