[Solved] Display namebox directly in front of dialogue?
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
[Solved] Display namebox directly in front of dialogue?
Hello, I searched the forum for a bit but I couldn't find exactly what I'm looking for. I'm trying to style my dialogue so that the speaker name is displayed in front of spoken text like movie subtitles. Here's an example of what I mean:
I know I could just manually add the name as part of the dialogue, but I wanted to see if there's a way to do it using the default namebox (so I can use my predefined character names and colors). I assume I'd have to reposition the namebox in the gui but I'm not sure how to account for varying lengths of dialogue text. Any ideas?
I know I could just manually add the name as part of the dialogue, but I wanted to see if there's a way to do it using the default namebox (so I can use my predefined character names and colors). I assume I'd have to reposition the namebox in the gui but I'm not sure how to account for varying lengths of dialogue text. Any ideas?
Last edited by niho on Sun May 29, 2022 1:44 pm, edited 1 time in total.
- Ocelot
- Lemma-Class Veteran
- Posts: 2400
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Display namebox directly in front of dialogue?
How exactly do you want to position your namebox and text?
* Name always starts at the same position, text immediately after (position of text would shift depending on name length)? hbox with automatically sized Text displayables is the answer.
* Text always starts at certain position, name immediately precedes it? hbox with fixed size name, which is aligned to the right or two separate Text displayabkes, name with xanchor 1., text with xanchor 0., both positioned at same x-coordinate.
* Something else?
* Name always starts at the same position, text immediately after (position of text would shift depending on name length)? hbox with automatically sized Text displayables is the answer.
* Text always starts at certain position, name immediately precedes it? hbox with fixed size name, which is aligned to the right or two separate Text displayabkes, name with xanchor 1., text with xanchor 0., both positioned at same x-coordinate.
* Something else?
< < insert Rick Cook quote here > >
Re: Display namebox directly in front of dialogue?
Sorry, I'm not sure what you mean by "automatically sized Text displayables." As in simply putting the text in an hbox and using the default style properties? I tried that but the namebox would always appear above the dialogue (even when I gave them the same x-coordinates).* Name always starts at the same position, text immediately after (position of text would shift depending on name length)? hbox with automatically sized Text displayables is the answer.
I also tried using yalign to position them. It works somewhat but since they're treated as two different displayables it doesn't have the same effect for multiline dialogue. Here's my current code and the (unintended) effect:
Code: Select all
screen say(who, what):
style_prefix "say"
window:
id "window"
hbox:
id "namebox"
style "namebox"
if who is not None:
text who id "who"
text what id "what" yalign 0.8
Re: Display namebox directly in front of dialogue?
You have different font sizes in this example, unlike your first "Mickey: Whoever you are…" example. So I'm not sure wha you think should be correct behavior here.
But you can get consistent vertical positioning if you set "yalign 0" on both the 'who' box and the 'what' box. If you want to match the text baselines across both, even when you're using different font sizes, then that's a fixed number of pixels offset. I think you can get that with something more like:
No idea if 24 will be the right px offset for you, but you can fiddle until it looks right. Both text fields would want the same integer value, whatever it is.
But you can get consistent vertical positioning if you set "yalign 0" on both the 'who' box and the 'what' box. If you want to match the text baselines across both, even when you're using different font sizes, then that's a fixed number of pixels offset. I think you can get that with something more like:
Code: Select all
hbox:
id "namebox"
style "namebox"
if who is not None:
text who:
id "who"
yanchor renpy.BASELINE
ypos 24 # your larger font size, probably
text what:
id "what"
yanchor renpy.BASELINE
ypos 24 # your larger font size, probably
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Re: Display namebox directly in front of dialogue?
No matter how much I fiddled with the offset/pos/whatever values I just couldn't get it to look the way I wanted, even when the fonts were the same size. I finally found a workaround but I've realized that this is probably more trouble than it's worth... (because I'd have to redefine the characters' names as text tags anyways). If anyone has any other ideas I'm open to suggestions but I'll probably just mark this as solved Thank you both for your help.
- m_from_space
- Miko-Class Veteran
- Posts: 957
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: Display namebox directly in front of dialogue?
The say screen has to include a text-object with id "what" containing the same text as the argument "what". The "who" id doesn't seem to matter on the other hand. So my workaround for your initial question would be: Hide the "what" text outside of the screen and create your subtitle line. (You may want to think about what happens when you present the user with a choice screen though.)
Code: Select all
screen say(who, what):
style_prefix "say"
window:
id "window"
# the original what object, just shifted to the right, out of the screen
text what id "what" xpos 1.0 slow_cps False
# your subtitle like dialogue
if who is None:
text "[what]" slow_cps True
else:
text "[who]: [what]" slow_cps True
Re: Display namebox directly in front of dialogue?
I did something similar, but it seems like as long as you don't give an id the text won't be styled properly. So either way I'd have to use custom text tags, but thank you.
- m_from_space
- Miko-Class Veteran
- Posts: 957
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: [Solved] Display namebox directly in front of dialogue?
What do you mean by it not being styled properly? You can add styles. I thought your goals is to have a similar styling than in your original post. Also if you want to add a character's style as part of the "what" argument, you can just define the character like this:
Code: Select all
define niho = Character("Niho", what_prefix="{=nihospeak}", what_suffix="{/nihospeak}")
style nihospeak:
font: ...
size: ...
Re: [Solved] Display namebox directly in front of dialogue?
Sorry, I should've been more clear. I know how to style the text myself, I meant that it won't be styled automatically using the gui config variables without the who/what id. Also I got the look I wanted, I was just looking for an easier way to do it lol. Though I didn't think of using prefix/suffix so I'll play around with it some more. Thanks again
- m_from_space
- Miko-Class Veteran
- Posts: 957
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: [Solved] Display namebox directly in front of dialogue?
I literally just woke up and the solution hit right in my face, I actually gave it to myself inside the last post without realizing. It's so much easier and I am really laughing about how I wanted to solve this in such a complex way.niho wrote: ↑Sun May 29, 2022 3:25 pm Sorry, I should've been more clear. I know how to style the text myself, I meant that it won't be styled automatically using the gui config variables without the who/what id. Also I got the look I wanted, I was just looking for an easier way to do it lol. Though I didn't think of using prefix/suffix so I'll play around with it some more. Thanks again
Just create your character like the following.
This way nothing about styles changes, it's everything you need with a single argument inside. (Still wondering why I didn't think about it first.)
Code: Select all
define m = Character(None, ... , what_prefix="Mickey: ")
Re: [Solved] Display namebox directly in front of dialogue?
Clever! But that won't lay out the hanging indent for the second line, if the dialog is long.m_from_space wrote: ↑Wed Jun 01, 2022 1:08 am This way nothing about styles changes, it's everything you need with a single argument inside.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
- m_from_space
- Miko-Class Veteran
- Posts: 957
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: [Solved] Display namebox directly in front of dialogue?
This also works but afaik there's no way to change the color of the prefix alone so I'd still need to use text tags. I have found other uses for prefixes/suffixes though so I appreciate the suggestion.m_from_space wrote: ↑Wed Jun 01, 2022 1:08 amCode: Select all
define m = Character(None, ... , what_prefix="Mickey: ")
- m_from_space
- Miko-Class Veteran
- Posts: 957
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: [Solved] Display namebox directly in front of dialogue?
This solves exactly what you where asking for in your original question, so I don't quite understand the reaction. What exactly do you mean by "not be able to change the color of the prefix alone"? Of course you can change the color of the prefix, it's just text. What's the problem with text tags anyway?
Re: [Solved] Display namebox directly in front of dialogue?
If the line of dialog wraps in the text box, you'll get
Code: Select all
Mickey: Whoever you are on that
train, listen up
Code: Select all
Mickey: Whoever you are on that
train, listen up
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Who is online
Users browsing this forum: babayi0827, Bing [Bot]