summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-09 11:19:22 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-09 11:19:22 -0500
commitc85f91cc5e0f9e94717fbc36ebef3b2637986121 (patch)
tree0bd1c5555d6395c5fc77540202296c93fc0b98f0
parent3f6a071f6728b4d08553220d4174018a4080b176 (diff)
downloadtanetane-c85f91cc5e0f9e94717fbc36ebef3b2637986121.tar.gz
tanetane-c85f91cc5e0f9e94717fbc36ebef3b2637986121.tar.bz2
tanetane-c85f91cc5e0f9e94717fbc36ebef3b2637986121.zip
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.
-rw-r--r--res/scripts/script0001.lua2
-rw-r--r--src/message_system.cpp31
-rw-r--r--src/message_system.h3
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()
2 SetAnimation("boney", "barking") 2 SetAnimation("boney", "barking")
3 local barkingNoise = LoopSound("barking_at_hallucination.wav") 3 local barkingNoise = LoopSound("barking_at_hallucination.wav")
4 4
5 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) 5 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)
6 WaitForEndOfMessage() 6 WaitForEndOfMessage()
7 7
8 SetAnimation("boney", "crouch") 8 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) {
52 // If both lines are totally revealed, see if we can scroll up a line. 52 // 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 53 // This is doable as long as the next line isn't the sentinel value that
54 // means an A press is required. 54 // means an A press is required.
55 if (!lines_.empty() && lines_.front() != "\n") { 55 if (!lines_.empty() && lines_.front() != "\f") {
56 if (linesToShow_.size() == 2) { 56 if (linesToShow_.size() == 2) {
57 linesToShow_.pop_front(); 57 linesToShow_.pop_front();
58 } 58 }
@@ -105,15 +105,24 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName
105 speaker_ = speakerType; 105 speaker_ = speakerType;
106 speakerName_ = speakerName; 106 speakerName_ = speakerName;
107 107
108 bool shouldAddBlank = false;
109
108 auto lineChunks = splitStr<std::list<std::string>>(std::string(msg), "\n"); 110 auto lineChunks = splitStr<std::list<std::string>>(std::string(msg), "\n");
109 for (const std::string& text : lineChunks) { 111 for (std::string text : lineChunks) {
112 if (text.substr(0, 1) == "\f") {
113 text.erase(0, 1);
114 shouldAddBlank = false;
115
116 if (lines_.empty() || lines_.back() != "\f") {
117 lines_.push_back("\f");
118 }
119 }
120
110 auto words = splitStr<std::list<std::string>>(text, " "); 121 auto words = splitStr<std::list<std::string>>(text, " ");
111 122
112 std::string curLine; 123 std::string curLine;
113 int curWidth = 0; 124 int curWidth = 0;
114 bool firstWord = true; 125 bool firstWord = true;
115 bool shouldAddBlank = false;
116
117 // I'm gonna be frank and admit it: I'm not gonna take hyphenation into 126 // I'm gonna be frank and admit it: I'm not gonna take hyphenation into
118 // consideration. Please don't write any words that are wider than the 127 // consideration. Please don't write any words that are wider than the
119 // textbox. 128 // textbox.
@@ -136,7 +145,7 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName
136 145
137 if (shouldAddBlank) { 146 if (shouldAddBlank) {
138 shouldAddBlank = false; 147 shouldAddBlank = false;
139 lines_.push_back("\n"); 148 lines_.push_back("\f");
140 } else { 149 } else {
141 shouldAddBlank = true; 150 shouldAddBlank = true;
142 } 151 }
@@ -152,14 +161,20 @@ void MessageSystem::displayMessage(std::string_view msg, std::string speakerName
152 } 161 }
153 162
154 lines_.push_back(curLine); 163 lines_.push_back(curLine);
155 lines_.push_back("\n"); 164
165 if (shouldAddBlank) {
166 shouldAddBlank = false;
167 lines_.push_back("\f");
168 } else {
169 shouldAddBlank = true;
170 }
156 } 171 }
157 172
158 if (linesToShow_.empty()) { 173 if (linesToShow_.empty()) {
159 linesToShow_.push_back(MessageLine { .text = lines_.front() }); 174 linesToShow_.push_back(MessageLine { .text = lines_.front() });
160 lines_.pop_front(); 175 lines_.pop_front();
161 176
162 if (lines_.front() != "\n") { 177 if (lines_.front() != "\f") {
163 linesToShow_.push_back(MessageLine { .text = lines_.front() }); 178 linesToShow_.push_back(MessageLine { .text = lines_.front() });
164 lines_.pop_front(); 179 lines_.pop_front();
165 } 180 }
@@ -182,7 +197,7 @@ void MessageSystem::advanceText() {
182 return; 197 return;
183 } 198 }
184 199
185 if (lines_.front() != "\n") { 200 if (lines_.front() != "\f") {
186 return; 201 return;
187 } 202 }
188 203
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:
33 33
34 void hideCutsceneBars(); 34 void hideCutsceneBars();
35 35
36 // Adds text to the message queue. Separate lines with \n.
37 // \f is a special character -- put it after a \n to indicate that a button
38 // press is required to advance text.
36 void displayMessage( 39 void displayMessage(
37 std::string_view msg, 40 std::string_view msg,
38 std::string speakerName = "", 41 std::string speakerName = "",