diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-07 03:57:09 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-07 03:57:09 +0000 |
| commit | fd070849940355741b69fe5fbdf75a01dcc8f424 (patch) | |
| tree | 068b2d87e5db33fe9978a8a1fd5c3fef8697bd55 /src/ui.c | |
| parent | 382cb08822808f57902f67a842259e64afb33e72 (diff) | |
| download | FindThings-fd070849940355741b69fe5fbdf75a01dcc8f424.tar.gz FindThings-fd070849940355741b69fe5fbdf75a01dcc8f424.tar.bz2 FindThings-fd070849940355741b69fe5fbdf75a01dcc8f424.zip | |
Cool text animation thingy
Diffstat (limited to 'src/ui.c')
| -rw-r--r-- | src/ui.c | 48 |
1 files changed, 40 insertions, 8 deletions
@@ -18,7 +18,7 @@ void resizeInteractionChat(InteractionChat* chat, const Settings* settings) void initInteractionChat(InteractionChat* chat, const Settings* settings) { - memset(&chat->text, 0, INTERACTION_CHAT_MAX * sizeof(char)); + clearInteractionChat(chat); chat->visible = false; chat->entityId = ENTITY_NONE; @@ -37,17 +37,37 @@ void hideInteractionChat(InteractionChat* chat) void setInteractionChat(InteractionChat* chat, const char* text) { - strncpy(chat->text, text, INTERACTION_CHAT_MAX * sizeof(char) - 1); + strncpy(chat->text, text, INTERACTION_CHAT_MAX - 1); + chat->textSize = getStringLength(text, INTERACTION_CHAT_MAX); + chat->displayUpTo = 0; + chat->lastCharacterUpdate = GetTime(); } void writeToInteractionChat(InteractionChat* chat, const char* text) { - strncat(chat->text, text, INTERACTION_CHAT_MAX * sizeof(char) - 1); + strncat(chat->text, text, INTERACTION_CHAT_MAX - 1); + chat->textSize += getStringLength(text, INTERACTION_CHAT_MAX); + chat->textSize %= INTERACTION_CHAT_MAX; + chat->lastCharacterUpdate = GetTime(); } void clearInteractionChat(InteractionChat* chat) { - memset(&chat->text, 0, INTERACTION_CHAT_MAX * sizeof(char)); + memset(&chat->text, 0, INTERACTION_CHAT_MAX); + memset(&chat->displayedText, 0, INTERACTION_CHAT_MAX); + chat->textSize = 0; + chat->displayUpTo = 0; +} + +bool isInteractionChatAnimationDone(InteractionChat* chat) +{ + return chat->displayUpTo >= chat->textSize; +} + +void endInteractionChatAnimation(InteractionChat* chat) +{ + chat->displayUpTo = chat->textSize; + strncpy(chat->displayedText, chat->text, chat->textSize); } void updateInteractionChat(InteractionChat* chat, Game* game) @@ -72,6 +92,19 @@ void updateInteractionChat(InteractionChat* chat, Game* game) DrawRectangleLinesEx(chat->rect, lineThickness, BLACK); + // Do cool animation. + double currentTime = GetTime(); + + if (chat->displayUpTo < chat->textSize && + currentTime - chat->lastCharacterUpdate >= + game->settings.interactionChatAnimationSpeed) + { + chat->lastCharacterUpdate = currentTime; + chat->displayedText[chat->displayUpTo] = chat->text[chat->displayUpTo]; + ++chat->displayUpTo; + } + + // Draw text. if (chat->entityId != ENTITY_NONE) { DrawText(TextFormat("%s says:", getEntityName(chat->entityId)), @@ -81,7 +114,7 @@ void updateInteractionChat(InteractionChat* chat, Game* game) WHITE); } - DrawText(chat->text, + DrawText(chat->displayedText, chat->rect.x + border, chat->rect.y + (border * 2.0) + fontSize, fontSize, @@ -127,8 +160,7 @@ void setInteractionMenu(InteractionMenu* menu, for (int index = 0; index < itemCount; ++index) { - strncpy(menu->items[index], items[index], - INTERACTION_LABEL_MAX * sizeof(char) - 1); + strncpy(menu->items[index], items[index], INTERACTION_LABEL_MAX - 1); } } @@ -136,7 +168,7 @@ void resetInteractionMenu(InteractionMenu* menu) { for (int index = 0; index < INTERACTION_MENU_MAX; ++index) { - memset(menu->items[index], 0, INTERACTION_LABEL_MAX * sizeof(char)); + memset(menu->items[index], 0, INTERACTION_LABEL_MAX); } menu->itemCount = 0; |
