[Solved] Display namebox directly in front of dialogue?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Message
Author
User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

[Solved] Display namebox directly in front of dialogue?

#1 Post by niho »

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:
Image
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.

User avatar
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?

#2 Post by Ocelot »

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?
< < insert Rick Cook quote here > >

User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

Re: Display namebox directly in front of dialogue?

#3 Post by niho »

* 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.
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).

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 
Image

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Display namebox directly in front of dialogue?

#4 Post by zmook »

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:

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
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.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

Re: Display namebox directly in front of dialogue?

#5 Post by niho »

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.

User avatar
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?

#6 Post by m_from_space »

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

User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

Re: Display namebox directly in front of dialogue?

#7 Post by niho »

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.

User avatar
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?

#8 Post by m_from_space »

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: ...

User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

Re: [Solved] Display namebox directly in front of dialogue?

#9 Post by niho »

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 :)

User avatar
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?

#10 Post by m_from_space »

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 :)
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.

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: ")

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: [Solved] Display namebox directly in front of dialogue?

#11 Post by zmook »

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.
Clever! But that won't lay out the hanging indent for the second line, if the dialog is long.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
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?

#12 Post by m_from_space »

zmook wrote: Wed Jun 01, 2022 9:30 amClever! But that won't lay out the hanging indent for the second line, if the dialog is long.
I don't understand, what do you mean?

User avatar
niho
Newbie
Posts: 21
Joined: Fri Apr 15, 2022 11:31 pm
itch: nihomi
Discord: niho#0953
Contact:

Re: [Solved] Display namebox directly in front of dialogue?

#13 Post by niho »

m_from_space wrote: Wed Jun 01, 2022 1:08 am

Code: Select all

define m = Character(None, ... , what_prefix="Mickey: ")
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.

User avatar
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?

#14 Post by m_from_space »

niho wrote: Wed Jun 01, 2022 7:37 pmThis 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.
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?

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: [Solved] Display namebox directly in front of dialogue?

#15 Post by zmook »

m_from_space wrote: Wed Jun 01, 2022 3:42 pm
zmook wrote: Wed Jun 01, 2022 9:30 amClever! But that won't lay out the hanging indent for the second line, if the dialog is long.
I don't understand, what do you mean?
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
instead of

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

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], simple_human