Store original position of text box

This stores the original x-position and y-position of the text box, and
when a text box gets repositioned, it will use those unless a crewmate
position overrides it.

This is the original position of the text box, before centering or
crewmate position is considered.

This fixes a bug where a cutscene text box can be "shifted" from its
normal position via CTRL+F8 cycling if there is a translation that is
too long for the screen and thus gets pushed by adjust(). I tested this
with the text box in the Comms Relay cutscene that starts with "If YOU
can find a teleporter".

This is not applicable to function-based translations
(TEXTTRANSLATE_FUNCTION), because the responsibility of correctly
positioning the text box resides with the function.
This commit is contained in:
Misa 2024-01-21 14:56:08 -08:00 committed by Misa Elizabeth Kai
parent 9b56a53d98
commit c50da88ad4
4 changed files with 25 additions and 3 deletions

View File

@ -3344,6 +3344,8 @@ void Graphics::textboxoriginalcontextauto(void)
{
context.script_name = script.scriptname;
}
context.x = textboxes[m].xp;
context.y = textboxes[m].yp;
textboxes[m].original = context;
}

View File

@ -773,6 +773,8 @@ void scriptclass::run(void)
context.text_case = textcase;
context.lines = std::vector<std::string>(txt);
context.script_name = scriptname;
context.x = textx;
context.y = texty;
graphics.textboxcrewmateposition(&textcrewmateposition);
graphics.textboxoriginalcontext(&context);

View File

@ -78,7 +78,7 @@ void textboxclass::centery(void)
void textboxclass::applyposition(void)
{
resize();
repositionfromcrewmate();
reposition();
if (should_centerx)
{
centerx();
@ -165,11 +165,18 @@ void textboxclass::resize(void)
h = lines.size()*(font::height(print_flags) + linegap) + 16 - linegap;
}
void textboxclass::repositionfromcrewmate(void)
void textboxclass::reposition(void)
{
// Function-based translation overrides position.
if (translate == TEXTTRANSLATE_FUNCTION)
{
return;
}
const int font_height = font::height(print_flags);
// Reposition based off crewmate position, if applicable
// Otherwise use original position, if applicable
if (crewmate_position.override_x)
{
if (crewmate_position.dir == 1) // left
@ -181,6 +188,11 @@ void textboxclass::repositionfromcrewmate(void)
xp = crewmate_position.x - 16;
}
}
else
{
xp = original.x;
}
if (crewmate_position.override_y)
{
if (crewmate_position.text_above)
@ -199,6 +211,10 @@ void textboxclass::repositionfromcrewmate(void)
yp = crewmate_position.y + 26;
}
}
else
{
yp = original.y;
}
}
void textboxclass::addline(const std::string& t)

View File

@ -19,6 +19,8 @@ struct TextboxCrewmatePosition
struct TextboxOriginalContext
{
int x;
int y;
std::vector<std::string> lines;
std::string script_name;
char text_case;
@ -85,7 +87,7 @@ public:
void resize(void);
void repositionfromcrewmate(void);
void reposition(void);
void addline(const std::string& t);