设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 83|回复: 0

[转载发布] Custom Text Styles v0.91

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    4 天前
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4593

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    23193
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28680

    灌水之王

    发表于 前天 17:54 | 显示全部楼层 |阅读模式
    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
    1. //=============================================================================
    2. // Custom_FontStyles.js
    3. //=============================================================================
    4. /*:
    5. * @target MZ
    6. * @plugindesc You can now customize your text
    7. * @author kopa
    8. * @help
    9. *
    10. * @param Text Options
    11. * @text _FONT OPTIONS
    12. *
    13. * @param fontColor
    14. * @desc Color of the font in hex or rbg.
    15. * @text Font Color
    16. * @type string
    17. * @default #ffffff
    18. *
    19. * @param outlineColor
    20. * @desc Color of the outline in hex or rbg.
    21. * @text Outline Color
    22. * @type string
    23. * @default rgba(0,0,0,1)
    24. *
    25. * @param outlineThickness
    26. * @desc Thickness of the outline.
    27. * @text Outline Thickness
    28. * @type number
    29. * @max 15
    30. * @min 1
    31. * @default 3
    32. *
    33. * @param fontItalic
    34. * @text Italic
    35. * @type boolean
    36. * @on true
    37. * @off false
    38. * @desc
    39. * @default false
    40. *
    41. * @param fontBold
    42. * @text Bold
    43. * @type boolean
    44. * @on true
    45. * @off false
    46. * @desc
    47. * @default false
    48. *
    49. * @param Shadow Options
    50. * @text _SHADOW OPTIONS
    51. *
    52. * @param useShadow
    53. * @text Use Shadow
    54. * @type boolean
    55. * @on true
    56. * @off false
    57. * @desc
    58. * @default false
    59. *
    60. * @param shadowX
    61. * @desc X position of the shadow relative to the text
    62. * @text Shadow X Position
    63. * @type number
    64. * @default 3
    65. *
    66. * @param shadowY
    67. * @desc Y position of the shadow relative to the text
    68. * @text Shadow Y Position
    69. * @type number
    70. * @default 3
    71. *
    72. * @param shadowOpacity
    73. * @desc Opacity of the Shadow (min:0, max:1)
    74. * @text Shadow Opacity
    75. * @type number
    76. * @default 0.40
    77. * @max 1
    78. * @min 0
    79. * @decimals 2
    80. *
    81. * @param menu
    82. * @text _MENU OPTIONS
    83. *
    84. * @param textAlign
    85. * @text Text Alignment
    86. * @desc Alignment of the text in menus
    87. * @type select
    88. * @default center
    89. * @option center
    90. * @option left
    91. * @option right
    92. *
    93. * @param dialog
    94. * @text _DIALOG OPTIONS
    95. *
    96. * @param leftPadding
    97. * @desc Message left padding
    98. * @text Left Padding
    99. * @type number
    100. * @default 3
    101. *
    102. * @param leftPaddingFace
    103. * @desc Message left padding when using faceset
    104. * @text Left Padding Face
    105. * @type number
    106. * @default 20
    107. *
    108. *
    109. * @help Custom_TextStyles.js
    110. *
    111. * This plugin draws text
    112. *
    113. *
    114. *-----------------------------------------------------------------------------
    115. * How to use this plugin
    116. *-----------------------------------------------------------------------------
    117. * Simply install to your plugins folder and turn it on in the Plugin Manager.
    118. * This plugin should almost certainly go at the top of the list;
    119. * we are changing how the base engine peforms a DrawText function.
    120. *
    121. *-----------------------------------------------------------------------------
    122. * About the license of this plugin (License)
    123. *-----------------------------------------------------------------------------
    124. * This plugin is released under the MIT License.
    125. *
    126. *-----------------------------------------------------------------------------
    127. * The released versions of this plugin (Change log)
    128. *-----------------------------------------------------------------------------
    129. *
    130. *
    131. */
    132. var CTS = CTS || {}; CTS.params  = CTS.params || {};
    133. (($_$) => {
    134.     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')));}
    135.     // Store/Set the parameters
    136.     $_$.par = getPluginParameters();
    137.     // Just set default in case none was specified in via plugin manager
    138.     $_$.par['Parameter Name'] = $_$.par['Parameter Name'] || 0;
    139.     console.log($_$.par['Parameter Name'])
    140. })(CTS.params);
    141. const leftpadding = parseFloat(CTS.params.par['leftPadding']);
    142. const leftpaddingface = parseFloat(CTS.params.par['leftPaddingFace']);
    143. const shadowposx = parseFloat(CTS.params.par['shadowX']);
    144. const shadowposy = parseFloat(CTS.params.par['shadowY']);
    145. const shadowopa = parseFloat(CTS.params.par['shadowOpacity']);
    146. const shadowoutlineopa = shadowopa - 0.1;
    147. Window_Base.prototype.drawText = function(text, x, y, maxWidth, align) {
    148.     this.contents.drawText(text, x, y, maxWidth, this.lineHeight(), CTS.params.par['textAlign']);
    149. };
    150. Window_Base.prototype.changeTextColor = function(color) {
    151.     this.contents.textColor = CTS.params.par['fontColor'];
    152. };
    153. Window_Base.prototype.changeOutlineColor = function(color) {
    154.     this.contents.outlineColor = CTS.params.par['outlineColor'];
    155. };
    156. Window_Message.prototype.newLineX = function(textState) {
    157.     const faceExists = $gameMessage.faceName() !== "";
    158.     const faceWidth = ImageManager.faceWidth;
    159.     const spacing = leftpaddingface;
    160.     const margin = faceExists ? faceWidth + spacing : leftpadding;
    161.     return textState.rtl ? this.innerWidth - margin : margin;
    162. };
    163. Bitmap.prototype.initialize = function(width, height) {
    164.     this._canvas = null;
    165.     this._context = null;
    166.     this._baseTexture = null;
    167.     this._image = null;
    168.     this._url = "";
    169.     this._paintOpacity = 255;
    170.     this._smooth = true;
    171.     this._loadListeners = [];
    172.     // "none", "loading", "loaded", or "error"
    173.     this._loadingState = "none";
    174.     if (width > 0 && height > 0) {
    175.         this._createCanvas(width, height);
    176.     }
    177.     /**
    178.      * The face name of the font.
    179.      *
    180.      * @type string
    181.      */
    182.     this.fontFace = "sans-serif";
    183.     /**
    184.      * The size of the font in pixels.
    185.      *
    186.      * @type number
    187.      */
    188.     this.fontSize = 16;
    189.     /**
    190.      * Whether the font is bold.
    191.      *
    192.      * @type boolean
    193.      */
    194.     this.fontBold = CTS.params.par['fontBold'];
    195.     /**
    196.      * Whether the font is italic.
    197.      *
    198.      * @type boolean
    199.      */
    200.     this.fontItalic = CTS.params.par['fontItalic'];
    201.     /**
    202.      * The color of the text in CSS format.
    203.      *
    204.      * @type string
    205.      */
    206.     this.textColor = "#ffffff";
    207.     /**
    208.      * The color of the outline of the text in CSS format.
    209.      *
    210.      * @type string
    211.      */
    212.     this.outlineColor = "rgba(0, 0, 0, 0.5)";
    213.     /**
    214.      * The width of the outline of the text.
    215.      *
    216.      * @type number
    217.      */
    218.     this.outlineWidth = CTS.params.par['outlineThickness'];
    219. };
    220. Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
    221.   
    222.     if (CTS.params.par['useShadow'] == "true") {
    223.   
    224.     // [Note] Different browser makes different rendering with
    225.     //   textBaseline == 'top'. So we use 'alphabetic' here.
    226.     const context = this.context;
    227.     const alpha = context.globalAlpha;
    228.     maxWidth = maxWidth || 0xffffffff;
    229.     let tx = x;
    230.     let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
    231.     if (align === "center") {
    232.         tx += maxWidth / 2;
    233.     }
    234.     if (align === "right") {
    235.         tx += maxWidth;
    236.     }
    237.     context.save();
    238.     context.font = this._makeFontNameText();
    239.     context.textAlign = align;
    240.     context.textBaseline = "alphabetic";
    241.     context.globalAlpha = 1;
    242.     this._drawTextShadowOutline(text, tx + shadowposx, ty + shadowposy, maxWidth);
    243.     this._drawTextOutline(text, tx, ty, maxWidth);
    244.     context.globalAlpha = alpha;
    245.     this._drawTextShadow(text, tx + shadowposx, ty + shadowposy, maxWidth);
    246.     this._drawTextBody(text, tx, ty, maxWidth);
    247.     context.restore();
    248.     this._baseTexture.update();
    249.     }
    250.     else {
    251.        // [Note] Different browser makes different rendering with
    252.     //   textBaseline == 'top'. So we use 'alphabetic' here.
    253.     const context = this.context;
    254.     const alpha = context.globalAlpha;
    255.     maxWidth = maxWidth || 0xffffffff;
    256.     let tx = x;
    257.     let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
    258.     if (align === "center") {
    259.         tx += maxWidth / 2;
    260.     }
    261.     if (align === "right") {
    262.         tx += maxWidth;
    263.     }
    264.     context.save();
    265.     context.font = this._makeFontNameText();
    266.     context.textAlign = align;
    267.     context.textBaseline = "alphabetic";
    268.     context.globalAlpha = 1;
    269.     this._drawTextOutline(text, tx, ty, maxWidth);
    270.     context.globalAlpha = alpha;
    271.     this._drawTextBody(text, tx, ty, maxWidth);
    272.     context.restore();
    273.     this._baseTexture.update();  
    274.     }
    275. };
    276. Bitmap.prototype._drawTextShadow = function(text, tx, ty, maxWidth) {
    277.     const context = this.context;
    278.     context.fillStyle = "rgba(0, 0, 0, "+shadowopa+")";
    279.     context.fillText(text, tx, ty, maxWidth);
    280. };
    281. Bitmap.prototype._drawTextShadowOutline = function(text, tx, ty, maxWidth) {
    282.     const context = this.context;
    283.     context.strokeStyle = "rgba(0, 0, 0, "+shadowoutlineopa+")";
    284.     context.lineWidth = 3;
    285.     context.lineJoin = "round";
    286.     context.strokeText(text, tx, ty, maxWidth);
    287. };
    复制代码
    Let me know if theres any bugs.

    No credits needed.


    本贴来自国际rpgmaker官方论坛作者:kopa处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/custom-text-styles-v0-91.142923/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-16 14:19 , Processed in 0.064033 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表