累计送礼: 0 个 累计收礼: 1 个 TA的每日心情 开心 4 天前
签到天数: 209 天
连续签到: 2 天
[LV.7]常住居民III
管理员
VIP
7
卡币
23195
OK点
16
推广点
0
同能卷
50
积分 28683
Custom_TextStyles.js v0.91
Some basic font style customizing.
FEATURES
-----------------
* Font color
* Font outline color / thickness
* Font shadow
* Font bold /italic
* Message box left padding
HOW TO INSTALL
-----------------
* Copy the code in a text file "Custom_FontStyles.js" in /js/plugins
* Add it and turn it ON in your plugins database
* Set parameters as you like
Spoiler: SCRIPT
//============================================================================= // Custom_FontStyles.js //============================================================================= /*: * @target MZ * @plugindesc You can now customize your text * @author kopa * @help * * @param Text Options * @text _FONT OPTIONS * * @param fontColor * @desc Color of the font in hex or rbg. * @text Font Color * @type string * @default #ffffff * * @param outlineColor * @desc Color of the outline in hex or rbg. * @text Outline Color * @type string * @default rgba(0,0,0,1) * * @param outlineThickness * @desc Thickness of the outline. * @text Outline Thickness * @type number * @max 15 * @min 1 * @default 3 * * @param fontItalic * @text Italic * @type boolean * @on true * @off false * @desc * @default false * * @param fontBold * @text Bold * @type boolean * @on true * @off false * @desc * @default false * * @param Shadow Options * @text _SHADOW OPTIONS * * @param useShadow * @text Use Shadow * @type boolean * @on true * @off false * @desc * @default false * * @param shadowX * @desc X position of the shadow relative to the text * @text Shadow X Position * @type number * @default 3 * * @param shadowY * @desc Y position of the shadow relative to the text * @text Shadow Y Position * @type number * @default 3 * * @param shadowOpacity * @desc Opacity of the Shadow (min:0, max:1) * @text Shadow Opacity * @type number * @default 0.40 * @max 1 * @min 0 * @decimals 2 * * @param menu * @text _MENU OPTIONS * * @param textAlign * @text Text Alignment * @desc Alignment of the text in menus * @type select * @default center * @option center * @option left * @option right * * @param dialog * @text _DIALOG OPTIONS * * @param leftPadding * @desc Message left padding * @text Left Padding * @type number * @default 3 * * @param leftPaddingFace * @desc Message left padding when using faceset * @text Left Padding Face * @type number * @default 20 * * * @help Custom_TextStyles.js * * This plugin draws text * * *----------------------------------------------------------------------------- * How to use this plugin *----------------------------------------------------------------------------- * Simply install to your plugins folder and turn it on in the Plugin Manager. * This plugin should almost certainly go at the top of the list; * we are changing how the base engine peforms a DrawText function. * *----------------------------------------------------------------------------- * About the license of this plugin (License) *----------------------------------------------------------------------------- * This plugin is released under the MIT License. * *----------------------------------------------------------------------------- * The released versions of this plugin (Change log) *----------------------------------------------------------------------------- * * */ var CTS = CTS || {}; CTS.params = CTS.params || {}; (($_$) => { function getPluginParameters() {var a = document.currentScript || (function() { var b = document.getElementsByTagName('script'); return b[b.length - 1]; })(); return PluginManager.parameters(a.src.substring((a.src.lastIndexOf('/') + 1), a.src.indexOf('.js')));} // Store/Set the parameters $_$.par = getPluginParameters(); // Just set default in case none was specified in via plugin manager $_$.par['Parameter Name'] = $_$.par['Parameter Name'] || 0; console.log($_$.par['Parameter Name']) })(CTS.params); const leftpadding = parseFloat(CTS.params.par['leftPadding']); const leftpaddingface = parseFloat(CTS.params.par['leftPaddingFace']); const shadowposx = parseFloat(CTS.params.par['shadowX']); const shadowposy = parseFloat(CTS.params.par['shadowY']); const shadowopa = parseFloat(CTS.params.par['shadowOpacity']); const shadowoutlineopa = shadowopa - 0.1; Window_Base.prototype.drawText = function(text, x, y, maxWidth, align) { this.contents.drawText(text, x, y, maxWidth, this.lineHeight(), CTS.params.par['textAlign']); }; Window_Base.prototype.changeTextColor = function(color) { this.contents.textColor = CTS.params.par['fontColor']; }; Window_Base.prototype.changeOutlineColor = function(color) { this.contents.outlineColor = CTS.params.par['outlineColor']; }; Window_Message.prototype.newLineX = function(textState) { const faceExists = $gameMessage.faceName() !== ""; const faceWidth = ImageManager.faceWidth; const spacing = leftpaddingface; const margin = faceExists ? faceWidth + spacing : leftpadding; return textState.rtl ? this.innerWidth - margin : margin; }; Bitmap.prototype.initialize = function(width, height) { this._canvas = null; this._context = null; this._baseTexture = null; this._image = null; this._url = ""; this._paintOpacity = 255; this._smooth = true; this._loadListeners = []; // "none", "loading", "loaded", or "error" this._loadingState = "none"; if (width > 0 && height > 0) { this._createCanvas(width, height); } /** * The face name of the font. * * @type string */ this.fontFace = "sans-serif"; /** * The size of the font in pixels. * * @type number */ this.fontSize = 16; /** * Whether the font is bold. * * @type boolean */ this.fontBold = CTS.params.par['fontBold']; /** * Whether the font is italic. * * @type boolean */ this.fontItalic = CTS.params.par['fontItalic']; /** * The color of the text in CSS format. * * @type string */ this.textColor = "#ffffff"; /** * The color of the outline of the text in CSS format. * * @type string */ this.outlineColor = "rgba(0, 0, 0, 0.5)"; /** * The width of the outline of the text. * * @type number */ this.outlineWidth = CTS.params.par['outlineThickness']; }; Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) { if (CTS.params.par['useShadow'] == "true") { // [Note] Different browser makes different rendering with // textBaseline == 'top'. So we use 'alphabetic' here. const context = this.context; const alpha = context.globalAlpha; maxWidth = maxWidth || 0xffffffff; let tx = x; let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35); if (align === "center") { tx += maxWidth / 2; } if (align === "right") { tx += maxWidth; } context.save(); context.font = this._makeFontNameText(); context.textAlign = align; context.textBaseline = "alphabetic"; context.globalAlpha = 1; this._drawTextShadowOutline(text, tx + shadowposx, ty + shadowposy, maxWidth); this._drawTextOutline(text, tx, ty, maxWidth); context.globalAlpha = alpha; this._drawTextShadow(text, tx + shadowposx, ty + shadowposy, maxWidth); this._drawTextBody(text, tx, ty, maxWidth); context.restore(); this._baseTexture.update(); } else { // [Note] Different browser makes different rendering with // textBaseline == 'top'. So we use 'alphabetic' here. const context = this.context; const alpha = context.globalAlpha; maxWidth = maxWidth || 0xffffffff; let tx = x; let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35); if (align === "center") { tx += maxWidth / 2; } if (align === "right") { tx += maxWidth; } context.save(); context.font = this._makeFontNameText(); context.textAlign = align; context.textBaseline = "alphabetic"; context.globalAlpha = 1; this._drawTextOutline(text, tx, ty, maxWidth); context.globalAlpha = alpha; this._drawTextBody(text, tx, ty, maxWidth); context.restore(); this._baseTexture.update(); } }; Bitmap.prototype._drawTextShadow = function(text, tx, ty, maxWidth) { const context = this.context; context.fillStyle = "rgba(0, 0, 0, "+shadowopa+")"; context.fillText(text, tx, ty, maxWidth); }; Bitmap.prototype._drawTextShadowOutline = function(text, tx, ty, maxWidth) { const context = this.context; context.strokeStyle = "rgba(0, 0, 0, "+shadowoutlineopa+")"; context.lineWidth = 3; context.lineJoin = "round"; context.strokeText(text, tx, ty, maxWidth); }; 复制代码 Let me know if theres any bugs.
No credits needed.
本贴来自国际rpgmaker官方论坛作者:kopa处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/custom-text-styles-v0-91.142923/
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x