How can I make hover textbutton stay hovered until another textbutton is hovered over?

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
User avatar
mcload89
Newbie
Posts: 4
Joined: Sun May 26, 2024 4:09 pm
Contact:

How can I make hover textbutton stay hovered until another textbutton is hovered over?

#1 Post by mcload89 »

Hi there.

I'm trying to make a text button's background stay selected when hovered, and only change when another text button is hovered over, making it the new selected button. This should continue as the user moves between text buttons.

Here's an example so it's better to understand what i'm trying to achieve. https://i.imgur.com/Qwer6V5.gif

I managed to get the background on the textbutton using "style", any ideas how to achieve above mentioned effect?

User avatar
Andredron
Miko-Class Veteran
Posts: 738
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#2 Post by Andredron »

Code: Select all

screen hover_button():
    zorder 10

    imagebutton:
        idle "button_idle.png"
        hover "button_hover.png"
        selected_idle "button_selected.png"
        action Jump("label_name")

label start:
    show screen hover_button

User avatar
mcload89
Newbie
Posts: 4
Joined: Sun May 26, 2024 4:09 pm
Contact:

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#3 Post by mcload89 »

Andredron wrote: Mon May 27, 2024 1:44 am

Code: Select all

screen hover_button():
    zorder 10

    imagebutton:
        idle "button_idle.png"
        hover "button_hover.png"
        selected_idle "button_selected.png"
        action Jump("label_name")

label start:
    show screen hover_button
I'm sorry but this is not at all what i'm looking for.

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

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#4 Post by m_from_space »

mcload89 wrote: Sun May 26, 2024 4:23 pm I managed to get the background on the textbutton using "style", any ideas how to achieve above mentioned effect?
I mean I would just use a screen variable that remembers which button is currently prominent.

Code: Select all

screen myscreen():
    default active = None
    vbox:
        textbutton "Play":
            action NullAction()
            hovered SetScreenVariable("active", 0)
            if active == 0:
                background Solid("#f0f5")
        textbutton "Options":
            action NullAction()
            hovered SetScreenVariable("active", 1)
            if active == 1:
                background Solid("#f0f5")

User avatar
mcload89
Newbie
Posts: 4
Joined: Sun May 26, 2024 4:09 pm
Contact:

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#5 Post by mcload89 »

m_from_space wrote: Mon May 27, 2024 5:42 am
mcload89 wrote: Sun May 26, 2024 4:23 pm I managed to get the background on the textbutton using "style", any ideas how to achieve above mentioned effect?
I mean I would just use a screen variable that remembers which button is currently prominent.

Code: Select all

screen myscreen():
    default active = None
    vbox:
        textbutton "Play":
            action NullAction()
            hovered SetScreenVariable("active", 0)
            if active == 0:
                background Solid("#f0f5")
        textbutton "Options":
            action NullAction()
            hovered SetScreenVariable("active", 1)
            if active == 1:
                background Solid("#f0f5")
Thanks this seems to work great, is there a way i could make one of the buttons already "active" with the background without having to hover over it, but still hide, when hovered over a different button?

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

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#6 Post by m_from_space »

mcload89 wrote: Mon May 27, 2024 6:11 am Thanks this seems to work great, is there a way i could make one of the buttons already "active" with the background without having to hover over it, but still hide, when hovered over a different button?
Yeah, just set the screen variable to this button's "id" so to speak when initializing it.

Code: Select all

screen myscreen():
    # make the Play button hovered by default
    default active = 0
    ...

User avatar
mcload89
Newbie
Posts: 4
Joined: Sun May 26, 2024 4:09 pm
Contact:

Re: How can I make hover textbutton stay hovered until another textbutton is hovered over?

#7 Post by mcload89 »

m_from_space wrote: Mon May 27, 2024 1:01 pm
mcload89 wrote: Mon May 27, 2024 6:11 am Thanks this seems to work great, is there a way i could make one of the buttons already "active" with the background without having to hover over it, but still hide, when hovered over a different button?
Yeah, just set the screen variable to this button's "id" so to speak when initializing it.

Code: Select all

screen myscreen():
    # make the Play button hovered by default
    default active = 0
    ...
Worked great, appreciate your help man! All the best!

Post Reply

Who is online

Users browsing this forum: Ocelot, Semrush [Bot]