Split textwraps, move more textboxes to new system

This splits the text wrapping functionality of Graphics::textboxwrap to
a new function textboxclass::wrap, and with this new function, some more
text boxes can be moved to the new TEXTTRANSLATE_FUNCTION system.
Namely, Game Saved (specifically the game failing to save text box),
instructional text boxes in Space Station 1, and the Intermission 1
instructional text boxes.
This commit is contained in:
Misa
2024-01-20 21:33:57 -08:00
committed by Misa Elizabeth Kai
parent de00dd4031
commit 94b9722b7b
4 changed files with 233 additions and 143 deletions

View File

@@ -5,6 +5,7 @@
#include "Font.h"
#include "Localization.h"
#include "UTF8.h"
#include "Vlogging.h"
textboxclass::textboxclass(int gap)
{
@@ -255,6 +256,40 @@ void textboxclass::centertext(void)
padtowidth(w-16);
}
int textboxclass::wrap(int pad)
{
/* This function just takes a single-line textbox and wraps it...
* pad = the total number of characters we are going to pad this textbox.
* (or how many characters we should stay clear of 288 pixels width in general)
* Only to be used after a manual graphics.createtextbox[flipme] call,
* or the retranslation of a text box created with said call.
* Returns the new, total height of the textbox. */
if (lines.empty())
{
vlog_error("textboxclass::wrap() has no first line!");
return 16;
}
std::string wrapped = font::string_wordwrap_balanced(
print_flags,
lines[0],
36 * 8 - pad * 8
);
lines.clear();
size_t startline = 0;
size_t newline;
do {
size_t pos_n = wrapped.find('\n', startline);
size_t pos_p = wrapped.find('|', startline);
newline = SDL_min(pos_n, pos_p);
addline(wrapped.substr(startline, newline-startline));
startline = newline + 1;
} while (newline != std::string::npos);
return h;
}
void textboxclass::copyoriginaltext(void)
{
// Copy the original back, but keep the limit of lines in mind