mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39:43 +01:00
Properly fix setfont/setrtl in between text boxes
There used to be a problem with the setfont and setrtl script commands. Namely, if you used them in between text boxes naïvely, without any careful thought, then the fading out text box would suddenly gain the font of the new one. A kludge solution to this was implemented by simply blocking the script until the existing text box faded out before switching the font or RTL, and shipped for 2.4.0. However, a better solution is to simply bake the font flags in to the text box, so that way, if the level font switches, then the text box keeps its font. This is only for custom levels, because in the main game, the font in a text box needs to be able to change depending on language. But it seems like custom level translations weren't much on the roadmap, and so even the existing hack didn't support changing the font based on translation (even though translation of custom level cutscenes is supported). So baking the font flags into the text box here doesn't make things any worse. It also makes things better, arguably, by allowing multiple text boxes to exist on screen at once with different fonts. Maybe in the future we'll need a flag that specifies that the font should change depending on language if a translation in said language exists for the text box, or something like that. For people that want to override the fonts of every existing text box on screen, you can specify "all" as the second parameter of setfont or setrtl to do so.
This commit is contained in:
parent
ea8633514d
commit
a9f0d81804
3 changed files with 50 additions and 30 deletions
|
@ -95,8 +95,8 @@ uint8_t font_idx_options_n = 0;
|
|||
uint8_t font_idx_options[20];
|
||||
|
||||
static bool font_level_is_interface = false;
|
||||
static bool font_idx_level_is_custom = false;
|
||||
static uint8_t font_idx_level = 0;
|
||||
bool font_idx_level_is_custom = false;
|
||||
uint8_t font_idx_level = 0;
|
||||
|
||||
static void codepoint_split(
|
||||
const uint32_t codepoint,
|
||||
|
@ -765,13 +765,14 @@ static Font* container_get(FontContainer* container, uint8_t idx)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static Font* fontsel_to_font(int sel, bool* rtl)
|
||||
static Font* fontsel_to_font(int sel, bool* rtl, bool custom)
|
||||
{
|
||||
/* Take font selection integer (0-31) and turn it into the correct Font
|
||||
* 0: PR_FONT_INTERFACE - use interface font
|
||||
* 1: PR_FONT_LEVEL - use level font
|
||||
* 2: PR_FONT_8X8 - use 8x8 font no matter what
|
||||
* 3-31: - use (main) font index 0-28
|
||||
* 3-31: - use font index 0-28 (depending on custom, from
|
||||
* PR_FONT_IDX_IS_CUSTOM)
|
||||
*
|
||||
* rtl will be set depending on whether we're requesting the interface
|
||||
* font (take it from the lang attributes) or level font (take it from
|
||||
|
@ -808,6 +809,10 @@ static Font* fontsel_to_font(int sel, bool* rtl)
|
|||
return container_get(&fonts_main, font_idx_8x8);
|
||||
}
|
||||
|
||||
if (custom)
|
||||
{
|
||||
return container_get(&fonts_custom, sel-3);
|
||||
}
|
||||
return container_get(&fonts_main, sel-3);
|
||||
}
|
||||
|
||||
|
@ -816,7 +821,9 @@ static PrintFlags decode_print_flags(uint32_t flags)
|
|||
{
|
||||
PrintFlags pf;
|
||||
pf.scale = FLAG_PART(0, 3) + 1;
|
||||
pf.font_sel = fontsel_to_font(FLAG_PART(3, 5), &pf.rtl);
|
||||
pf.font_sel = fontsel_to_font(
|
||||
FLAG_PART(3, 5), &pf.rtl, flags & PR_FONT_IDX_IS_CUSTOM
|
||||
);
|
||||
if (flags & PR_RTL_FORCE)
|
||||
{
|
||||
pf.rtl = true;
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#define PR_CJK_HIGH (2 << 20) /* larger fonts should stick out fully on the top */
|
||||
#define PR_RTL_FORCE (1 << 22) /* force the RTL flag, not needed if the font is set to INTERFACE or LEVEL */
|
||||
#define PR_RTL_XFLIP (1 << 23) /* in RTL languages, mirror the X axis, so left is 320 and right is 0, and invert the meaning of PR_LEFT and PR_RIGHT */
|
||||
#define PR_FONT_IDX_IS_CUSTOM (1 << 24) /* with PR_FONT_IDX, mark that the font index is of a custom font */
|
||||
|
||||
|
||||
namespace font
|
||||
|
@ -64,6 +65,9 @@ namespace font
|
|||
extern uint8_t font_idx_options_n;
|
||||
extern uint8_t font_idx_options[20];
|
||||
|
||||
extern uint8_t font_idx_level;
|
||||
extern bool font_idx_level_is_custom;
|
||||
|
||||
bool find_main_font_by_name(const char* name, uint8_t* idx);
|
||||
const char* get_main_font_name(uint8_t idx);
|
||||
const char* get_main_font_display_name(uint8_t idx);
|
||||
|
|
|
@ -798,6 +798,16 @@ void scriptclass::run(void)
|
|||
graphics.textboxcentery();
|
||||
}
|
||||
|
||||
if (map.custommode)
|
||||
{
|
||||
uint32_t flags = PR_FONT_IDX(font::font_idx_level, cl.rtl);
|
||||
if (font::font_idx_level_is_custom)
|
||||
{
|
||||
flags |= PR_FONT_IDX_IS_CUSTOM;
|
||||
}
|
||||
graphics.textboxprintflags(flags);
|
||||
}
|
||||
|
||||
graphics.textboxadjust();
|
||||
if (words[0] == "speak_active")
|
||||
{
|
||||
|
@ -2480,21 +2490,6 @@ void scriptclass::run(void)
|
|||
}
|
||||
}
|
||||
else if (words[0] == "setfont" || words[0] == "setrtl")
|
||||
{
|
||||
// If any textbox is currently fading out, wait for that first
|
||||
bool blocked = false;
|
||||
for (size_t i = 0; i < graphics.textboxes.size(); i++)
|
||||
{
|
||||
if (graphics.textboxes[i].tm == 2)
|
||||
{
|
||||
scriptdelay = 1;
|
||||
position--;
|
||||
blocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!blocked)
|
||||
{
|
||||
if (words[0] == "setrtl")
|
||||
{
|
||||
|
@ -2515,6 +2510,20 @@ void scriptclass::run(void)
|
|||
{
|
||||
font::set_level_font(raw_words[1].c_str());
|
||||
}
|
||||
if (argexists[2] && words[2] == "all")
|
||||
{
|
||||
/* Immediately update all text boxes. */
|
||||
uint32_t flags = PR_FONT_IDX(font::font_idx_level, cl.rtl);
|
||||
if (font::font_idx_level_is_custom)
|
||||
{
|
||||
flags |= PR_FONT_IDX_IS_CUSTOM;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < graphics.textboxes.size(); i++)
|
||||
{
|
||||
graphics.textboxes[i].print_flags = flags;
|
||||
graphics.textboxes[i].resize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue