47 lines
974 B
GDScript
47 lines
974 B
GDScript
class_name FullInventoryMenu extends Panel
|
|
|
|
@export var itemLine:PackedScene = null;
|
|
@export var itemList:Control = null;
|
|
var inventory:Inventory = null;
|
|
|
|
func _ready() -> void:
|
|
hide()
|
|
|
|
_updateItemList()
|
|
|
|
func _exit_tree() -> void:
|
|
pass
|
|
|
|
func open(inventory:Inventory = null) -> void:
|
|
if self.inventory != null:
|
|
self.inventory.inventoryUpdated.disconnect(_updateItemList)
|
|
|
|
if inventory == null:
|
|
inventory = ITEM.PLAYER_INVENTORY;
|
|
|
|
self.inventory = inventory;
|
|
self.inventory.inventoryUpdated.connect(_updateItemList)
|
|
_updateItemList()
|
|
self.show()
|
|
|
|
func close() -> void:
|
|
self.hide()
|
|
|
|
func isOpen() -> bool:
|
|
return self.visible
|
|
|
|
func _updateItemList() -> void:
|
|
if inventory == null:
|
|
return
|
|
|
|
# Clear item list
|
|
while itemList.get_child_count() > 0:
|
|
var child = itemList.get_child(0)
|
|
itemList.remove_child(child)
|
|
child.queue_free()
|
|
|
|
for stack in inventory.contents:
|
|
var node = itemLine.instantiate()
|
|
node.setStack(stack)
|
|
itemList.add_child(node)
|