yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
448 stars 46 forks source link

LinesPanel does not appear to be respecting TextFamilies #187

Closed Rakaneth closed 6 years ago

Rakaneth commented 6 years ago

While playing with my main screen layout, I was experimenting with LinesPanel and style markups when I came across this:

public static void addMessageLP(String template, Object...args)
{
    String rawText = String.format(template, args);
    IColoredString<Color> toWrite = GDXMarkup.instance.colorString(rawText);
    lp.addFirst(toWrite);
}

TextFamily slab = DefaultResources.getSlabFamily();
slab.width(cellWidth).height(cellHeight).initBySize();
final int nl = LinesPanel.computeMaxLines(slab.font(), msgPixelHeight);
lp = new LinesPanel<Color>(GDXMarkup.instance, slab, nl);
addMessageLP("[/]This text should be italic;[] this text is not.");

This is the result: image

This works properly with SquidMessageBox, however.

image

tommyettinger commented 6 years ago

There are probably more than a few places in SquidLib that use BitmapFonts directly, without using the TextCellFactory.draw() method that TextFamily overrides to add the italic/bold behavior. I'll see if there's a good fix for this in LinesPanel.

tommyettinger commented 6 years ago

I think I figured out a better way to handle the assets for TextFamily, and it might even work with a normal TextCellFactory, which would be nice. I need to try some things, but if this works it would mean using a different asset than what is currently used for the four versions of a TextFamily font (it may be a slightly smaller download size, too). I'll get to work... This might be a little rough-looking for the first try.

tommyettinger commented 6 years ago

I closed this in a commit, but it should also be mentioned here: this should be fixed now, but the two default TextFamily assets are different now (effectively, they're 4 fonts merged into one). I will update SquidSetup at some point to carry the new assets, probably after I add some more for good measure. The files needed to use the "Slab" family are (these are links directly to files): https://raw.githubusercontent.com/SquidPony/SquidLib/master/assets/Iosevka-Slab-Family-distance.fnt and https://raw.githubusercontent.com/SquidPony/SquidLib/master/assets/Iosevka-Slab-Family-distance.png . The files needed to use the "Lean" family are (these are also links directly to files): https://raw.githubusercontent.com/SquidPony/SquidLib/master/assets/Iosevka-Family-distance.fnt and https://raw.githubusercontent.com/SquidPony/SquidLib/master/assets/Iosevka-Family-distance.png . The older method with an atlas and four .fnt files isn't needed any more, and these can actually work just fine in a normal TextCellFactory. DefaultResources still returns these fonts as TextFamily values, in case I extend TextFamily further and to keep the existing code working, but pretty much all the different methods on TextFamily (there were about 4) aren't there any more, and the class is used just like TextCellFactory. This allows code that expects a normal TextCellFactory or BitmapFont to use the TextFamily as a TextCellFactory without changes, or as a BitmapFont just by getting the .font() of the TextFamily.

LinesPanel now has the option to pass a TextCellFactory instead of a BitmapFont in more places, which I'd encourage if you use one for other parts of the class.