2024-07-09 22:33:38 +02:00
|
|
|
class_name ItemGrid
|
|
|
|
extends GridContainer
|
|
|
|
|
|
|
|
@export var slot_scene:PackedScene
|
2024-09-06 12:34:18 +02:00
|
|
|
@export var rows:int = 1
|
2024-07-09 22:33:38 +02:00
|
|
|
|
2024-09-06 12:34:18 +02:00
|
|
|
func displayStacks(item_stacks:Array[ItemStack]):
|
2024-07-09 22:33:38 +02:00
|
|
|
for child in get_children():
|
|
|
|
child.queue_free()
|
2024-09-06 12:34:18 +02:00
|
|
|
child.get_parent().remove_child(child)
|
|
|
|
|
|
|
|
for item_stack in item_stacks:
|
|
|
|
var slot:ItemSlot = slot_scene.instantiate()
|
2024-09-08 10:54:39 +02:00
|
|
|
slot.set_drag_drop_flags(ItemSlot.ALLOW_DRAG | ItemSlot.ALLOW_DROP)
|
2024-09-06 12:34:18 +02:00
|
|
|
add_child(slot)
|
|
|
|
|
|
|
|
if item_stack != null:
|
2024-09-08 10:54:39 +02:00
|
|
|
slot.display(item_stack)
|
2024-07-09 22:33:38 +02:00
|
|
|
|
2024-09-06 12:34:18 +02:00
|
|
|
var item_count = rows * columns
|
|
|
|
|
|
|
|
while get_child_count() < item_count:
|
|
|
|
add_child(slot_scene.instantiate())
|
|
|
|
|
|
|
|
func display(item_stacks:Array[Item]):
|
|
|
|
for child in get_children():
|
|
|
|
child.queue_free()
|
|
|
|
child.get_parent().remove_child(child)
|
|
|
|
|
|
|
|
for item in item_stacks:
|
2024-07-09 22:33:38 +02:00
|
|
|
var slot:ItemSlot = slot_scene.instantiate()
|
|
|
|
add_child(slot)
|
2024-09-08 10:54:39 +02:00
|
|
|
var item_stack:ItemStack = ItemStack.new()
|
|
|
|
item_stack.item = item
|
|
|
|
item_stack.count = 1
|
|
|
|
slot.display(item_stack)
|
2024-09-06 12:34:18 +02:00
|
|
|
|
|
|
|
var item_count = rows * columns
|
|
|
|
|
|
|
|
while get_child_count() < item_count:
|
|
|
|
add_child(slot_scene.instantiate())
|