From 5e37c9a7034edfc4eec4d4ed15224b0f63c736af Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 21 Mar 2022 10:40:31 -0400 Subject: fancier textboxes --- src/renderer.cpp | 25 +++++++++++++++---------- src/renderer.h | 2 ++ src/sign.cpp | 23 +++++++++++++++++++++++ src/sign.h | 4 ++++ 4 files changed, 44 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/renderer.cpp b/src/renderer.cpp index 2fc6023..afc022e 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -121,6 +121,8 @@ void Renderer::loadAllTextures() { loadTextureFromFile("read_instruction.png", readInstruction_); loadTextureFromFile("menu.png", menuBg_); loadTextureFromFile("help.png", help_); + loadTextureFromFile("message.png", messageBg_); + loadTextureFromFile("feather.png", feather_); loadTextureFromFile("title0.png", titles_[0]); SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); @@ -455,16 +457,8 @@ void Renderer::renderGame( opacity = game.sign.signDisplayFade.getProgress(255, 0); } - SDL_Rect signRect { - 0, - GAME_HEIGHT / 2 - (45 * 2 + 1 + MESSAGE_MARGIN * 2) / 2, - GAME_WIDTH, - 45 * 2 + 1 + MESSAGE_MARGIN * 2 - }; - - SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, opacity); - SDL_RenderFillRect(ren_.get(), &signRect); + SDL_SetTextureAlphaMod(messageBg_.get(), opacity); + SDL_RenderCopy(ren_.get(), messageBg_.get(), nullptr, nullptr); if (game.sign.signDisplayState == SignInstructionState::Visible) { int lineIndex = 0; @@ -493,6 +487,17 @@ void Renderer::renderGame( lineIndex++; } + + if (game.sign.showNextArrow) { + SDL_Rect destRect { + GAME_WIDTH - MESSAGE_MARGIN - 32, + GAME_HEIGHT / 2 + (45 + 1 + MESSAGE_MARGIN) / 2 + game.sign.nextArrowBobPos - 32, + 64, + 64 }; + + SDL_SetRenderTarget(ren_.get(), overlays.get()); + SDL_RenderCopy(ren_.get(), feather_.get(), nullptr, &destRect); + } } } diff --git a/src/renderer.h b/src/renderer.h index 549f64a..136d0bf 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -188,6 +188,8 @@ private: texture_ptr readInstruction_; texture_ptr menuBg_; texture_ptr help_; + texture_ptr messageBg_; + texture_ptr feather_; std::array titles_; std::array titleWidths_; diff --git a/src/sign.cpp b/src/sign.cpp index b9299d6..e488108 100644 --- a/src/sign.cpp +++ b/src/sign.cpp @@ -92,6 +92,8 @@ void Sign::update(size_t dt, Game& game) { } if (fullyRevealed) { + showNextArrow = false; + if (linesToShow.back().pause) { linesToShow.back().pause = false; // Play a sound @@ -126,6 +128,27 @@ void Sign::update(size_t dt, Game& game) { } linesToShow.push_back(lines.front()); lines.pop_front(); + } else { + showNextArrow = true; + } + } + } + + if (showNextArrow) { + nextArrowBobTimer_.accumulate(dt); + while (nextArrowBobTimer_.step()) { + if (nextArrowBobDown_) { + nextArrowBobPos++; + + if (nextArrowBobPos >= 4) { + nextArrowBobDown_ = false; + } + } else { + nextArrowBobPos--; + + if (nextArrowBobPos <= 0) { + nextArrowBobDown_ = true; + } } } } diff --git a/src/sign.h b/src/sign.h index c90a8fd..8a69fd3 100644 --- a/src/sign.h +++ b/src/sign.h @@ -35,11 +35,15 @@ public: Interpolation signDisplayFade; std::list lines; std::list linesToShow; + bool showNextArrow = false; + int nextArrowBobPos = 0; private: TTF_Font* font_; Timer textAdvTimer_ { 15 }; + bool nextArrowBobDown_ = true; + Timer nextArrowBobTimer_ { 125 }; }; #endif /* end of include guard: SIGN_H_B0491849 */ -- cgit 1.4.1