TinyAdventure/ui/item_grid.gd

42 lines
1.0 KiB
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()
slot.set_drag_drop_flags(ItemSlot.ALLOW_DRAG | ItemSlot.ALLOW_DROP)
add_child(slot)
if item_stack != null:
slot.display(item_stack)
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)
var item_stack:ItemStack = ItemStack.new()
item_stack.item = item
item_stack.count = 1
slot.display(item_stack)
var item_count = rows * columns
while get_child_count() < item_count:
add_child(slot_scene.instantiate())