2 Commits

2 changed files with 19 additions and 20 deletions
Split View
  1. +0
    -8
      autoloads/inventory_manager.gd
  2. +19
    -12
      scenes/ui/inventory/inventory.gd

+ 0
- 8
autoloads/inventory_manager.gd View File

@ -30,14 +30,6 @@ func _ready() -> void:
self.remove_from_inventory.connect(_on_remove_from_inventory)
# TODO: REMOVE ME
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_up"):
add_to_inventory.emit("003", 1)
elif event.is_action_pressed("ui_down"):
remove_from_inventory.emit("003", 1)
func available_space(item_id: String) -> int:
var full_stacks: int = floor(_inventory_cache[item_id].total / DBItems.data[item_id].max_stack_size)
var space_in_stacks: int = (


+ 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