diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-11 13:13:36 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-11 13:13:36 +0000 |
| commit | e853966be38ae6c5319df137c3b04a86e52b562b (patch) | |
| tree | 76a7b271ac1795098ebb8d797a523fbcbfc54080 /src/ui.c | |
| parent | 013ac4a2f4ae24d71f425f31edd77a8e29ed1da8 (diff) | |
| download | FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.tar.gz FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.tar.bz2 FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.zip | |
Diffstat (limited to 'src/ui.c')
| -rw-r--r-- | src/ui.c | 68 |
1 files changed, 43 insertions, 25 deletions
@@ -83,10 +83,10 @@ void updateInteractionChat(InteractionChat* chat, Game* game) } Color background = DARKGRAY; - background.a = game->settings.interactionAlpha; + background.a = game->settings.uiAlpha; DrawRectangleRec(chat->rect, background); - float lineThickness = game->settings.interactionOutlineSize; + float lineThickness = game->settings.uiOutlineSize; float border = lineThickness + 1.0; int fontSize = game->settings.interactionFontSize; @@ -134,7 +134,7 @@ void resizeInteractionMenu(InteractionMenu* menu, const Settings* settings) settings->interactionFontSize; menu->rect.x = 0.0; menu->rect.y = GetRenderHeight() - settings->interactionChatHeight - - menu->rect.height - settings->interactionOutlineSize; + menu->rect.height - settings->uiOutlineSize; } void initInteractionMenu(InteractionMenu* menu, const Settings* settings) @@ -198,10 +198,10 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game) // Draw background. Color background = DARKGRAY; - background.a = game->settings.interactionAlpha; + background.a = game->settings.uiAlpha; DrawRectangleRec(menu->rect, background); - float lineThickness = game->settings.interactionOutlineSize; + float lineThickness = game->settings.uiOutlineSize; float border = lineThickness + 1.0; int fontSize = game->settings.interactionFontSize; @@ -228,19 +228,20 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game) } } -void resizeInventory(Inventory* inventory) +void resizeInventory(Inventory* inventory, const Settings* settings) { - inventory->rect.width = 300.0; - inventory->rect.height = 300.0; + float outlineThickness = settings->uiOutlineSize * 2.0; + float spriteSize = INVENTORY_SPRITE_SIZE * INVENTORY_SCALE; + inventory->rect.width = INVENTORY_COLUMNS * spriteSize + outlineThickness; + inventory->rect.height = INVENTORY_ROWS * spriteSize + outlineThickness; 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) +void initInventory(Inventory* inventory, const Settings* settings) { - resizeInventory(inventory); - inventory->visable = true; - inventory->itemCount = 40; + resizeInventory(inventory, settings); + inventory->visable = false; + inventory->itemCount = 0; } void showInventory(Inventory* inventory) @@ -253,7 +254,7 @@ void hideInventory(Inventory* inventory) inventory->visable = false; } -void addItemToInventory(Inventory* inventory, EntityItem item) +void addItemToInventory(Inventory* inventory, InventoryItem item) { // If item is already in the inventory. for (int index = 0; index < inventory->itemCount; ++index) @@ -277,11 +278,17 @@ void addItemToInventory(Inventory* inventory, EntityItem item) } } -void updateInventory(Inventory* inventory) +void updateInventory(Inventory* inventory, Game* game) { if (IsWindowResized()) { - resizeInventory(inventory); + resizeInventory(inventory, &game->settings); + } + + // Handle toggle key. + if (IsKeyPressed(game->settings.toggleInventoryKey)) + { + inventory->visable = !inventory->visable; } if (!inventory->visable) @@ -290,30 +297,41 @@ void updateInventory(Inventory* inventory) } // Draw background. - int outlineThickness = 3; - DrawRectangleRec(inventory->rect, PINK); + float outlineThickness = game->settings.uiOutlineSize; + Color backgroundColor = PINK; + backgroundColor.a = game->settings.uiAlpha; + DrawRectangleRec(inventory->rect, backgroundColor); DrawRectangleLinesEx(inventory->rect, outlineThickness, BLACK); // Draw items. + float spriteSize = INVENTORY_SPRITE_SIZE * INVENTORY_SCALE; 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 maxX = inventory->rect.width + inventory->rect.x - spriteSize; + int maxY = inventory->rect.height + inventory->rect.y - spriteSize; int x = startX; int y = startY; + int fontSize = spriteSize / 3.0; 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); + InventoryItem* item = &inventory->items[index]; + + DrawTextureEx(game->assets.textures[item->textureId], (Vector2){x, y}, 0.0, + INVENTORY_SCALE, WHITE); + + // Draw count. + if (item->count > 1) + { + DrawText(TextFormat("%d", item->count), x, y, fontSize, BLACK); + } - x += INVENTORY_SPRITE_SIZE; + x += spriteSize; if (x >= maxX) { x = startX; - y += INVENTORY_SPRITE_SIZE; + y += spriteSize; } } } |
