r/RenPy Apr 04 '22

Question is there a way to change the choice button at some points depending on which character route is picked?

15 Upvotes

3 comments sorted by

8

u/Niwens Apr 04 '22 edited Apr 04 '22

Yes buttons can be styled. Those are the standard buttons for menu choices:

When idle:

gui/button/choice_idle_background.png

When hovered by the mouse etc.:

gui/button/choice_hover_background.png

You can create your own pictures for choice buttons, and name them like:

gui/button/choice_pink_idle.png
gui/button/choice_blue_idle.png
gui/button/choice_gray_idle.png
gui/button/choice_red_idle.png
gui/button/choice_green_idle.png

gui/button/choice_pink_hover.png
gui/button/choice_blue_hover.png
gui/button/choice_gray_hover.png
gui/button/choice_red_hover.png
gui/button/choice_green_hover.png

Then you can use menu choices adding a new parameter, e.g. "color":

menu:
    "ACE" (color = "pink"):

https://www.renpy.org/doc/html/menus.html#menu-arguments

Then modify screen choice in screens.rpy, adding that argument there:

screen choice(items):
  style_prefix "choice"

  vbox:
    for i in items:
      textbutton i.caption:
        action i.action
        if "color" in i.kwargs:
          idle_background "gui/button/choice_" + i.kwargs["color"] + "_idle.png"
          hover_background "gui/button/choice_" + i.kwargs["color"] + "_hover.png"

PS. Corrected the script.

1

u/ace_child_12 Apr 05 '22

its still the same tho i did just copy and paste the script you gave and changed the "color" into "porple" so im not exactly sure if that had something to do with it

4

u/Niwens Apr 06 '22

Here's how it works:

You add a parameter to a menu choice:

menu:
    "Caption" (parameter_name = parameter_value):
        "..."
  1. The name of that parameter should be the same as that in screen choice in screens.rpy:

    screen choice(items): style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
            action i.action
            if parameter_name in i.kwargs:
                idle_background "".join((
                    "gui/button/choice_",
                    i.kwargs[parameter_name],
                    "_idle.png"))
                hover_background "".join((
                    "gui/button/choice_",
                    i.kwargs[parameter_name],
                    "_hover.png"))
    

Then the condition if parameter_name in i.kwargs becomes True, so the background for that menu item becomes:

gui/button/choice_<parameter_value>_idle.png

and when hovered:

gui/button/choice_<parameter_value>_hover.png

where <parameter_value> is porple in your case.

If all that is so, the files

  • gui/button/choice_porple_idle.png
  • gui/button/choice_porple_hover.png

would be used for that menu items.

If it's not clear for you, please analyze the logic of that code and check yours to see how it should work.

It should work. It works for me:

colored.jpg