BitmapFont -> Font / Bugfixes

This commit is contained in:
Anuken
2020-07-30 16:59:53 -04:00
parent f39609d1ef
commit 06b08c80c2
13 changed files with 52 additions and 43 deletions

View File

@@ -91,7 +91,7 @@ public class Bar extends Element{
Draw.color();
BitmapFont font = Fonts.outline;
Font font = Fonts.outline;
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
lay.setText(font, name);

View File

@@ -13,7 +13,7 @@ import arc.graphics.*;
import arc.graphics.Pixmap.*;
import arc.graphics.Texture.*;
import arc.graphics.g2d.*;
import arc.graphics.g2d.BitmapFont.*;
import arc.graphics.g2d.Font.*;
import arc.graphics.g2d.PixmapPacker.*;
import arc.graphics.g2d.TextureAtlas.*;
import arc.math.*;
@@ -30,11 +30,11 @@ public class Fonts{
private static ObjectIntMap<String> unicodeIcons = new ObjectIntMap<>();
private static ObjectMap<String, String> stringIcons = new ObjectMap<>();
public static BitmapFont def;
public static BitmapFont outline;
public static BitmapFont chat;
public static BitmapFont icon;
public static BitmapFont tech;
public static Font def;
public static Font outline;
public static Font chat;
public static Font icon;
public static Font tech;
public static int getUnicode(String content){
return unicodeIcons.get(content, 0);
@@ -62,17 +62,17 @@ public class Fonts{
FreeTypeFontParameter param = fontParameter();
Core.assets.load("default", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.def = (BitmapFont)f;
Core.assets.load("chat", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.chat = (BitmapFont)f;
Core.assets.load("icon", BitmapFont.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
Core.assets.load("default", Font.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.def = (Font)f;
Core.assets.load("chat", Font.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.chat = (Font)f;
Core.assets.load("icon", Font.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
size = 30;
incremental = true;
characters = "\0";
}})).loaded = f -> Fonts.icon = (BitmapFont)f;
}})).loaded = f -> Fonts.icon = (Font)f;
}
public static void loadContentIcons(){
Seq<BitmapFont> fonts = Seq.with(Fonts.chat, Fonts.def, Fonts.outline);
Seq<Font> fonts = Seq.with(Fonts.chat, Fonts.def, Fonts.outline);
Texture uitex = Core.atlas.find("logo").getTexture();
int size = (int)(Fonts.def.getData().lineHeight/Fonts.def.getData().scaleY);
@@ -119,11 +119,11 @@ public class Fonts{
UI.packer = new PixmapPacker(2048, 2048, Format.rgba8888, 2, true);
FileHandleResolver resolver = new InternalFileHandleResolver();
Core.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
Core.assets.setLoader(BitmapFont.class, null, new FreetypeFontLoader(resolver){
Core.assets.setLoader(Font.class, null, new FreetypeFontLoader(resolver){
ObjectSet<FreeTypeFontParameter> scaled = new ObjectSet<>();
@Override
public BitmapFont loadSync(AssetManager manager, String fileName, Fi file, FreeTypeFontLoaderParameter parameter){
public Font loadSync(AssetManager manager, String fileName, Fi file, FreeTypeFontLoaderParameter parameter){
if(fileName.equals("outline")){
parameter.fontParameters.borderWidth = Scl.scl(2f);
parameter.fontParameters.spaceX -= parameter.fontParameters.borderWidth;
@@ -146,11 +146,11 @@ public class Fonts{
size = 18;
}};
Core.assets.load("outline", BitmapFont.class, new FreeTypeFontLoaderParameter("fonts/font.ttf", param)).loaded = t -> Fonts.outline = (BitmapFont)t;
Core.assets.load("outline", Font.class, new FreeTypeFontLoaderParameter("fonts/font.ttf", param)).loaded = t -> Fonts.outline = (Font)t;
Core.assets.load("tech", BitmapFont.class, new FreeTypeFontLoaderParameter("fonts/tech.ttf", new FreeTypeFontParameter(){{
Core.assets.load("tech", Font.class, new FreeTypeFontLoaderParameter("fonts/tech.ttf", new FreeTypeFontParameter(){{
size = 18;
}})).loaded = f -> Fonts.tech = (BitmapFont)f;
}})).loaded = f -> Fonts.tech = (Font)f;
}
/** Merges the UI and font atlas together for better performance. */
@@ -184,7 +184,7 @@ public class Fonts{
page.updateTexture(TextureFilter.linear, TextureFilter.linear, false);
}
public static TextureRegionDrawable getGlyph(BitmapFont font, char glyph){
public static TextureRegionDrawable getGlyph(Font font, char glyph){
Glyph g = font.getData().getGlyph(glyph);
if(g == null) throw new IllegalArgumentException("No glyph: " + glyph + " (" + (int)glyph + ")");

View File

@@ -27,7 +27,7 @@ public class ChatFragment extends Table{
private boolean shown = false;
private TextField chatfield;
private Label fieldlabel = new Label(">");
private BitmapFont font;
private Font font;
private GlyphLayout layout = new GlyphLayout();
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50);
private Color shadowColor = new Color(0, 0, 0, 0.4f);

View File

@@ -14,6 +14,7 @@ public class LoadingFragment extends Fragment{
private Table table;
private TextButton button;
private Bar bar;
private Label nameLabel;
@Override
public void build(Group parent){
@@ -23,11 +24,13 @@ public class LoadingFragment extends Fragment{
t.add().height(133f).row();
t.add(new WarningBar()).growX().height(24f);
t.row();
t.add("$loading").name("namelabel").pad(10f).style(Styles.techLabel);
nameLabel = t.add("$loading").pad(10f).style(Styles.techLabel).get();
t.row();
t.add(new WarningBar()).growX().height(24f);
t.row();
text("$loading");
bar = t.add(new Bar()).pad(3).size(500f, 40f).visible(false).get();
t.row();
button = t.button("$cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get();
@@ -48,8 +51,8 @@ public class LoadingFragment extends Fragment{
}
public void setText(String text){
table.<Label>find("namelabel").setText(text);
table.<Label>find("namelabel").setColor(Pal.accent);
text(text);
nameLabel.setColor(Pal.accent);
}
public void show(){
@@ -57,11 +60,11 @@ public class LoadingFragment extends Fragment{
}
public void show(String text){
table.<Label>find("namelabel").setColor(Color.white);
nameLabel.setColor(Color.white);
bar.visible = false;
table.clearActions();
table.touchable = Touchable.enabled;
table.<Label>find("namelabel").setText(text);
text(text);
table.visible = true;
table.color.a = 1f;
table.toFront();
@@ -73,4 +76,19 @@ public class LoadingFragment extends Fragment{
table.touchable = Touchable.disabled;
table.actions(Actions.fadeOut(0.5f), Actions.visible(false));
}
private void text(String text){
nameLabel.setText(text);
CharSequence realText = nameLabel.getText();
//fallback to the default font if characters are missing
for(int i = 0; i < realText.length(); i++){
if(Fonts.tech.getData().getGlyph(realText.charAt(i)) == null){
nameLabel.setStyle(Styles.defaultLabel);
return;
}
}
nameLabel.setStyle(Styles.techLabel);
}
}

View File

@@ -24,7 +24,7 @@ public class ScriptConsoleFragment extends Table{
private boolean open = false, shown;
private TextField chatfield;
private Label fieldlabel = new Label(">");
private BitmapFont font;
private Font font;
private GlyphLayout layout = new GlyphLayout();
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50);
private Color shadowColor = new Color(0, 0, 0, 0.4f);