The RPG Maker Resource Kit

RMRK RPG Maker Creation => MV => MV Scripts Database => Topic started by: modern algebra on October 31, 2015, 03:51:22 PM

Title: [MV] Global Text Codes 1.0.1
Post by: modern algebra on October 31, 2015, 03:51:22 PM
Global Text Codes
Version: 1.0.1
Author: modern algebra
Date: 31 October 2015

Version History



Description


Use basic escape codes in any text on any window. Be aware that drawing text with escape codes is slow, so it is possible that some computers will experience lag if this is used too much in any one frame.

Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fs28.postimg.org%2Fn9qy1o1fh%2FGlobal_Text_Codes.png&hash=4b6ab8f3199ae5bb9bc71bbcf3885eb80e8a944b) (http://postimg.org/image/u07fb3ol5/)
Example showing \i[n] codes used for the options, \c[n] codes used on the names, and \{ and \} used for the class names.

Features


Instructions

Save the script in your plugins folder and import it through the Plugin Manager.

This plugin allows you to use basic escape codes in any text field, so long as you include \* in the text field. By default, the options are limited to \c[n]; \i[n]; \v[x]; \n[x]; \pn[x]; \{; \}; and \G. They may be expanded by other message scripts which add escape codes, but not likely by all such escape codes as some would be necessarily restricted to the message window.

When using codes like \c[n] and others that change the font settings, remember that you should set it back to normal afterwards. In other words, write "\*\c[3]Text\c[0]" and not just "\*\c[3]Text"

Plugin


You can download the .js file from Pastebin: http://pastebin.com/jXGbUgDL

Code: [Select]
//=============================================================================
//  GlobalTextCodes.js
//=============================================================================
//  Version: 1.0.2
//  Date: 21 November 2015
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*:
 * @plugindesc Use basic escape codes in any window for any text
 * @author Modern Algebra (rmrk.net)
 * @help This plugin allows you to use basic escape codes in any text field, so long
 * as you include \* in the text field. By default, the options are limited to
 * \c[n]; \i[n]; \v[x]; \n[x]; \pn[x]; \{; \}; and \G. They may be expanded by
 * other message scripts which add escape codes, but not likely by all such
 * escape codes as some would be necessarily restricted to the message window.
 *
 * When using codes like \c[n] and others that change the font settings,
 * remember that you should set it back to normal afterwards. In other words,
 * write "\*\c[3]Text\c[0]" and not just "\*\c[3]Text"
 */
//=============================================================================

var Imported = Imported || {};
Imported.MA_GlobalTextCodes = true;

var ModernAlgebra = ModernAlgebra || {};
ModernAlgebra.GTC = {};

(function() {
   
// Draw Text - Check for \* and drawTextEx if it is present
ModernAlgebra.GTC.window_Base_drawText =
            Window_Base.prototype.drawText;
Window_Base.prototype.drawText = function() {
var text = arguments[0];
if ((typeof text === 'string' || text instanceof String) && text.match(/\\\*/i)) {
var tx = this.magtcCalculateAlignmentExX.apply(this, arguments);
// Draw Special Text if the \* code is present
this.drawTextEx(text, tx, arguments[2]);
} else {
// Draw Normal Text otherwise
    ModernAlgebra.GTC.window_Base_drawText.apply(this, arguments);
}
};

// Convert Escape Characters - delete \* codes
    ModernAlgebra.GTC.window_Base_convertEscapeCharacters =
            Window_Base.prototype.convertEscapeCharacters;
    Window_Base.prototype.convertEscapeCharacters = function() {
        var text = ModernAlgebra.GTC.window_Base_convertEscapeCharacters.apply(this, arguments)
        text = text.replace(/\x1b\*/, ''); // Remove \* Codes
        return text;
    };

// Calculate Alignment Ex X - Get display X when using different alignment
Window_Base.prototype.magtcCalculateAlignmentExX = function(text, tx, y, mw, align) {
if (align === 'center' || align === 'right') {
// Calculate line length and adjust x based on alignment
var tw = this.magtcMeasureTextEx(text);
var blankSpace = mw - tw;
if (align === 'center') {
blankSpace = blankSpace / 2;
}
tx = tx + blankSpace;
}
return tx
};

// Measure text that has escape codes
Window_Base.prototype.magtcMeasureTextEx = function(text) {
// Create temporary bitmap for testing to accomodate other scripts with unknown codes
this._magtcAlignmentTesting = true;
var realContents = this.contents;
this.contents = new Bitmap(24, 24);
this.resetFontSettings();
// Draw TextEx on the temporary Bitmap
var firstLine = text.match(/^\n?(.+)\n?/)[0] || '';
var tw = this.drawTextEx(firstLine, 0, 0);
// Restore normal contents
this._magtcAlignmentTesting = null;
this.contents = realContents;
return tw
}

})();

Credit



Support


Post in this thread if you have any comments or questions. It is perfectly fine to post here even if this topic has not been posted in for a very long time.

Please do not message me privately, as any concerns you have are likely shared by others and they will benefit from our correspondence being public. Additionally, I am often absent, and posting publicly will allow other members to assist you when I am unable to do so quickly.

Terms of Use


You are welcome to use this script in any project of yours, whether it is commercial or non-commercial. There is no need to credit me, and please feel free to modify the plugin in whatever ways suit your project.

Basically, my plugin is your plugin, but please do not re-post this plugin or any modified version of it on another forum or website.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: yuyu! on October 31, 2015, 07:07:30 PM
Definitely one of my favorite scripts to use in the past makers. ;___;

Thanks for writing it, modern! ^_^
Title: Re: [MV] Global Text Codes 1.0.1
Post by: Wiimeiser on October 31, 2015, 10:45:53 PM
Help text is missing.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: modern algebra on October 31, 2015, 10:53:24 PM
Do you mean the text that shows up in the Plugin Manager when you press the help button? Or do you mean the text that would show up in a help window in-game (like the description of an item)? Or do you mean something else.

In any case, I have been unable to detect an error when I've tested the script, so please let me know some more details so that I can hopefully find and fix the problem.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: &&&&&&&&&&&&& on October 31, 2015, 11:20:35 PM
Loved the VXA version.
Kicks the UI up another notch.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: Wiimeiser on November 02, 2015, 03:31:49 AM
The Plugin Manager help text and description is what's blank.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: modern algebra on November 02, 2015, 03:57:59 AM
OK, it has to do with how Pastebin is naming the file when you download it from there. I will change the name to avoid that problem in the future, but you can just rename the .js file to "GlobalTextCodes.js" and everything should come back.
Title: Re: [MV] Global Text Codes 1.0.1
Post by: Nessiah on November 19, 2015, 12:09:43 AM
Aaa MA is back! I can't wait for your animated parallax and pictures <3
Title: Re: [MV] Global Text Codes 1.0.1
Post by: estriole on November 23, 2015, 11:04:13 AM
first of all... thanks for this amazing plugin...
some sugestion though...
can you make this plugin doesn't have to add \*  to activate it...?
i try modifying your plugin
Code: [Select]
ModernAlgebra.GTC.window_Base_drawText =
            Window_Base.prototype.drawText;
Window_Base.prototype.drawText = function() {
               // if it's window message... then call old method
if (this.constructor == Window_Message)
return ModernAlgebra.GTC.window_Base_drawText.apply(this, arguments);
                           
var text = arguments[0];
if ((typeof text === 'string' || text instanceof String)) {
var tx = this.magtcCalculateAlignmentExX.apply(this, arguments);
// Draw Special Text if the \* code is present
this.drawTextEx(text, tx, arguments[2]);
} else {
// Draw Normal Text otherwise
    ModernAlgebra.GTC.window_Base_drawText.apply(this, arguments);
}
};
removing the match inside the if. and it work. can i request you to implement this changes to your script?
or there's a problem about the edit i done which i don't know?
and any particular reason why we should add \* if we want to use escape code

since i have autocolor plugins which will auto convert certain text to \c[x]text\c[0]
so by needing to use \* it will require to modify all my database while if not... this plugin will become plug and play with my plugin :D.

maybe if you still want to use \* at least plugin parameter to switch from requiring \* and not requiring \*
Title: Re: [MV] Global Text Codes 1.0.1
Post by: estriole on November 27, 2015, 09:29:04 AM
ignore my post above...
apparently it caused lag when using it with yanfly battle engine core's visual selection.
so using \* to only draw what needed to be colored is fine approach.