| 132 | } |
| 133 | |
| 134 | void Window_Message::StartMessageProcessing(PendingMessage pm) { |
| 135 | text.clear(); |
| 136 | pending_message = std::move(pm); |
| 137 | |
| 138 | if (!IsVisible()) { |
| 139 | DebugLogResetFrameCounter(); |
| 140 | } |
| 141 | DebugLog("{}: MSG START"); |
| 142 | |
| 143 | if (!pending_message.IsActive()) { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | const auto& lines = pending_message.GetLines(); |
| 148 | |
| 149 | int num_lines = 0; |
| 150 | auto append = [&](const std::string& line) { |
| 151 | bool force_page_break = (!line.empty() && line.back() == '\f'); |
| 152 | |
| 153 | text.append(line, 0, line.size() - force_page_break); |
| 154 | if (line.empty() || text.back() != '\n') { |
| 155 | text.push_back('\n'); |
| 156 | } |
| 157 | ++num_lines; |
| 158 | |
| 159 | if (num_lines == GetMaxLinesPerPage() || force_page_break) { |
| 160 | text.push_back('\f'); |
| 161 | num_lines = 0; |
| 162 | } |
| 163 | }; |
| 164 | |
| 165 | if (pending_message.IsWordWrapped()) { |
| 166 | for (const std::string& line : lines) { |
| 167 | /* TODO: don't take commands like \> \< into account when word-wrapping */ |
| 168 | Game_Message::WordWrap( |
| 169 | line, |
| 170 | width - 24, |
| 171 | [&](std::string_view wrapped_line) { |
| 172 | append(std::string(wrapped_line)); |
| 173 | } |
| 174 | ); |
| 175 | } |
| 176 | } else { |
| 177 | for (const std::string& line : lines) { |
| 178 | append(line); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (text.empty() || text.back() != '\f') { |
| 183 | text.push_back('\f'); |
| 184 | } |
| 185 | |
| 186 | item_max = min(4, pending_message.GetNumChoices()); |
| 187 | |
| 188 | text_index = text.data(); |
| 189 | |
| 190 | DebugLog("{}: MSG TEXT \n{}", text); |
| 191 |
no test coverage detected