From 88bafaec3f64dd3afe2d025920ef332161be50f3 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 28 Nov 2023 19:12:31 -0600 Subject: [PATCH] Text navigation for visual novel added. --- Crawler/Version.h | 2 +- Crawler/VisualNovel.cpp | 37 +++++++++++++++++++--- Crawler/VisualNovel.h | 23 ++++++++++++++ Crawler/assets/backgrounds/rest.png | Bin 0 -> 5502 bytes Crawler/assets/config/story/Chapter 1.txt | 2 +- 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Crawler/assets/backgrounds/rest.png diff --git a/Crawler/Version.h b/Crawler/Version.h index a89c6e83..97ffe9fc 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 3212 +#define VERSION_BUILD 3225 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/VisualNovel.cpp b/Crawler/VisualNovel.cpp index a2e246c4..5ea17963 100644 --- a/Crawler/VisualNovel.cpp +++ b/Crawler/VisualNovel.cpp @@ -38,6 +38,7 @@ SUCH DAMAGE. #include "DEFINES.h" #include "Unlock.h" #include "Menu.h" +#include "util.h" INCLUDE_game INCLUDE_GFX @@ -177,6 +178,7 @@ void VisualNovel::LoadVisualNovel(std::string storyLevelName){ } void VisualNovel::Update(){ if(game->KEY_CONFIRM.Pressed()){ + activeText=""; novel.ExecuteNextCommand(); } locationDisplayTime=std::max(0.f,locationDisplayTime-game->GetElapsedTime()); @@ -204,8 +206,14 @@ void VisualNovel::Draw(){ game->DrawShadowStringPropDecal(game->GetScreenSize()/2-textSize/2,locationDisplayText,WHITE,VERY_DARK_BLUE,{2.f,2.f}); } if(activeText.length()>0){ - Menu::DrawThemedWindow({24.f,game->GetScreenSize().y-60.f},{48.f,-12.f}); - Menu::DrawThemedWindow({24.f,game->GetScreenSize().y-48.f},{game->GetScreenSize().x-48.f,20.f}); + vf2d nameDisplayPos={24.f,game->GetScreenSize().y-60.f}; + vf2d nameDisplayWindowSize={48.f,-12.f}; + 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); + game->DrawShadowStringPropDecal(nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize/2,speakerDisplayName); + game->DrawShadowStringPropDecal(dialogDisplayPos-vf2d{10,10},activeText); } } @@ -220,6 +228,7 @@ void LocationCommand::Execute(VisualNovel&vn){ } LocationCommand::LocationCommand(std::string location) :location(location){} +CommandType::CommandType LocationCommand::GetType(){return CommandType::LOCATION;} void BackgroundCommand::Execute(VisualNovel&vn){ vn.backgroundFilename=backgroundFilename; @@ -227,6 +236,7 @@ void BackgroundCommand::Execute(VisualNovel&vn){ } BackgroundCommand::BackgroundCommand(std::string backgroundFilename) :backgroundFilename(backgroundFilename){} +CommandType::CommandType BackgroundCommand::GetType(){return CommandType::BACKGROUND;} void LeftCommand::Execute(VisualNovel&vn){ vn.leftCharacters=characters; @@ -234,6 +244,7 @@ void LeftCommand::Execute(VisualNovel&vn){ } LeftCommand::LeftCommand(std::vectorcharacters) :characters(characters){} +CommandType::CommandType LeftCommand::GetType(){return CommandType::LEFT;} void RightCommand::Execute(VisualNovel&vn){ vn.rightCharacters=characters; @@ -241,6 +252,7 @@ void RightCommand::Execute(VisualNovel&vn){ } RightCommand::RightCommand(std::vectorcharacters) :characters(characters){} +CommandType::CommandType RightCommand::GetType(){return CommandType::RIGHT;} void SpeakerCommand::Execute(VisualNovel&vn){ vn.speakerDisplayName=displayedName; @@ -251,12 +263,29 @@ SpeakerCommand::SpeakerCommand(std::string speaker) :displayedName(speaker),actualSpeakerName(speaker){} SpeakerCommand::SpeakerCommand(std::string displayedName,std::string speaker) :displayedName(displayedName),actualSpeakerName(speaker){} +CommandType::CommandType SpeakerCommand::GetType(){return CommandType::SPEAKER;} void DialogCommand::Execute(VisualNovel&vn){ - vn.activeText=dialog; + bool mustDisplay=vn.activeText.length()==0; + std::string newText=util::WrapText(game,vn.activeText+(vn.activeText.length()>0?" ":"")+dialog,game->GetScreenSize().x-48,true,{1,1}); + if(game->GetTextSizeProp(newText).y>40){//Hit the maximum of 3 lines. + if(!mustDisplay){ + vn.commandIndex--; + } + }else{ + vn.activeText=newText; + if(vn.commandIndexGetType(); + if(nextCommandType==CommandType::DIALOG){ //Only add to dialog when the next command type is a dialog as well. + vn.ExecuteNextCommand(); + } + } + } } DialogCommand::DialogCommand(std::string dialog) :dialog(dialog){} +CommandType::CommandType DialogCommand::GetType(){return CommandType::DIALOG;} void PauseCommand::Execute(VisualNovel&vn){} -PauseCommand::PauseCommand(){} \ No newline at end of file +PauseCommand::PauseCommand(){} +CommandType::CommandType PauseCommand::GetType(){return CommandType::PAUSE;} \ No newline at end of file diff --git a/Crawler/VisualNovel.h b/Crawler/VisualNovel.h index 866b98d6..b5b90277 100644 --- a/Crawler/VisualNovel.h +++ b/Crawler/VisualNovel.h @@ -39,17 +39,32 @@ SUCH DAMAGE. class VisualNovel; +namespace CommandType{ + enum CommandType{ + PAUSE, + DIALOG, + SPEAKER, + BACKGROUND, + RIGHT, + LEFT, + LOCATION + }; +} + class Command{ friend class VisualNovel; virtual void Execute(VisualNovel&vn)=0; protected: Command(); +public: + virtual CommandType::CommandType GetType()=0; }; class PauseCommand final:public Command{ public: void Execute(VisualNovel&vn)override; PauseCommand(); + CommandType::CommandType GetType()final override; }; class DialogCommand final:public Command{ @@ -57,6 +72,7 @@ class DialogCommand final:public Command{ public: void Execute(VisualNovel&vn)override; DialogCommand(std::string dialog); + CommandType::CommandType GetType()final override; }; class SpeakerCommand final:public Command{ @@ -66,6 +82,7 @@ public: void Execute(VisualNovel&vn)override; SpeakerCommand(std::string speaker); SpeakerCommand(std::string displayedName,std::string speaker); + CommandType::CommandType GetType()final override; }; class BackgroundCommand final:public Command{ @@ -73,6 +90,7 @@ class BackgroundCommand final:public Command{ public: void Execute(VisualNovel&vn)override; BackgroundCommand(std::string backgroundFilename); + CommandType::CommandType GetType()final override; }; class RightCommand final:public Command{ @@ -80,6 +98,7 @@ class RightCommand final:public Command{ public: void Execute(VisualNovel&vn)override; RightCommand(std::vectorcharacters); + CommandType::CommandType GetType()final override; }; class LeftCommand final:public Command{ @@ -87,6 +106,7 @@ class LeftCommand final:public Command{ public: void Execute(VisualNovel&vn)override; LeftCommand(std::vectorcharacters); + CommandType::CommandType GetType()final override; }; class LocationCommand final:public Command{ @@ -94,6 +114,7 @@ class LocationCommand final:public Command{ public: void Execute(VisualNovel&vn)override; LocationCommand(std::string location); + CommandType::CommandType GetType()final override; }; class VisualNovel{ @@ -114,6 +135,8 @@ class VisualNovel{ std::vectorleftCharacters; std::vectorrightCharacters; std::string backgroundFilename; + std::string prevBackgroundFilename; + float transitionTime=0; std::vectorcommands; int commandIndex=0; std::string locationDisplayText=""; diff --git a/Crawler/assets/backgrounds/rest.png b/Crawler/assets/backgrounds/rest.png new file mode 100644 index 0000000000000000000000000000000000000000..5b695b3b24d65b1a1d9ef94c57a5efe97a307eb6 GIT binary patch literal 5502 zcmeHKdsGuw8Xq1;g@U3|l*T2-MNyf&NXP>sQ9u$Uf=C6#*JNfA2FQbCLV~V5bbYdx zsjH3V62Y?_y>JI8p#c7MzY*GlJSq9*@#nzVOr75~!gZIV&%NVy%~l{9w$ z7=6?|&i{H`YDdvRRxnm+cdj> zFsv@C4_oM-z4B?=nD@Gp0>%Us)PC~$nt+l~8`IAv2V7iIgMPAd&*YYs(fLjOCT`;B zss16hso0S2diL)7lWw`g=>B#!Wlrv_qTOUac0*1!}Az!oy<~;o;AV2PGG++$@!! zjUBTlX8zv4dk+m+AApsvTIS=O5%_lCsx?;^qZQuk_n28j4_McJ$nNej9*k_ zHXFQM&-jf@@R=OxGv&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ivM2D0T>)tk}*eSIQzl>~tnt!rpb#NBvW6!j!r*l?Mwyz`~uWWmI_Fier zIA;5qz!l5-;0@wX8#lFPcl6T-Ki3@tIXrBr?)gkB-5xBhy8%S$V4H{RXfK%MBx|&W irTiau*|EjFE;Wr?*dNF2s{q#^q==jwab)JQRsRCi%;Dhx literal 0 HcmV?d00001 diff --git a/Crawler/assets/config/story/Chapter 1.txt b/Crawler/assets/config/story/Chapter 1.txt index 1aed8d86..6e1c415a 100644 --- a/Crawler/assets/config/story/Chapter 1.txt +++ b/Crawler/assets/config/story/Chapter 1.txt @@ -106,7 +106,7 @@ 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} [] 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.