I wrote up a small Plugin that will center the Show Choice text, taking into account any escape characters you have.
Spoiler: Example Screenshot
You can download it from
here, or copy-paste it into your own file from below:
Spoiler: Plugin Code
Code:
/*:
* @plugindesc Centers text used in Show Choice event commands
* @author Zevia
*
* @help Causes all text drawn using the Show Choice command to be centered.
* This plugin is likely not compatible with other plugins that modify the
* drawItem function of Window_ChoiceList. You can try placing this Plugin
* above other Plugins that modify it for compatibility, but otherwise,
* it will require a compatibility fix / enhancement.
*/
(function(module) {
'use strict';
module.Zevia = module.Zevia || {};
var CenterChoiceText = module.Zevia.CenterChoiceText = {};
CenterChoiceText.drawItem = Window_ChoiceList.prototype.drawItem;
Window_ChoiceList.prototype.drawItem = function(index) {
var text = this.commandName(index);
this.drawTextEx(
text,
((this.width - this.textWidthEx(text)) / 2) - this.standardPadding(),
this.itemRectForText(index).y
);
};
})(window);
Since this is Learning JavaScript, what I did is modify the Window_ChoiceList.prototype.drawItem function, which is what draws the text for each choice in a Show Choice Window. That function normally figures out the x and y coordinates, as well as the width of the "text rectangle," using the itemRectForText method that's available on everything that extends Window_Selectable.
Instead of using the x position that the itemRectForText returns (which is typically just however much padding you have set on the window), a new x position is determined by taking the width of the window, subtracting the width of the text (once escape characters have been processed), then dividing that by 2. Since the window's width typically doesn't include the padding, there's an additional step of subtracting the window's padding.
Since I'm directly changing the logic of the drawItem function for Window_ChoiceList, the Plugin is not designed to be compatible with other Plugins that might modify the same function, so you'll need compatibility fixes for others - though you might get it to work by simply placing it first in your list of Plugins, if other Plugins
have been designed to be compatible.