diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-11 20:47:46 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-11 20:47:46 -0500 |
commit | ec511705ce96d80d4e2a36054769c211448e8ec8 (patch) | |
tree | e0a70671430a84472024d54b934df3248924ec4d /src/message_system.cpp | |
parent | d9be54853910c2086013846661e0dc4a8603c20e (diff) | |
download | tanetane-ec511705ce96d80d4e2a36054769c211448e8ec8.tar.gz tanetane-ec511705ce96d80d4e2a36054769c211448e8ec8.tar.bz2 tanetane-ec511705ce96d80d4e2a36054769c211448e8ec8.zip |
Added choice prompts
"A presses" are also no longer special values in the lines list, but are rather a field on the MessageLine object.
Diffstat (limited to 'src/message_system.cpp')
-rw-r--r-- | src/message_system.cpp | 82 |
1 files changed, 58 insertions, 24 deletions
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) { | |||
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | line.charsRevealed += CHARS_TO_REVEAL; | 42 | if (line.isChoice) { |
43 | if (line.charsRevealed > line.text.size()) { | ||
44 | line.charsRevealed = line.text.size(); | 43 | line.charsRevealed = line.text.size(); |
44 | choiceSelection_ = 0; | ||
45 | } else { | ||
46 | line.charsRevealed += CHARS_TO_REVEAL; | ||
47 | if (line.charsRevealed > line.text.size()) { | ||
48 | line.charsRevealed = line.text.size(); | ||
49 | } | ||
45 | } | 50 | } |
51 | |||
46 | advancedChars = true; | 52 | advancedChars = true; |
47 | break; | 53 | break; |
48 | } | 54 | } |
@@ -50,14 +56,14 @@ void MessageSystem::tick(double dt) { | |||
50 | 56 | ||
51 | if (!advancedChars) { | 57 | if (!advancedChars) { |
52 | // If both lines are totally revealed, see if we can scroll up a line. | 58 | // If both lines are totally revealed, see if we can scroll up a line. |
53 | // This is doable as long as the next line isn't the sentinel value that | 59 | // This is doable as long as the last currently visible line doesn't |
54 | // means an A press is required. | 60 | // have the flag that means an A press is required. |
55 | if (!lines_.empty() && lines_.front() != "\f") { | 61 | if (!lines_.empty() && !linesToShow_.back().pause) { |
56 | if (linesToShow_.size() == 2) { | 62 | if (linesToShow_.size() == 2) { |
57 | linesToShow_.pop_front(); | 63 | linesToShow_.pop_front(); |
58 | } | 64 | } |
59 | 65 | ||
60 | linesToShow_.push_back(MessageLine { .text = lines_.front() }); | 66 | linesToShow_.push_back(lines_.front()); |
61 | lines_.pop_front(); | 67 | lines_.pop_front(); |
62 | } else { | 68 | } else { |
63 | showNextArrow_ = true; | 69 | showNextArrow_ = true; |
@@ -113,8 +119,8 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName | |||
113 | text.erase(0, 1); | 119 | text.erase(0, 1); |
114 | shouldAddBlank = false; | 120 | shouldAddBlank = false; |
115 | 121 | ||
116 | if (lines_.empty() || lines_.back() != "\f") { | 122 | if (!lines_.empty()) { |
117 | lines_.push_back("\f"); | 123 | lines_.back().pause = true; |
118 | } | 124 | } |
119 | } | 125 | } |
120 | 126 | ||
@@ -139,13 +145,13 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName | |||
139 | } | 145 | } |
140 | 146 | ||
141 | if (nextWidth > MESSAGE_TEXT_WIDTH) { | 147 | if (nextWidth > MESSAGE_TEXT_WIDTH) { |
142 | lines_.push_back(curLine); | 148 | lines_.push_back({.text = curLine}); |
143 | curLine = word; | 149 | curLine = word; |
144 | curWidth = wordWidth + game_.getFont().getCharacterWidth(' '); | 150 | curWidth = wordWidth + game_.getFont().getCharacterWidth(' '); |
145 | 151 | ||
146 | if (shouldAddBlank) { | 152 | if (shouldAddBlank) { |
147 | shouldAddBlank = false; | 153 | shouldAddBlank = false; |
148 | lines_.push_back("\f"); | 154 | lines_.back().pause = true; |
149 | } else { | 155 | } else { |
150 | shouldAddBlank = true; | 156 | shouldAddBlank = true; |
151 | } | 157 | } |
@@ -160,52 +166,66 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName | |||
160 | firstWord = false; | 166 | firstWord = false; |
161 | } | 167 | } |
162 | 168 | ||
163 | lines_.push_back(curLine); | 169 | lines_.push_back({.text = curLine}); |
164 | 170 | ||
165 | if (shouldAddBlank) { | 171 | if (shouldAddBlank) { |
166 | shouldAddBlank = false; | 172 | shouldAddBlank = false; |
167 | lines_.push_back("\f"); | 173 | lines_.back().pause = true; |
168 | } else { | 174 | } else { |
169 | shouldAddBlank = true; | 175 | shouldAddBlank = true; |
170 | } | 176 | } |
171 | } | 177 | } |
172 | 178 | ||
173 | if (lines_.empty() || lines_.back() != "\f") { | 179 | if (!lines_.empty()) { |
174 | lines_.push_back("\f"); | 180 | lines_.back().pause = true; |
175 | } | 181 | } |
176 | 182 | ||
177 | if (linesToShow_.empty()) { | 183 | if (linesToShow_.empty()) { |
178 | linesToShow_.push_back(MessageLine { .text = lines_.front() }); | 184 | linesToShow_.push_back(lines_.front()); |
179 | lines_.pop_front(); | 185 | lines_.pop_front(); |
180 | 186 | ||
181 | if (lines_.front() != "\f") { | 187 | if (!linesToShow_.back().pause) { |
182 | linesToShow_.push_back(MessageLine { .text = lines_.front() }); | 188 | linesToShow_.push_back(lines_.front()); |
183 | lines_.pop_front(); | 189 | lines_.pop_front(); |
184 | } | 190 | } |
185 | } | 191 | } |
186 | } | 192 | } |
187 | 193 | ||
194 | void MessageSystem::showChoice(std::string choice1, std::string choice2) { | ||
195 | MessageLine line; | ||
196 | line.text = std::string(8, ' ') + choice1 + std::string(11, ' ') + choice2; | ||
197 | line.pause = true; | ||
198 | line.isChoice = true; | ||
199 | line.choicePos[0] = 8; | ||
200 | line.choicePos[1] = 8 + 11 + choice1.size(); | ||
201 | |||
202 | lines_.push_back(line); | ||
203 | } | ||
204 | |||
188 | void MessageSystem::advanceText() { | 205 | void MessageSystem::advanceText() { |
206 | // Cutscene must be active. | ||
189 | if (barsState_ != BarsState::Open) { | 207 | if (barsState_ != BarsState::Open) { |
190 | return; | 208 | return; |
191 | } | 209 | } |
210 | if (linesToShow_.empty()) { | ||
211 | return; | ||
212 | } | ||
192 | 213 | ||
214 | // We can only advance if all visible lines are fully revealed. | ||
193 | for (const MessageLine& line : linesToShow_) { | 215 | for (const MessageLine& line : linesToShow_) { |
194 | if (line.charsRevealed != line.text.size()) { | 216 | if (line.charsRevealed != line.text.size()) { |
195 | return; | 217 | return; |
196 | } | 218 | } |
197 | } | 219 | } |
198 | 220 | ||
199 | if (lines_.empty()) { | 221 | // If the last visible line doesn't have a pause, then the cutscene |
200 | linesToShow_.clear(); | 222 | // will automatically progress without us doing anything. |
223 | if (!linesToShow_.back().pause) { | ||
201 | return; | 224 | return; |
202 | } | 225 | } |
203 | 226 | ||
204 | if (lines_.front() != "\f") { | 227 | // Clear the current pause. |
205 | return; | 228 | linesToShow_.back().pause = false; |
206 | } | ||
207 | |||
208 | lines_.pop_front(); | ||
209 | showNextArrow_ = false; | 229 | showNextArrow_ = false; |
210 | 230 | ||
211 | if (lines_.empty()) { | 231 | if (lines_.empty()) { |
@@ -215,6 +235,20 @@ void MessageSystem::advanceText() { | |||
215 | } | 235 | } |
216 | } | 236 | } |
217 | 237 | ||
238 | void MessageSystem::selectFirstChoice() { | ||
239 | if (isChoiceActive() && choiceSelection_ != 0) { | ||
240 | choiceSelection_ = 0; | ||
241 | game_.getMixer().playSound("../res/sfx/horizontal_menu.wav"); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | void MessageSystem::selectSecondChoice() { | ||
246 | if (isChoiceActive() && choiceSelection_ != 1) { | ||
247 | choiceSelection_ = 1; | ||
248 | game_.getMixer().playSound("../res/sfx/horizontal_menu.wav"); | ||
249 | } | ||
250 | } | ||
251 | |||
218 | double MessageSystem::getCutsceneBarsProgress() const { | 252 | double MessageSystem::getCutsceneBarsProgress() const { |
219 | switch (barsState_) { | 253 | switch (barsState_) { |
220 | case BarsState::Closed: return 0.0; | 254 | case BarsState::Closed: return 0.0; |