Working around the lack of a pressed button state?

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
trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Working around the lack of a pressed button state?

#1 Post by trailsiderice »

I've already mentioned in the renpy gripes thread that I'm frequently held back by the lack of a pressed state for buttons, since I often want to create a pressed state button animation or background image for a button when the button is pressed. But is there a way to work around it? I've searched around everywhere and found nothing, but I'm certain I can't be the *only* person who's ever wanted to make a fancy button pressed state.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Working around the lack of a pressed button state?

#2 Post by Imperf3kt »

selected_idle and selected_hover work for buttons that don't need to be held, maybe this?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#3 Post by trailsiderice »

Imperf3kt wrote: Sun Nov 12, 2023 4:25 am selected_idle and selected_hover work for buttons that don't need to be held, maybe this?
that's what everyone always suggests, and I don't understand why, because it's not an adequate solution by any means. if I want a button's pressed animation/background image to *only* play/show when the button is being held down, and not continue to show even when the button is not being held down, neither of these work, as far as I've been able to tell.

I've tried using those and cannot get them to work in the way that I want them to for this purpose.

If you have an idea for how I could get something like this to work properly, I'd love to hear it.

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#4 Post by trailsiderice »

And this is usually the point where the conversation about this topic dies. I've asked about this issue on reddit, on discord, and now here, and every time without fail, someone suggests "selected_hover", doesnt elaborate on how they intend that to work, and when I explain I've tried that already to little success, the thread dies.

Is that seriously it? Am I the only person on earth interested in finding a solution to this?

The closest I've ever come to finding a solution was one thread I found that very unhelpfully mentioned that renpy has the ability to detect mousedown on screens, but didnt explain how... I thought maybe if I set the selected condition of a button to mousedown, I could get it working, but the person who said this was possible didnt give any information on HOW, and I couldnt find anything anywhere else, including in the documentation.

This is all extremely frustrating. This is such a simple thing that I should be able to do. I am not willing to give up on this, but I need some help from literally anyone.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Working around the lack of a pressed button state?

#5 Post by Imperf3kt »

I don't know what else to say tbh.
Without further context about what you are trying to achieve, I can only guess at what might do what you want
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#6 Post by trailsiderice »

Imperf3kt wrote: Sun Nov 12, 2023 5:13 pm I don't know what else to say tbh.
Without further context about what you are trying to achieve, I can only guess at what might do what you want
I don't know what else I'm supposed to say to describe what I'm trying to achieve.

I want a button that, when pressed, changes its visual appearance in some way to indicate that it is being pressed down. Say, for example, making the button graphic slightly smaller to visually simulate being pressed down. When the mouse is released, I want the button's visual appearance to go back to how it was before, regardless of whether or not the button is still being hovered or not.

The reason I'm being kind of vague about the specific way I want the button to change on click is because I want to be able to vary the way it changes from button to button—say for example one button gets a little bit visually smaller while pressed, but another one turns green while clicked, and maybe in another instance I can have an imagebutton of a character sprite that winks while clicked. I want to be able to do this with both image and text buttons.

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#7 Post by trailsiderice »

I cannot in good faith believe that this is an issue nobody else in the world has any interest in solving.

I don't know what kind of context you want. I feel like I've explained myself pretty well. If there's something confusing about what I've said, please tell me and I'll try to clear it up.

I don't want this thread to die like every other thread I've made on this issue. I am very picky about my game's UI and this is something I'd really like to solve.

I don't need someone to write code for me, or come up with an answer. I just need to be pointed in the right direction, one that actually has a reasonable chance of working, unlike the selected hover solution.

Alternatively if someone can tell me if it's possible to assign the mousedown state to a variable (perhaps as a boolean? so that if mousedown is true, then the button state is selected), as well as HOW to do that, then maybe I can set the selected condition to that, and use the selected_hover solution.
Last edited by trailsiderice on Mon Nov 13, 2023 12:12 am, edited 1 time in total.

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#8 Post by trailsiderice »

the only way i can envision the selected_hover solution working is something like:

Code: Select all

textbutton ("Click here"):
	idle_background "idle_background.png"
	selected_hover_background "pressed_background.png"
	action NullAction()
	selected # some such variable that determines whether the left mouse is pressed
the problem being I don't know what variable I can use to determine what state the left mouse button is in.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2429
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Working around the lack of a pressed button state?

#9 Post by Ocelot »

So, you want something like that?
https://drive.google.com/file/d/1WNZ2vw ... drive_link

If so, here is the code I used. It is quick and dirty, and you will have to adapt it to your needs:

Code: Select all

default pressed = False

label after_load:
    $ pressed = False
    return

screen over():
    key "mousedown_1" capture False action SetVariable("pressed", True)
    key "mouseup_1"   capture False action SetVariable("pressed", False)

init python:
    config.overlay_screens.append("over")

screen button_test:
    vbox:
        button:
            selected pressed
            action NullAction()
            idle_child           Text("This button is: Not Pressed")
            hover_child          Text("This button is: Not Pressed")
            selected_hover_child Text("This button is: Pressed")
        null height 50
        if pressed:
            text "Left mouse button is: Pressed"
        else:
            text "Left mouse button is: Not Pressed"

label start:
    show screen button_test
    "" (advance=False)
    return
Another approach is to create a CDD which will listen for mouse events and set its child accordingly. Maybe even making it into custom Screen Language statement.
< < insert Rick Cook quote here > >

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#10 Post by trailsiderice »

Ocelot wrote: Mon Nov 13, 2023 2:42 am If so, here is the code I used. It is quick and dirty, and you will have to adapt it to your needs:

It seems simple enough, but I can't get it to work.

even copying your code near exactly doesn't work. It simply doesn't change the pressed variable when anything is clicked.

The only difference between your code and my code is that I'm trying to get it to work on a main menu screen, so I'm not calling it from inside a label. Does this not work on main menus? If not, it kind of defeats the reason I need it...


ah wait, scratch that, I had an idea: i added "use over" to the very end of my menu screen and it seems to be working properly now. I'm going to do a bit more testing with it, but this seems promising. Thank you very much for your help! It's really appreciated.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2429
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Working around the lack of a pressed button state?

#11 Post by Ocelot »

Ah, yes, overlay screens are only used in-game. config.always_shown_screens will be more appropriate for this if you want to use it menus too. Or do what you did and add keys directly to the screens that needs them.
< < insert Rick Cook quote here > >

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Working around the lack of a pressed button state?

#12 Post by trailsiderice »

Ocelot wrote: Mon Nov 13, 2023 4:43 am Ah, yes, overlay screens are only used in-game. config.always_shown_screens will be more appropriate for this if you want to use it menus too. Or do what you did and add keys directly to the screens that needs them.
Oh, that's good to know. That might be the better set up, since I'm sure at some point I'll forget to add "use over" somewhere when I need it, and then get confused as to why it isn't working. Thanks for letting me know about that!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]