Game Inventory management UI

About Game Inventory System in SDL


Problem:

Every time I make a 2d game, I have to code up a custom inventory management UI in SDL or make up one with hard-coded data/positions etc..

Solution:

A single header library that I can pull into my CMake project that uses SDL2 that I can invoke as such:

CreateInventory(Path to SupportedItemData.json)

Supported Item Data is a json of the format: ItemName, MaxItemCount, ItemImagePng Callback to ClickHandlers

In the Game Loop, I drop in an inventory object Then I call inventoryItems.render() in the draw() call of the gameLoop. The interaction with the inventory class will be limited.

Implementation details:

SDL based Immediate mode UI Inventory: Font CreateInventory(ItemList<Item>) Render: Rectangle chrome Sub rectangles Textures within rectangles AddItem: RemoveItem: Collapse ClickCallbacks() -> User defined

Item: MaxCapacity, Image Texture

Read more
Filters

Recent Activity

Hour 17:

Final project upload:

  1. Inventory to map dragging works.
  2. Item counts go down.
  3. Dragging items around default color = red(should be green for a valid drop location but whatever).
  4. Can't drag and drop items with count = 0 or restricted items like the helm.

Progress Update

Now supports drag and drop of items across the map from the inventory. The inventory logic is all in a single class: Inventory.cpp.
A transparent sprite is drawn when a user clicks on an item and drags it across the map.
The sprite is colored red (for now) and when the click is released, the item is "dropped" onto the map.

Future Work:

Support dragging and dropping items into crafting slots in the inventory menu.