Ren'Py Adapting the choice screen.

Ying Ko

Member
Jun 16, 2018
419
766
Code:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action


define config.narrator_menu = True


style choice_vbox is vbox
style choice_button is button
style choice_button_text is button_text

style choice_vbox:
    xalign 0.5
    ypos 405
    yanchor 0.5

    spacing gui.choice_spacing

style choice_button is default:
    properties gui.button_properties("choice_button")

style choice_button_text is default:
    properties gui.button_text_properties("choice_button")

This is the choice screen, from the screens.rpy, as provided by Ren’Py. I was wondering how it could be adapted it to provide, when hovered, an additional piece of information. I would like the information to not be displayed within the text button but rather elsewhere on the screen. The idea being when the user hovers their cursor over the choice they would be given additional insight into what they were choosing, but when they withdraw their cursor the additional information is removed. This information would, of course, be determined within the script.rpy, much like the i.caption and i.action. Thank you in advance.
 

drKlauz

Newbie
Jul 5, 2018
40
24
Something like
Code:
screen choice(items):
  style_prefix "choice"
  default current_hint=""
  text current_hint align(0.5,0.1)
  vbox:
    for choice in items:
      $hint,sep,caption=choice.caption.rpartition("|")
      textbutton caption:
        action [SetScreenVariable("current_hint",""),choice.action]
        hovered SetScreenVariable("current_hint",hint)
        unhovered SetScreenVariable("current_hint","")

label start:
  menu:
    "what next?"
    "shop choice hint|shop":
      menu:
        "what should i buy?"
        "clothes":
          "fits nice"
        "food":
          "yum-yum!"
    "rest choice hint|rest":
      "yawn"
  return
 
  • Like
Reactions: Ying Ko

Ying Ko

Member
Jun 16, 2018
419
766
Something like
Code:
screen choice(items):
  style_prefix "choice"
  default current_hint=""
  text current_hint align(0.5,0.1)
  vbox:
    for choice in items:
      $hint,sep,caption=choice.caption.rpartition("|")
      textbutton caption:
        action [SetScreenVariable("current_hint",""),choice.action]
        hovered SetScreenVariable("current_hint",hint)
        unhovered SetScreenVariable("current_hint","")

label start:
  menu:
    "what next?"
    "shop choice hint|shop":
      menu:
        "what should i buy?"
        "clothes":
          "fits nice"
        "food":
          "yum-yum!"
    "rest choice hint|rest":
      "yawn"
  return
Thank you again. It works like a charm.
 
  • Like
Reactions: drKlauz

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
The statement isnt' something static. Among other things it let you . And Ren'py already come with two way to deal with , so you don't need to create your own one.

Therefore, you don't need to over complicate your code, split strings and have a lot of properties for your buttons. Something like this is more than enough :
Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                if "hint" in i.kwargs:
                    tooltip i.kwargs["hint"]

    $ tt = GetTooltip()
    if tt:
        frame:
            xalign 0.5 yalign 0.0
            text tt

label start:
    menu:
        "some choice"( hint="with some hint" ):
            pass
        "other choice"( hint="with another hint" ):
            pass
        "no hint choice":
            pass

    "DONE"
    return
 

Ying Ko

Member
Jun 16, 2018
419
766
The statement isnt' something static. Among other things it let you . And Ren'py already come with two way to deal with , so you don't need to create your own one.

Therefore, you don't need to over complicate your code, split strings and have a lot of properties for your buttons. Something like this is more than enough :
Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                if "hint" in i.kwargs:
                    tooltip i.kwargs["hint"]

    $ tt = GetTooltip()
    if tt:
        frame:
            xalign 0.5 yalign 0.0
            text tt

label start:
    menu:
        "some choice"( hint="with some hint" ):
            pass
        "other choice"( hint="with another hint" ):
            pass
        "no hint choice":
            pass

    "DONE"
    return
Thank you, a little choice to muse over. I'll give the documentation a peruse, to see what Ren'Py comes with.