So as say on the title, the idea is to change the look of the textbox during the game. The example is to change thing when we change the room we are in, but it can be used in various context, like for example displaying a different textbox during a fight scene to enlight the action etc.
Here we will see how to change the background image of the textbox, but once you understand it, you can change everything you want using the method, the text color, the size etc. I tried to explain it very slowly so it can help to learn style, variable, and if statement^^.
Okay let's go, so for this example let's say we want by default a blue textbox. But when we come in the bedroom we want it purple, and when we come in the living room we want it red.
Let's go !
So we will need 3 textbox images (you can find those used in this example as attachments), all put in our gui file.
Then, we are going to create a variable to indicate in which room we are, by default, I will set it up as normal.
Code: Select all
init python:
setup_textbox = "normal"
Then, in the screen.rpy file, I need to find what define the window display, so you need to find this code :
Code: Select all
screen say(who, what):
style_prefix "say"
window:
id "window"
if who is not None:
window:
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
## Make the namebox available for styling through the Character object.
init python:
config.character_id_prefixes.append('namebox')
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
background Image("gui/textbox.png", xalign=0.5, yalign=1.0)
Be carefull, the most important is that the variable names match, so do spell them very carefully. Plus, since the underscore, is used in style, don't use them for your name. For exemple write "livingroom" and not "living_room" it can lead to error in this particular context.
Code: Select all
window:
if setup_textbox =="bedroom": #if the variable is "bedroom"
style "window_bedroom" #then we display the style "window_bedroom".
id "window_bedroom"
elif setup_textbox == "livingroom": #if the variable is "livingroom".
style "window_livingroom" #then we display the style "window_livingroom"!
id "window_livingroom"
else: #If the variable is neither bedroom, or livingroom, or whatever thing we have set before, then we display the default one.
id "window"
style "window"
First off all, we are going to modify the default one to put our blue textbox on it !
So
Code: Select all
style window:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox.png", xalign=0.5, yalign=1.0)
Code: Select all
style window:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox_blue.png", xalign=0.5, yalign=1.0) #we change the name of the picture accordingly of the name in the gui.
Code: Select all
style window_bedroom:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox_purple.png", xalign=0.5, yalign=1.0)
Code: Select all
style window_livingroom:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox_red.png", xalign=0.5, yalign=1.0)
Sooo, if we take everything together, we now have this code :
Code: Select all
init python:
setup_textbox = "normal"
screen say(who, what):
style_prefix "say"
window:
if setup_textbox =="bedroom": #if the variable is "bedroom"
style "window_bedroom" #then we display the style "window_bedroom".
id "window_bedroom"
elif setup_textbox == "livingroom": #if the variable is "livingroom".
style "window_livingroom" #then we display the style "window_livingroom"!
id "window_livingroom"
else: #If the variable is neither bedroom, or livingroom, or whatever thing we have set before, then we display the default one.
id "window"
style "window"
if who is not None:
window:
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
## Make the namebox available for styling through the Character object.
init python:
config.character_id_prefixes.append('namebox')
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
background Image("gui/textbox_blue.png", xalign=0.5, yalign=1.0)
style window_bedroom:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox_purple.png", xalign=0.5, yalign=1.0)
style window_livingroom:
xalign 0.5
xfill True
yalign gui.textbox_yalign
ysize gui.textbox_height
background Image("gui/textbox_red.png", xalign=0.5, yalign=1.0)
Okay! But now, how can we decide when we want to change screen ?
Well, it's simple, we will just have to change the variable in the game, so in the script.rpy file !
For example, we will add
Code: Select all
setup_textbox = "bedroom"
if you want to try, here a quick code :
Code: Select all
label start:
"Normal set up"
"Now we are going on the living room"
$setup_textbox = "livingroom"
"Now we are in the living room"
"Now we are going in the bedroom"
$setup_textbox ="bedroom"
"Now we are in the bedroom"
"Well, let's go in another place"
$setup_textbox ="normal" #don't forget to take it back by default when we don't need the special ones anymore !
"Things get back to normal !"
return
Code: Select all
setup_textbox = "normal"