diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-17 23:05:49 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-17 23:05:49 +0000 |
| commit | edaafadf2c5de7f23dfc20d420e973ed9dc92039 (patch) | |
| tree | 1cbfc2cbdbbda1052144947eef39224ff01877ce | |
| parent | 0cddd5649838c0d37c0e4b12786d040ffdb01c97 (diff) | |
| download | FindThings-edaafadf2c5de7f23dfc20d420e973ed9dc92039.tar.gz FindThings-edaafadf2c5de7f23dfc20d420e973ed9dc92039.tar.bz2 FindThings-edaafadf2c5de7f23dfc20d420e973ed9dc92039.zip | |
Progress, I guess...
| -rw-r--r-- | src/entity.h | 3 | ||||
| -rw-r--r-- | src/game.c | 4 | ||||
| -rw-r--r-- | src/game.h | 2 | ||||
| -rw-r--r-- | src/player.h | 2 | ||||
| -rw-r--r-- | src/settings.c | 3 | ||||
| -rw-r--r-- | src/settings.h | 3 | ||||
| -rw-r--r-- | src/ui.c | 68 | ||||
| -rw-r--r-- | src/ui.h | 23 |
8 files changed, 105 insertions, 3 deletions
diff --git a/src/entity.h b/src/entity.h index 65e5b2a..3a707c9 100644 --- a/src/entity.h +++ b/src/entity.h @@ -8,7 +8,8 @@ #define ENTITY_COUNT 14 #define INTERACTION_MENU_MAX 9 -#define INTERACTION_LABEL_MAX 64 +#define INTERACTION_LABEL_MAX 6 +#define INTERACTION_CHAT_MAX 256 #define ENTITY_DEFAULT_STATE -1 typedef int8_t EntityId; @@ -85,6 +85,9 @@ void initGame(Game* game) // Map. initMap(&game->map, &game->world, &game->settings); + // Interaction chat. + initInteractionChat(&game->chat); + disableGameCursor(game); } @@ -186,6 +189,7 @@ void updateGameScene(Game* game) drawGameScreen(game); updateMap(&game->map, game); + updateInteractionChat(&game->chat, game); // Cross hair. if (IsKeyPressed(game->settings.toggleCrossHairKey)) @@ -5,6 +5,7 @@ #include "world.h" #include "entity.h" #include "map.h" +#include "ui.h" #ifndef GAME_H #define GAME_H @@ -24,6 +25,7 @@ struct Game { World world; Model skybox; Map map; + InteractionChat chat; SceneId sceneId; bool isCursorEnabled; diff --git a/src/player.h b/src/player.h index 03b7141..71c9993 100644 --- a/src/player.h +++ b/src/player.h @@ -4,7 +4,7 @@ #define PLAYER_H #define PLAYER_HEIGHT 2.0 -#define PLAYER_SPEED 80.0 // 8.0 +#define PLAYER_SPEED 8.0 #define PLAYER_MAX_SELECT_DISTANCE 10.0 typedef struct { diff --git a/src/settings.c b/src/settings.c index 96c0fe8..5f7f823 100644 --- a/src/settings.c +++ b/src/settings.c @@ -21,12 +21,13 @@ Settings defaultSettings() .isMapPreviewEnabledDefault = true, .mapPreviewWidth = 300.0, .mapPreviewHeight = 300.0, - .mapAlpha = (unsigned char)255.0 * 0.80, + .mapAlpha = (unsigned char)255.0 * 0.8, .mapPreviewZoomDefault = 3.0, .mapLowColor = (Color){255, 255, 0, 255}, .mapHighColor = (Color){0, 0, 255, 255}, .mapColorCount = 7.0, .mapZoomSpeed = 0.2, + .interactionChatAlpha = (unsigned char)255.0 * 0.9, .mouseSpeed = 0.1, .forwardKey = KEY_W, .backwardKey = KEY_S, diff --git a/src/settings.h b/src/settings.h index 6418c2e..0782fbb 100644 --- a/src/settings.h +++ b/src/settings.h @@ -44,6 +44,9 @@ typedef struct { float mapColorCount; float mapZoomSpeed; + // Interaction chat. + unsigned char interactionChatAlpha; + // Controls. float mouseSpeed; KeyboardKey forwardKey; diff --git a/src/ui.c b/src/ui.c new file mode 100644 index 0000000..a250b01 --- /dev/null +++ b/src/ui.c @@ -0,0 +1,68 @@ +#include "ui.h" +#include "game.h" +#include "settings.h" + +// TODO: byebye magic numbers + +void resizeInteractionChat(InteractionChat* chat) +{ + float renderWidth = GetRenderWidth(); + float renderHeight = GetRenderHeight(); + float height = 200.0; + + chat->rect = (Rectangle){ + 0.0, + renderHeight - height, + renderWidth, + height + }; +} + +void initInteractionChat(InteractionChat* chat) +{ + memset(&chat->text, 0, INTERACTION_CHAT_MAX * sizeof(char)); + chat->visible = true; + + resizeInteractionChat(chat); + writeToInteractionChat(chat, "test test test test test\ntest test test test test test test test"); +} + +void showInteractionChat(InteractionChat* chat) +{ + chat->visible = true; +} + +void hideInteractionChat(InteractionChat* chat) +{ + chat->visible = false; +} + +void writeToInteractionChat(InteractionChat* chat, const char* text) +{ + strncat(chat->text, text, INTERACTION_CHAT_MAX * sizeof(char) - 1); +} + +void clearInteractionChat(InteractionChat* chat) +{ + memset(&chat->text, 0, INTERACTION_CHAT_MAX * sizeof(char)); +} + +void updateInteractionChat(InteractionChat* chat, Game* game) +{ + if (IsWindowResized()) + { + resizeInteractionChat(chat); + } + + if (!chat->visible) + { + return; + } + + Color background = DARKGRAY; + background.a = game->settings.interactionChatAlpha; + DrawRectangleRec(chat->rect, background); + + DrawRectangleLinesEx(chat->rect, 2.0, BLACK); + DrawText(chat->text, chat->rect.x + 3.0, chat->rect.y + 3.0, 20, GREEN); +} diff --git a/src/ui.h b/src/ui.h new file mode 100644 index 0000000..8de144f --- /dev/null +++ b/src/ui.h @@ -0,0 +1,23 @@ +#include "utils.h" +#include "entity.h" +#include "world.h" + +#ifndef UI_H +#define UI_H + +#define INTERACTION_CHAT_COLUMN_MAX 80 + +typedef struct { + char text[INTERACTION_CHAT_MAX]; + Rectangle rect; + bool visible; +} InteractionChat; + +void initInteractionChat(InteractionChat* chat); +void showInteractionChat(InteractionChat* chat); +void hideInteractionChat(InteractionChat* chat); +void writeToInteractionChat(InteractionChat* chat, const char* text); +void clearInteractionChat(InteractionChat* chat); +void updateInteractionChat(InteractionChat* chat, Game* game); + +#endif |
