Ellpeck / MLEM

Libraries for MonoGame and FNA that provide abstractions, quality of life improvements and additional features like a ui system and easy input handling.
https://mlem.ellpeck.de/
MIT License
84 stars 6 forks source link

Allow for `MLEM.Formatting.Token` to have partial visibility. #2

Closed c272 closed 2 years ago

c272 commented 2 years ago

I'm attempting to create a dialogue box system similar to that of any visual novel, where the text slowly appears within the text box character by character using TokenizedString and Token, however I've run into a few practical problems with the system:

This PR proposes a solution to this by allowing Token to have a visible span, outside of which characters are not drawn. Please let me know if this is something you'd want upstream, and if so what you'd want changing to merge in. If not I'm happy to keep this in my downstream branch.

Ellpeck commented 2 years ago

Since Code supports a custom DrawCharacter method, you can simply add a text formatting code that only draws characters based on a certain time or maximum limit with exactly the same implementation that you proposed, so this doesn't need a separate implementation in the TokenizedString class.

Behavior like that also wouldn't require a separate downstream branch!

Ellpeck commented 2 years ago

(For reference, this part of WobblyCode makes use of very similar behavior to what I'm proposing for a custom code: https://github.com/Ellpeck/MLEM/blob/main/MLEM/Formatting/Codes/WobblyCode.cs#L32-L35)

c272 commented 2 years ago

Thank you, my apologies, I didn't know about the code system's draw overrides... This makes things a lot simpler!