Page 1 of 1

Changing textbox appearance at runtime for a scene

Posted: Fri Feb 10, 2017 7:34 am
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 :)!

Re: Changing textbox appearance at runtime for a scene

Posted: Fri Feb 10, 2017 8:58 am
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.

Re: Changing textbox appearance at runtime for a scene

Posted: Fri Feb 10, 2017 10:15 am
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.

Re: Changing textbox appearance at runtime for a scene

Posted: Fri Feb 10, 2017 4:03 pm
by InvertMouse
Yep, those solutions work Divona. Thank you so much you expert :)!