Modifying YEP - Core Engine

Hi there.

I am trying to figure out how to modify Victor Sant's Control Text so that it doesn't offset the alignment of the text when adding an escape code as a prefix.

It's a short code but I'm not sure what to change in it.

Control Text.jpg


Spoiler: Script
/*
* ==============================================================================
* ** Victor Engine MV - Control Text
* ------------------------------------------------------------------------------
* Version History:
* v 1.00 - 2015.12.29 > First release.
* ==============================================================================
*/

var Imported = Imported || {};
Imported['VE - Control Text'] = '1.00';

var VictorEngine = VictorEngine || {};
VictorEngine.ControlText = VictorEngine.ControlText || {};

(function() {

VictorEngine.ControlText.loadDatabase = DataManager.loadDatabase;
DataManager.loadDatabase = function() {
VictorEngine.ControlText.loadDatabase.call(this);
PluginManager.requiredPlugin.call(PluginManager, 'VE - Control Text', 'VE - Basic Module', '1.06');
};

VictorEngine.ControlText.requiredPlugin = PluginManager.requiredPlugin;
PluginManager.requiredPlugin = function(name, required, version) {
if (!VictorEngine.BasicModule) {
var msg = 'The plugin ' + name + ' requires the plugin ' + required;
msg += ' v' + version + ' or higher installed to work properly.';
msg += ' Go to http://victorenginescripts.wordpress.com/ to download the plugin.';
throw new Error(msg);
} else {
VictorEngine.ControlText.requiredPlugin.call(this, name, required, version)
};
};

})();

/*:
*------------------------------------------------------------------------------
* @plugindesc v1.00 - Use escape codes everywhere on windowns.
* @author Victor Sant
*
* @param Automatic Text Code
* @desc Enable escape codes for all text.
* true - ON false - OFF
* @Default true
*
* ------------------------------------------------------------------------------
* @Help
* ------------------------------------------------------------------------------
*
* Escape codes are codes such as \c[x], \n[x], \i[x] and others, that
* can be used on messages and some other windows.
*
* Text with codes are slower than the default draw text. Also, text with
* codes won't stretch to fit the text width. So you can set if all text will
* automatically use codes or if only specified text will do.
* If you set the plugin parameter 'Automatic Text Code' true, all text will
* use escape codes. If it's disabled, you will need to add the escape code
* \# at the start of any text you might want to use escape codes.
*
* ------------------------------------------------------------------------------
*/

(function() {

//=============================================================================
// Parameters
//=============================================================================

if (Imported['VE - Basic Module']) {
var parameters = VictorEngine.getPluginParameters();
VictorEngine.Parameters = VictorEngine.Parameters || {};
VictorEngine.Parameters.ControlText = {};
VictorEngine.Parameters.ControlText.AutoText = eval(parameters["Automatic Text Code"]);
};

//=============================================================================
// Window_Base
//=============================================================================

/* Overwritten function */
Window_Base.prototype.processNormalCharacter = function(textState) {
var c = textState.text[textState.index++];
var w = VictorEngine.ControlText.textWidth.call(this, c);
this.contents.drawText(c, textState.x, textState.y, w * 2, textState.height);
textState.x += w;
};

VictorEngine.ControlText.drawText = Window_Base.prototype.drawText;
Window_Base.prototype.drawText = function(text, x, y, maxWidth, align) {
if (text) var sign = String(text).match(/^\\#/);
if (VictorEngine.Parameters.ControlText.AutoText || (sign && sign[0].contains("\#"))) {
this.drawCodeText(String(text), x, y, maxWidth, align)
} else {
VictorEngine.ControlText.drawText.call(this, text, x, y, maxWidth, align);
}
};

VictorEngine.ControlText.convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
Window_Base.prototype.convertEscapeCharacters = function(text) {
text = VictorEngine.ControlText.convertEscapeCharacters.call(this, text);
text = VictorEngine.ControlText.convertEscapeCharacters.call(this, text);
text = VictorEngine.ControlText.convertEscapeCharacters.call(this, text);
text = text.replace(/\x1b\#/g, '');
return text;
};

VictorEngine.ControlText.textWidth = Window_Base.prototype.textWidth;
Window_Base.prototype.textWidth = function(text) {
if (text) var sign = String(text).match(/^\\#/);
if (VictorEngine.Parameters.ControlText.AutoText || (sign && sign[0].contains("\#"))) {
return this.getCodeX(String(text)).width
} else {
return VictorEngine.ControlText.textWidth.call(this, text);
}
};

Window_Base.prototype.drawCodeText = function(text, x, y, maxWidth, align) {
if (text) {
var x = this.getCodeX(text, x, y, maxWidth, align).x
var textState = { index: 0, x: x, y: y, left: x };
textState.text = this.convertEscapeCharacters(text);
textState.height = this.calcTextHeight(textState, false);
while (textState.index < textState.text.length) {
this.processCharacter(textState);
}
}
};

Window_Base.prototype.getCodeX = function(text, x, y, maxWidth, align) {
if (text) {
var textState = { index: 0, x: 0 };
textState.text = this.convertEscapeCharacters(text);
while (textState.index < textState.text.length) {
this.processCharacter(textState);
}
if (align === 'center') x += (maxWidth - textState.x) / 2;
if (align === 'right') x += (maxWidth - textState.x);
return {x: x, width: textState.x};
} else {
return {x: 0, width: 0};
}
};

})();

Would really appreciate it.

Also, the added Screenshot is to meant to focus on the "Skill Pool" that is being offset. I am using ARP_Command Icons to create icons for the commands, but as far other text I haven't found a script as versatile as VE's.

Thank you.
This doesn't look like alignment offset to me.
It's align: center mode.
EDIT: Nevermind, didn't rread the second half. 😀
This doesn't look like alignment offset to me.
It's align: center mode.

The alignment of commands is center which is using ARP_Command Icons. The problem is within the "Skill Pool" in Moogle_X's Skill Equip which is using an escape code using VE's Command Text. It has the same issue in other scenes. This was just an example I pulled. But it has a vertical alignment problem, maybe because I shrunk the font size. Sorry it wasn't clear with the screenshot. Since a lot is going on compared to the stock Scene_Skill
No, it's not because you shrunk the font size, it's because the engine takes the icon as a part of the text, so it measures line height by that icon instead of the text, since the icon height is greater than text height. But separating these would be rather tricky due to how the code is written.
Hmm... That might not be the only issue. I've tried using escape codes for colors and its doing the vertical offset still x.x I could post more SS if needed. I think something within the escape code is messing with the TextState. I tried a different Plugin with the same concept. It it still did that.
Elements.jpg

States.jpg
Here is another example within Yanfly's own stuff. Disregard Escape Codes for a moment, and check how the tables for Elements and States work differently. Is this what you were talking about splitting Icon and Text data? Because Without escape codes Elements and Extra Parameters (another page) don't typically account for Icons but since States within the default database usually have icons he coded the padding differently.

BUT, the difference is the "Polymorph" doesn't have an icon and yet it was able to be vertically aligned.
While Physical (using an escape code) doesn't align properly and all the none escape coded Elements also are aligned properly.

I'm reading Yanfly's code. But I just don't know where to start... unfortunately...

Also, With escape codes on or off, the elements and extra parameters are still offset.
As bonus SS, I'll include the weird alignment issue when I also just use a color escape code:
Ranks.jpg
Anyway, I created a Dummy Game to test YEP_Core Engine and Status Core and noticed that his core Engine does something really weird with the Font Size (28). When it is at Default it properly aligns text within the rectangles... however is I reduce that, that's when the y value for positioning for both Elements and Extra Parameters are getting skewed.

Since the Extra Params get a secondary font size option. As long as the default font size is 28, it is able to vertically align properly. But again the issue is when the Default Font size is reduced the vertical alignment is getting messed up. However base parameters and states regardless of Default Font size are able to stay aligned properly. There is a eval for alignment that is different for the other two pages versus the "general" & the states page.

I'm sifting through it to figure out what it could be...
Hello. I modified the title because after more fiddling and checking compatibility with other plugins.

I'm finding a ridiculous amount of issues with how YEP handles smaller fonts. It's also inconsistent. Where sometimes it would vertically align smaller fonts properly... other parts there is simply now padding added for vertical alignment.

Cases of these are found in his Message Core where Nameplates and Text are giving no padding. And his Status Menu Core where certain parameters are not being aligned properly.

Original thread: https://forums.rpgmakerweb.com/threads/modifying-yep-core-engine.90824/