Browse Source

chore: Split toggle_inventory() for convenience

pull/24/head
Ryan Reed 3 weeks ago
parent
commit
fc46230dba
1 changed files with 19 additions and 12 deletions
  1. +19
    -12
      scenes/ui/inventory/inventory.gd

+ 19
- 12
scenes/ui/inventory/inventory.gd View File

@ -2,12 +2,12 @@ class_name Inventory
extends Control
@export var inventory_resource: InventoryResource
@export var item_rect_scene: PackedScene
@export var grid_container: GridContainer
@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
@export var highlight_theme: Resource ## The theme to apply on mouse_enter of the InventoryItemRect
var selected_item: int = 0
@ -52,16 +52,11 @@ func refresh_inventory_grid() -> void:
create_item_cell(null)
func toggle_inventory() -> void:
visible = not visible
if visible:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
InventoryManager.inventory_opened.emit()
get_tree().paused = true
_close_inventory()
else:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
InventoryManager.inventory_closed.emit()
get_tree().paused = false
_open_inventory()
## Add any items from the existing inventory resource
func update_inventory_with_resource() -> void:
@ -72,6 +67,18 @@ func update_inventory_with_resource() -> void:
InventoryManager.add_to_inventory.emit(item_resource.id, item_resource.amount)
func _close_inventory() -> void:
visible = false
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
InventoryManager.inventory_closed.emit()
func _open_inventory() -> void:
refresh_inventory_grid()
visible = true
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
InventoryManager.inventory_opened.emit()
func _on_item_added(_item_id: String, _amount: int) -> void:
refresh_inventory_grid()


Loading…
Cancel
Save