|
|
@ -6,6 +6,11 @@ extends Control |
|
|
|
@export var item_rect_scene: PackedScene |
|
|
|
@export var grid_container: GridContainer |
|
|
|
|
|
|
|
@export var highlight_theme: Resource |
|
|
|
|
|
|
|
var items: Array[Node] = [] |
|
|
|
var selected_item: int = 0 |
|
|
|
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void: |
|
|
|
if event.is_action_pressed("open_inventory"): |
|
|
@ -14,9 +19,15 @@ func _input(event: InputEvent) -> void: |
|
|
|
func _ready() -> void: |
|
|
|
InventoryManager.item_picked_up.connect(add_item) |
|
|
|
InventoryManager.item_dropped.connect(subtract_item) |
|
|
|
|
|
|
|
for item: InventoryItemRect in grid_container.get_children(): |
|
|
|
item.queue_free() |
|
|
|
|
|
|
|
for item_resource: DBItemResource in inventory_resource.inventory: |
|
|
|
add_item(item_resource) |
|
|
|
|
|
|
|
refresh_items() |
|
|
|
|
|
|
|
|
|
|
|
func add_item(item_resource: DBItemResource, amount: int = 1) -> void: |
|
|
|
var item_rect: InventoryItemRect = find_item_rect(item_resource) |
|
|
@ -29,8 +40,7 @@ func add_item(item_resource: DBItemResource, amount: int = 1) -> void: |
|
|
|
else: |
|
|
|
item_rect = item_rect_scene.instantiate() |
|
|
|
grid_container.add_child(item_rect) |
|
|
|
item_rect.item_resource = item_resource |
|
|
|
item_rect.update_rect() |
|
|
|
item_rect.init(item_resource, highlight_theme) |
|
|
|
|
|
|
|
func find_item_rect(item_resource: DBItemResource) -> InventoryItemRect: |
|
|
|
var rect: InventoryItemRect = null |
|
|
@ -56,6 +66,9 @@ func subtract_item(item_resource: DBItemResource) -> void: |
|
|
|
else: |
|
|
|
push_error("Attempting to subtract amount (" + str(item_resource.amount) + " from nonexistent inventory item (" + str(item_resource.name) + ")") |
|
|
|
|
|
|
|
func refresh_items() -> void: |
|
|
|
items = grid_container.get_children() |
|
|
|
|
|
|
|
func toggle_inventory() -> void: |
|
|
|
visible = not visible |
|
|
|
|
|
|
|