TinyAdventure/ui/item_grid.gd

38 lines
901 B
GDScript

class_name ItemGrid
extends GridContainer
@export var slot_scene:PackedScene
@export var rows:int = 1
func displayStacks(item_stacks:Array[ItemStack]):
for child in get_children():
child.queue_free()
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)
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:
var slot:ItemSlot = slot_scene.instantiate()
add_child(slot)
slot.display(item, 1)
var item_count = rows * columns
while get_child_count() < item_count:
add_child(slot_scene.instantiate())