Skip to content

Containers & Chests

Creating an interactive container (like a chest) in v2.0 is handled entirely by the UIStateManager. You no longer need to manually toggle visibility or manage mouse states.

Step-by-Step Setup

1. Physical Container & Inventory

  1. Create a StaticBody3D or RigidBody3D for your chest.
  2. Add an InventoryComponent as a child. Set the Capacity.

2. Create the Chest UI Scene

  1. Create a new Scene.
  2. Add a ModularInventoryPanel (or use SlotGrid + InventoryBinder).
  3. Save this scene.

3. Interaction Logic

When the player presses "E", use the UIStateManager to open both the player and chest inventories.

@export var player_ui_scene: PackedScene
@export var chest_ui_scene: PackedScene
@export var player_inv: InventoryComponent
@export var chest_inv: InventoryComponent

func open_chest():
    # 1. Open Player Inventory (Role: "player" -> anchors to the right)
    UIStateManager.open_panel(
        player_ui_scene,
        player_inv.inventory,
        "Inventory",
        "player"
    )

    # 2. Open Chest Inventory (Role: "container" -> anchors to the left)
    UIStateManager.open_panel(
        chest_ui_scene,
        chest_inv.inventory,
        "Chest",
        "container"
    )
The UIStateManager automatically: - Calls InputMode.ui() to show the mouse cursor. - Adds a dark background overlay. - Tells UICoordinator to position them side-by-side.

4. Closing the Container

To close the container, simply call close_all().

func close_chest():
    UIStateManager.close_all()
The UIStateManager automatically: - Frees the UI panels. - Calls InputMode.game() to capture the mouse. - Removes the background overlay.

Quick Moving Items

Because both panels are registered with the UIStateManager, players can now Shift+Click items to instantly transfer them between the chest and their inventory!