Skip to content

InventoryUI ​

Inherits: PanelUI < Control

Clean and Simple Universal Inventory UI - Refactored to extend PanelUI Updated to remove VENDOR_INVENTORY logic (now handled by dedicated VendorSlotUI)

Description ​

PLAYER_INVENTORY: Player's inventory

  • Drag & Drop: Move items around freely
  • Right-click: Use/Equip items (ItemInstance.use() handles everything)

EXTERNAL_INVENTORY: Loot containers, corpses, etc.

  • Drag & Drop: Move items in/out freely (loot <-> inventory)
  • Right-click: Auto-loot item to player inventory

PLAYER_VENDOR_INVENTORY: Player inventory in shop context

  • Right-click: Sell item to vendor (instead of use)
  • Shows vendor buy price in tooltips

READONLY: Display only, no interactions

  • No interactions allowed
  • Used for crafting material displays, quest rewards, etc.

Properties ​

InventoryContextcontextInventoryContext.PLAYER_INVENTORY
Stringtitle""
boolshow_currencytrue
boolallow_drag_and_droptrue
boolshow_kept_asidetrue
intgrid_columns4
PackedSceneinventory_slot_scene
PackedScenecurrency_display_scene

Variables ​

InventoryComponentinventory_data
Variantinventory_owner
VendorInventoryComponentvendor_data
Array[Control]slot_uis[]

Methods ​

voidinitialize_ui( system_hub: GameHost.SystemHub )
voidsetup_player_inventory( inventory: InventoryComponent, window_title: String = "" )
voidsetup_external_inventory( inventory: InventoryComponent, inv_owner: Variant, window_title: String = "" )
voidsetup_player_vendor_inventory( inventory: InventoryComponent, vendor: VendorInventoryComponent, window_title: String = "" )
InventoryContextget_context()
InventoryComponentget_inventory_data()
VendorInventoryComponentget_vendor_data()
Entityget_inventory_owner()
voidset_title( new_title: String )
voidrefresh()
voidcleanup()

Enumerations ​

enum InventoryContext ​

The options of inventory context: player inventory, external inventory, player vendor inventory, readonly.

  • PLAYER_INVENTORY = 0 - Player's main inventory
  • EXTERNAL_INVENTORY = 1 - Containers, loot, etc.
  • PLAYER_VENDOR_INVENTORY = 2 - Player inventory while in shop
  • READONLY = 3 - No interactions allowed

Constants ​

  • int GRID_CELL_SIZE = 44 - The size of one slot in pixels.

Property descriptions ​

InventoryContext context = InventoryContext.PLAYER_INVENTORY ​

Whose inventory the window shows (the player, a container, a vendor ...).

String title = "" ​

The title of the window.

bool show_currency = true ​

True shows the currencies.

bool allow_drag_and_drop = true ​

True lets the player drag items.

bool show_kept_aside = true ​

Lists the items that are kept aside (quest items that take no space) under the slots, as "Quest items". Off = the window does not show them at all (they stay in the bag)

int grid_columns = 4 ​

How many slots are in a row.

PackedScene inventory_slot_scene ​

The scene of one slot.

PackedScene currency_display_scene ​

The scene of one currency display.

Variable descriptions ​

InventoryComponent inventory_data ​

The inventory shown.

Variant inventory_owner ​

Who owns the inventory.

VendorInventoryComponent vendor_data ​

The stock of the vendor, when it shows one.

Array[Control] slot_uis = [] ​

The slots shown.

Method descriptions ​

void initialize_ui( system_hub: GameHost.SystemHub ) ​

Sets the part up with the hub of the game systems: connects the signals it listens to and fills it.

void setup_player_inventory( inventory: InventoryComponent, window_title: String = "" ) ​

Setup player inventory (normal or vendor context)

void setup_external_inventory( inventory: InventoryComponent, inv_owner: Variant, window_title: String = "" ) ​

Setup external inventory (containers, loot, etc.)

void setup_player_vendor_inventory( inventory: InventoryComponent, vendor: VendorInventoryComponent, window_title: String = "" ) ​

Setup player inventory in vendor context (for selling to vendor)

InventoryContext get_context() ​

Whose inventory the window shows.

InventoryComponent get_inventory_data() ​

The inventory shown.

VendorInventoryComponent get_vendor_data() ​

The stock of the vendor, when it shows one.

Entity get_inventory_owner() ​

Who owns the inventory.

void set_title( new_title: String ) ​

Sets the title of the window.

void refresh() ​

Fills the grid and the currencies again.

void cleanup() ​

Disconnects the inventory and clears the grid.