DEV Community

Cover image for Ren'Py choice menu customization: position, hover sounds and a choice the cat won't let you pick
Darrell Best
Darrell Best

Posted on

Ren'Py choice menu customization: position, hover sounds and a choice the cat won't let you pick

A Ren'Py choice menu on the right side of the screen. The mouse moves down the buttons and each one turns pink on hover, the locked Pet Biscuit button stays gray with a hint under it, two choices get picked and turn gold, and then Pet Biscuit becomes clickable. Recorded in Ren'Py 8.6.1

The stock Ren'Py choice menu is two gray bars parked in the middle of the screen. That is exactly where your character's face is. It is also where a cat would sit if a cat were designing your UI.

It has a second habit that is worse. If a choice has an if on it and the condition is false, the stock menu hides the choice completely. The player never learns it existed. Nothing to want, nothing to come back for.

This post fixes both. By the end you will have the menu in the GIF above:

  • It sits on the right, out of the way, with its bottom edge just above the textbox.
  • Each button has its own art for idle, hover, picked before, and locked.
  • Hovering plays a soft bloop and clicking plays a click.
  • A locked choice stays on screen, grayed out, with a one line hint saying why.

It is one new file of under 60 lines. Every code block below is copied from the files that ran in Ren'Py 8.6.1, and the GIF is a recording of that run.

Our test subject is Biscuit, the cafe cat. Biscuit does not approve of you yet.

Side by side: the stock Ren'Py choice menu on the left, the customized one on the right. Same scene, same question

Look at the left half closely. There are only two choices. The third one, Pet Biscuit, is in the script, but the stock menu hid it because its condition was false. On the right it is back, grayed out, with the reason under it.

0. What you need

  • A Ren'Py 8 project made from the launcher. I tested at the default 1280x720.
  • Four button images, one per state: idle, hover, selected and disabled, all the same size. Put them in game/ui/. Mine are 768x120 and come from Cozy VN UI Essentials (01_choice_idle.png through 04_choice_disabled.png). Any four PNGs with the same layout work.
  • Two short sounds in game/audio/, one for hover and one for click. Mine are hover_bloop_01.ogg and click_soft_01.ogg from Cozy UI Sound Kit, about 0.2 seconds each.

1. The test scene

Put this in script.rpy, replacing what is there:

# script.rpy: one cafe, one cat, one menu that loops until the cat approves of you.
define b = Character("Biscuit")
default trust = 0

image bg cafe = Solid("#e9d5b9")

label start:
    scene bg cafe
    "Biscuit the cafe cat is sitting on the counter. Judging you."

label biscuit_menu:
    menu:
        "Biscuit is waiting. What do you do?"

        "Offer Biscuit a sardine":
            $ trust += 1
            "Biscuit eats the sardine. Trust goes up by exactly one sardine."
            jump biscuit_menu

        "Ask Biscuit about the weather":
            $ trust += 1
            "Biscuit blinks slowly. You decide that was a forecast."
            jump biscuit_menu

        "Pet Biscuit" (hint="Biscuit has not approved you yet.") if trust >= 2:
            b "Mrrp."
            "You are allowed three pets. You get three pets."
            return
Enter fullscreen mode Exit fullscreen mode

The menu loops. Each sardine or weather question adds one point of trust, and at two points Biscuit allows petting.

The interesting line is the last choice. It has two extras:

  • if trust >= 2 is a normal Ren'Py menu condition. While it is false, the choice is locked.
  • (hint="Biscuit has not approved you yet.") is a menu argument. Ren'Py passes it to the choice screen as a keyword, and the screen decides what to do with it. The stock screen ignores it. Ours shows it under a locked choice.

Run the game now and you get the left half of the image above: two gray bars and no sign of the cat at all. The cat is fine. The menu is the problem.

2. Show locked choices instead of hiding them

Make a new file, game/choice_menu.rpy. The rest of the post goes in this file.

# choice_menu.rpy: a choice menu that moves out of the way, wears real button art, makes a sound and shows locked choices.

# 1. Show choices whose if-condition is False, grayed out, instead of hiding them.
define config.menu_include_disabled = True
Enter fullscreen mode Exit fullscreen mode

That one line changes how every menu in the game treats a false if. With it on, the choice still reaches the choice screen, but its button is insensitive. Insensitive is Ren'Py's word for "you can see it, you cannot press it."

I clicked the locked choice twice in a test run. Nothing happened: no click sound, no jump, the menu stayed put. Biscuit was unmoved, which is on brand.

3. One image per button state

# 2. One image per button state. The numbers are the nine-slice borders: left, top, right, bottom.
image choice idle = Frame("ui/01_choice_idle.png", 72, 34, 72, 34)
image choice hover = Frame("ui/02_choice_hover.png", 72, 34, 72, 34)
image choice chosen = Frame("ui/03_choice_selected.png", 72, 34, 72, 34)
image choice locked = Frame("ui/04_choice_disabled.png", 72, 34, 72, 34)
Enter fullscreen mode Exit fullscreen mode

Frame is Ren'Py's nine-slice. It keeps the corners at their real size and stretches only the middle, so one 768 pixel wide button can be any width without the rounded corners turning into ovals.

The four numbers are the border sizes in pixels: left, top, right, bottom. That order matters. Frame takes them positionally in exactly that order, so Frame("x.png", 72, 34, 72, 34) means 72 on the sides and 34 on top and bottom. For these buttons the numbers come from the kit's atlas.json. For your own art, measure how far the corner decoration reaches in from each edge.

The names choice idle, choice hover and the rest are just image names, so the styles further down can refer to them by name.

4. The screen

# 3. The screen. Ren'Py shows it for every menu: statement in the game.
screen choice(items):
    vbox:
        style "cozy_choice_menu"

        for i in items:
            button:
                style "cozy_choice_button"
                action i.action
                selected i.chosen

                vbox:
                    yalign 0.5
                    text i.caption style "cozy_choice_caption"
                    if not i.action.sensitive and "hint" in i.kwargs:
                        text i.kwargs["hint"] style "cozy_choice_hint"
Enter fullscreen mode Exit fullscreen mode

Ren'Py calls the screen named choice for every menu: in the game and hands it a list called items, one per choice. The stock version lives in screens.rpy. You do not need to delete it: screens.rpy starts with init offset = -1, so a screen choice in your own file wins. In the test run, this screen replaced the stock one with no other changes.

Each item gives you:

  • i.caption, the text of the choice.
  • i.action, what happens on click. Hand it to the button. It also knows whether the choice is locked, through i.action.sensitive.
  • i.chosen, True if the player has picked this choice before. Setting selected i.chosen is what turns a picked choice gold in the GIF.
  • i.kwargs, the menu arguments from the script. That is where hint arrives.

So the hint line reads: if this choice is locked and the script gave it a hint, show the hint under the caption. A choice with no hint, or an unlocked one, shows just the caption.

A note from my first attempt. I used style_prefix "cozy_choice" here, which is what the stock screen does, and the caption text drifted to the right. The prefix also applies to the small vbox inside each button, so that inner vbox picked up the menu's position style (xalign 0.95) and slid its text over. Giving the outer vbox and the button an explicit style fixed it. If your text ever wanders off inside a button, check what your inner containers are inheriting.

5. Move the menu

# 4. Where the menu sits: right side, bottom edge just above the textbox.
style cozy_choice_menu:
    xalign 0.95
    yanchor 1.0
    ypos 520
    spacing 8
Enter fullscreen mode Exit fullscreen mode
  • xalign 0.95 puts the column near the right edge. I also ran it with xalign 0.05, and the column moved to the left side, same everything else. 0.5 puts it back in the middle, if you miss the cat.
  • yanchor 1.0 with ypos 520 pins the bottom of the column at y 520, so the menu grows upward as you add choices. The stock textbox is 185 pixels tall at 720p and starts at y 535, so 520 leaves a small gap above it.
  • spacing 8 is the gap between buttons.

Because the menu grows upward from a fixed bottom edge, extra choices never cover the textbox. The column just gets taller. At this button height four choices fit on a 720p screen. A fifth would push the top one off the screen, so if you need five, have a word with your writer.

6. The buttons: art, states and sounds

# 5. The button: size, text padding, one background per state, and sounds.
style cozy_choice_button:
    xsize 620
    ysize 120
    padding (92, 26, 66, 24)
    background "choice idle"
    hover_background "choice hover"
    selected_idle_background "choice chosen"
    insensitive_background "choice locked"
    hover_sound "audio/hover_bloop_01.ogg"
    activate_sound "audio/click_soft_01.ogg"
Enter fullscreen mode Exit fullscreen mode
  • xsize 620 and ysize 120. The width can be anything, thanks to Frame. The height I kept at the art's own 120 pixels. The round icon on the left of these buttons sits in the part of the image that stretches, so a much shorter button would squash it.
  • padding (92, 26, 66, 24) keeps the text clear of the icon and the arrow. Left, top, right, bottom again. These are the kit's recommended text padding from atlas.json.
  • background is the idle look, and also the fallback for any state without its own line.
  • hover_background is the mouse-over look. The hover_ prefix also covers a selected button that is hovered, so a picked choice still lights up when you point at it.
  • selected_idle_background is the gold "picked before" look, only when the mouse is somewhere else.
  • insensitive_background is the locked look.

Then the sounds. hover_sound plays when a button gets focus and activate_sound plays on click. The test run used Ren'Py's dummy audio driver, so nothing was audible. Instead I logged every sound file Ren'Py sent to the audio driver during the GIF run. The hover sound fired each time the mouse landed on an unlocked button, the click fired on each pick, and the locked button got nothing at all, which is right, because you cannot hover a choice you are not allowed to have. The GIF itself is silent.

Keep the hover sound short and quiet. Players sweep the mouse up and down a menu while they decide, and a loud hover sound turns indecision into a drum solo.

7. Text that matches the state

# 6. Text colors per state. A locked choice fades, a hovered one warms up.
style cozy_choice_caption:
    size 28
    idle_color "#6a3e26"
    hover_color "#b04a5a"
    insensitive_color "#8f8578"

style cozy_choice_hint:
    size 18
    italic True
    color "#8f8578"
Enter fullscreen mode Exit fullscreen mode

The caption is cocoa brown when idle, rose when hovered, and a soft gray when locked. Text inside a button follows the button's state, so hover_color and insensitive_color work here without any extra code.

The hint is smaller, italic and always gray. It only ever appears on locked choices, so it never needs a hover color.

That is the whole file. Run the game, offer Biscuit a sardine, and watch the button go gold when the menu comes back.

Small things worth knowing

  • "Picked before" means ever. Ren'Py stores chosen in persistent data, not in the save, so a choice the player picked on a previous playthrough is still marked on the next one. That is great for route-heavy games ("you have tried this one") and confusing in a linear game. If you only want the gold look during the current loop, drop the selected line.
  • Testing locked choices. If a choice stays locked when it should not, the problem is almost always the condition, not the screen. Put "[trust]" in a line of dialogue for a minute and watch the number.
  • Different art sizes. If your buttons are a different size, change the four Frame numbers, ysize and padding together. Those three sets of numbers all describe the same picture.

Want the buttons without drawing them?

Cozy VN UI Essentials sample: the four standard choice button states, idle, hover, selected and disabled

The buttons in this post are the standard set from Cozy VN UI Essentials. Drawing four matching states that line up pixel for pixel is the fiddly part, and measuring the borders is the boring part. The kit has both done: 12 choice buttons in standard, rose and compact looks, each with idle, hover, selected and disabled states, plus nameplates, dialogue frames and affection meters in the same warm palette. Every PNG is transparent with no text baked in, and atlas.json lists the nine-slice borders and text padding for each piece, which is where the numbers in this post came from. The rose set is the same size, so trying it is a matter of changing four file names.

The hover bloop and the soft click are from Cozy UI Sound Kit, which has 120 short interface sounds as WAV and OGG, hovers and clicks included.

Biscuit still does not approve of you. That one is not in any kit.

Cozy VN UI Essentials on itch: https://angelofcuriosity.itch.io/cozy-vn-ui

Top comments (0)