Show buttons when hovered over another button?

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
pokestat
Newbie
Posts: 6
Joined: Tue Dec 12, 2017 12:54 pm
Contact:

Show buttons when hovered over another button?

#1 Post by pokestat »

I have an imagebutton, and when I hover over it, I want the player to see two smaller imagebuttons appear on top. The player should be able to click on the smaller buttons while the mouse is still hovered over the larger imagebutton. When the mouse moves away from the larger imagebutton, the smaller imagebuttons should be hidden.

The button should look like this when I hover:
https://imgur.com/a/0YXJn

Here is my test code:

Code: Select all

screen inner_buttons():
    frame:
        xpos 100
        ypos 100
        xanchor 0
        yanchor 0
        vbox:
            imagebutton:
                idle "images/one.png"
                xpos 0
                ypos 0
                action tt.Action("one")
    
            imagebutton:
                idle "images/two.png"
                xpos 0
                ypos 150
                action tt.Action("two")

screen important_button():
    imagebutton:
        idle "images/smile.png"
        hovered ShowTransient("inner_buttons")
        unhovered Hide("inner_buttons")
        xpos 100
        ypos 100
        xanchor 0
        yanchor 0

    frame:
        vbox:
            text tt.value
            
init:
    default tt = Tooltip("No button selected.")

label start:
    call screen important_button

Basically, when I click on the smaller buttons, it updates the tooltip text.

But the result is just the larger button is shown, and any hover action does nothing:

https://imgur.com/a/kHVgr


What did I do wrong?
Attachments
on hover
on hover
button.png (10.96 KiB) Viewed 1153 times
the result I see
the result I see

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Show buttons when hovered over another button?

#2 Post by Alex »

Why do you use ShowTransient instead of Show?
https://www.renpy.org/doc/html/screen_actions.html#Show

pokestat
Newbie
Posts: 6
Joined: Tue Dec 12, 2017 12:54 pm
Contact:

Re: Show buttons when hovered over another button?

#3 Post by pokestat »

I switched to using Show() instead, but nothing still shows up. Am I using hover correctly? I'm thinking maybe that's not firing.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Show buttons when hovered over another button?

#4 Post by Alex »

Looks like when you hover over inner button, the important button looses focus and hides the screen - comment out unhovered action to test it.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Show buttons when hovered over another button?

#5 Post by Remix »

Though you will have to resolve the 'loses focus' issue pointed out by Alex (maybe by toggling a variable with a mousearea or button: container in the small button screen that mimics the main button action... you should also note:
A button without action or sensitive will by default be insensitive and thus not respond to events, so either 'action NullAction()' or 'sensitive True' in the main button...

I would use a variable toggle myself... (pseudo code to give idea - if they show and hide on each repeat hover, then expand to suit)

Code: Select all

default show_minis = False
screen main_button:
    imagebutton:
        hovered ToggleVariable( 'show_minis' )
        sensitive True
    if show_minis:
        use mini_buttons_screen
Frameworks & Scriptlets:

pokestat
Newbie
Posts: 6
Joined: Tue Dec 12, 2017 12:54 pm
Contact:

Re: Show buttons when hovered over another button?

#6 Post by pokestat »

Thanks Remix, that was the issue. Setting an action makes the hover events work. I also added a mousearea to resolve the focus issue, which works great!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], BadMustard