summary refs log tree commit diff stats
path: root/src/message_system.cpp
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 /src/message_system.cpp
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.
Diffstat (limited to 'src/message_system.cpp')
-rw-r--r--src/message_system.cpp31
1 files changed, 23 insertions, 8 deletions
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