- Edited
I have a question about dragging and dropping for an inventory. If I have been using a panel as my inv_ui_slot that contains the item (Sprite2D) and want to communicate with my inventory every time I drag a slot to another slot it can run my swap function. Would I be able to use a built in dragging function like _get_drag_data etc. Or am I coming at this from a bad approach. Either way how would I go about implementing this.
My node structure looks like this for my Inv_UI_slot:
Panel -> sprite2D, CenterContainer -> panel -> sprite2D, label
This is my inv_ui_slot.gd script:
@onready var item_visual: Sprite2D = $CenterContainer/Panel/item_display
@onready var amount_text: Label = $CenterContainer/Panel/Label
# Function to update the visual representation of the inventory slot
func update(slot: InvSlot):
if !slot.item:
# Hide the visual if there's no item
item_visual.visible = false
amount_text.visible = false
else:
# Show the visual and update the texture if there's an item
item_visual.visible = true
item_visual.texture = slot.item.texture
amount_text.visible = true
amount_text.text = str(slot.amount)
func _get_drag_data(at_position):
var drag_slot = Panel.new()
set_drag_preview(drag_slot)
func _can_drop_data(at_position, data):
pass
func _drop_data(at_position, data):
pass