diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-19 13:26:41 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-19 13:26:41 +0000 |
| commit | 2a3922ecd4a975c84e7c6efb3b5f0fe182b99d20 (patch) | |
| tree | d25c35b6bf9c64db557e698a96171480bbbfdf2d | |
| parent | 8823db2da13322b006f36081901c48fe9419649c (diff) | |
| download | FindThings-2a3922ecd4a975c84e7c6efb3b5f0fe182b99d20.tar.gz FindThings-2a3922ecd4a975c84e7c6efb3b5f0fe182b99d20.tar.bz2 FindThings-2a3922ecd4a975c84e7c6efb3b5f0fe182b99d20.zip | |
Inventory selection and blinky
| -rw-r--r-- | src/settings.c | 1 | ||||
| -rw-r--r-- | src/settings.h | 1 | ||||
| -rw-r--r-- | src/ui.c | 58 | ||||
| -rw-r--r-- | src/ui.h | 4 |
4 files changed, 56 insertions, 8 deletions
diff --git a/src/settings.c b/src/settings.c index 14b9257..e4ddd5a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -44,6 +44,7 @@ Settings defaultSettings() .interactionChatHeight = 300.0, .interactionMenuWidth = 500.0, .interactionChatAnimationSpeed = 0.03, + .inventoryItemBlinkSpeed = 0.5, .mouseSpeed = 0.1, .forwardKey = KEY_W, .backwardKey = KEY_S, diff --git a/src/settings.h b/src/settings.h index 5d1b9c1..a094058 100644 --- a/src/settings.h +++ b/src/settings.h @@ -66,6 +66,7 @@ typedef struct { float interactionChatHeight; float interactionMenuWidth; float interactionChatAnimationSpeed; + float inventoryItemBlinkSpeed; // Controls. float mouseSpeed; @@ -230,7 +230,7 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game) void resizeInventory(Inventory* inventory, const Settings* settings) { - float outlineThickness = settings->uiOutlineSize * 2.0; + float outlineThickness = settings->uiOutlineSize; float spriteSize = INVENTORY_SPRITE_SIZE * INVENTORY_SCALE; inventory->rect.width = INVENTORY_COLUMNS * spriteSize + outlineThickness; inventory->rect.height = INVENTORY_ROWS * spriteSize + outlineThickness; @@ -244,14 +244,16 @@ void initInventory(Inventory* inventory, const Settings* settings) inventory->itemCount = 0; } -void showInventory(Inventory* inventory) +void showInventory(Inventory* inventory, Game* game) { inventory->visable = true; + enableGameCursor(game); } -void hideInventory(Inventory* inventory) +void hideInventory(Inventory* inventory, Game* game) { inventory->visable = false; + disableGameCursor(game); } void addItemToInventory(Inventory* inventory, InventoryItem item) @@ -288,7 +290,14 @@ void updateInventory(Inventory* inventory, Game* game) // Handle toggle key. if (IsKeyPressed(game->settings.toggleInventoryKey)) { - inventory->visable = !inventory->visable; + if (inventory->visable) + { + hideInventory(inventory, game); + } + else + { + showInventory(inventory, game); + } } if (!inventory->visable) @@ -303,7 +312,6 @@ void updateInventory(Inventory* inventory, Game* game) 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; @@ -313,12 +321,47 @@ void updateInventory(Inventory* inventory, Game* game) int y = startY; int fontSize = spriteSize / 3.0; + // Mouse stuff. + Vector2 mousePosition = GetMousePosition(); + int mouseRow = (mousePosition.y - inventory->rect.y) / spriteSize; + int mouseColumn = (mousePosition.x - inventory->rect.x) / spriteSize; + bool mouseIsSelecting = mouseRow >= 0 + && mouseRow < (inventory->rect.height / spriteSize) - 1 + && mouseColumn >= 0 + && mouseColumn < (inventory->rect.width / spriteSize) - 1; + + if (mouseIsSelecting) + { + // Draw selection + DrawRectangleLinesEx( + (Rectangle){ + mouseColumn * spriteSize + inventory->rect.x, + mouseRow * spriteSize + inventory->rect.y, + spriteSize, + spriteSize + }, + outlineThickness, + BLACK); + } + + int row = 0; + int column = 0; + + // Draw items. for (int index = 0; index < inventory->itemCount; ++index) { InventoryItem* item = &inventory->items[index]; + Color color = WHITE; + + // Make it blink when selected. + if (mouseIsSelecting && row == mouseRow && column == mouseColumn && + (int)(GetTime() / game->settings.inventoryItemBlinkSpeed) % 2 == 0) + { + color = RED; + } DrawTextureEx(game->assets.textures[item->textureId], (Vector2){x, y}, 0.0, - INVENTORY_SCALE, WHITE); + INVENTORY_SCALE, color); // Draw count. if (item->count > 1) @@ -327,11 +370,14 @@ void updateInventory(Inventory* inventory, Game* game) } x += spriteSize; + ++column; if (x >= maxX) { x = startX; y += spriteSize; + ++row; + column = 0; } } } @@ -71,8 +71,8 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game); // Inventory void initInventory(Inventory* inventory, const Settings* settings); -void showInventory(Inventory* inventory); -void hideInventory(Inventory* inventory); +void showInventory(Inventory* inventory, Game* game); +void hideInventory(Inventory* inventory, Game* game); void addItemToInventory(Inventory* inventory, InventoryItem item); void updateInventory(Inventory* inventory, Game* game); |
