MV Yanfly Message Core Name Box

Hello! I want to make sure the texts on the name box is always centered, so whatever length the name is, it would adapt and center itself to the max length of the name box.

I can move the namebox to center, and add some padding to make the texts relatively centered, but it really depends on how long the name is. Sometimes it unaligns itself and it just look weird.
I attached the plugin parameter + how they look like in game.
You can also see the box I want them to be in.
How are you making those?

The text is centered in the name box, which automatically resizes itself to it - that's the reddish and gray.

The problem is you have this other thing on the screen which appears to be a piece of static artwork, the tan and white.
my guess you can try is open the plugin to line 1120,

change:
JavaScript:
this.drawTextEx(this._text, padding, 0, this.contents.width);

// to

this.drawTextEx(this._text, padding, 0, this.contents.width, "center");

I dont have much time to check, or if its correct, but that if its correct, it should
align in the center of the width.
my guess you can try is open the plugin to line 1120
You don't need to change the plugin - it automatically resizes the name box to keep the name centered.

1698058698895.png

1698058708888.png

1698058721988.png


The problem is whatever artwork the OP is displaying underneath.
drawTextEx doesn't accept an alignment by default, but it does return the resultant width of the text it has drawn, and YEP Message Core conveniently defines a textWidthEx method to get that width.

You could try something like this (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Extends YEP_MessageCore: fixed-width name box with centred text.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/162298/
 * @base YEP_MessageCore
 * @orderAfter YEP_MessageCore
 * @help Free to use and/or modify for any project, no credit required.
 * Should be loaded after YEP_MessageCore.
 */

// Requirement check.
;if (!Imported.YEP_MessageCore)
  throw new Error("This plugin must be loaded after YEP_MessageCore.");

// Override - fixed-width name box.
Window_NameBox.prototype.windowWidth = function() {
  return 200;  // whatever you want the width to be (px)
};

// Patch - centre name in box.
void (function(alias) {
"use strict";
  Window_NameBox.prototype.refresh = function() {
    // refresh as usual
    alias.apply(this, arguments);
    // get alignment offset (centre)
    var dx  = Math.floor((this.width - this.textWidthEx(this._text)) / 2);
    // get default padding
    var pad = eval(Yanfly.Param.MSGNameBoxPadding) / 2;
    // redraw
    this.contents.clear();
    this.resetFontSettings();
    this.changeTextColor(this.textColor(Yanfly.Param.MSGNameBoxColor));
    this.drawTextEx(this._text, pad + dx, 0);
  };
})(Window_NameBox.prototype.refresh);
How are you making those?

The text is centered in the name box, which automatically resizes itself to it - that's the reddish and gray.

The problem is you have this other thing on the screen which appears to be a piece of static artwork, the tan and white.
Hello! Sorry for the late reply, yes they are images using Galv's Message Background.
You were right about the image size that I was using, I'm going to adjust it now. Thanks!

drawTextEx doesn't accept an alignment by default, but it does return the resultant width of the text it has drawn, and YEP Message Core conveniently defines a textWidthEx method to get that width.

You could try something like this (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Extends YEP_MessageCore: fixed-width name box with centred text.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/162298/
 * @base YEP_MessageCore
 * @orderAfter YEP_MessageCore
 * @help Free to use and/or modify for any project, no credit required.
 * Should be loaded after YEP_MessageCore.
 */

// Requirement check.
;if (!Imported.YEP_MessageCore)
  throw new Error("This plugin must be loaded after YEP_MessageCore.");

// Override - fixed-width name box.
Window_NameBox.prototype.windowWidth = function() {
  return 200;  // whatever you want the width to be (px)
};

// Patch - centre name in box.
void (function(alias) {
"use strict";
  Window_NameBox.prototype.refresh = function() {
    // refresh as usual
    alias.apply(this, arguments);
    // get alignment offset (centre)
    var dx  = Math.floor((this.width - this.textWidthEx(this._text)) / 2);
    // get default padding
    var pad = eval(Yanfly.Param.MSGNameBoxPadding) / 2;
    // redraw
    this.contents.clear();
    this.resetFontSettings();
    this.changeTextColor(this.textColor(Yanfly.Param.MSGNameBoxColor));
    this.drawTextEx(this._text, pad + dx, 0);
  };
})(Window_NameBox.prototype.refresh);

It works amazingly to what I needed. Thank you very much!

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-message-core-name-box.162298/