GDevelop-extensions icon indicating copy to clipboard operation
GDevelop-extensions copied to clipboard

New extension: OnPressDetector

Open github-actions[bot] opened this issue 2 years ago • 7 comments

Description

This extension adds the ability to detect Mouse 'On Click' and Keyboard 'On Press' conditions, so that events will only run when the key/button were just pressed, rather than held down.

Useful so that holding down the mouse button and moving over a button does not trigger the button being activated.

How to use the extension

Put either the 'Detect Mouse On Click Event' or 'Detect Keyboard On Press Event' as conditions for any events that need to be triggered immediately on a mouse press / keyboard button click, and not trigger if mouse or keyboard buttons are being held thereafter.

For example, to make sure a button is only triggered when it is clicked and not when the mouse button is held down and dragged over it, create the following event:

Conditions:

  • Mouse Button Left 'OnClick' Detected
  • The cursor/touch is on 'Button'

Events:

  • Trigger any relevant button events

Checklist

  • [X] I've followed all of the best practices.
  • [X] I confirm that this extension can be integrated to this GitHub repository, distributed and MIT licensed.
  • [X] I am aware that the extension may be updated by anyone, and do not need my explicit consent to do so.

What tier of review do you aim for your extension?

Reviewed

Example file

OnClickDetectorExample.zip

Extension file

OnPressDetector.zip

github-actions[bot] avatar Aug 04 '22 19:08 github-actions[bot]

Hello @Kapusta-dev 👋 that's a cool extension :) i noticed few things in the extension that require a lil fix:

• Rather than using timers, you can use a better and stable way, which is (Boolean variable) here is an edited events of your example showing how to do it : 11111

• Short description should be shorter than what you have currently.

• Long description shouldn't have the same short description sentence, unless you want that.

Honestly, the extension can be done using a Boolean variable as i showed above, so currently its very basic and simple and unlikely to get merged into GDevelop Reviewed extensions, But it can be added in the community extensions if you still want it in :3

Thanks for submitting the extension 💖 would love to see more extensions from you as well 😉

VegeTato avatar Aug 09 '22 21:08 VegeTato

Hey @VegeTato Thanks for the information! I'll have to edit the short and long descriptions per your suggestions.

The button example provided was just a quick way to demonstrate the ease of use for the extension, and a situation where it would come in handy. Here is another example, where the boolean method isn't so straightforward / easy to implement: image

With the existing mouse events it will cycle through all the colors at once. With this extension it will cycle through each color per click.

As I'm using my extension more though I'm finding a few gotchas here and there (i.e. in certain cases the event must be called/exist on event where the parent is not shared, otherwise it does not run the mouse release timer. It must also be the first condition in the block) so perhaps it's not suited yet to be added officially and definitely needs some more work on it.

I'll have to keep poking at it - I think GDevelop would definitely benefit from an easy and straightforward 'mouse on click' event.

Thanks again!

Kapusta-dev avatar Aug 10 '22 04:08 Kapusta-dev

Thank you for submitting an extension.

Do you know about this other submission?

  • https://github.com/GDevelopApp/GDevelop-extensions/pull/495

I think it may answer the same kind of issues.

D8H avatar Aug 10 '22 08:08 D8H

Thanks D8H, that's a great extension and definitely solves the issue for buttons.

Per my second example in the comment above the goal for the extension was to also solve general mouse 'on click' detection for instances where you're not interacting with a button directly. I'll edit the description to reflect that, I think I focused too much on the button example. :)

Kapusta-dev avatar Aug 10 '22 13:08 Kapusta-dev

ok, I guess the logic would be very similar to the "Double-click" extension. It could be interesting to see if they used the same logic.

I can't think of any UI that does something different for a mouse button release and a pressed + release in a short amount of time. Can you give some examples?

D8H avatar Aug 10 '22 14:08 D8H

Quickly looked at the double click extension and it does seem like they use timers for the delay between clicks, and variables to count the number of clicks within the 'max delay' time.

This extension wouldn't necessarily have to be for UI, I'd apply it to any instance where I want something to happen when the user clicks the mouse, and not wait for the release to happen. Holding the mouse would evaluate to 'true' too many times.

Here is a simple state machine example: image

This immediately jumps to green no matter which order you put the events in. I could re-structure it so to achieve the desired outcome: image

But that's not optimal when you're trying to keep track of states over a large project. I'd want the conditions to be under each state.

Here is the same first block with the extension: image

Each click goes through the states, first changing to red, and then on the second click changing to green. Still not ideal because you have to order the events in reverse, else they will all trigger, but hopefully gets the idea across.

I personally used this extension to create a visual novel game for the latest GDevelop game jam. I was using the boolean method that VegeTato described to keep track of mouse clicks and only advance text on the first click (So if they hold the mouse button down it won't just keep advancing the text, they would have to click again) but that was a bit cumbersome having to check for the boolean every time I have a mouse click condition, therefore I created this extension and thought it might be useful for others.

As mentioned though, there's a lot of edge cases with it right now, so I wouldn't want it added officially just yet, I'll need to keep working on it, or hopefully an official implementation at some point. Not sure what the rules are for mentioning other engines, but there are a few that have 'on-click' conditions which comes in handy a lot.

Kapusta-dev avatar Aug 10 '22 15:08 Kapusta-dev

As mentioned though, there's a lot of edge cases with it right now, so I wouldn't want it added officially just yet, I'll need to keep working on it, or hopefully an official implementation at some point.

ok

Not sure what the rules are for mentioning other engines, but there are a few that have 'on-click' conditions which comes in handy a lot.

No engine is Voldemort here. You can speak freely of Construct, ClickTeam, Godot or anything else 😄

D8H avatar Aug 10 '22 16:08 D8H