Browse Source

wip: Clear Inventory when InventoryManager.clear_inventory emitted

pull/24/head
Ryan Reed 3 weeks ago
parent
commit
2f1ce26bdc
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      scenes/ui/inventory/inventory.gd

+ 9
- 4
scenes/ui/inventory/inventory.gd View File

@ -5,12 +5,9 @@ extends Control
@export var inventory_resource: InventoryResource ## A starting inventory to initialize the inventory with
@export var item_rect_scene: PackedScene ## The scene to use for each individual item stack in the inventory
@export var grid_container: GridContainer ## Container for inventory items
@export var max_items: int = 40 # 4 rows of 10
@export var highlight_theme: Resource ## The theme to apply on mouse_enter of the InventoryItemRect
var selected_item: int = 0
func _input(event: InputEvent) -> void:
if event.is_action_pressed("open_inventory"):
@ -22,6 +19,7 @@ func _ready() -> void:
InventoryManager.item_added.connect(_on_item_added) # Should be added after update_inventory_with_resource()
InventoryManager.item_removed.connect(_on_item_removed) # Should be added after update_inventory_with_resource()
InventoryManager.clear_inventory.connect(_on_clear_inventory)
func create_item_cell(item_resource: DBItemResource) -> void:
@ -29,7 +27,7 @@ func create_item_cell(item_resource: DBItemResource) -> void:
grid_container.add_child(item_rect)
item_rect.init(item_resource, highlight_theme)
func find_item_rect(item_resource: DBItemResource) -> InventoryItemRect:
func find_item_cell(item_resource: DBItemResource) -> InventoryItemRect:
var rect: InventoryItemRect = null
for item_rect: InventoryItemRect in grid_container.get_children():
@ -79,6 +77,13 @@ func _open_inventory() -> void:
InventoryManager.inventory_opened.emit()
func _on_clear_inventory() -> void:
for item: InventoryItemRect in grid_container.get_children():
item.queue_free()
for _i: int in range(InventoryManager.max_inventory_items):
create_item_cell(null)
func _on_item_added(_item_id: String, _amount: int) -> void:
refresh_inventory_grid()


Loading…
Cancel
Save