diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-22 02:43:07 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-22 02:43:07 +0000 |
| commit | dabcd8342e77d4bfac4f7bc5cee8643121d379f7 (patch) | |
| tree | 1579174ab37568d269aacef5788a1baf042ac9d0 | |
| parent | 2254600c6dfb50333327ddb94457427596b51807 (diff) | |
| download | FindThings-dabcd8342e77d4bfac4f7bc5cee8643121d379f7.tar.gz FindThings-dabcd8342e77d4bfac4f7bc5cee8643121d379f7.tar.bz2 FindThings-dabcd8342e77d4bfac4f7bc5cee8643121d379f7.zip | |
Interaction menu going well
| -rw-r--r-- | src/entities/ron.c | 28 | ||||
| -rw-r--r-- | src/entities/ron.h | 2 | ||||
| -rw-r--r-- | src/entity.c | 2 | ||||
| -rw-r--r-- | src/settings.c | 1 | ||||
| -rw-r--r-- | src/settings.h | 1 | ||||
| -rw-r--r-- | src/ui.c | 53 | ||||
| -rw-r--r-- | src/ui.h | 10 |
7 files changed, 88 insertions, 9 deletions
diff --git a/src/entities/ron.c b/src/entities/ron.c index bd32e6a..834c119 100644 --- a/src/entities/ron.c +++ b/src/entities/ron.c @@ -1,4 +1,5 @@ #include "ron.h" +#include "ui.h" void initRon(Entity* entity) { @@ -14,3 +15,30 @@ void updateRon(Entity* entity, Game* game) { DrawModel(game->assets.models[RON_MODEL], entity->position, 1.0, WHITE); } + +InteractionCommand interactWithRon(Entity* entity, Game* game, + Selection selection) +{ + InteractionMenu* menu = &game->interactionMenu; + + const InteractionItems items = { + "test 1", + "test 2", + "test 3", + "test 4", + "test 5", + "test 6", + "test 7", + "test 8", + "test 9" + }; + + switch (selection) + { + case SELECTION_INTERACT: + setInteractionMenu(menu, items, 9); + return INTERACTION_SHOW_MENU; + default: + return INTERACTION_END; + } +} diff --git a/src/entities/ron.h b/src/entities/ron.h index 10858c1..ed0dbd2 100644 --- a/src/entities/ron.h +++ b/src/entities/ron.h @@ -7,6 +7,8 @@ void initRon(Entity* entity); void updateRon(Entity* entity, Game* game); +InteractionCommand interactWithRon(Entity* entity, Game* game, + Selection selection); #endif diff --git a/src/entity.c b/src/entity.c index df14f34..ea9c66c 100644 --- a/src/entity.c +++ b/src/entity.c @@ -23,7 +23,7 @@ const EntityEntry entityEntries[ENTITY_COUNT] = { (EntityEntry){"Medical Trash", initMedicalTrash, updateMedicalTrash, NULL, NULL, false, true}, (EntityEntry){"John", initJohn, updateJohn, NULL, NULL, false, true}, - (EntityEntry){"Ron", initRon, updateRon, NULL, NULL, false, true} + (EntityEntry){"Ron", initRon, updateRon, NULL, interactWithRon, false, true} }; Entity createEntity(EntityId id, Vector3 position) diff --git a/src/settings.c b/src/settings.c index 81a5aba..6a4d76a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -34,6 +34,7 @@ Settings defaultSettings() .interactionAlpha = (unsigned char)255.0 * 0.9, .interactionOutlineSize = 2.0, .interactionChatHeight = 300.0, + .interactionMenuWidth = 500.0, .mouseSpeed = 0.1, .forwardKey = KEY_W, .backwardKey = KEY_S, diff --git a/src/settings.h b/src/settings.h index 53972d3..188e447 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,6 +54,7 @@ typedef struct { unsigned char interactionAlpha; float interactionOutlineSize; float interactionChatHeight; + float interactionMenuWidth; // Controls. float mouseSpeed; @@ -96,12 +96,11 @@ void updateInteractionChat(InteractionChat* chat, Game* game) void resizeInteractionMenu(InteractionMenu* menu, const Settings* settings) { - menu->rect = (Rectangle){ - 0.0, - 0.0, - GetRenderWidth() - settings->mapPreviewWidth, - GetRenderHeight() - settings->interactionChatHeight - }; + menu->rect.width = settings->interactionMenuWidth; + menu->rect.height = (INTERACTION_MENU_MAX + 4) * settings->interactionFontSize; + menu->rect.x = 0.0; + menu->rect.y = GetRenderHeight() - settings->interactionChatHeight - + menu->rect.height - settings->interactionOutlineSize; } void initInteractionMenu(InteractionMenu* menu, const Settings* settings) @@ -112,12 +111,34 @@ void initInteractionMenu(InteractionMenu* menu, const Settings* settings) menu->entityId = ENTITY_NONE; } +void setInteractionMenu(InteractionMenu* menu, + const InteractionItems items, + int itemCount) +{ + // Check for out of bounds. + if (itemCount > INTERACTION_MENU_MAX) + { + TraceLog(LOG_ERROR, "itemCount > INTERACTION_MENU_MAX"); + return; + } + + menu->itemCount = itemCount; + + for (int index = 0; index < itemCount; ++index) + { + strncpy(menu->items[index], items[index], + INTERACTION_LABEL_MAX * sizeof(char) - 1); + } +} + void resetInteractionMenu(InteractionMenu* menu) { for (int index = 0; index < INTERACTION_MENU_MAX; ++index) { memset(menu->items[index], 0, INTERACTION_LABEL_MAX * sizeof(char)); } + + menu->itemCount = 0; } void showInteractionMenu(InteractionMenu* menu) @@ -142,6 +163,7 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game) /* return; */ /* } */ + // Draw background. Color background = DARKGRAY; background.a = game->settings.interactionAlpha; DrawRectangleRec(menu->rect, background); @@ -151,4 +173,23 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game) int fontSize = game->settings.interactionFontSize; DrawRectangleLinesEx(menu->rect, lineThickness, BLACK); + + Vector2 position = (Vector2){menu->rect.x + border, + menu->rect.y + border}; + + // Draw top information. + DrawText("Press a number key to select", position.x, position.y, fontSize, + WHITE); + + position.y += fontSize + fontSize; + + + // Draw items. + for (int index = 0; index < menu->itemCount; ++index) + { + DrawText(TextFormat("%d: ", index + 1), position.x, position.y, fontSize, WHITE); + DrawText(TextFormat(" %s", menu->items[index]), position.x, position.y, + fontSize, GREEN); + position.y += fontSize; + } } @@ -5,7 +5,9 @@ #ifndef UI_H #define UI_H -#define INTERACTION_CHAT_COLUMN_MAX 80 +#define INTERACTION_COLUMN_MAX 80 + +typedef char InteractionItems[INTERACTION_MENU_MAX][INTERACTION_LABEL_MAX]; typedef struct { char text[INTERACTION_CHAT_MAX]; @@ -15,7 +17,8 @@ typedef struct { } InteractionChat; typedef struct { - char items[INTERACTION_MENU_MAX][INTERACTION_LABEL_MAX]; + InteractionItems items; + int itemCount; Rectangle rect; bool visible; EntityId entityId; @@ -32,6 +35,9 @@ void updateInteractionChat(InteractionChat* chat, Game* game); // Interaction menu procedures. void initInteractionMenu(InteractionMenu* menu, const Settings* settings); +void setInteractionMenu(InteractionMenu* menu, + const InteractionItems items, + int itemCount); void resetInteractionMenu(InteractionMenu* menu); void showInteractionMenu(InteractionMenu* menu); void hideInteractionMenu(InteractionMenu* menu); |
