diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-22 08:34:40 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-22 08:34:40 +0000 |
| commit | 08c502d813b11b1f9dd7b7143a0987454c76ea32 (patch) | |
| tree | 8caa319d59ab991a270495f5b9f9c263eb2de74f | |
| parent | db04bfb989a5ebbd1f57e9983a2bb819c3ce4d67 (diff) | |
| download | FindThings-08c502d813b11b1f9dd7b7143a0987454c76ea32.tar.gz FindThings-08c502d813b11b1f9dd7b7143a0987454c76ea32.tar.bz2 FindThings-08c502d813b11b1f9dd7b7143a0987454c76ea32.zip | |
Menu item selection
| -rw-r--r-- | src/entities/ron.c | 5 | ||||
| -rw-r--r-- | src/entity.c | 10 | ||||
| -rw-r--r-- | src/entity.h | 2 | ||||
| -rw-r--r-- | src/player.c | 14 | ||||
| -rw-r--r-- | src/settings.c | 3 | ||||
| -rw-r--r-- | src/settings.h | 1 | ||||
| -rw-r--r-- | src/ui.c | 3 |
7 files changed, 36 insertions, 2 deletions
diff --git a/src/entities/ron.c b/src/entities/ron.c index 5c60b9f..d01f25a 100644 --- a/src/entities/ron.c +++ b/src/entities/ron.c @@ -41,6 +41,11 @@ InteractionCommand interactWithRon(Entity* entity, Game* game, case SELECTION_LEAVE: return INTERACTION_END; default: + if (selection >= SELECTION_MENU_ITEM && selection < SELECTION_LEAVE) + { + printf("%d\n", getInteractionMenuIndex(selection)); + } + return INTERACTION_DO_NOTHING; } } diff --git a/src/entity.c b/src/entity.c index ea9c66c..bcb7735 100644 --- a/src/entity.c +++ b/src/entity.c @@ -152,6 +152,16 @@ InteractionCommand interactWithEntity(Entity* entity, Game* game, return INTERACTION_END; } +int getInteractionMenuIndex(Selection selection) +{ + if (selection < SELECTION_MENU_ITEM || selection >= SELECTION_LEAVE) + { + return SELECTION_NONE; + } + + return selection - SELECTION_MENU_ITEM; +} + BoundingBox entityBoxFromScale(float scale, float width, float height) { Vector2 size = (Vector2){width / height * scale, scale}; diff --git a/src/entity.h b/src/entity.h index bdb0967..9d6bf9a 100644 --- a/src/entity.h +++ b/src/entity.h @@ -54,6 +54,7 @@ enum InteractionCommand { }; enum Selection { + SELECTION_NONE = -1, SELECTION_INTERACT, SELECTION_NEXT_MESSAGE, SELECTION_MENU_ITEM, // +x to select any given menu entry @@ -98,6 +99,7 @@ float getEntityDistance(Entity entity, Vector3 position); InteractionCommand interactWithEntity(Entity* entity, Game* game, Selection selection); +int getInteractionMenuIndex(Selection selection); BoundingBox entityBoxFromScale(float scale, float width, float height); diff --git a/src/player.c b/src/player.c index 27a4780..2b72477 100644 --- a/src/player.c +++ b/src/player.c @@ -165,6 +165,8 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game, void playerUpdateSelectedEntity(Player* player, WorldUID uid, Game* game) { Entity* entity = &game->world.entities[uid]; + InteractionChat* chat = &game->interactionChat; + InteractionMenu* menu = &game->interactionMenu; // If the entity can be selected. if (!playerCanEntityBeSelected(player, *entity)) @@ -184,15 +186,27 @@ void playerUpdateSelectedEntity(Player* player, WorldUID uid, Game* game) // Draw outline. DrawBoundingBox(entity->box, player->isInteracting ? YELLOW : PINK); + // Number keys for menu selection. + int keyPressed = GetKeyPressed(); + // Handle key presses. if (IsKeyPressed(game->settings.interactKey)) { playerInteractWithEntity(player, uid, game, SELECTION_INTERACT); } + else if (IsKeyPressed(game->settings.leaveKey)) + { + playerInteractWithEntity(player, uid, game, SELECTION_LEAVE); + } else if (IsKeyPressed(game->settings.nextMessageKey)) { playerInteractWithEntity(player, uid, game, SELECTION_NEXT_MESSAGE); } + else if (keyPressed >= KEY_ONE && keyPressed <= KEY_NINE) + { + playerInteractWithEntity(player, uid, game, + SELECTION_MENU_ITEM + (keyPressed - KEY_ONE)); + } } void updatePlayer(Player* player, Game* game) diff --git a/src/settings.c b/src/settings.c index 6a4d76a..2fdc29a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -46,6 +46,7 @@ Settings defaultSettings() .toggleMapPreviewKey = KEY_P, .defaultMapZoomKey = KEY_Z, .interactKey = KEY_E, - .nextMessageKey = KEY_ENTER + .nextMessageKey = KEY_ENTER, + .leaveKey = KEY_L }; } diff --git a/src/settings.h b/src/settings.h index 188e447..bed506d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -69,6 +69,7 @@ typedef struct { KeyboardKey defaultMapZoomKey; KeyboardKey interactKey; KeyboardKey nextMessageKey; + KeyboardKey leaveKey; } Settings; Settings defaultSettings(); @@ -97,7 +97,8 @@ void updateInteractionChat(InteractionChat* chat, Game* game) void resizeInteractionMenu(InteractionMenu* menu, const Settings* settings) { menu->rect.width = settings->interactionMenuWidth; - menu->rect.height = (INTERACTION_MENU_MAX + 4) * settings->interactionFontSize; + 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; |
