mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 09:54:10 +03:00
Save special text box state using functions
This adds a way to save the text box state of the crew remaining, ACTION prompt, etc. text boxes by just letting there be a function that is called to retranslate the text box when needed. It also adds a way to ignore translating a text box and to leave it alone, in case there's actually no text in the text box, which is the case with Level Complete and Game Complete. Both ways are now in an enum, TextboxTranslate. The former is TEXTTRANSLATE_FUNCTION and the latter is TEXTTRANSLATE_NONE. The existing way of translating text boxes became TEXTTRANSLATE_CUTSCENE, since it's only used for cutscene scripts. Here's a quick guide to the three ways of creating a text box now. - TEXTTRANSLATE_NONE: You must call graphics.textboxoriginalcontextauto() to save the existing text to the original context of the text box, as that will be copied back to the text box after the text of the text box is updated due to not having a translation. - TEXTTRANSLATE_CUTSCENE: Translates the text from cutscenes.xml, and overrides the spacing (padding and text centering). Shouldn't need to be used outside of scriptclass. - TEXTTRANSLATE_FUNCTION: You must pass in a function that takes in a single parameter, a pointer to the textboxclass object to be modified. General advice when retranslating text is to clear the `lines` vector and then push_back the retranslated text. The function is also solely responsible for spacing. In most cases, you will also need to call graphics.textboxapplyposition() or graphics.textboxadjust() afterwards. (Some text boxes shouldn't use graphics.textboxadjust() as they are within the 10-pixel inner border around the screen that textboxclass::adjust tries to push the text box out of.) This commit doesn't fix every text box just yet, though. But it fixes the Level Complete, Game Complete, crew remaining, and ACTION prompt text boxes, for a start.
This commit is contained in:
@@ -32,6 +32,8 @@ textboxclass::textboxclass(int gap)
|
||||
should_centery = false;
|
||||
|
||||
print_flags = PR_FONT_LEVEL;
|
||||
translate = TEXTTRANSLATE_NONE;
|
||||
function = NULL;
|
||||
fill_buttons = false;
|
||||
|
||||
sprites.clear();
|
||||
@@ -41,6 +43,7 @@ textboxclass::textboxclass(int gap)
|
||||
crewmate_position = TextboxCrewmatePosition();
|
||||
original = TextboxOriginalContext();
|
||||
original.text_case = 1;
|
||||
spacing = TextboxSpacing();
|
||||
}
|
||||
|
||||
void textboxclass::addsprite(int x, int y, int tile, int col)
|
||||
@@ -71,7 +74,7 @@ void textboxclass::centery(void)
|
||||
resize();
|
||||
}
|
||||
|
||||
void textboxclass::adjust(void)
|
||||
void textboxclass::applyposition(void)
|
||||
{
|
||||
resize();
|
||||
repositionfromcrewmate();
|
||||
@@ -83,6 +86,12 @@ void textboxclass::adjust(void)
|
||||
{
|
||||
centery();
|
||||
}
|
||||
}
|
||||
|
||||
void textboxclass::adjust(void)
|
||||
{
|
||||
resize();
|
||||
applyposition();
|
||||
if (xp < 10) xp = 10;
|
||||
if (yp < 10) yp = 10;
|
||||
if (xp + w > 310) xp = 310 - w;
|
||||
@@ -246,16 +255,59 @@ void textboxclass::centertext(void)
|
||||
padtowidth(w-16);
|
||||
}
|
||||
|
||||
void textboxclass::translate(void)
|
||||
void textboxclass::copyoriginaltext(void)
|
||||
{
|
||||
// Copy the original back, but keep the limit of lines in mind
|
||||
lines.clear();
|
||||
for (size_t i = 0; i < original.lines.size(); i++)
|
||||
{
|
||||
addline(original.lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void textboxclass::applyoriginalspacing(void)
|
||||
{
|
||||
if (spacing.centertext)
|
||||
{
|
||||
centertext();
|
||||
}
|
||||
if (spacing.pad_left > 0 || spacing.pad_right > 0)
|
||||
{
|
||||
pad(spacing.pad_left, spacing.pad_right);
|
||||
}
|
||||
if (spacing.padtowidth > 0)
|
||||
{
|
||||
padtowidth(spacing.padtowidth);
|
||||
}
|
||||
}
|
||||
|
||||
void textboxclass::updatetext(void)
|
||||
{
|
||||
switch (translate)
|
||||
{
|
||||
case TEXTTRANSLATE_NONE:
|
||||
copyoriginaltext();
|
||||
applyoriginalspacing();
|
||||
break;
|
||||
case TEXTTRANSLATE_CUTSCENE:
|
||||
translatecutscene();
|
||||
break;
|
||||
case TEXTTRANSLATE_FUNCTION:
|
||||
if (function == NULL)
|
||||
{
|
||||
SDL_assert(0 && "function is NULL!");
|
||||
break;
|
||||
}
|
||||
function(this);
|
||||
}
|
||||
}
|
||||
|
||||
void textboxclass::translatecutscene(void)
|
||||
{
|
||||
if (!loc::is_cutscene_translated(original.script_name))
|
||||
{
|
||||
// Copy the original back, but keep the limit of lines in mind
|
||||
lines.clear();
|
||||
for (size_t i = 0; i < original.lines.size(); i++)
|
||||
{
|
||||
addline(original.lines[i]);
|
||||
}
|
||||
copyoriginaltext();
|
||||
applyoriginalspacing();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -274,6 +326,8 @@ void textboxclass::translate(void)
|
||||
const loc::TextboxFormat* format = loc::gettext_cutscene(original.script_name, eng, original.text_case);
|
||||
if (format == NULL || format->text == NULL || format->text[0] == '\0')
|
||||
{
|
||||
copyoriginaltext();
|
||||
applyoriginalspacing();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user