Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly fix using setfont()/setrtl() script commands in between text boxes #1132

Merged
merged 1 commit into from Jan 23, 2024

Conversation

InfoTeddy
Copy link
Collaborator

@InfoTeddy InfoTeddy commented Jan 22, 2024

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.

Here is an example of what you can do now.

2024-01-22_12-15-34_1x

Legal Stuff:

By submitting this pull request, I confirm that...

  • My changes may be used in a future commercial release of VVVVVV
  • I will be credited in a CONTRIBUTORS file and the "GitHub Friends"
    section of the credits for all of said releases, but will NOT be compensated
    for these changes unless there is a prior written agreement

@Daaaav
Copy link
Contributor

Daaaav commented Jan 22, 2024

This is broken for custom level fonts. Print flags can currently encode individual main fonts (built-in 8x8, Japanese, Chinese, etc...), but not individual fonts from level assets, which are stored in a separate FontContainer with their own index. When you use setfont(), you're changing what PR_FONT_LEVEL means, and for fonts that come from level assets, PR_FONT_LEVEL is the only way to display them. So without further changes, there can only be one level asset font onscreen at the same time.

Print bitflag

Font selection:

  • 0: Use whatever the INTERFACE language/font is
  • 1: [PR_FONT_LEVEL] Use whatever the LEVEL language/font is (used for room names, cutscene dialogue, roomtext, etc, but not “Press ENTER to...”)
  • 2: [PR_FONT_8X8] Use 8x8 font no matter what
  • 3-31: Use specific font (used for language screen, levels list... use function to convert from langcode like "ja" to this number) [PR_FONT_IDX(idx, rtl)]

So if you want to actually make it work this way, you'd have to extend the bitflag with a way to also encode individual level-specific fonts. Something like 32-63 for level-specific fonts 0-31, or a separate bit that just changes the meaning of the existing 0-31.

Also, I think there's actually a nice side effect of the existing system - with internal scripting you could currently make text animate by switching fonts while keeping a textbox displayed! A change like this would make that impossible. Maybe it'd be cool to support both usecases somehow...

@InfoTeddy
Copy link
Collaborator Author

Fixed. Also, overriding the fonts of every existing text box is now possible by specifying all as the second parameter of setfont or setrtl.

Copy link
Contributor

@Daaaav Daaaav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks mostly alright from the code side? Just a couple small things, and I haven't tested it out yet.

I was honestly expecting a change like this to be way more invasive 😄

desktop_version/src/Font.cpp Outdated Show resolved Hide resolved
desktop_version/src/Font.h Outdated Show resolved Hide resolved
desktop_version/src/Script.cpp Outdated Show resolved Hide resolved
desktop_version/src/Script.cpp Outdated Show resolved Hide resolved
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.
@InfoTeddy
Copy link
Collaborator Author

Fixed.

@InfoTeddy InfoTeddy merged commit a9f0d81 into TerryCavanagh:master Jan 23, 2024
3 checks passed
@InfoTeddy InfoTeddy deleted the general-bug-fixes-2 branch January 23, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants