Centering Choice Text

nathanlink169

Game Dev by Career, no idea what I'm doing
Veteran
Joined
Aug 15, 2013
Messages
52
Reaction score
19
First Language
English
Primarily Uses
RMMV
Hi all,

The goal that I'm looking to achieve is to center the text inside of the choice menu. I know that you can center the choice menu itself (and I have), but I'm more looking to center the choices themselves. The reason why is because I have extended the minimum window width.

On line 1415 of rpg_windows.js, there is the Window_Command.prototype.itemTextAlign method. Changing that will change some of the text in the game (i.e. the main menu), but not a basic choice menu, from what I can see.
 

Attachments

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,314
Reaction score
315
First Language
German
Primarily Uses
RMMV
Interesting question, sadly i dont know the answer and assume you would need some kind of Text Message Plugin.
A workaround would be to center it manualy by inserting "Empty Spaces" infront of the Questions with space Bar Button.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,399
Reaction score
880
First Language
EN
Primarily Uses
RMMV
It's tricky because the choice window uses drawTextEx so it can process escape codes like \C[x], \{, etc. I.e. the text effectively needs to be "written out" an extra time to find out how wide it is.

I found a plugin (forum post, github) called RS_MessageAlign (requires Yanfly's Message Core), which lets you align the text in Show Text commands. Not sure if it affects Show Choices as well, and if not how easy it'd be to make it do so, but it's a step in that direction~ :kaophew:
 

nathanlink169

Game Dev by Career, no idea what I'm doing
Veteran
Joined
Aug 15, 2013
Messages
52
Reaction score
19
First Language
English
Primarily Uses
RMMV
Interesting question, sadly i dont know the answer and assume you would need some kind of Text Message Plugin.
A workaround would be to center it manualy by inserting "Empty Spaces" infront of the Questions with space Bar Button.
I know it'll take a plugin, hence why I'm asking in the Javascript boards :wink:

It's tricky because the choice window uses drawTextEx so it can process escape codes like \C[x], \{, etc. I.e. the text effectively needs to be "written out" an extra time to find out how wide it is.

I found a plugin (forum post, github) called RS_MessageAlign (requires Yanfly's Message Core), which lets you align the text in Show Text commands. Not sure if it affects Show Choices as well, and if not how easy it'd be to make it do so, but it's a step in that direction~ :kaophew:
Interesting! I'll take a look and see if I can de-construct that to work with the choice menus as well. I'll let you know what I find!
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
622
Reaction score
329
First Language
English
Primarily Uses
RMMV
I wrote up a small Plugin that will center the Show Choice text, taking into account any escape characters you have.


You can download it from here, or copy-paste it into your own file from below:
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.
 

nathanlink169

Game Dev by Career, no idea what I'm doing
Veteran
Joined
Aug 15, 2013
Messages
52
Reaction score
19
First Language
English
Primarily Uses
RMMV
I wrote up a small Plugin that will center the Show Choice text, taking into account any escape characters you have.


You can download it from here, or copy-paste it into your own file from below:
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.
I’ll take a look at this, thank you so much for your help!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Setup a system to cull enemies that are too far from the player to matter, and to spawn new ones just outside of view. Take that lag! :LZSexcite:
That trope is alive more than ever, not so much elemental Crystal's but gathering magical objects or doing "task" to unlock this oddly specific thing is everywhere, I saw it saw it in the IT 2 remake, avengers and every season of supernatural
It's raining...in winter :")
I was stunned-STUNNED-to find that I have been working on my current project since November. It feels like so much less time than that.
Stream will be live shortly with some art! Going to do a recolor, then start on a new monster! Feel free to drop by!

Forum statistics

Threads
93,712
Messages
914,864
Members
123,316
Latest member
Ceoxy-
Top