Customising the namebox background

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.
Post Reply
Message
Author
User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Customising the namebox background

#1 Post by Kinmoku »

Hi all,

This should be easy but because I'm using the new GUI I'm a little stuck... How do I customise the namebox / say_who background? I want to change the colour for different characters, and completely remove it for others.

Here's my code:

Code: Select all

screen say(who, what):
    style_prefix "say"
    
    window:
        id "window"

        if who is not None:

            window:
                style "namebox"
                text who id "who"

        text what id "what"
        
        
style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("images/ui/name_black.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign) # I want to change name_black.png for name_red.png depending on character
    padding gui.namebox_borders.padding
My characters:

Code: Select all

define m = Character("Millie", color="#FFF", who_ypos=12, what_ypos=90, window_background="images/ui/box_present.png", all_at_once=False) # default black
define a = Character("Avery", color="#FFF", who_ypos=12, what_ypos=90, window_background="images/ui/box_present.png", all_at_once=False) # I want the red box here
define mx = Character("Millie", color="#000", who_ypos=70, what_ypos=140, window_background="images/ui/box_memory.png", all_at_once=False) # This one uses a different window_background, and I want to completely remove the namebox.

# etc
I tried a few edits here but nothing worked sadly.
Any ideas?

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Customising the namebox background

#2 Post by Scribbles »

I'm just guessing.... but I wonder if you could include an if statement in the screen code where the Frame info is

Code: Select all

if who == "character name": ##make sure the string matches the exact character name
    background Frame(...)## put the actual frame info in though not ... lol
elif who == "Character name 2":
    background Frame(...)
## then have an else statement just in case
else:
    background Frame(...)
may or may not work, someone else might have a way better/easier solution though! :)
Image - Image -Image

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Customising the namebox background

#3 Post by Kinmoku »

I'm just guessing.... but I wonder if you could include an if statement in the screen code where the Frame info is
CODE: SELECT ALL
if who == "character name": ##make sure the string matches the exact character name
background Frame(...)## put the actual frame info in though not ... lol
elif who == "Character name 2":
background Frame(...)
## then have an else statement just in case
else:
background Frame(...)
may or may not work, someone else might have a way better/easier solution though! :)
This sounded like a perfect solution, but sadly it isn't working.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 148: end of line expected.
    if who == "Millie":
    ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
I tried "Millie" "Avery" "m" "a", even "if who is m" but the same error would pop up. I guess characters can't be used in this way? I see no reason why not... Perhaps the code is wrong :? Here's my edited code to style namebox in screens.rpy anyway:

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    if who == m:
        background Frame("images/ui/name_black.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
        padding gui.namebox_borders.padding
        
    elif who == a:
        background Frame("images/ui/name_black.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
        padding gui.namebox_borders.padding

    else:
        padding gui.namebox_borders.padding

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: Customising the namebox background

#4 Post by Pyr0 »

You're using screen syntax in a style statement. Imagine you're painting a sculpture. Screens are the clay (they decide the shape of things) while styles are the paint (they just make something that already exist look different). You can't use ifs in style statements, while you can in screens. However I think I have a solution that will save you a lot of headaches.

First of all, go to your screens.rpy file and identify the Say screen. It looks exactly like this:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"
        
        if who is not None:

            window:
            
                style "namebox"
                text who id "who"

        text what id "what"


    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
Copy it and paste it right below. Change its name to whatever you want (doesn't really matter) and add a third parameter (again, name it whatever you want). Then you go to the window that contains the "who" and tell it to use your third parameter as a background. That's it.

Code: Select all

screen say_custom(who, what, namebox_background):
    style_prefix "say"

    window:
        id "window"
        
        if who is not None:

            window:
                background namebox_background
                style "namebox"
                text who id "who"

        text what id "what"


    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
The only thing left to do is tell your characters to use this new screen, and give them what namebox to use. You do it in the Character function. Add a 'screen' keyword which is equal to the name of your new screen (in my case, "say_custom". Don't forget the quotes) and a 'show_*third parameter name*' (in my case, show_namebox_background).

Code: Select all

define your_character = Character(*all the stuff you already have*, screen = "say_custom", show_namebox_background = "your_background.png")
It should work just fine. Tell me if anything goes wrong.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Customising the namebox background

#5 Post by Kinmoku »

Ah thank you, this makes sense :) I can never get my head around screens!

I'll try it out now and come back if I have any issues. Thank you very much!

obi_dev
Newbie
Posts: 7
Joined: Wed Aug 16, 2017 9:12 pm
Contact:

Re: Customising the namebox background

#6 Post by obi_dev »

I am actually having a similarissue as this, but I would actually like to customize the textbox window. I seem to be failing at doing so, badly.
Basically, for my MC, i want the side image to be left aligned but the window to be styled differently (i.e. padding differences) and for other characters, right aligned and matching padding styles.

I succeeded in getting the images to swap sides, but the dialogue window actually uses both window styles. I've tried same name, different ID's. Not really sure what else to do for something that seems so simple. Or maybe im trying to over complicate it.

In the example, say has top padding and say_MC has left padding and both are being applied when any character speaks.

Code: Select all

define mc       = Character("[mcName]", color="#000000", image="mc", screen="say_MC")
define de       = Character("[suName]", color="#000000", image="de")

Code: Select all

screen say(who, what):
    tag speaking
    window:
        id "window"
        if who is not None:
            window:
                style "namebox"
                text who id "who"
        text what id "what"

    if not renpy.variant("small"):
        add SideImage() xalign 1.0 yalign 1.0

style window is default
style say_label is default
style say_dialogue is default
style say_thought is say_dialogue

style namebox is default
style namebox_label is say_label

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height
    left_padding 0
    top_padding 50
    background Image("gui/textbox.png", xalign=0.5, yalign=1.0, yoffset=70)

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/namebox.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
    padding gui.namebox_borders.padding

style say_label:
    properties gui.text_properties("name", accent=True)
    xalign gui.name_xalign
    yalign 0.5

style say_dialogue:
    properties gui.text_properties("dialogue")

    xpos gui.dialogue_xpos
    xsize gui.dialogue_width
    ypos gui.dialogue_ypos

Code: Select all

screen say_MC(who, what):
    tag speaking
    window:
        id "window"
        text what id "what"

    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0

style window is default
style say_dialogue is default
style say_thought is say_dialogue

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height
    left_padding 600
    top_padding 0
    background Image("gui/textbox.png", xalign=0.5, yalign=1.0, yoffset=20)

style say_dialogue:
    properties gui.text_properties("dialogue")
    xpos gui.dialogue_xpos
    xsize gui.dialogue_width
    ypos gui.dialogue_ypos

obi_dev
Newbie
Posts: 7
Joined: Wed Aug 16, 2017 9:12 pm
Contact:

Re: Customising the namebox background

#7 Post by obi_dev »

Actually, found the answer. By adding the properties to the character, I was able to control it.
I edited say to everything I need. Cut say_MC down to just flipping the image and adding props to the character

Code: Select all

define mc       = Character("[mcName]", color="#000000", image="mc", screen="say_MC", window_right_padding=40, window_left_padding=360)

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Customising the namebox background

#8 Post by Kinmoku »

I find the easiest way to edit the dialogue is with the character boxes!

I'm actually trying to add another style of say screen (the previous say_custom worked), but it's not working. I'm unsure what I'm doing wrong, but I've tried a lot of combinations and it keeps defaulting to the default, funnily enough.

Here's my new screen, default style, and new style (black) in screen.rpy:

Code: Select all

screen say_black(who, what, background):
    style_prefix "black"
    
    window:
        id "window"

        if who is not None:
            window:
                background None
                text who id "who"

        text what id "what"

style window is default
style say_label is default
style say_dialogue is default
style say_thought is say_dialogue

#style namebox is default
style namebox_label is say_label

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height
    padding gui.namebox_borders.padding

style say_label:
    color gui.accent_color
    font gui.name_font
    size gui.name_text_size
    xalign gui.name_xalign
    yalign 0.1
    bold False

style say_dialogue:
    xpos gui.text_xalign # changed from pos
    xanchor gui.text_xalign
    xsize gui.text_width
    ypos gui.text_yalign # changed from pos

    text_align gui.text_xalign
    layout ("subtitle" if gui.text_xalign else "tex")
    
style black_label:
    color "#FFF"
    font gui.name_font
    size 48
    xalign 0.5
    yalign 0.1
    bold False

style black_dialogue:
    xalign 0.5
    xsize 40
    yalign 0.5
    color "#FFF"
And here's my character:

Code: Select all

define mb = Character("Millie", color="#FFF", window_background=None, screen = "say_black", all_at_once=False)
But it's not working.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Customising the namebox background

#9 Post by PyTom »

If it taked background as a parameter, you're going to want to give show_background as an argument to Character.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Customising the namebox background

#10 Post by Kinmoku »

Hey, so 2 years later I am back!

I've tried to recreate this (however, not using the second "custom" say screen) but it's not working and crashing with this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 5149, in script
    mil "Hmm."
Exception: Unknown keyword arguments: namebox_background

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 5149, in script
    mil "Hmm."
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 706, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/exports.py", line 1336, in say
    who(what, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/character.py", line 1139, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "/Applications/renpy-6.99.11-sdk/renpy/character.py", line 842, in do_display
    **display_args)
  File "/Applications/renpy-6.99.11-sdk/renpy/character.py", line 552, in display_say
    what_text = renpy.display.screen.get_widget(what_text[0], what_text[1], what_text[2])
  File "/Applications/renpy-6.99.11-sdk/renpy/display/screen.py", line 1284, in get_widget
    screen.update()
  File "/Applications/renpy-6.99.11-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 158, in apply_arguments
    return parameters.apply(args, kwargs, ignore_errors)
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 145, in apply
    raise Exception("Unknown keyword arguments: %s" % ( ", ".join(values.keys())))
Exception: Unknown keyword arguments: namebox_background

Darwin-17.7.0-x86_64-i386-64bit
Ren'Py 7.3.2.320
My Friend Katie 1.0
Wed Sep 11 18:26:39 2019
Here's what I have in screens:

Code: Select all

screen say(who, what):
    style_prefix "say"

    if (sayscreen_label is not None):
        window at say_window_animation:
            id "window"

            if who is not None:

                window:
                    id "namebox"
                    style "namebox"
                    text who id "who"

            text what id "what" at text_fade_in
            
    else:
        window:
            id "window"

            if who is not None:

                window:
                    background namebox_background ## added this
                    id "namebox"
                    style "namebox"
                    text who id "who"

            text what id "what"

    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
And my characters in script.rpy:

Code: Select all

define mil = Character("Millie", who_xpos=46, who_ypos=40, color="#f7f7f6", window_xpos=440, window_ypos=790, window_xmaximum=970, window_xfill=True, window_background="thought", show_namebox_background = "gui/namebox_millie.png", callback=speaker("millie"), all_at_once=False)
define dad = Character("Dad", who_xpos=46, who_ypos=40, color="#f7f7f6", window_xpos=440, window_ypos=790, window_xmaximum=970, window_xfill=True, window_background="thought", show_namebox_background = "gui/namebox_dad.png", callback=speaker("millie"), all_at_once=False)
These are a bit of a mouthful!

I'll dig out my old files if I can't find an answer, but it seems like all my code is correct... I just don't have the second custom say screen.

Any ideas?

Post Reply

Who is online

Users browsing this forum: No registered users