From 19be2ac58b09c5240a32e6a4f41cd9f6cda03d07 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 12 Feb 2021 00:14:38 -0500 Subject: Added message bullets --- src/message_system.cpp | 11 +++++++++-- src/message_system.h | 1 + src/renderer.cpp | 33 ++++++++++++++++++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/message_system.cpp b/src/message_system.cpp index a969427..98b5f83 100644 --- a/src/message_system.cpp +++ b/src/message_system.cpp @@ -124,6 +124,12 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName } } + bool bulleted = false; + if (text.substr(0, 2) == "* ") { + text.erase(0, 2); + bulleted = true; + } + auto words = splitStr>(text, " "); std::string curLine; @@ -145,9 +151,10 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName } if (nextWidth > MESSAGE_TEXT_WIDTH) { - lines_.push_back({.text = curLine}); + lines_.push_back({.text = curLine, .bulleted = bulleted}); curLine = word; curWidth = wordWidth + game_.getFont().getCharacterWidth(' '); + bulleted = false; if (shouldAddBlank) { shouldAddBlank = false; @@ -166,7 +173,7 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName firstWord = false; } - lines_.push_back({.text = curLine}); + lines_.push_back({.text = curLine, .bulleted = bulleted}); if (shouldAddBlank) { shouldAddBlank = false; diff --git a/src/message_system.h b/src/message_system.h index ea27f14..7f9d287 100644 --- a/src/message_system.h +++ b/src/message_system.h @@ -24,6 +24,7 @@ struct MessageLine { bool pause = false; bool isChoice = false; int choicePos[2] = {-1, -1}; + bool bulleted = false; }; class MessageSystem : public System { diff --git a/src/renderer.cpp b/src/renderer.cpp index 0c70ef5..0e77bb9 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -201,17 +201,28 @@ void Renderer::render(Game& game) { // 18x, 127y1, 143y2 if (line.charsRevealed > 0) { - SDL_Rect srcRect { - 0, 0, messageLines_[lineIndex].charIndexToWidth[line.charsRevealed], - game.getFont().getCharacterHeight() - }; - SDL_Rect destRect { - 18, - 127 + 16 * lineIndex, - srcRect.w, - srcRect.h }; - - SDL_RenderCopy(ren_.get(), messageLines_[lineIndex].renderedTex.get(), &srcRect, &destRect); + { + SDL_Rect srcRect { + 0, 0, messageLines_[lineIndex].charIndexToWidth[line.charsRevealed], + game.getFont().getCharacterHeight() + }; + SDL_Rect destRect { + 18, + 127 + 16 * lineIndex, + srcRect.w, + srcRect.h }; + + SDL_RenderCopy(ren_.get(), messageLines_[lineIndex].renderedTex.get(), &srcRect, &destRect); + } + + if (line.bulleted) { + vec2i charLoc = game.getFont().getCharacterLocation('^'); + vec2i charSize = game.getFont().getCharacterSize('^'); + SDL_Rect srcRect { charLoc.x(), charLoc.y(), charSize.w(), charSize.h() }; + SDL_Rect destRect { 13, 127 + 16 * lineIndex, charSize.w(), charSize.h() }; + + SDL_RenderCopy(ren_.get(), textures_.at(game.getFont().getTextureId()).get(), &srcRect, &destRect); + } } lineIndex++; -- cgit 1.4.1