Global Text Codes
Version: 1.0.1
Author: modern algebra
Date: 31 October 2015
Version History
- <Version 1.0.2> 2015-11-21 - Made overwritten functions publicly accessible
- <Version 1.0.1> 2015-10-31 - Fixed an error that had been introduced by last-minute adjustments
- <Version 1.0.0> 2015-10-31 - Original Release
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.
ScreenshotsExample showing \i[n] codes used for the options, \c[n] codes used on the names, and \{ and \} used for the class names.
Features - Can use some escape codes anywhere
- Using codes will not disrupt alignment
- Should be compatible with most escape codes added by message scripts
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//=============================================================================
// 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.