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:
Misa
2024-01-20 20:27:31 -08:00
committed by Misa Elizabeth Kai
parent 0ea0b8e00b
commit de00dd4031
7 changed files with 204 additions and 37 deletions

View File

@@ -117,13 +117,16 @@ public:
void textboxcrewmateposition(const TextboxCrewmatePosition* crewmate_position);
void textboxoriginalcontext(const TextboxOriginalContext* original_context);
void textboxoriginalcontextauto(void);
void textboxcase(char text_case);
void textboxtranslate(void);
void textboxtranslate(TextboxTranslate translate, TextboxFunction function);
void textboxcommsrelay(void);
void textboxapplyposition(void);
void textboxadjust(void);
void addline(const std::string& t);