This commit is contained in:
Andriy Yednarovych
2026-02-22 19:26:26 +01:00
parent fd1ff19c4c
commit e877c5f058
211 changed files with 9385 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
class_name InventoryUi extends Control
const INVENTORY_SLOT = preload("res://gui/pause/inventory/inventory_slot.tscn")
@export var data: InventoryData
var focus_index := 1
func _ready() -> void:
PauseMenu.shown.connect(update)
PauseMenu.hidden.connect(clear)
clear()
data.changed.connect(on_inventory_changed)
func clear() -> void:
for child in get_children():
child.queue_free()
func update() -> void:
for slot in data.slots:
var new_slot = INVENTORY_SLOT.instantiate()
add_child(new_slot)
new_slot.slot_data = slot
new_slot.focus_entered.connect(on_item_focused)
if !data.slots.is_empty():
await get_tree().process_frame
get_child(focus_index).grab_focus()
func on_inventory_changed() -> void:
clear()
update()
func on_item_focused() -> void:
for child_index in get_child_count():
if get_child(child_index).has_focus():
focus_index = child_index
return