+1 vote

I have a "turn tracker", a list of icons representing all the units in play and their turn order. I want to allow the player to change the order by clicking on the icon of a friedly unit, and dragging it in another position in the queue, with some restrictions. However, I want the turn-tracker to update in real time:
* When you click and drag an icon across the tracker, its position updates accordingly.
* When you release the icon into a valid position, the change becomes permanent
* Releasing outside the tracker or right-clicking discards any changes.

My tree looks like this:

- HBoxContainer (Container for all unit icons)
    - PanelContainer (Unit)
        - TextureRect (Unit icon)
        - Other UI elements: name Label, health bar, etc
    - PanelContainer (Unit)
    - PanelContainer (Unit)
    - PanelContainer (Unit)

I'm aware of the built-in drag and drap functions (getdragdata, candragdata, drop_data) but I'm unsure how to implement the logic.

Godot version 3.3.4
in Engine by (194 points)
edited by

This is likely going to require a custom implementation from you. To my knowledge, the built in drag and drop functions operate similarly to dragging icons around your desktop (if it allowed for swapping). The "drag preview" that you can set only shows an icon by the mouse as you're dragging around the screen and isn't "aware" of other draggable data on screen like yours would need to be.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.