TinyAdventure/ui/item_grid.gd

38 lines
901 B
GDScript
Raw Normal View History

2024-07-09 22:33:38 +02:00
class_name ItemGrid
extends GridContainer
@export var slot_scene:PackedScene
@export var rows:int = 1
2024-07-09 22:33:38 +02:00
func displayStacks(item_stacks:Array[ItemStack]):
2024-07-09 22:33:38 +02:00
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)
2024-07-09 22:33:38 +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)
slot.display(item, 1)
var item_count = rows * columns
while get_child_count() < item_count:
add_child(slot_scene.instantiate())