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

@@ -85,7 +85,7 @@ public class UI implements ApplicationListener, Loadable{
Fonts.def.getData().markupEnabled = true; Fonts.def.getData().markupEnabled = true;
Fonts.def.setOwnsTexture(false); Fonts.def.setOwnsTexture(false);
Core.assets.getAll(BitmapFont.class, new Seq<>()).each(font -> font.setUseIntegerPositions(true)); Core.assets.getAll(Font.class, new Seq<>()).each(font -> font.setUseIntegerPositions(true));
Core.scene = new Scene(); Core.scene = new Scene();
Core.input.addProcessor(Core.scene); Core.input.addProcessor(Core.scene);
@@ -118,7 +118,7 @@ public class UI implements ApplicationListener, Loadable{
@Override @Override
public Seq<AssetDescriptor> getDependencies(){ public Seq<AssetDescriptor> getDependencies(){
return Seq.with(new AssetDescriptor<>(Control.class), new AssetDescriptor<>("outline", BitmapFont.class), new AssetDescriptor<>("default", BitmapFont.class), new AssetDescriptor<>("chat", BitmapFont.class)); return Seq.with(new AssetDescriptor<>(Control.class), new AssetDescriptor<>("outline", Font.class), new AssetDescriptor<>("default", Font.class), new AssetDescriptor<>("chat", Font.class));
} }
@Override @Override

View File

@@ -35,7 +35,7 @@ public class WaveGraph extends Table{
Lines.precise(true); Lines.precise(true);
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
BitmapFont font = Fonts.outline; Font font = Fonts.outline;
lay.setText(font, "1"); lay.setText(font, "1");

View File

@@ -205,7 +205,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
Draw.z(Layer.playerName); Draw.z(Layer.playerName);
float z = Drawf.text(); float z = Drawf.text();
BitmapFont font = Fonts.def; Font font = Fonts.def;
GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
final float nameHeight = 11; final float nameHeight = 11;
final float textHeight = 15; final float textHeight = 15;

View File

@@ -172,7 +172,7 @@ public class LoadRenderer implements Disposable{
Lines.poly(w/2, h/2, 4, rad2); Lines.poly(w/2, h/2, 4, rad2);
if(assets.isLoaded("tech")){ if(assets.isLoaded("tech")){
BitmapFont font = assets.get("tech"); Font font = assets.get("tech");
font.getData().markupEnabled = true; font.getData().markupEnabled = true;
int panei = 0; int panei = 0;
@@ -461,7 +461,7 @@ public class LoadRenderer implements Disposable{
String key = name.contains("script") ? "scripts" : name.contains("content") ? "content" : name.contains("mod") ? "mods" : name.contains("msav") || String key = name.contains("script") ? "scripts" : name.contains("content") ? "content" : name.contains("mod") ? "mods" : name.contains("msav") ||
name.contains("maps") ? "map" : name.contains("ogg") || name.contains("mp3") ? "sound" : name.contains("png") ? "image" : "system"; name.contains("maps") ? "map" : name.contains("ogg") || name.contains("mp3") ? "sound" : name.contains("png") ? "image" : "system";
BitmapFont font = assets.get("tech"); Font font = assets.get("tech");
font.setColor(Pal.accent); font.setColor(Pal.accent);
Draw.color(Color.black); Draw.color(Color.black);
font.draw(red + "[[[[ " +key + " ]]\n\n"+orange+"<" + Version.modifier + " " + (Version.build == 0 ? " [init]" : Version.build == -1 ? " custom" : " " + Version.build) + ">", w/2f, h/2f + 110*s, Align.center); font.draw(red + "[[[[ " +key + " ]]\n\n"+orange+"<" + Version.modifier + " " + (Version.build == 0 ? " [init]" : Version.build == -1 ? " custom" : " " + Version.build) + ">", w/2f, h/2f + 110*s, Align.center);

View File

@@ -172,7 +172,7 @@ public class MinimapRenderer implements Disposable{
} }
public void drawLabel(float x, float y, String text, Color color){ public void drawLabel(float x, float y, String text, Color color){
BitmapFont font = Fonts.outline; Font font = Fonts.outline;
GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
boolean ints = font.usesIntegerPositions(); boolean ints = font.usesIntegerPositions();
font.getData().setScale(1 / 1.5f / Scl.scl(1f)); font.getData().setScale(1 / 1.5f / Scl.scl(1f));

View File

@@ -59,15 +59,6 @@ public class ItemStack implements Comparable<ItemStack>{
return stacks; return stacks;
} }
public static void insert(Seq<ItemStack> stacks, Item item, int amount){
ItemStack stack = stacks.find(i -> i.item == item);
if(stack == null){
stacks.add(new ItemStack(item, amount));
}else{
stack.amount += amount;
}
}
@Override @Override
public int compareTo(ItemStack itemStack){ public int compareTo(ItemStack itemStack){
return item.compareTo(itemStack.item); return item.compareTo(itemStack.item);

View File

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

View File

@@ -13,7 +13,7 @@ import arc.graphics.*;
import arc.graphics.Pixmap.*; import arc.graphics.Pixmap.*;
import arc.graphics.Texture.*; import arc.graphics.Texture.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.graphics.g2d.BitmapFont.*; import arc.graphics.g2d.Font.*;
import arc.graphics.g2d.PixmapPacker.*; import arc.graphics.g2d.PixmapPacker.*;
import arc.graphics.g2d.TextureAtlas.*; import arc.graphics.g2d.TextureAtlas.*;
import arc.math.*; import arc.math.*;
@@ -30,11 +30,11 @@ public class Fonts{
private static ObjectIntMap<String> unicodeIcons = new ObjectIntMap<>(); private static ObjectIntMap<String> unicodeIcons = new ObjectIntMap<>();
private static ObjectMap<String, String> stringIcons = new ObjectMap<>(); private static ObjectMap<String, String> stringIcons = new ObjectMap<>();
public static BitmapFont def; public static Font def;
public static BitmapFont outline; public static Font outline;
public static BitmapFont chat; public static Font chat;
public static BitmapFont icon; public static Font icon;
public static BitmapFont tech; public static Font tech;
public static int getUnicode(String content){ public static int getUnicode(String content){
return unicodeIcons.get(content, 0); return unicodeIcons.get(content, 0);
@@ -62,17 +62,17 @@ public class Fonts{
FreeTypeFontParameter param = fontParameter(); FreeTypeFontParameter param = fontParameter();
Core.assets.load("default", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.def = (BitmapFont)f; Core.assets.load("default", Font.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.def = (Font)f;
Core.assets.load("chat", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.chat = (BitmapFont)f; Core.assets.load("chat", Font.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> Fonts.chat = (Font)f;
Core.assets.load("icon", BitmapFont.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{ Core.assets.load("icon", Font.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
size = 30; size = 30;
incremental = true; incremental = true;
characters = "\0"; characters = "\0";
}})).loaded = f -> Fonts.icon = (BitmapFont)f; }})).loaded = f -> Fonts.icon = (Font)f;
} }
public static void loadContentIcons(){ 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(); Texture uitex = Core.atlas.find("logo").getTexture();
int size = (int)(Fonts.def.getData().lineHeight/Fonts.def.getData().scaleY); 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); UI.packer = new PixmapPacker(2048, 2048, Format.rgba8888, 2, true);
FileHandleResolver resolver = new InternalFileHandleResolver(); FileHandleResolver resolver = new InternalFileHandleResolver();
Core.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); 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<>(); ObjectSet<FreeTypeFontParameter> scaled = new ObjectSet<>();
@Override @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")){ if(fileName.equals("outline")){
parameter.fontParameters.borderWidth = Scl.scl(2f); parameter.fontParameters.borderWidth = Scl.scl(2f);
parameter.fontParameters.spaceX -= parameter.fontParameters.borderWidth; parameter.fontParameters.spaceX -= parameter.fontParameters.borderWidth;
@@ -146,11 +146,11 @@ public class Fonts{
size = 18; 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; size = 18;
}})).loaded = f -> Fonts.tech = (BitmapFont)f; }})).loaded = f -> Fonts.tech = (Font)f;
} }
/** Merges the UI and font atlas together for better performance. */ /** Merges the UI and font atlas together for better performance. */
@@ -184,7 +184,7 @@ public class Fonts{
page.updateTexture(TextureFilter.linear, TextureFilter.linear, false); 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); Glyph g = font.getData().getGlyph(glyph);
if(g == null) throw new IllegalArgumentException("No glyph: " + glyph + " (" + (int)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 boolean shown = false;
private TextField chatfield; private TextField chatfield;
private Label fieldlabel = new Label(">"); private Label fieldlabel = new Label(">");
private BitmapFont font; private Font font;
private GlyphLayout layout = new GlyphLayout(); private GlyphLayout layout = new GlyphLayout();
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50); 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); 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 Table table;
private TextButton button; private TextButton button;
private Bar bar; private Bar bar;
private Label nameLabel;
@Override @Override
public void build(Group parent){ public void build(Group parent){
@@ -23,11 +24,13 @@ public class LoadingFragment extends Fragment{
t.add().height(133f).row(); t.add().height(133f).row();
t.add(new WarningBar()).growX().height(24f); t.add(new WarningBar()).growX().height(24f);
t.row(); 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.row();
t.add(new WarningBar()).growX().height(24f); t.add(new WarningBar()).growX().height(24f);
t.row(); t.row();
text("$loading");
bar = t.add(new Bar()).pad(3).size(500f, 40f).visible(false).get(); bar = t.add(new Bar()).pad(3).size(500f, 40f).visible(false).get();
t.row(); t.row();
button = t.button("$cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get(); 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){ public void setText(String text){
table.<Label>find("namelabel").setText(text); text(text);
table.<Label>find("namelabel").setColor(Pal.accent); nameLabel.setColor(Pal.accent);
} }
public void show(){ public void show(){
@@ -57,11 +60,11 @@ public class LoadingFragment extends Fragment{
} }
public void show(String text){ public void show(String text){
table.<Label>find("namelabel").setColor(Color.white); nameLabel.setColor(Color.white);
bar.visible = false; bar.visible = false;
table.clearActions(); table.clearActions();
table.touchable = Touchable.enabled; table.touchable = Touchable.enabled;
table.<Label>find("namelabel").setText(text); text(text);
table.visible = true; table.visible = true;
table.color.a = 1f; table.color.a = 1f;
table.toFront(); table.toFront();
@@ -73,4 +76,19 @@ public class LoadingFragment extends Fragment{
table.touchable = Touchable.disabled; table.touchable = Touchable.disabled;
table.actions(Actions.fadeOut(0.5f), Actions.visible(false)); 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 boolean open = false, shown;
private TextField chatfield; private TextField chatfield;
private Label fieldlabel = new Label(">"); private Label fieldlabel = new Label(">");
private BitmapFont font; private Font font;
private GlyphLayout layout = new GlyphLayout(); private GlyphLayout layout = new GlyphLayout();
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50); 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); private Color shadowColor = new Color(0, 0, 0, 0.4f);

View File

@@ -238,7 +238,7 @@ public class Block extends UnlockableContent{
if(renderer.pixelator.enabled()) return 0; if(renderer.pixelator.enabled()) return 0;
Color color = valid ? Pal.accent : Pal.remove; Color color = valid ? Pal.accent : Pal.remove;
BitmapFont font = Fonts.outline; Font font = Fonts.outline;
GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
boolean ints = font.usesIntegerPositions(); boolean ints = font.usesIntegerPositions();
font.setUseIntegerPositions(false); font.setUseIntegerPositions(false);

View File

@@ -62,7 +62,7 @@ public class MessageBlock extends Block{
public void drawSelect(){ public void drawSelect(){
if(renderer.pixelator.enabled()) return; if(renderer.pixelator.enabled()) return;
BitmapFont font = Fonts.outline; Font font = Fonts.outline;
GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
boolean ints = font.usesIntegerPositions(); boolean ints = font.usesIntegerPositions();
font.getData().setScale(1 / 4f / Scl.scl(1f)); font.getData().setScale(1 / 4f / Scl.scl(1f));