From c50da88ad4275f0437b051ac96bcb3146dab04e3 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 21 Jan 2024 14:56:08 -0800 Subject: [PATCH] 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. --- desktop_version/src/Graphics.cpp | 2 ++ desktop_version/src/Script.cpp | 2 ++ desktop_version/src/Textbox.cpp | 20 ++++++++++++++++++-- desktop_version/src/Textbox.h | 4 +++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index d994ecd1..b40947ea 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -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; } diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index f36c1636..0c08673a 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -773,6 +773,8 @@ void scriptclass::run(void) context.text_case = textcase; context.lines = std::vector(txt); context.script_name = scriptname; + context.x = textx; + context.y = texty; graphics.textboxcrewmateposition(&textcrewmateposition); graphics.textboxoriginalcontext(&context); diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index 1d44b2d9..499440ad 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -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) diff --git a/desktop_version/src/Textbox.h b/desktop_version/src/Textbox.h index aaa54ea4..4483491c 100644 --- a/desktop_version/src/Textbox.h +++ b/desktop_version/src/Textbox.h @@ -19,6 +19,8 @@ struct TextboxCrewmatePosition struct TextboxOriginalContext { + int x; + int y; std::vector 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);