Snippets

SinnyStar [Ren'Py] Tooltip on hovered choice button

Created by Sinny Star
init python:
    # keys are the choice names
    # values are a 3-tuple of image, xpos, and ypos
    choice_map = {
        "To be" :
            ("images/to_be.png", 500, 100),
        "Not to be" :
            ("images/not_to_be.png", 600, 200)
    }

    # get the right tooltip values from the choice name
    def GetChoiceTooltip(choice = None):
        if choice in choice_map:
            return choice_map[choice]
        else:
            return None
           
init:
    # Slide transform for the tooltip
    transform trn_choicetooltip:
        on show:
            xalign 0.3 alpha 0.0
            easein 0.5 xalign 0.5 alpha 1.0
        on hide:
            xalign 0.5
            easeout 0.5 xalign 0.7 alpha 0.0

# Separate screen for the tooltip           
screen choice_tooltip(img, x, y):
    add img xpos x ypos y at trn_choicetooltip

# The main choice screen    
screen choice(items):

    default choiceTooltip = None

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5

        vbox:
            style "menu"
            spacing 2
            
            for caption, action, chosen in items:
            
                $ choiceTooltip = GetChoiceTooltip(caption)
            
                if action:

                    button:
                        action action
                        style "menu_choice_button"

                        text caption style "menu_choice"
                                              
                        if choiceTooltip is not None:
                            hovered ShowTransient("choice_tooltip", dissolve, choiceTooltip[0], choiceTooltip[1], choiceTooltip[2])
                            unhovered Hide("choice_tooltip", dissolve)

                else:
                    text caption style "menu_caption"
1
2
3
4
5
6
7
8
9
label start:
    "To be or not to be?"
    menu:
        "To be":  # will show an image
            "You chose 'to be'."
        "Not to be":  # will show an image
            "You chose 'not to be'."
        "That is the question":  # will not show an image
            "But I wanted the answer..."

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.