aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2026-01-10 10:25:32 +0000
committernathan <nathansmith@disroot.org>2026-01-10 10:25:32 +0000
commit013ac4a2f4ae24d71f425f31edd77a8e29ed1da8 (patch)
treedffc4b36c7c94a734940d0e3fac3536be99c2ad6 /src/ui.c
parent6e0fabd2798d7e602e243a35a922703cde7ef750 (diff)
downloadFindThings-013ac4a2f4ae24d71f425f31edd77a8e29ed1da8.tar.gz
FindThings-013ac4a2f4ae24d71f425f31edd77a8e29ed1da8.tar.bz2
FindThings-013ac4a2f4ae24d71f425f31edd77a8e29ed1da8.zip
Working on inventory
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/ui.c b/src/ui.c
index 66560bb..ac176b8 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -228,10 +228,19 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game)
}
}
+void resizeInventory(Inventory* inventory)
+{
+ inventory->rect.width = 300.0;
+ inventory->rect.height = 300.0;
+ inventory->rect.x = GetRenderWidth() / 2.0 - inventory->rect.width / 2.0;
+ inventory->rect.y = GetRenderHeight() / 2.0 - inventory->rect.height / 2.0;
+}
+
void initInventory(Inventory* inventory)
{
- inventory->visable = false;
- inventory->itemCount = 0;
+ resizeInventory(inventory);
+ inventory->visable = true;
+ inventory->itemCount = 40;
}
void showInventory(Inventory* inventory)
@@ -244,10 +253,67 @@ void hideInventory(Inventory* inventory)
inventory->visable = false;
}
-void addItemToInventory(Inventory* inventory, InventoryItem item)
+void addItemToInventory(Inventory* inventory, EntityItem item)
{
+ // If item is already in the inventory.
+ for (int index = 0; index < inventory->itemCount; ++index)
+ {
+ if (inventory->items[index].id == item.id)
+ {
+ inventory->items[index].count += item.count;
+ return;
+ }
+ }
+
+ // Add item to inventory.
+ if (inventory->itemCount >= INVENTORY_MAX)
+ {
+ TraceLog(LOG_ERROR, "inventory->itemCount >= INVENTORY_MAX");
+ }
+ else
+ {
+ inventory->items[inventory->itemCount] = item;
+ ++inventory->itemCount;
+ }
}
void updateInventory(Inventory* inventory)
{
+ if (IsWindowResized())
+ {
+ resizeInventory(inventory);
+ }
+
+ if (!inventory->visable)
+ {
+ return;
+ }
+
+ // Draw background.
+ int outlineThickness = 3;
+ DrawRectangleRec(inventory->rect, PINK);
+ DrawRectangleLinesEx(inventory->rect, outlineThickness, BLACK);
+
+ // Draw items.
+ int startX = inventory->rect.x + outlineThickness;
+ int startY = inventory->rect.y + outlineThickness;
+ int maxX = inventory->rect.width + inventory->rect.x - INVENTORY_SPRITE_SIZE;
+ int maxY = inventory->rect.height + inventory->rect.y -
+ INVENTORY_SPRITE_SIZE;
+ int x = startX;
+ int y = startY;
+
+ for (int index = 0; index < inventory->itemCount; ++index)
+ {
+ DrawRectangle(x, y, INVENTORY_SPRITE_SIZE, INVENTORY_SPRITE_SIZE, GRAY);
+ DrawText(TextFormat("%d\n", index), x, y, 16, BLACK);
+
+ x += INVENTORY_SPRITE_SIZE;
+
+ if (x >= maxX)
+ {
+ x = startX;
+ y += INVENTORY_SPRITE_SIZE;
+ }
+ }
}