Customisable buttons/widgets: style, images, translations?

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
chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Customisable buttons/widgets: style, images, translations?

#1 Post by chronoluminaire »

Hello. For the Tile and Unit Engines, I'm wanting to provide the user with the ability to customise the look of the buttons, text, frames, and adjustments, and it seems that a custom style would be the way to do that.

I'm really not very familiar with Ren'Py's style system, so I just wanted to check. Should I use Indexed Styles for this? And if so, should I style my "End Turn" button with style.button["tileengine"], style.button["endturn"], or style.button["tileengine endturn"]? If this isn't the best way, what should I do?

And I seem to recall seeing something in the doc about letting certain specified buttons be automatically replaced with imagebuttons if the user specifies some parameter somewhere. Does that only apply to buttons on the internal Ren'Py menus, or is there some way for me to offer that to my users?

Finally, on a related note, I'd like to offer the user an easy way to change the text on the buttons, if they want. Is there any way to use the config.translations dictionary for this, so that the user could add entries like

Code: Select all

$ config.translations = {"End Turn" : "Bring It On"}
Or is this only usable by things inside Ren'Py?
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

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: Customisable buttons/widgets: style, images, translations?

#2 Post by PyTom »

chronoluminaire wrote: I'm really not very familiar with Ren'Py's style system, so I just wanted to check. Should I use Indexed Styles for this? And if so, should I style my "End Turn" button with style.button["tileengine"], style.button["endturn"], or style.button["tileengine endturn"]? If this isn't the best way, what should I do?
The way I do it is to have code that creates engine_button and engine_button_text styles, and then to index _them_.
And I seem to recall seeing something in the doc about letting certain specified buttons be automatically replaced with imagebuttons if the user specifies some parameter somewhere. Does that only apply to buttons on the internal Ren'Py menus, or is there some way for me to offer that to my users?
It should work with all indexed-style buttons, as of 6.6.
Finally, on a related note, I'd like to offer the user an easy way to change the text on the buttons, if they want. Is there any way to use the config.translations dictionary for this, so that the user could add entries like

Code: Select all

$ config.translations = {"End Turn" : "Bring It On"}
Or is this only usable by things inside Ren'Py?
For text to be translated, you have to call the _ function. I'd wrap this all up in a single function, giving the following code:

Code: Select all

init python:
    style.engine_button = Style(style.button)
    style.engine_button_text = Style(style.button_text)

    def engine_button(text, **kwargs):
        ui.textbutton(
            _(text), 
            style=style.engine_button[text], 
            text_style=style.engine_button_text[text], 
            **kwargs)
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

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Customisable buttons/widgets: style, images, translations?

#3 Post by chronoluminaire »

That's awesome, PyTom. Thanks. I can put that to work straight away.

One more question:
PyTom wrote:
And I seem to recall seeing something in the doc about letting certain specified buttons be automatically replaced with imagebuttons if the user specifies some parameter somewhere. Does that only apply to buttons on the internal Ren'Py menus, or is there some way for me to offer that to my users?
It should work with all indexed-style buttons, as of 6.6.
So will the possibility for that transformation be automatically provided by me using indexed styles and/or the _ function?

And to test it, how do I use this / direct the users to use this? I've found the 6.6.0 changelog which says: "This makes it possible to define imagebuttons and imagelabels in the style.button and style.label styles, rather than in all sorts of different styles." But I can't find any other doc page indicating actually how to use a style to turn a textbutton into an imagebuttons / imagelabel.

Thanks!
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

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: Customisable buttons/widgets: style, images, translations?

#4 Post by PyTom »

http://www.renpy.org/wiki/renpy/doc/ref ... ge_buttons

theme.image_buttons is responsible for turning a button into an image button.
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

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Customisable buttons/widgets: style, images, translations?

#5 Post by chronoluminaire »

PyTom wrote:http://www.renpy.org/wiki/renpy/doc/ref ... ge_buttons

theme.image_buttons is responsible for turning a button into an image button.
Aha, thanks. And presumably if I want strings of text created with ui.text to be translatable by theme.image_labels, presumably I need to give them a style based on style.label? Except that says it's for the "windows" surrounding the text. Should I wrap my calls to ui.text() inside ui.window(), even if they're already inside a vbox inside a larger frame or window?

Thanks a lot for the help on this. This looks like a very powerful system - I just want to understand how to write my code to take full advantage of it.
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

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: Customisable buttons/widgets: style, images, translations?

#6 Post by PyTom »

Yeah. Nowadays, the canonical way to create a label is with:

Code: Select all

ui.window(style=style.my_label[label])
ui.text(_(label), style=style.my_label_text[label])
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

Post Reply

Who is online

Users browsing this forum: NeonNights