From b437202e13c12980c36f313fc7c60d10279552e1 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 28 Nov 2023 19:27:23 -0600 Subject: [PATCH] Background fading transition added. --- Crawler/Version.h | 2 +- Crawler/VisualNovel.cpp | 18 +++++++++++++++--- Crawler/VisualNovel.h | 1 + Crawler/assets/config/story/Chapter 1.txt | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Crawler/Version.h b/Crawler/Version.h index 97ffe9fc..8a914ced 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -35,7 +35,7 @@ SUCH DAMAGE. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3225 +#define VERSION_BUILD 3226 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/VisualNovel.cpp b/Crawler/VisualNovel.cpp index 5ea17963..29927f72 100644 --- a/Crawler/VisualNovel.cpp +++ b/Crawler/VisualNovel.cpp @@ -177,11 +177,12 @@ void VisualNovel::LoadVisualNovel(std::string storyLevelName){ Menu::themeSelection="Purple"; } void VisualNovel::Update(){ - if(game->KEY_CONFIRM.Pressed()){ + if(transitionTime==0&&game->KEY_CONFIRM.Pressed()){ activeText=""; novel.ExecuteNextCommand(); } locationDisplayTime=std::max(0.f,locationDisplayTime-game->GetElapsedTime()); + transitionTime=std::max(0.f,transitionTime-game->GetElapsedTime()); } void VisualNovel::ExecuteNextCommand(){ if(commandIndexDrawDecal({0,0},GFX["backgrounds/"+backgroundFilename].Decal()); + float alpha=1; + if(transitionTime>0){ + alpha=util::lerp(0,1,1-(transitionTime/maxTransitionTime)); + } + if(prevBackgroundFilename!=""){ + game->DrawDecal({0,0},GFX["backgrounds/"+prevBackgroundFilename].Decal()); + } + game->DrawDecal({0,0},GFX["backgrounds/"+backgroundFilename].Decal(),{1,1},{255,255,255,uint8_t(255*alpha)}); }else{ game->FillRectDecal({0,0},game->GetScreenSize()); } @@ -208,7 +216,9 @@ void VisualNovel::Draw(){ if(activeText.length()>0){ vf2d nameDisplayPos={24.f,game->GetScreenSize().y-60.f}; vf2d nameDisplayWindowSize={48.f,-12.f}; - Menu::DrawThemedWindow(nameDisplayPos,nameDisplayWindowSize); + if(speakerDisplayName.length()>0){ + Menu::DrawThemedWindow(nameDisplayPos,nameDisplayWindowSize); + } vf2d dialogDisplayPos={24.f,game->GetScreenSize().y-48.f}; Menu::DrawThemedWindow(dialogDisplayPos,{game->GetScreenSize().x-48.f,20.f}); vf2d speakerTextSize=game->GetTextSizeProp(speakerDisplayName); @@ -231,7 +241,9 @@ LocationCommand::LocationCommand(std::string location) CommandType::CommandType LocationCommand::GetType(){return CommandType::LOCATION;} void BackgroundCommand::Execute(VisualNovel&vn){ + vn.prevBackgroundFilename=vn.backgroundFilename; vn.backgroundFilename=backgroundFilename; + vn.transitionTime=2.0f; vn.ExecuteNextCommand(); } BackgroundCommand::BackgroundCommand(std::string backgroundFilename) diff --git a/Crawler/VisualNovel.h b/Crawler/VisualNovel.h index b5b90277..9cf33898 100644 --- a/Crawler/VisualNovel.h +++ b/Crawler/VisualNovel.h @@ -137,6 +137,7 @@ class VisualNovel{ std::string backgroundFilename; std::string prevBackgroundFilename; float transitionTime=0; + static constexpr float maxTransitionTime=2.0f; std::vectorcommands; int commandIndex=0; std::string locationDisplayText=""; diff --git a/Crawler/assets/config/story/Chapter 1.txt b/Crawler/assets/config/story/Chapter 1.txt index 6e1c415a..7fe0c87a 100644 --- a/Crawler/assets/config/story/Chapter 1.txt +++ b/Crawler/assets/config/story/Chapter 1.txt @@ -106,13 +106,13 @@ What shall I do. I can't return to the Kingdom without it. [You] First you should rest. Once you are able to walk on your own again, we can think about a solution for your lost object. -{BACKGROUND sea.png} +{BACKGROUND rest.png} [] You set up a tent and a campfire a little outside of the main camp where the tragedy happened and help Sherman to move over. Without the corpses surrounding you, you relax a little bit. For the rest of the day you keep an Eye on Sherman while he recovers. - +{BACKGROUND sea.png} The next day Sherman no longer lying down, instead sitting on the grass. [Sherman]