-
Notifications
You must be signed in to change notification settings - Fork 46
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
color crazy strings #16
Comments
The method that takes an |
I am trying to use a
|
@Rakaneth > cool screenshot :-) @tommyettinger will be able to help you as he coded |
@smelc I did try replacing this with a TextPanel, which does properly display the color string; however, now I have a problem that new text added to the panel after initialization isn't getting drawn.. |
I'll take a look at the code and try writing or improving a demo to test this better than the current tests do. It seems like I missed something in the demos. Also, Wolf's Den is a great name. |
@Rakaneth > Indeed TextPanel is designed for displaying text that is known at initialization time. It'll never update its text afterwards. You should try LinesPanel if you wanna draw using libgdx's Bitmap font directly, it's the gdx-direct alternative to SquidMessageBox. |
This is relevant for #16 . The implementation of appendMessage() for String correctly added an item to the internal List of IColoredString values, but appendMessage() for IColoredString did not. This should work now. I was considering adding a method to IMarkup to escape non-markup usage of characters that might be mistaken for markup, but it doesn't seem needed and would break anything that implements IMarkup. So, the code I wrote is only present in comments in markup-related files.
The first issue mentioned should be fixed as of the latest commit; some of the SquidMessageBox code updated the List of IColoredStrings when a String was appended, but didn't update that List when an IColoredString was added. SquidMessageBox should work now. As smelc said, LinesPanel should fit your needs; it can also handle non-fixed-width fonts (several are in DefaultResources; I like |
Thanks for the update! I did wire up a On a separate note, I did try to throw together another implementation of
I couldn't find a way to get a String name of a Color, though; is this possible? |
It's possible for LARP on! |
Woah... it shouldn't have changed to that, if it changed at all since you last used it.
If the third item in the list doesn't look like |
I got it figured out. I used I fixed this by reaching directly into |
Now, I have a different issue. I've gone back to |
What are you trying to do with the markup? Is this your custom implementation that uses names of colors? I'm not totally sure how all of the code involved fits together, but libGDX can be configured to treat a String like EDIT: You can enable markup on a BitmapFont with |
Right now, I just want to be able to send IMarked-up strings to a |
Most of the distance field fonts now include the full block image at Unicode codepoint 0. That block was previously a separate Texture, and that has performance downsides when mostly rendering text. By keeping an entire text-based line as potentially one String with different colors, we also open up possibilities for both optimizing our drawing a little better, and for using markup on long Strings (as I'd like to have for #16 )Though the fonts should keep the changes in this commit for later (it gave me a chance to improve some unrelated spacing issues in some fonts), TextCellFactory will have its changes in this commit immediately reverted, since not all fonts have a block at codepoint 0, including probably all user-created fonts. The solution is probably to use a subclass of TextCellFactory for fonts we know have been made to use the block in the font, and default to the normal separate texture for all other fonts.
This was directly inspired by #16 and Rakaneth's approach to generating IColoredStrings by parsing GDX color markup; this way also uses regular expressions, but uses RegExodus like the rest of SquidLib for GWT compatibility. Some more-advanced and less-documented RegExodus features are used here to simplify the code, at least for me since I've attempted to understand RegExodus for a while now. This can generate colorful text like at the bottom of this screenshot, https://i.imgur.com/CBsLzdL.png , using code like this: ``` IColoredString<Color> text = GDXMarkup.instance.colorString( "Use numpad or vi-keys ([CW Bright Red]h[CW Bright Apricot]j[CW Bright Yellow]k[CW Bright Lime]l" + "[CW Bright Jade]y[CW Bright Azure]u[CW Bright Sapphire]b[CW Flush Purple]n[]) to move. Use " + "[CW Pale Indigo]?[] for help, [CW Faded Brown]f[] to filter colors, [CW Gray White]q[] to quit. " + "Click the top or bottom border of this box to scroll."); ``` This wrapper around GDX markup isn't the most convenient way of specifying colors that I can think of, but it's pretty nice.
@Rakaneth , I liked your idea to parse markup in a straightforward way with regexes, so I implemented it in the last commit, 467ff8c . It uses the RegExodus library (which SquidLib already depends on) instead of
If you have ideas for extra features, we aren't limited to the things GDX's color markup supports, and SquidLib could support extra syntax and options that build on GDX markup. |
That looks great! I can see advantages for lots of games using this, like NetHack (with many colors of dragon) could differentiate which enemy did which action by coloring the name of the enemy to match their color in the game map. That could be like "The [Red]Dragon[] breathes fire at you!" Somewhat off-topic, but what do "Dmg 2k2" and "Atk 2k1" mean in your screenshot? |
The "XkY" notation means to roll X dice and keep the highest Y (something I got from the 7th Sea tabletop RPG). In this case, the dice are exploding d6s. An attacker rolls his Atk value, trying to meet or exceed his opponent's Def value. If so, he rolls his Dmg value to determine how much raw damage is dealt; this is increased by a high Attack roll and reduced by armor and magical protection(values not shown in screenshot, but will be plugged into the HUD soon). The dice values are currently raw Strings that my custom Dice module knows how to roll, but I am considering making them a small class instead. EDIT: I just saw the SquidLib |
Ah, glad Dice is proving useful! I just started adding a few features to its dice notation parsing a few days ago, and since you mentioned it, today I went back and added support in the notation for |
@tommyettinger > I suppose bold and italic require providing additional bitmap fonts ? |
@smelc , sort of. The way I have them implemented in TextFamily (a subclass of TextCellFactory that delegates most of its work to its parent), these multi-part fonts load normal, bold, italic, and bold italic fonts from an atlas (which can hold more textures, if needed). A small addition to TextCellFactory, the |
This is relevant for #16 . The implementation of appendMessage() for String correctly added an item to the internal List of IColoredString values, but appendMessage() for IColoredString did not. This should work now. I was considering adding a method to IMarkup to escape non-markup usage of characters that might be mistaken for markup, but it doesn't seem needed and would break anything that implements IMarkup. So, the code I wrote is only present in comments in markup-related files.
Most of the distance field fonts now include the full block image at Unicode codepoint 0. That block was previously a separate Texture, and that has performance downsides when mostly rendering text. By keeping an entire text-based line as potentially one String with different colors, we also open up possibilities for both optimizing our drawing a little better, and for using markup on long Strings (as I'd like to have for #16 )Though the fonts should keep the changes in this commit for later (it gave me a chance to improve some unrelated spacing issues in some fonts), TextCellFactory will have its changes in this commit immediately reverted, since not all fonts have a block at codepoint 0, including probably all user-created fonts. The solution is probably to use a subclass of TextCellFactory for fonts we know have been made to use the block in the font, and default to the normal separate texture for all other fonts.
This was directly inspired by #16 and Rakaneth's approach to generating IColoredStrings by parsing GDX color markup; this way also uses regular expressions, but uses RegExodus like the rest of SquidLib for GWT compatibility. Some more-advanced and less-documented RegExodus features are used here to simplify the code, at least for me since I've attempted to understand RegExodus for a while now. This can generate colorful text like at the bottom of this screenshot, https://i.imgur.com/CBsLzdL.png , using code like this: ``` IColoredString<Color> text = GDXMarkup.instance.colorString( "Use numpad or vi-keys ([CW Bright Red]h[CW Bright Apricot]j[CW Bright Yellow]k[CW Bright Lime]l" + "[CW Bright Jade]y[CW Bright Azure]u[CW Bright Sapphire]b[CW Flush Purple]n[]) to move. Use " + "[CW Pale Indigo]?[] for help, [CW Faded Brown]f[] to filter colors, [CW Gray White]q[] to quit. " + "Click the top or bottom border of this box to scroll."); ``` This wrapper around GDX markup isn't the most convenient way of specifying colors that I can think of, but it's pretty nice.
add the ability to pass in an array of colors for the foreground and background to colorize when a string prints
The text was updated successfully, but these errors were encountered: