From c85f91cc5e0f9e94717fbc36ebef3b2637986121 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 9 Feb 2021 11:19:22 -0500 Subject: Added newlines that don't require A presses \n in a text message just indicates a newline. \n\f is a newline with an A press. --- res/scripts/script0001.lua | 2 +- src/message_system.cpp | 31 +++++++++++++++++++++++-------- src/message_system.h | 3 +++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/res/scripts/script0001.lua b/res/scripts/script0001.lua index 326b37c..fcf7029 100644 --- a/res/scripts/script0001.lua +++ b/res/scripts/script0001.lua @@ -2,7 +2,7 @@ function script0001() SetAnimation("boney", "barking") local barkingNoise = LoopSound("barking_at_hallucination.wav") - DisplayMessage("Lucas. It's me, Flint. Your father.\nI found Claus. He's here. After three years I've finally found your brother.\nLook at me when I'm talking to you, Lucas.\nWhen Claus gets home, we won't need you anymore. You're nothing compared to him.", "Flint", SpeakerType.MAN) + DisplayMessage("Lucas. It's me, Flint. Your father.\n\fI found Claus. He's here. After three years I've finally found your brother.\n\fLook at me when I'm talking to you, Lucas.\n\fWhen Claus gets home, we won't need you anymore.\nYou're nothing compared to him.", "Flint", SpeakerType.MAN) WaitForEndOfMessage() SetAnimation("boney", "crouch") diff --git a/src/message_system.cpp b/src/message_system.cpp index f9803ed..15d9847 100644 --- a/src/message_system.cpp +++ b/src/message_system.cpp @@ -52,7 +52,7 @@ void MessageSystem::tick(double dt) { // If both lines are totally revealed, see if we can scroll up a line. // This is doable as long as the next line isn't the sentinel value that // means an A press is required. - if (!lines_.empty() && lines_.front() != "\n") { + if (!lines_.empty() && lines_.front() != "\f") { if (linesToShow_.size() == 2) { linesToShow_.pop_front(); } @@ -105,15 +105,24 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName speaker_ = speakerType; speakerName_ = speakerName; + bool shouldAddBlank = false; + auto lineChunks = splitStr>(std::string(msg), "\n"); - for (const std::string& text : lineChunks) { + for (std::string text : lineChunks) { + if (text.substr(0, 1) == "\f") { + text.erase(0, 1); + shouldAddBlank = false; + + if (lines_.empty() || lines_.back() != "\f") { + lines_.push_back("\f"); + } + } + auto words = splitStr>(text, " "); std::string curLine; int curWidth = 0; bool firstWord = true; - bool shouldAddBlank = false; - // I'm gonna be frank and admit it: I'm not gonna take hyphenation into // consideration. Please don't write any words that are wider than the // textbox. @@ -136,7 +145,7 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName if (shouldAddBlank) { shouldAddBlank = false; - lines_.push_back("\n"); + lines_.push_back("\f"); } else { shouldAddBlank = true; } @@ -152,14 +161,20 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName } lines_.push_back(curLine); - lines_.push_back("\n"); + + if (shouldAddBlank) { + shouldAddBlank = false; + lines_.push_back("\f"); + } else { + shouldAddBlank = true; + } } if (linesToShow_.empty()) { linesToShow_.push_back(MessageLine { .text = lines_.front() }); lines_.pop_front(); - if (lines_.front() != "\n") { + if (lines_.front() != "\f") { linesToShow_.push_back(MessageLine { .text = lines_.front() }); lines_.pop_front(); } @@ -182,7 +197,7 @@ void MessageSystem::advanceText() { return; } - if (lines_.front() != "\n") { + if (lines_.front() != "\f") { return; } diff --git a/src/message_system.h b/src/message_system.h index 85ecd65..155f9c6 100644 --- a/src/message_system.h +++ b/src/message_system.h @@ -33,6 +33,9 @@ public: void hideCutsceneBars(); + // Adds text to the message queue. Separate lines with \n. + // \f is a special character -- put it after a \n to indicate that a button + // press is required to advance text. void displayMessage( std::string_view msg, std::string speakerName = "", -- cgit 1.4.1