diff options
Diffstat (limited to 'src/ui.c')
| -rw-r--r-- | src/ui.c | 58 |
1 files changed, 52 insertions, 6 deletions
@@ -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; } } } |
