We know menu text can fit the width of the window.
But is there a plugin to do that for dialogue message box?
I'm playing with custom fonts and localization recently, but sometimes the English lines become too long. It is a headache to edit them.
Edit* OH, I think I solved it. It is easier than I thought.
JavaScript:
Window_Base.prototype.measureEscapeCharacter = function(code, textState) {
switch (code) {
case 'C':
this.obtainEscapeParam(textState)
break;
case 'I':
this.obtainEscapeParam(textState);
textState.w+=Window_Base._iconWidth + 4;
break;
case '{':
this.makeFontBigger();
break;
case '}':
this.makeFontSmaller();
break;
}
};
Window_Base.prototype.measureNormalCharacter = function(textState) {
var c = textState.text[textState.index++];
var w = this.textWidth(c);
textState.w += w;
};
Window_Base.prototype.measureLineWidth = function(textState) {
var lf = false;
var fsz = this.contents.fontSize;
textState = Object.assign({},textState);
textState.w = 0;
while(textState.index<textState.text.length&&!lf){
switch (textState.text[textState.index]) {
case '\n':
lf=true;
break;
case '\f':
lf=true;
break;
case '\x1b':
this.measureEscapeCharacter(this.obtainEscapeCode(textState), textState);
break;
default:
this.measureNormalCharacter(textState);
break;
}
}
this.contents.fontSize = fsz;
return textState.w;
};
Window_Base.prototype.processNormalCharacter = function(textState) {
var lw = this.measureLineWidth(textState);
var lr = this.contents.width-this.textPadding()-textState.x;
var c = textState.text[textState.index++];
var w = this.textWidth(c) ;
if(lr<lw && lr>0){
w *= lr / lw;
}
this.contents.drawText(c, textState.x, textState.y, w, textState.height);
textState.x += w;
};