Add a "clicked" signal to Card3D.#21
Conversation
…te examples to work with the clicked event.
|
Welcome back @camperotactico Thanks again for your great insight. I have some feedback on the change you've suggested. I understand the issue you're running into and recognize the strange single click behavior. I don't know if the timer implementation works well with the current state of things in the library.
Recording.2025-10-01.234304.mp4You're on the right track. I think the problem is in the interaction between It currently behaves like this:
This causes the behavior you showed in the video because it starts a drag event, and recognizes your mouse position is in a place where it should swap cards. I think a proper solution could look something like one of these approaches
That could give a better control of receiving click events and when to start dragging or to ignore it for a click. And we wouldn't need to rely on a timer to delay action. let me know what you think. |
|
Hello Tyson, thanks for the elaborate response. I hadn't realised of the issues my changes brought to the project. It is a good thing you gave the branch a try. I am going to revert the changes, take a different a different approach following your suggestion and update the PR as soon as I can. I will get back at you if I find any issue with the new approach. |
|
Hey, I have done some thinking and I At the moment, 'card_collection_3d.gd` emits a "card_selected()" signal when a card is just pressed and then "card_clicked()" when the card is released. I believe the naming for this last signal is problematic and should be refactored to "card_deselected()" as it is closer to what it really does: Every time a card is dragged around within its collection (to rearrange the cards, for example) the signal is emitted while I would expect that signal to only be emitted when the card is pressed and released without dragging it around. The card collection really isn't handling any click logic, and I am not sure the drag controller should either, as it would make it have two responsibilities. Perhaps we could just refactor that signal and then come up with a new class like "CardClickHandler" that could, optionally, be added to the scene and would check for both CardCollection and DragController signals and determine when cards are clicked. What do you think? |
|
Yes, I think what you described about the events selecting and deselecting is appropriate. That would make the card collection a bit more cohesive. It doesn't make sense to emit a I like the idea of However, CardCollection is not listening for mouse move events currently. I haven't thought about exactly what it might look like yet. But, I'm open to either idea. 😄 |
|
Great, I will update the signal name for the time being. As for I noticed every element on this asset use mouse inputs. I understand this is so that |
|
for what it's worth I don't think we'd necessarily need to implement the "selecting on click" option now. I was thinking it could be a possibility in the future. About adding input to a separate script or resource, I haven't thought much about what that could look like. If you have a concrete idea of what you're thinking of I'd be happy to hear. I'm still a Godot novice ha. But generally I am happy with the current state of event handling as I think they all have separate concerns.
This more or less matches the pattern we'd see in Godot where |
…signal' into add-card3d-clicked-signal
…ing mouse button inputs.
|
Forget what I suggested about the inputs, I didn't had the code in front of me and I was writing from memory so I got confused about what parts of the code where doing what. I have just pushed some commits that: I still haven't add the On a different note, I realised the DragController listens to InputMouseButton events to stop the drag, but since the CardCollection3D has a However, when I tried that, I noticed Card3D was not sending a mouse_up signal the moment it was moved around the screen. After some research, I learnt that enabling This resulted in a more clean solution, where the mouse_up and mouse_down events were being sent from the Card -> Collection -> DragController. I reverted this change because then I found a weird bug which I couldn't properly trace: When I dragged a card outside the game window, only from the bottom of it, the card wouldn't send the I spent a bit of time trying to figure out what was causing it, but after a while I gave up. I wrote all of this in case you want to replicate the issue and hopefully can figure out what I was missing. I will work on the |
|
This is looking pretty good. The behavior is very clean now. I recall running into the same issue of missing signals when moving the mouse off screen while dragging. And to be honest I assumed it was a godot bug, because I saw the behavior was different an OSX and Windows. Or maybe it's entirely platform dependant? 🤷♂️ So I settled on listening for the mouse up event like it is currently. I do want to look at the changes a bit more thoroughly because I have noticed a few times where card collections are stuck in the "drop preview" mode. It doesn't happen often and maybe a preexisting problem, but I have only just noticed it with this change. I did take the liberty of upgrading to godot 4.5 on the main branch to reduce some of the clutter on this MR. Do you mind rebasing so this MR is can be strictly just the fix of the "clicked" signals. apart from the godot 4.5 upgrade changes the "imported_formats" were changed on many of the imported textures. like I'm not familiar with the difference. Was this an intentional commit? I tried looking up the difference and am still not sure which option is better. |
|
Hello, I just rebased this branch with your latest version of main. I see now that the changes in the texture imports here are not the same as in main. I haven't modified the import settings on purpose, it happens automatically every time I open the project. I am working on a Linux ARM64 machine, so I wonder if that is triggering the editor to reimport the textures? I am going to look for more information online to see if someone else is having the same issue. For the time being, I can revert those changes if you rather not modify them. I will look into the dragging out of the screen bug. If I am able to replicate the issue on an empty project I will report a bug to the Godot engine. |
|
ok cool. If there's a good reason to update the texture stuff that can be a separate pull request |
|
Hello again, I just pushed a new commit that addresses the feedback you left + removes the texture import changes. If everything is right, please do not merge yet as I still have to work on the click feature. |
I forgot to mention this, but I created an issue in the Godot engine for this particular problem: 111410, and today it got marked as a bug. |
…e example to allow click functionality.
|
Hello again @tdecker91 I just pushed a commit that includes a In short, what now happens is that the Ideally, the variable should be set to |
|
Looks great, thanks for doing this 👍 |
Hello again,
In a project I am working on using this asset I noticed it was difficult to read the text on certain cards. Because of that, I started working on a "pop up" window that displays all the details of the card. To show the window, the player has to tap on a card.
I noticed
CardCollection3Dalready has a "card_clicked(card)" method, however I couldn't trigger a "tapping" or "clicking" action nicely without also triggering the "selection" on theDragController. This makes it so tapping on a card near the edge of a collection creates this card switching side-effect:cards-switching-when-clicking-them.mp4
What this PR aims to do is solve this issue without modifying too much of the existing code:
Card3Dnow includes a "click_threshold" timer and a "card3d_clicked" signal:As it can be seen in the video below, the cards can now be clicked without causing the switching effect, and they can also be dragged as usual.
cards-not-swithcing-after-the-change.mp4
Let me know what do you think about this change and if you have any suggestion.