Changing textbox appearance at runtime for a scene

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
InvertMouse
Regular
Posts: 95
Joined: Sat May 31, 2014 3:41 am
Completed: Unhack
Organization: InvertMouse
Location: Sydney, Australia
Contact:

Changing textbox appearance at runtime for a scene

#1 Post by InvertMouse »

Hello :). I want to ask if it is possible to change the appearance of a textbox at runtime. For instance, with cursors, I can call:

Code: Select all

def changeCursor():
        setattr(config, "mouse", {'default' : [('assets/images/cursor_alt.png', 0, 0)]})

changeCursor()
And with the textbox, I can customize it using:

Code: Select all

style.window.background = Frame("assets/images/game/game_gui.png", xxx, yyy)
However, if I call the above while the story is progressing, the window does not change. The update only seems to happen if the command is called while I am in the menu. Is there another function I am supposed to call?

It is possible to update the textbox for a specific character via:

Code: Select all

$ narrator = Character(None, window_background="dialoguebox_noname.png")
But I would like to change the dialogue box for an entire scene. Something like:

Code: Select all

# Textbox style 1.

"Hello!"

"Hey man."

"Yo you ready to change the style?"

"Okay, change it."

# Textbox style 2.

"Did it work?"

"Yeah."
Also, I would like to ask if it is possible to change the say screen's imagemaps at runtime. These ones:

Code: Select all

screen say:

imagemap:
        
        ground "assets/images/game/game_ground.png"
        idle "assets/images/game/game_idle.png"
        hover "assets/images/game/game_hover.png"
        selected_idle "assets/images/game/game_selected_idle.png"
        selected_hover "assets/images/game/game_selected_hover.png"
I want to change the dialogue box and those button imagemaps at the same time. Mind letting me know? Thank you :)!
Image

User avatar
mihaeru
Newbie
Posts: 18
Joined: Mon Sep 22, 2014 2:00 pm
Projects: working on my first project "Madness in my heart"(VN)
Location: Spain
Contact:

Re: Changing textbox appearance at runtime for a scene

#2 Post by mihaeru »

I have similar problem here I want to change style.menu_window.xalign in script.rpy f¡le but can't do it. Hope someone give us the solution.

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Changing textbox appearance at runtime for a scene

#3 Post by Divona »

What you need is "style.rebuild()".

Code: Select all

init python:

    def changeTextBoxBackground(image_path):
        style.window.background = Frame(image_path)
        style.rebuild()

label start:

    # Textbox style 1.
    $ changeTextBoxBackground("gui/textbox_1.png")

    "Hello!"

    "Hey man."

    "Yo you ready to change the style?"

    "Okay, change it."

    # Textbox style 2.
    $ changeTextBoxBackground("gui/textbox_2.png")

    "Did it work?"

    "Yeah."
Other way to do it is to use ConditionSwitch:

Code: Select all

default textbox_style = 1

define narrator = Character(None, window_background = ConditionSwitch(
    "textbox_style == 2", "gui/textbox_2.png",
    "True", "gui/textbox_1.png"
))

label start:

    # Textbox style 1.
    $ textbox_style = 1

    "Hello!"

    "Hey man."

    "Yo you ready to change the style?"

    "Okay, change it."

    # Textbox style 2.
    $ textbox_style = 2

    "Did it work?"

    "Yeah."
Third way to do it is to have two file name like "textbox_1.png" and "textbox_2.png", and just change variable:

Code: Select all

default textbox_style = 1

define narrator = Character(None, windowbackground = "gui/textbox_[textbox_style].png"

label start:

    # Textbox style 1.
    $ textbox_style = 1

    "Hello!"

    "Hey man."

    "Yo you ready to change the style?"

    "Okay, change it."

    # Textbox style 2.
    $ textbox_style = 2

    "Did it work?"

    "Yeah."
For imagemap in "screen say", should be able to do the same thing. Have the file name follow by "_1" for first one, and "_2" for second one, then set variable to do the switching:

Code: Select all

default textbox_style = 1

screen say(who, what):

    imagemap:
        
        ground "assets/images/game/game_ground_[textbox_style].png"
        idle "assets/images/game/game_idle_[textbox_style].png"
        hover "assets/images/game/game_hover_[textbox_style].png"
        selected_idle "assets/images/game/game_selected_idle_[textbox_style].png"
        selected_hover "assets/images/game/game_selected_hover_[textbox_style].png"

label start:

    # Textbox style 1.
    $ textbox_style = 1

    "Hello!"

    "Hey man."

    "Yo you ready to change the style?"

    "Okay, change it."

    # Textbox style 2.
    $ textbox_style = 2

    "Did it work?"

    "Yeah."
Here also another one if you don't want to follow the name structure for some reason:

Code: Select all

default textbox_style = 2

screen say(who, what):

    if textbox_style == 2:

        imagemap:
        
            ground "assets/images/game/game_ground_2.png"
            idle "assets/images/game/game_idle_2.png"
            hover "assets/images/game/game_hover_2.png"
            selected_idle "assets/images/game/game_selected_idle_2.png"
            selected_hover "assets/images/game/game_selected_hover_2.png"

    else:

        imagemap:
        
            ground "assets/images/game/game_ground.png"
            idle "assets/images/game/game_idle.png"
            hover "assets/images/game/game_hover.png"
            selected_idle "assets/images/game/game_selected_idle.png"
            selected_hover "assets/images/game/game_selected_hover.png"

label start:

    # Textbox style 1.
    $ textbox_style = 1

    "Hello!"

    "Hey man."

    "Yo you ready to change the style?"

    "Okay, change it."

    # Textbox style 2.
    $ textbox_style = 2

    "Did it work?"

    "Yeah."
Pick whatever way that work and suit your need.
Completed:
Image

User avatar
InvertMouse
Regular
Posts: 95
Joined: Sat May 31, 2014 3:41 am
Completed: Unhack
Organization: InvertMouse
Location: Sydney, Australia
Contact:

Re: Changing textbox appearance at runtime for a scene

#4 Post by InvertMouse »

Yep, those solutions work Divona. Thank you so much you expert :)!
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]