diff --git a/_docs/api.md b/_docs/api.md index 737333e3..9f6d03e9 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -1747,7 +1747,7 @@ ctx: 要绘制到的画布 content: 要绘制的内容;转义字符不允许保留 \t, \b 和 \f config: 绘制配置项,目前暂时包含如下内容(均为可选) left, top:起始点位置;maxWidth:单行最大宽度;color:默认颜色;align:左中右 -fontSize:字体大小;lineHeight:行高;time:打字机间隔 +fontSize:字体大小;lineHeight:行高;time:打字机间隔;font:默认字体 返回值:绘制信息 calWidth: fn(name: string|CanvasRenderingContext2D, text: string, font?: string) -> number diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js index 22b340a8..63b7ef14 100644 --- a/_server/CodeMirror/defs.js +++ b/_server/CodeMirror/defs.js @@ -3561,7 +3561,7 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [ "!type": "fn(name: string|CanvasRenderingContext2D, x?: number, y?: number, width?: number, height?: number)" }, "drawTextContent": { - "!doc": "绘制一段文字到某个画布上面
ctx: 要绘制到的画布
content: 要绘制的内容;转义字符不允许保留 \\t, \\b 和 \\f
config: 绘制配置项,目前暂时包含如下内容(均为可选)
left, top:起始点位置;maxWidth:单行最大宽度;color:默认颜色;align:左中右
fontSize:字体大小;lineHeight:行高;time:打字机间隔
返回值:绘制信息", + "!doc": "绘制一段文字到某个画布上面
ctx: 要绘制到的画布
content: 要绘制的内容;转义字符不允许保留 \\t, \\b 和 \\f
config: 绘制配置项,目前暂时包含如下内容(均为可选)
left, top:起始点位置;maxWidth:单行最大宽度;color:默认颜色;align:左中右
fontSize:字体大小;lineHeight:行高;time:打字机间隔;font:字体名
返回值:绘制信息", "!type": "fn(ctx: string|CanvasRenderingContext2D, content: string, config: ?)" }, "calWidth": { diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index ce76e341..d1f8e882 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -104,7 +104,7 @@ editor_blockly = function () { MotaActionFunctions.parse( eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g, function (c) { return {'<': '<', '>': '>', '&': '&'}[c]; - }).replace(/\\(r|f|i|c|d|e|z)/g,'\\\\$1')), + }).replace(/\\(r|f|i|c|d|e|g|z)/g,'\\\\$1')), editor_blockly.entryType ); } @@ -190,7 +190,7 @@ editor_blockly = function () { return; } var code = Blockly.JavaScript.workspaceToCode(editor_blockly.workspace); - code = code.replace(/\\(i|c|d|e|z)/g, '\\\\$1'); + code = code.replace(/\\(i|c|d|e|g|z)/g, '\\\\$1'); eval('var obj=' + code); if (this.checkAsync(obj) && confirm("警告!存在不等待执行完毕的事件但却没有用【等待所有异步事件处理完毕】来等待" + "它们执行完毕,这样可能会导致录像检测系统出问题。\n你要返回修改么?")) return; @@ -272,7 +272,7 @@ editor_blockly = function () { return true; } - var code = "[" + Blockly.JavaScript.blockToCode(b).replace(/\\(i|c|d|e|z)/g, '\\\\$1') + "]"; + var code = "[" + Blockly.JavaScript.blockToCode(b).replace(/\\(i|c|d|e|g|z)/g, '\\\\$1') + "]"; eval("var obj="+code); if (obj.length == 0) return true; obj = obj[0]; @@ -654,6 +654,7 @@ editor_blockly = function () { namesObj.allColors = ["aqua(青色)", "black(黑色)", "blue(蓝色)", "fuchsia(品红色)", "gray(灰色)", "green(深绿色)", "lime(绿色)", "maroon(深红色)", "navy(深蓝色)", "gold(金色)", "olive(黄褐色)", "orange(橙色)", "purple(品红色)", "red(红色)", "silver(淡灰色)", "teal(深青色)", "white(白色)", "yellow(黄色)"]; + namesObj.allFonts = [main.styles.font].concat(main.fonts); namesObj.allDoors = ["this"].concat(Object.keys(maps_90f36752_8815_4be8_b32b_d7fad1d0542e) .map(function (key) { return maps_90f36752_8815_4be8_b32b_d7fad1d0542e[key]; }) .filter(function (one) { return one.doorInfo != null; }) @@ -708,9 +709,18 @@ editor_blockly = function () { } } + // 对\g进行补全 + index = content.lastIndexOf("\\g["); + if (index >= 0) { + var after = content.substring(index + 3); + if (after.indexOf("]") < 0) { + return filter(namesObj.allFonts, after); + } + } + // 对\进行补全! if (content.charAt(content.length - 1) == '\\') { - return ["n(换行)", "f(立绘)", "r(变色)", "i(图标)", "z(暂停打字)", "t(标题图标)", "b(对话框)", "c(字体大小)", "d(粗体)", "e(斜体)"]; + return ["n(换行)", "f(立绘)", "r(变色)", "i(图标)", "z(暂停打字)", "t(标题图标)", "b(对话框)", "c(字体大小)", "d(粗体)", "e(斜体)", "g(字体)"]; } return []; diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index f68ddf6e..c9f71c13 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -450,7 +450,7 @@ function omitedcheckUpdateFunction(event) { } } try { - var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\(i|c|d|e|z)/g, '\\\\$1'); + var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\(i|c|d|e|g|z)/g, '\\\\$1'); editor_blockly.setValue(code); } catch (error) { editor_blockly.setValue(String(error)); diff --git a/libs/ui.js b/libs/ui.js index e13c6fc9..0a33482a 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1036,11 +1036,11 @@ ui.prototype._getDrawableIconInfo = function (id) { return [image,icon]; } -ui.prototype._buildFont = function (fontSize, bold, italic) { +ui.prototype._buildFont = function (fontSize, bold, italic, font) { var textAttribute = core.status.textAttribute || core.initStatus.textAttribute, globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute; if (bold == null) bold = textAttribute.bold; - return (bold?"bold ":"") + (italic?"italic ":"") + (fontSize || textAttribute.textfont) + "px " + globalAttribute.font; + return (bold?"bold ":"") + (italic?"italic ":"") + (fontSize || textAttribute.textfont) + "px " + (font || globalAttribute.font); } ////// 绘制一段文字到某个画布上面 @@ -1048,11 +1048,12 @@ ui.prototype._buildFont = function (fontSize, bold, italic) { // content:要绘制的内容;转义字符目前只允许留 \n, \r[...], \i[...], \c[...], \d, \e // config:绘制配置项,目前暂时包含如下内容(均为可选) // left, top:起始点位置;maxWidth:单行最大宽度;color:默认颜色;align:左中右 -// fontSize:字体大小;lineHeight:行高;time:打字机间隔 +// fontSize:字体大小;lineHeight:行高;time:打字机间隔;font:字体类型 ui.prototype.drawTextContent = function (ctx, content, config) { ctx = core.getContextByName(ctx); // 设置默认配置项 var textAttribute = core.status.textAttribute || core.initStatus.textAttribute; + var globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute; config = core.clone(config || {}); config.left = config.left || 0; config.right = config.left + (config.maxWidth == null ? (ctx != null ? ctx.canvas.width : core.__PIXELS__) : config.maxWidth) @@ -1063,6 +1064,7 @@ ui.prototype.drawTextContent = function (ctx, content, config) { config.align = config.align || textAttribute.align || "left"; config.fontSize = config.fontSize || textAttribute.textfont; config.lineHeight = config.lineHeight || (config.fontSize * 1.3); + config.defaultFont = config.font = config.font || globalAttribute.font; config.time = config.time || 0; config.interval = config.interval == null ? (textAttribute.interval || 0) : config.interval; @@ -1080,7 +1082,7 @@ ui.prototype.drawTextContent = function (ctx, content, config) { // 创建一个新的临时画布 var tempCtx = core.createCanvas('__temp__', 0, 0, ctx==null?1:ctx.canvas.width, ctx==null?1:ctx.canvas.height, -1); tempCtx.textBaseline = 'top'; - tempCtx.font = this._buildFont(config.fontSize, config.bold, config.italic); + tempCtx.font = this._buildFont(config.fontSize, config.bold, config.italic, config.font); tempCtx.fillStyle = config.color; config = this._drawTextContent_draw(ctx, tempCtx, content, config); core.deleteCanvas('__temp__'); @@ -1157,21 +1159,17 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) if (ch == '\\') { var c = content.charAt(config.index); if (c == 'i') return this._drawTextContent_drawIcon(tempCtx, content, config); - if (c == 'c') return this._drawTextContent_changeFont(tempCtx, content, config); + if (c == 'c') return this._drawTextContent_changeFontSize(tempCtx, content, config); if (c == 'd' || c == 'e') { config.index++; if (c == 'd') config.bold = !config.bold; if (c == 'e') config.italic = !config.italic; - tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic); + tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); return true; } + if (c == 'g') return this._drawTextContent_changeFont(tempCtx, content, config); if (c == 'z') return this._drawTextContent_emptyChar(tempCtx, content, config); } - // \\e 斜体切换 - if (ch == '\\' && content.charAt(config.index)=='e') { - config.italic = !config.italic; - tempCtx.font = this._buildFont(config.fontSize, config.bold, config.italic); - } // 检查是不是自动换行 var charwidth = core.calWidth(tempCtx, ch) + config.interval; if (config.maxWidth != null && config.offsetX + charwidth > config.maxWidth) { @@ -1228,7 +1226,7 @@ ui.prototype._drawTextContent_changeColor = function (tempCtx, content, config) return this._drawTextContent_next(tempCtx, content, config); } -ui.prototype._drawTextContent_changeFont = function (tempCtx, content, config) { +ui.prototype._drawTextContent_changeFontSize = function (tempCtx, content, config) { config.index++; // 检查是不是 [] var index = config.index, index2; @@ -1240,7 +1238,21 @@ ui.prototype._drawTextContent_changeFont = function (tempCtx, content, config) { } else config.currfont = config.fontSize; config.lineMaxHeight = Math.max(config.lineMaxHeight, config.currfont + config.lineMargin); - tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic); + tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); + return this._drawTextContent_next(tempCtx, content, config); +} + +ui.prototype._drawTextContent_changeFont = function (tempCtx, content, config) { + config.index++; + // 检查是不是 [] + var index = config.index, index2; + if (content.charAt(index) == '[' && ((index2=content.indexOf(']', index))>=0)) { + var str = content.substring(index+1, index2); + if (str=="") config.font = config.defaultFont; + else config.font = str; + config.index = index2 + 1; + } else config.font = config.defaultFont; + tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); return this._drawTextContent_next(tempCtx, content, config); } @@ -1295,7 +1307,7 @@ ui.prototype.getTextContentHeight = function (content, config) { } ui.prototype._getRealContent = function (content) { - return content.replace(/(\r|\\(r|c|d|e|z))(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "占1"); + return content.replace(/(\r|\\(r|c|d|e|g|z))(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "占1"); } ////// 绘制一个对话框 ////// diff --git a/runtime.d.ts b/runtime.d.ts index acb2cf43..33c7b442 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -2169,7 +2169,7 @@ declare class ui { * @param content 要绘制的内容;转义字符不允许保留 \t, \b 和 \f * @param config 绘制配置项,目前暂时包含如下内容(均为可选) * left, top:起始点位置;maxWidth:单行最大宽度;color:默认颜色;align:左中右 - * fontSize:字体大小;lineHeight:行高;time:打字机间隔 + * fontSize:字体大小;lineHeight:行高;time:打字机间隔;font:默认字体名 * @returns 绘制信息 */ drawTextContent(ctx: string | CanvasRenderingContext2D, content: string, config: any): any