How do I draw a text in costum menu with color change and new line?

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
Hello fellow RPG-Makers,

I have a costum menu and want to display item descriptions.
The drawText method will not suffice, because I need new lines and changing of textcolor.
Is there an easier way for me to display a costum text, than writing my own text interpreter code?

For example:

Item description in RPG Maker:

"This is a really cool [changeColor] item [\changeColor]. \n \n Additional information about this item."


Item description in-game:

"This is a really cool item.

Additional information about this item."

Am I missing a function, the game already uses for such tasks? I know you can change colors in the message windows,
but you can't create new lines. Am I going to have to create my own method to draw costum text like this in my costum
menu?

As always,
thank you in advance for your advice!

Kind regards,

Lanzy
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,194
Reaction score
724
First Language
Dutch
Primarily Uses
RMMV
you can use my TF function for it, but if you want a much nice one, you can use
TSR_TextColorAddon which extends it much wider and better than the one I have.

you can even do menu, skills, items, message, etc :)
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
you can use my TF function for it, but if you want a much nice one, you can use
TSR_TextColorAddon which extends it much wider and better than the one I have.

you can even do menu, skills, items, message, etc :)
This will save me so much time. Thank you kindly sir!

Now I only need a solution for the new line problem within the text.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
488
Reaction score
215
First Language
English
Primarily Uses
RMMV
I think you probably want the drawTextEx function, rather than drawText. That interprets all the text codes in your text.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
I think you probably want the drawTextEx function, rather than drawText. That interprets all the text codes in your text.
True, that would also be a solution for the color problem. But unfortunately not for the new line problem.
At least, new line is not an option in message box text codes.

//Edit: Ok nevermind, I guess \n is included as a new line command in textEx. Thanks!
//Edit2: new line code does NOT work, only when entering it in the developer console while the game is playing. But not ingame unfortunately.
 
Last edited:

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,194
Reaction score
724
First Language
Dutch
Primarily Uses
RMMV
just tested, it works without a plugin, you can just use \c[12] text here \c[0] (enter)
for a new \c[14]line here\c[0].

which is possible by default. no \n is need or <br> unless you have a plugin that allows you too?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
488
Reaction score
215
First Language
English
Primarily Uses
RMMV
Handling of newlines is included in drawTextEx. If you're calling it from a script and the string contains a newline already, then drawTextEx will go to a new line when it gets there. However, if you have text that contains the \n escape sequence rather than an actual newline, it will not work, as that \ will be removed by the escape parsing code and then you're left with just n which is obviously not a newline.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
Im calling the text from the item description, which only allows 2 lines in the database. It would be a bit difficult to have to save the text for item description anywhere else than in the box provided by MV.

I wrote a function now, that would take care of that.
for those who are interested:

JavaScript:
Window_MenuInventoryKeyList.prototype.updateDesc = function(item, x, y, lineSpace) {
    item ? text = item.description : text = "";
    var menuInvent = SceneManager._scene._menuInventory;
    var newLines = text.split("/n");
    var n = lineSpace || 20;
    menuInvent.contents.clear();
    menuInvent.refresh();
    menuInvent.resetTextColor();
    for (i = 0; i < newLines.length; i++) {
        menuInvent.drawTextEx(newLines[i], x, y);
        y += n;
    }
};
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,712
Reaction score
1,162
First Language
EN
Primarily Uses
RMMV
Explanation: while \n represents a new line, if you enter that into any text-entry field in the editor it'll be stored as two characters: backslash (encoded as \\) and n. :kaoback:

That said, if you were to have your code split on "\\n" instead, you'd encounter conflicts with the pre-existing escape sequence: \N[x] = name of actor ID x. So alternatives like /n or <br> tend to get used instead. :kaothx:
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
Let me rewrite this cleaner without my own game stuff in it:

JavaScript:
Window_AnyWindow.prototype.drawTextWithNewLines = function(item, x, y, lineSpace) {
    item ? text = item.description : text = "";
    var newLines = text.split("/n"); //Or any of your own split code
    var n = lineSpace || 20;
    for (i = 0; i < newLines.length; i++) {
        this.drawTextEx(newLines[i], x, y);
        y += n;
    }
};
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
488
Reaction score
215
First Language
English
Primarily Uses
RMMV
Since you're reading an item's description, I'm pretty sure you don't need a loop or even a new function for this. Just call:

JavaScript:
this.drawTextEx(item.description || "");
The drawTextEx function already handles newlines for you, as long as they're real newlines. If you're trying to make the item description more than two lines by adding a special code, then you can use the following call instead:

JavaScript:
var description = item.description || "";
description = description.replace(/<br>/g, '\n');
this.drawTextEx(description);
Basically, replace your special code with actual newlines, then call drawTextEx. If you want your special code to be /n, then replace /<br>/g with /\/n/g.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
Since you're reading an item's description, I'm pretty sure you don't need a loop or even a new function for this. Just call:

JavaScript:
this.drawTextEx(item.description || "");
The drawTextEx function already handles newlines for you, as long as they're real newlines. If you're trying to make the item description more than two lines by adding a special code, then you can use the following call instead:

JavaScript:
var description = item.description || "";
description = description.replace(/<br>/g, '\n');
this.drawTextEx(description);
Basically, replace your special code with actual newlines, then call drawTextEx. If you want your special code to be /n, then replace /<br>/g with /\/n/g.
Ok, so I tried your method, but it didn't work.

JavaScript:
Window_MenuInventoryKeyList.prototype.updateDesc = function(item, x, y) {
    var menuInvent = SceneManager._scene._menuInventory;
    menuInvent.contents.clear();
    menuInvent.refresh();
    menuInvent.resetTextColor();
    var description = item.description || "";
    description = description.replace(/<br>/g, '/\/n/g');
    menuInvent.drawTextEx(description, x, y);
};
Note that I also tried using "\n" instead of my "/n" and no difference unfortunately.

This is how it should look like (with my loop):
desciption.JPG

This is how it looks like with your method:
desciption2.JPG

This is the Text insert into the description box in MV:

"\C[2]LEVEL 3 KEYCARD\C[0]/n/nA \C[1]level 3 access\C[0] keycard for the \C[1]science labs\C[0] on the \C[1]UEG Phobos\C[0], which are off-limits for any
/nnon-essential personell./n/nBe advised - Entering without proper authorization or disguise might raise unwanted attention."


Remember, the description box only allows me to put in 2 lines of text, no line breaks.

This shouldn't sound demeaning or anything. I would love to not have to use a loop and solve all this in a few simple lines, but either I'm too stupid to make this work or RPG Maker is interfering somewhere in the process.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
488
Reaction score
215
First Language
English
Primarily Uses
RMMV
I believe you misapplied this line in my previous post:
If you want your special code to be /n, then replace /<br>/g with /\/n/g.
Your code is replacing <br> with /n instead of /n with \n.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
72
Reaction score
22
First Language
English
Primarily Uses
RMMV
I believe you misapplied this line in my previous post:


Your code is replacing <br> with /n instead of /n with \n.
If this is what you meant:
JavaScript:
description = description.replace(/\/n/g, '/n');
I get the same results as posted above.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
488
Reaction score
215
First Language
English
Primarily Uses
RMMV
Almost - you want '\n', not '/n'.
 

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

Latest Threads

Latest Profile Posts

I'm sure this question's been asked before, but I can't find an answer: is there any way to run the Steam version of RPGMaker *without* being logged into Steam? It's a frustrating extra step sometimes.
Been seeing bright flashes in the sky for a while, and thought it was my eyes playing tricks on me. Nope! Lightning. Now it's raining heavily. Seeing lightning, but not hearing thunder, is weird.
Small Update for myself:
>Two Dungeon maps are done, Dungeon 3 is in progress. Dungeon 4 needs work.
>4 characters set up out of a possible 6 but those come later.
>Hub area needs work.
>Game completion..., 20-25% maybe?
Does anyone else find writing dialogue hard?
You guys want more tutorials? Well not only are we doing new video tutorials with Driftwood, we've also brought in two contributing authors for the blog to get a new tutorial every week! First one here from @Avery
https://blog.rpgmakerweb.com/tutorials/tutorial-mapping-interior/

Next week we'll get something from @hiddenone

Forum statistics

Threads
100,712
Messages
978,627
Members
132,325
Latest member
ighjku
Top