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()
|
|
|
|
add_child(slot)
|
|
|
|
|
|
|
|
if item_stack != null:
|
|
|
|
slot.display(item_stack.item, item_stack.count)
|
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-06 12:34:18 +02:00
|
|
|
slot.display(item, 1)
|
|
|
|
|
|
|
|
var item_count = rows * columns
|
|
|
|
|
|
|
|
while get_child_count() < item_count:
|
|
|
|
add_child(slot_scene.instantiate())
|