[Solved] Something's odd with hover_alpha and tooltips

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
goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

[Solved] Something's odd with hover_alpha and tooltips

#1 Post by goldo »

Okay, i think I might be misunderstanding something but I can't make 'hover_alpha' work properly with tooltips in screens.

Whenever I have multiple elements using 'hover_alpha' and tooltip on the same screen, they all change alpha at the same time when hovering any one of them.

Here is an easy screen to reproduce it, using any picture as 'pic':

Code: Select all

screen hover_test:

    modal True

    frame align (0.5, 0.5):
        grid 5 1:
            for i in range(3):
                button action NullAction():
                    tooltip "Picture" # If you comment this line out, hover_alpha will work fine
                    add "pic" hover_alpha 1.0 idle_alpha 0.5 insensitive_alpha 0.2
            for t in ("Hello", "World"):
                textbutton t text_hover_underline True action NullAction() tooltip t
As you can see if you try it, all three image buttons change their alpha value simultaneously. It doesn't happen for text_hover_underline in the textbuttons, so it seems specific to hover_alpha.

If you remove the tooltip, hover_alpha works fine.

What am I missing? Thank you!
Last edited by goldo on Fri Mar 22, 2024 12:12 pm, edited 2 times in total.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Something's odd with hover_alpha and tooltips

#2 Post by jeffster »

I guess it's because you have three buttons inside of another button. And when your small buttons are hovered, that hover effect also goes to the large button. It's similar to how events are "bubbling" in HTML / CSS.

PS. I mean, I don't understand the whole process but that's a guess, off the top of my head.

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Something's odd with hover_alpha and tooltips

#3 Post by m_from_space »

goldo wrote: Thu Mar 07, 2024 8:46 am What am I missing? Thank you!
I must say that I've never seen a statement like "hover_alpha" before, and therefore I am surprised it even works. But the usual way would be something like this:

Code: Select all

image mybutton_idle:
    "pic"
    alpha 0.5

image mybutton_hover:
    "pic"

image mybutton_insensitive:
    "pic"
    alpha 0.2

screen hover_test():
    grid 3 1:
        for i in range(3):
            imagebutton auto "mybutton_%s":
                action NullAction()
                tooltip "Picture"
On the other hand, your outer button (which is weird in my opinion) doesn't have a defined action - not even a NullAction() - this shouldn't make it receive any events, since it is considered insensitive. But even when removing your outer button, your method doesn't quite work well. I would avoid this "hover_alpha" method.

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Something's odd with hover_alpha and tooltips

#4 Post by goldo »

Sorry about the nested button, but you can see the exact same behavior if you replace the parent button with a frame (I updated the code above).

m_from_space's solution works, however having to define three images for each picture is going to be a pain (as I have a couple hundreds of such images). Like I'd have an inventory full of items, and each item is supposed to light up when it is hovered.

Is there a solution that would work for heavier duty?

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Something's odd with hover_alpha and tooltips

#5 Post by jeffster »

goldo wrote: Fri Mar 08, 2024 10:09 am Sorry about the nested button, but you can see the exact same behavior if you replace the parent button with a frame (I updated the code above).
I checked it and it looks like hovering 2nd or 3rd button also causes 1st button become hovered.
Then of course unhovering 2nd or 3rd button does not make the 1st button unhovered.
It must be a bug, and you are welcome to report it at the bug tracker:
https://github.com/renpy/renpy/issues
m_from_space's solution works, however having to define three images for each picture is going to be a pain (as I have a couple hundreds of such images). Like I'd have an inventory full of items, and each item is supposed to light up when it is hovered.

Is there a solution that would work for heavier duty?
There are actions for "hovered" and "unhovered"
https://renpy.org/doc/html/screens.html#button

and we can use them to set some screen variable, used as the button's alpha value.

Here's one way (not sure if it's the most elegant solution, but it should work).

Code: Select all

screen hover_test:
    default unhovers = [0.5, 0.5, 0.5]
    default hovers = [[1.0, 0.5, 0.5], [0.5, 1.0, 0.5], [0.5, 0.5, 1.0]]
    default alphas = unhovers
    modal True
    frame align (0.5, 0.5):
        hbox:
            for i in range(3):
                button action NullAction():
                    tooltip "Picture"
                    add "pic" alpha alphas[i]
                    hovered SetScreenVariable("alphas", hovers[i])
                    unhovered SetScreenVariable("alphas", unhovers)

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Something's odd with hover_alpha and tooltips

#6 Post by goldo »

Thank you! This set me in the right direction.

Here is what I ended up implementing:

Code: Select all

screen hover():

    modal True

    default alpha_unhover = 0.6
    default alpha_hover = 1.0
    default alpha_dict = {k: 0.6 for k in button_list}

    for but in button_list:
         button background None action NullAction():
              hovered SetDict(alpha_dict, but, alpha_hover)
              unhovered SetDict(alpha_dict, but, alpha_unhover)
              add img alpha alpha_dict[but]
And it works without glitches! Marking the topic as solved, thank you.

Post Reply

Who is online

Users browsing this forum: Lucyper, Majestic-12 [Bot]