Search code examples
drag-and-dropparent-childgodotgdscript

Drag & Drop, dropping blocked by his children, how to avoid that?


Gonna try to be the more concise & clear possible.

Making a game, while I do use Drag & drop, wanna drop on a "panel", and add it to a list in that same panel. Well it already works actually. But not well.

The problem come that, I can only drop it on place where that "panel" doesn't have his children. So on empty place onto that panel. And I want it to be on the entire list, empty place or not.

So tried to do a children_has_point() to check while can_drop_data() is running, but seems the whole source of that problems is because can_drop_data() doesn't trigger if the draggable is over the childrens. So tried to try things with mouse_filter from the parent, and it doesn't seems to affect can_drop_data() neither.

So what can I do to fix/make it work the way I intend to ?

(By the way, I know that one of the solution would be to literraly create a Rect2 or something similar on top of that whole list panel to let know the can_drop_data() that it can be dropped on the whole list, but that seems more bothersome to do, trying to see if they aren't a better solution ?)

Well I hope this is not too messy and unclear question, prob not, but well I tried what I can. And this last line prob gonna get deleted too.


Solution

  • By the way, I know that one of the solution would be to literraly create a Rect2 or something similar on top of that whole list panel to let know the can_drop_data() that it can be dropped on the whole list

    Having a Control (e.g. a Panel) does not have to be much trouble, in particular: You do not have to create it on demand, instead you can having it always there, and bring it to top or push it to the bottom.


    I believe the issue is that children are taking mouse input. In this case it should be sufficient to set mouse_filter to MOUSE_FILTER_PASS (so if they don't handle the input it propagates to the parent) or to MOUSE_FILTER_IGNORE (so they don't take any mouse input).

    However, if always having that setting causes other problems, you would have to consider changing them in runtime. I'm going to suggest to add the Controls you need to modify in runtime to a node group, to make that code simpler.