From ec511705ce96d80d4e2a36054769c211448e8ec8 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 11 Feb 2021 20:47:46 -0500 Subject: Added choice prompts "A presses" are also no longer special values in the lines list, but are rather a field on the MessageLine object. --- src/message_system.cpp | 82 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 24 deletions(-) (limited to 'src/message_system.cpp') diff --git a/src/message_system.cpp b/src/message_system.cpp index a200abc..a969427 100644 --- a/src/message_system.cpp +++ b/src/message_system.cpp @@ -39,10 +39,16 @@ void MessageSystem::tick(double dt) { } } - line.charsRevealed += CHARS_TO_REVEAL; - if (line.charsRevealed > line.text.size()) { + if (line.isChoice) { line.charsRevealed = line.text.size(); + choiceSelection_ = 0; + } else { + line.charsRevealed += CHARS_TO_REVEAL; + if (line.charsRevealed > line.text.size()) { + line.charsRevealed = line.text.size(); + } } + advancedChars = true; break; } @@ -50,14 +56,14 @@ void MessageSystem::tick(double dt) { if (!advancedChars) { // 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() != "\f") { + // This is doable as long as the last currently visible line doesn't + // have the flag that means an A press is required. + if (!lines_.empty() && !linesToShow_.back().pause) { if (linesToShow_.size() == 2) { linesToShow_.pop_front(); } - linesToShow_.push_back(MessageLine { .text = lines_.front() }); + linesToShow_.push_back(lines_.front()); lines_.pop_front(); } else { showNextArrow_ = true; @@ -113,8 +119,8 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName text.erase(0, 1); shouldAddBlank = false; - if (lines_.empty() || lines_.back() != "\f") { - lines_.push_back("\f"); + if (!lines_.empty()) { + lines_.back().pause = true; } } @@ -139,13 +145,13 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName } if (nextWidth > MESSAGE_TEXT_WIDTH) { - lines_.push_back(curLine); + lines_.push_back({.text = curLine}); curLine = word; curWidth = wordWidth + game_.getFont().getCharacterWidth(' '); if (shouldAddBlank) { shouldAddBlank = false; - lines_.push_back("\f"); + lines_.back().pause = true; } else { shouldAddBlank = true; } @@ -160,52 +166,66 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName firstWord = false; } - lines_.push_back(curLine); + lines_.push_back({.text = curLine}); if (shouldAddBlank) { shouldAddBlank = false; - lines_.push_back("\f"); + lines_.back().pause = true; } else { shouldAddBlank = true; } } - if (lines_.empty() || lines_.back() != "\f") { - lines_.push_back("\f"); + if (!lines_.empty()) { + lines_.back().pause = true; } if (linesToShow_.empty()) { - linesToShow_.push_back(MessageLine { .text = lines_.front() }); + linesToShow_.push_back(lines_.front()); lines_.pop_front(); - if (lines_.front() != "\f") { - linesToShow_.push_back(MessageLine { .text = lines_.front() }); + if (!linesToShow_.back().pause) { + linesToShow_.push_back(lines_.front()); lines_.pop_front(); } } } +void MessageSystem::showChoice(std::string choice1, std::string choice2) { + MessageLine line; + line.text = std::string(8, ' ') + choice1 + std::string(11, ' ') + choice2; + line.pause = true; + line.isChoice = true; + line.choicePos[0] = 8; + line.choicePos[1] = 8 + 11 + choice1.size(); + + lines_.push_back(line); +} + void MessageSystem::advanceText() { + // Cutscene must be active. if (barsState_ != BarsState::Open) { return; } + if (linesToShow_.empty()) { + return; + } + // We can only advance if all visible lines are fully revealed. for (const MessageLine& line : linesToShow_) { if (line.charsRevealed != line.text.size()) { return; } } - if (lines_.empty()) { - linesToShow_.clear(); + // If the last visible line doesn't have a pause, then the cutscene + // will automatically progress without us doing anything. + if (!linesToShow_.back().pause) { return; } - if (lines_.front() != "\f") { - return; - } - - lines_.pop_front(); + // Clear the current pause. + linesToShow_.back().pause = false; showNextArrow_ = false; if (lines_.empty()) { @@ -215,6 +235,20 @@ void MessageSystem::advanceText() { } } +void MessageSystem::selectFirstChoice() { + if (isChoiceActive() && choiceSelection_ != 0) { + choiceSelection_ = 0; + game_.getMixer().playSound("../res/sfx/horizontal_menu.wav"); + } +} + +void MessageSystem::selectSecondChoice() { + if (isChoiceActive() && choiceSelection_ != 1) { + choiceSelection_ = 1; + game_.getMixer().playSound("../res/sfx/horizontal_menu.wav"); + } +} + double MessageSystem::getCutsceneBarsProgress() const { switch (barsState_) { case BarsState::Closed: return 0.0; -- cgit 1.4.1