draw icons in toolbox

This commit is contained in:
oc 2019-02-27 04:53:26 +08:00
parent bd008a2d48
commit 4372981cb3
4 changed files with 64 additions and 9 deletions

View File

@ -326,9 +326,12 @@ floorId指定的是目标楼层的唯一标识符ID
- 使用`\r[...]`来动态修改局部文本的颜色,如`\r[red]`。
- 使用`${}`来计算一个表达式的值,如`${status:atk+status:def}`。
- 使用`\f[...]`来同时插入一张立绘图,如`\f[1.png,100,200]`。
- 使用`\\i[...]`来在对话框中绘制一个图标,如`\\i[fly]`。
从V2.5.2开始,也允许绘制一张头像图在对话框中,只要通过`\t[1.png]`或`\t[标题,1.png]`的写法。
**使用`\\i[...]`绘制图标请注意:在事件块中,允许只写一个反斜杠`\i`,系统会自动转义成`\\i`;但是在脚本中必须两个反斜杠都写上!**
详细信息请参见[剧情文本控制](event#text显示一段文字剧情)中的说明。
从V2.5.2开始可以用一张WindowSkin图片作为对话框的背景皮肤。

View File

@ -267,6 +267,21 @@
]
```
从V2.5.5以后,也可以使用`\\i[...]`来在对话框中绘制一个图标。
这里可以使用一个合法ID32x48图块除外或使用一个系统图标`core.statusBar.icons`中的内容)。
``` js
"x,y": [ // 实际执行的事件列表
"\t[勇士]\b[up,hero]这是一个飞行器\\i[fly],这是一个破墙镐\\i[pickaxe]",
"\t[hero]也可以使用系统图标,比如这是存档\\i[save],这是工具栏\\i[toolbox]",
]
```
**可以在控制台中输入`core.statusBar.icons`以查看所有的系统图标定义。**
!> 注意,在事件块中,允许只写一个反斜杠`\i`,系统会自动转义成`\\i`;但是在脚本中必须两个反斜杠都写上!
另外值得一提的是,我们是可以在文字中计算一个表达式的值的。只需要将表达式用 `${ }`整个括起来就可以。
``` js

View File

@ -339,7 +339,7 @@ function omitedcheckUpdateFunction(event) {
}
}
try {
var code = Blockly.JavaScript.workspaceToCode(workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\i/g, '\\\\i');
codeAreaHL.setValue(code);
} catch (error) {
codeAreaHL.setValue(String(error));
@ -481,7 +481,8 @@ function omitedcheckUpdateFunction(event) {
MotaActionFunctions.parse(
eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g, function (c) {
return {'<': '&lt;', '>': '&gt;', '&': '&amp;'}[c];
}).replace(/\\r/g, '\\\\r').replace(/\\f/g, '\\\\f')),
}).replace(/\\r/g, '\\\\r').replace(/\\f/g, '\\\\f')
.replace(/\\i/,'\\\\i')),
document.getElementById('entryType').value
);
}
@ -555,6 +556,7 @@ function omitedcheckUpdateFunction(event) {
return;
}
var code = Blockly.JavaScript.workspaceToCode(editor_blockly.workspace);
code = code.replace(/\\i/g, '\\\\i');
eval('var obj=' + code);
setvalue(JSON.stringify(obj));
}

View File

@ -504,7 +504,7 @@ ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width)
}
ui.prototype.__drawText = function (canvas, content, content_left, content_top, valid_width,
color, per_height, time) {
color, per_height, text_font, time) {
core.setTextAlign(canvas, 'left');
var offsetx = content_left, offsety = content_top;
@ -543,6 +543,41 @@ ui.prototype.__drawText = function (canvas, content, content_left, content_top,
else currcolor = color;
return drawNext();
}
// \\i 绘制图标
if (ch == '\\' && content.charAt(index)=='i') {
// 绘制图标
var index2;
if (content.charAt(index+1) == '[' && ((index2=content.indexOf(']', index+1))>=0)) {
var str = content.substring(index+2, index2);
// --- 获得图标
var image = null, icon = null;
["terrains","animates","items","npcs","enemys"].forEach(function (v) {
if (core.isset(core.material.icons[v][str])) {
image = core.material.images[v];
icon = core.material.icons[v][str];
}
});
if (image == null) {
if (str in core.statusBar.icons) {
image = core.statusBar.icons[str];
icon = 0;
}
}
if (image != null) {
if (core.isset(valid_width) && offsetx + text_font + 6 > content_left + valid_width) {
index --;
offsetx = content_left;
offsety += per_height;
return drawNext();
}
// --- 绘制
core.drawImage(canvas, image, 0, 32*icon, 32, 32, offsetx + 2, offsety - text_font + 1, text_font+2, text_font+2);
offsetx += text_font + 6;
index = index2+1;
return true;
}
}
}
// 检查是不是自动换行
var charwidth = core.calWidth(canvas, ch);
if (core.isset(valid_width) && offsetx + charwidth > content_left + valid_width) {
@ -663,7 +698,7 @@ ui.prototype.drawTextBox = function(content, showAll) {
var globalFont = core.status.globalAttribute.font;
var font = textfont + 'px '+globalFont;
if (textAttribute.bold) font = "bold "+font;
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "");
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1");
var leftSpace = 25, rightSpace = 12;
if (core.isset(px) && core.isset(py)) leftSpace = 20;
@ -797,7 +832,7 @@ ui.prototype.drawTextBox = function(content, showAll) {
core.setFont('ui', font);
this.__drawText('ui', content, content_left, content_top, validWidth, textColor, textfont + 5,
this.__drawText('ui', content, content_left, content_top, validWidth, textColor, textfont + 5, textfont,
(showAll || textAttribute.time<=0 || core.status.event.id!='action')?0:textAttribute.time);
}
@ -819,7 +854,7 @@ ui.prototype.drawScrollText = function (content, time, callback) {
var font = textfont+"px "+core.status.globalAttribute.font;
if (textAttribute.bold) font = "bold "+font;
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "");
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1");
var contents = core.splitLines('ui', realContent), lines = contents.length;
// 计算总高度按1.4倍行距计算
@ -830,7 +865,7 @@ ui.prototype.drawScrollText = function (content, time, callback) {
tempCanvas.clearRect(0, 0, width, height);
tempCanvas.font = font;
this.__drawText(tempCanvas, content, offset, textfont, null, textColor, 1.4*textfont, 0);
this.__drawText(tempCanvas, content, offset, textfont, null, textColor, 1.4*textfont, textfont, 0);
// 开始绘制到UI上
core.clearMap('ui');
@ -898,7 +933,7 @@ ui.prototype.drawChoices = function(content, choices) {
// 获得name, image, icon
var info = this.getTitleAndIcon(content);
content = core.replaceText(info.content);
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "");
var realContent = content.replace(/(\r|\\r)(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "啊1");
id=info.id; name=info.name; image=info.image;
icon=info.icon; iconHeight=info.iconHeight; animate=info.animate;
if (id=='hero' || core.isset(icon))
@ -967,7 +1002,7 @@ ui.prototype.drawChoices = function(content, choices) {
}
core.setFont('ui', 'bold 15px '+globalFont);
this.__drawText('ui', content, content_left, content_top, validWidth, textColor, 20, 0);
this.__drawText('ui', content, content_left, content_top, validWidth, textColor, 20, 15, 0);
}
// 选项