mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Merge pull request #2615 from kevlahnota/newmaster2
move textrafonts to Assets
This commit is contained in:
@@ -35,12 +35,11 @@ import java.util.function.Function;
|
||||
* Class to create ui elements in the correct style
|
||||
*/
|
||||
public class Controls {
|
||||
static class LabelFix extends TextraLabel
|
||||
{
|
||||
public LabelFix(String text)
|
||||
{
|
||||
static class LabelFix extends TextraLabel {
|
||||
public LabelFix(String text) {
|
||||
super(text, getSkin(), getTextraFont());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(@Null String text) {
|
||||
this.storedText = text;
|
||||
@@ -50,10 +49,9 @@ public class Controls {
|
||||
layout();
|
||||
}
|
||||
}
|
||||
static class TextButtonFix extends TextraButton
|
||||
{
|
||||
public TextButtonFix(@Null String text)
|
||||
{
|
||||
|
||||
static class TextButtonFix extends TextraButton {
|
||||
public TextButtonFix(@Null String text) {
|
||||
super(text == null ? "NULL" : text, Controls.getSkin(), Controls.getTextraFont());
|
||||
}
|
||||
|
||||
@@ -63,6 +61,7 @@ public class Controls {
|
||||
this.getTextraLabel().setFont(Controls.getTextraFont());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return this.getTextraLabel().storedText;
|
||||
@@ -77,15 +76,17 @@ public class Controls {
|
||||
layout();
|
||||
}
|
||||
}
|
||||
|
||||
static public TextraButton newTextButton(String text) {
|
||||
TextraButton button = new TextButtonFix(text);
|
||||
// button.getTextraLabelCell().fill(true,false).expand(true,false);//keep it the same as TextButton
|
||||
button.getTextraLabel().setWrap(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
static public Rectangle getBoundingRect(Actor actor) {
|
||||
return new Rectangle(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight());
|
||||
}
|
||||
|
||||
static public boolean actorContainsVector(Actor actor, Vector2 point) {
|
||||
if (actor == null)
|
||||
return false;
|
||||
@@ -135,10 +136,9 @@ public class Controls {
|
||||
ret.setAlignment(Align.right);
|
||||
return ret;
|
||||
}
|
||||
static public<T> SelectBox newComboBox()
|
||||
{
|
||||
return new SelectBox<T>(getSkin())
|
||||
{
|
||||
|
||||
static public <T> SelectBox newComboBox() {
|
||||
return new SelectBox<T>(getSkin()) {
|
||||
|
||||
@Null
|
||||
protected Drawable getBackgroundDrawable() {
|
||||
@@ -161,6 +161,7 @@ public class Controls {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static public SelectBox<Float> newComboBox(Float[] text, float item, Function<Object, Void> func) {
|
||||
SelectBox<Float> ret = newComboBox();
|
||||
ret.getStyle().listStyle.selection.setTopHeight(4);
|
||||
@@ -219,8 +220,7 @@ public class Controls {
|
||||
}
|
||||
|
||||
static public Slider newSlider(float min, float max, float step, boolean vertical) {
|
||||
Slider ret = new Slider(min, max, step, vertical, getSkin())
|
||||
{
|
||||
Slider ret = new Slider(min, max, step, vertical, getSkin()) {
|
||||
@Override
|
||||
protected Drawable getBackgroundDrawable() {
|
||||
SliderStyle style = (SliderStyle) super.getStyle();
|
||||
@@ -250,6 +250,7 @@ public class Controls {
|
||||
return getBitmapFont("default", 1);
|
||||
}
|
||||
}
|
||||
|
||||
static public BitmapFont getBitmapFont(String fontName, float scaleXY) {
|
||||
getSkin().getFont(fontName).getData().setScale(scaleXY, scaleXY);
|
||||
return getSkin().getFont("default");
|
||||
@@ -275,15 +276,15 @@ public class Controls {
|
||||
}
|
||||
return Forge.getAssets().manager().get(skinFile.path(), Skin.class);
|
||||
}
|
||||
|
||||
public static Label newLabel(String name) {
|
||||
Label ret = new Label(name, getSkin());
|
||||
return ret;
|
||||
}
|
||||
static public Color colorFromString(String name)
|
||||
{
|
||||
|
||||
static public Color colorFromString(String name) {
|
||||
String upperCase = name.toUpperCase();
|
||||
if(upperCase.startsWith("0X")||upperCase.startsWith("#"))
|
||||
{
|
||||
if (upperCase.startsWith("0X") || upperCase.startsWith("#")) {
|
||||
return new Color(Long.decode(upperCase).intValue());
|
||||
}
|
||||
if (upperCase.equals("WHITE"))
|
||||
@@ -360,8 +361,7 @@ public class Controls {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String colorIdToTypingString(ColorSet color)
|
||||
{
|
||||
public static String colorIdToTypingString(ColorSet color) {
|
||||
//NOTE converting to uppercase will use pixelmana.atlas, higher quality pixel mana symbol.
|
||||
String colorId = "";
|
||||
if (color.hasWhite())
|
||||
@@ -378,6 +378,7 @@ public class Controls {
|
||||
colorId += "[+c]";
|
||||
return colorId;
|
||||
}
|
||||
|
||||
public static TypingLabel newTypingLabel(String name) {
|
||||
TypingLabel ret = new TypingLabel(name == null ? "" : name, getSkin(), getTextraFont());
|
||||
ret.setVariable("player_name", Current.player().getName());
|
||||
@@ -392,35 +393,17 @@ public class Controls {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Font textraFont=null;
|
||||
static Font keysFont=null;
|
||||
static public Font getKeysFont()
|
||||
{
|
||||
if(keysFont==null)
|
||||
{
|
||||
keysFont=new Font(getSkin().getFont("default"));
|
||||
keysFont.addAtlas(Config.instance().getAtlas(Paths.KEYS_ATLAS));
|
||||
}
|
||||
return keysFont;
|
||||
}
|
||||
static public Font getTextraFont()
|
||||
{
|
||||
if(textraFont==null)
|
||||
{
|
||||
textraFont=new Font(getSkin().getFont("default"), 0f, 2f, 0f, 0f);
|
||||
textraFont.integerPosition = false;
|
||||
textraFont.addAtlas(Config.instance().getAtlas(Paths.ITEMS_ATLAS), 0, 0, 0);
|
||||
textraFont.addAtlas(Config.instance().getAtlas(Paths.PIXELMANA_ATLAS), 0, -12f, 0);
|
||||
}
|
||||
return textraFont;
|
||||
}
|
||||
static public Font getTextraFont(String name)
|
||||
{
|
||||
Font font=new Font(getSkin().getFont(name));
|
||||
font.addAtlas(Config.instance().getAtlas(Paths.ITEMS_ATLAS));
|
||||
return font;
|
||||
static public Font getKeysFont() {
|
||||
return Forge.getAssets().getKeysFont(getSkin().getFont("default"), Config.instance().getAtlas(Paths.KEYS_ATLAS));
|
||||
}
|
||||
|
||||
static public Font getTextraFont() {
|
||||
return Forge.getAssets().getTextraFont(getSkin().getFont("default"), Config.instance().getAtlas(Paths.ITEMS_ATLAS), Config.instance().getAtlas(Paths.PIXELMANA_ATLAS));
|
||||
}
|
||||
|
||||
static public Font getTextraFont(String name) {
|
||||
return Forge.getAssets().getTextraFont(name, getSkin().getFont(name), Config.instance().getAtlas(Paths.ITEMS_ATLAS));
|
||||
}
|
||||
|
||||
|
||||
static public class AccountingLabel extends TextraLabel {
|
||||
@@ -445,8 +428,7 @@ public class Controls {
|
||||
currencyAmount = Current.player().getShards();
|
||||
currencyIcon = "[+Shards]";
|
||||
Current.player().onShardsChange(() -> update(AdventurePlayer.current().getShards(), true));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
currencyAmount = Current.player().getGold();
|
||||
currencyIcon = "[+Gold] "; //fix space since gold sprite is wider than a single glyph
|
||||
Current.player().onGoldChange(() -> update(AdventurePlayer.current().getGold(), true));
|
||||
@@ -459,12 +441,15 @@ public class Controls {
|
||||
public void setAnimationDelay(float animationDelay) {
|
||||
this.animationDelay = animationDelay;
|
||||
}
|
||||
|
||||
public float getAnimationDelay() {
|
||||
return animationDelay;
|
||||
}
|
||||
|
||||
public void update(int newAmount) {
|
||||
update(newAmount, false);
|
||||
}
|
||||
|
||||
public void update(int newAmount, boolean animate) {
|
||||
|
||||
if (animate) {
|
||||
@@ -473,8 +458,7 @@ public class Controls {
|
||||
replaceLabel(temporaryLabel);
|
||||
|
||||
t.schedule(new AccountingLabelUpdater(temporaryLabel), animationDelay);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
currencyAmount = newAmount;
|
||||
drawFinalLabel(false);
|
||||
}
|
||||
@@ -495,6 +479,7 @@ public class Controls {
|
||||
private TextraLabel getDefaultLabel() {
|
||||
return Controls.newTextraLabel(getLabelText(currencyAmount));
|
||||
}
|
||||
|
||||
private TextraLabel getUpdateLabel(int newAmount) {
|
||||
int delta = newAmount - currencyAmount;
|
||||
String updateText = delta == 0 ? "" : (delta < 0 ? NEGDECOR + delta * -1 : POSDECOR + delta);
|
||||
@@ -504,9 +489,11 @@ public class Controls {
|
||||
private String getLabelText(int amount) {
|
||||
return getLabelText(amount, "");
|
||||
}
|
||||
|
||||
private String getLabelText(int amount, String updateText) {
|
||||
return amount + " " + currencyIcon + updateText;
|
||||
}
|
||||
|
||||
private void replaceLabel(TextraLabel newLabel) {
|
||||
newLabel.setName(label.getName());
|
||||
newLabel.style = placeholder.style;
|
||||
@@ -528,7 +515,9 @@ public class Controls {
|
||||
drawFinalLabel(true);
|
||||
}
|
||||
}
|
||||
|
||||
TextraLabel target;
|
||||
|
||||
AccountingLabelUpdater(TextraLabel replacement) {
|
||||
this.target = replacement;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.TextureData;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.github.tommyettinger.textra.Font;
|
||||
import forge.Forge;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
@@ -42,7 +44,9 @@ public class Assets implements Disposable {
|
||||
private ObjectMap<String, Texture> tmxMap;
|
||||
private Texture defaultImage, dummy;
|
||||
private TextureParameter textureParameter;
|
||||
private ObjectMap<String, Font> textrafonts;
|
||||
private int cGen = 0, cGenVal = 0, cFB = 0, cFBVal = 0, cTM = 0, cTMVal = 0, cSF = 0, cSFVal = 0, cCF = 0, cCFVal = 0, aDF = 0, cDFVal = 0;
|
||||
|
||||
public Assets() {
|
||||
String titleFilename = Forge.isLandscapeMode() ? "title_bg_lq.png" : "title_bg_lq_portrait.png";
|
||||
try {
|
||||
@@ -62,6 +66,7 @@ public class Assets implements Disposable {
|
||||
fallback_skins().put(1, getDummy());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
try {
|
||||
@@ -81,6 +86,10 @@ public class Assets implements Disposable {
|
||||
defaultImage.dispose();
|
||||
if (dummy != null)
|
||||
dummy.dispose();
|
||||
if (textrafonts != null) {
|
||||
for (Font f : textrafonts.values())
|
||||
f.dispose();
|
||||
}
|
||||
cardArtCache.clear();
|
||||
avatarImages.clear();
|
||||
manaImages.clear();
|
||||
@@ -102,91 +111,109 @@ public class Assets implements Disposable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public MemoryTrackingAssetManager manager() {
|
||||
if (manager == null)
|
||||
manager = new MemoryTrackingAssetManager(new AbsoluteFileHandleResolver());
|
||||
return manager;
|
||||
}
|
||||
|
||||
public HashMap<Integer, FSkinFont> fonts() {
|
||||
if (fonts == null)
|
||||
fonts = new HashMap<>();
|
||||
return fonts;
|
||||
}
|
||||
|
||||
public HashMap<String, FImageComplex> cardArtCache() {
|
||||
if (cardArtCache == null)
|
||||
cardArtCache = new HashMap<>(1024);
|
||||
return cardArtCache;
|
||||
}
|
||||
|
||||
public HashMap<String, FImage> avatarImages() {
|
||||
if (avatarImages == null)
|
||||
avatarImages = new HashMap<>();
|
||||
return avatarImages;
|
||||
}
|
||||
|
||||
public HashMap<String, FSkinImage> manaImages() {
|
||||
if (manaImages == null)
|
||||
manaImages = new HashMap<>(128);
|
||||
return manaImages;
|
||||
}
|
||||
|
||||
public HashMap<String, FSkinImage> symbolLookup() {
|
||||
if (symbolLookup == null)
|
||||
symbolLookup = new HashMap<>(64);
|
||||
return symbolLookup;
|
||||
}
|
||||
|
||||
public HashMap<FSkinProp, FSkinImage> images() {
|
||||
if (images == null)
|
||||
images = new HashMap<>(512);
|
||||
return images;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> avatars() {
|
||||
if (avatars == null)
|
||||
avatars = new HashMap<>(150);
|
||||
return avatars;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> sleeves() {
|
||||
if (sleeves == null)
|
||||
sleeves = new HashMap<>(64);
|
||||
return sleeves;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> cracks() {
|
||||
if (cracks == null)
|
||||
cracks = new HashMap<>(16);
|
||||
return cracks;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> borders() {
|
||||
if (borders == null)
|
||||
borders = new HashMap<>();
|
||||
return borders;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> deckbox() {
|
||||
if (deckbox == null)
|
||||
deckbox = new HashMap<>();
|
||||
return deckbox;
|
||||
}
|
||||
|
||||
public HashMap<Integer, TextureRegion> cursor() {
|
||||
if (cursor == null)
|
||||
cursor = new HashMap<>();
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public ObjectMap<Integer, BitmapFont> counterFonts() {
|
||||
if (counterFonts == null)
|
||||
counterFonts = new ObjectMap<>();
|
||||
return counterFonts;
|
||||
}
|
||||
|
||||
public ObjectMap<String, Texture> generatedCards() {
|
||||
if (generatedCards == null)
|
||||
generatedCards = new ObjectMap<>(512);
|
||||
return generatedCards;
|
||||
}
|
||||
|
||||
public ObjectMap<Integer, Texture> fallback_skins() {
|
||||
if (fallback_skins == null)
|
||||
fallback_skins = new ObjectMap<>();
|
||||
return fallback_skins;
|
||||
}
|
||||
|
||||
public ObjectMap<String, Texture> tmxMap() {
|
||||
if (tmxMap == null)
|
||||
tmxMap = new ObjectMap<>();
|
||||
return tmxMap;
|
||||
}
|
||||
|
||||
public TextureParameter getTextureFilter() {
|
||||
if (textureParameter == null)
|
||||
textureParameter = new TextureParameter();
|
||||
@@ -201,6 +228,7 @@ public class Assets implements Disposable {
|
||||
}
|
||||
return textureParameter;
|
||||
}
|
||||
|
||||
public Texture getDefaultImage() {
|
||||
if (defaultImage == null) {
|
||||
FileHandle blankImage = Gdx.files.absolute(ForgeConstants.NO_CARD_FILE);
|
||||
@@ -228,6 +256,44 @@ public class Assets implements Disposable {
|
||||
}
|
||||
return dummy;
|
||||
}
|
||||
|
||||
public Font getTextraFont(BitmapFont bitmapFont, TextureAtlas item_atlas, TextureAtlas pixelmana_atlas) {
|
||||
if (textrafonts == null)
|
||||
textrafonts = new ObjectMap<>();
|
||||
if (!textrafonts.containsKey("textrafont")) {
|
||||
Font font = new Font(bitmapFont, 0f, 2f, 0f, 0f);
|
||||
font.addAtlas(item_atlas, 0f, 0f, 0f);
|
||||
font.addAtlas(pixelmana_atlas, 0f, -12f, 0f);
|
||||
font.integerPosition = false;
|
||||
textrafonts.put("textrafont", font);
|
||||
}
|
||||
return textrafonts.get("textrafont");
|
||||
}
|
||||
|
||||
public Font getKeysFont(BitmapFont bitmapFont, TextureAtlas keys_atlas) {
|
||||
if (textrafonts == null)
|
||||
textrafonts = new ObjectMap<>();
|
||||
if (!textrafonts.containsKey("keysfont")) {
|
||||
Font font = new Font(bitmapFont);
|
||||
font.addAtlas(keys_atlas);
|
||||
font.integerPosition = false;
|
||||
textrafonts.put("keysfont", font);
|
||||
}
|
||||
return textrafonts.get("keysfont");
|
||||
}
|
||||
|
||||
public Font getTextraFont(String name, BitmapFont bitmapFont, TextureAtlas items_atlas) {
|
||||
if (textrafonts == null)
|
||||
textrafonts = new ObjectMap<>();
|
||||
if (!textrafonts.containsKey(name)) {
|
||||
Font font = new Font(bitmapFont);
|
||||
font.addAtlas(items_atlas);
|
||||
font.integerPosition = false;
|
||||
textrafonts.put(name, font);
|
||||
}
|
||||
return textrafonts.get(name);
|
||||
}
|
||||
|
||||
public class MemoryTrackingAssetManager extends AssetManager {
|
||||
private int currentMemory;
|
||||
private Map<String, Integer> memoryPerFile;
|
||||
@@ -268,6 +334,7 @@ public class Assets implements Disposable {
|
||||
+ calculateObjectMaps(generatedCards()) + calculateObjectMaps(fallback_skins()) + calculateObjectMaps(tmxMap());
|
||||
return sum;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private int calculateObjectMaps(ObjectMap<?, Texture> objectMap) {
|
||||
if (!Forge.showFPS)
|
||||
@@ -322,6 +389,7 @@ public class Assets implements Disposable {
|
||||
cFBVal = sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
private int calcFonts() {
|
||||
if (!Forge.showFPS)
|
||||
return 0;
|
||||
@@ -337,6 +405,7 @@ public class Assets implements Disposable {
|
||||
cSFVal = val;
|
||||
return cSFVal;
|
||||
}
|
||||
|
||||
private int calcCounterFonts() {
|
||||
if (!Forge.showFPS)
|
||||
return 0;
|
||||
@@ -351,6 +420,7 @@ public class Assets implements Disposable {
|
||||
cCFVal = val;
|
||||
return cCFVal;
|
||||
}
|
||||
|
||||
private int calcBitmapFont(BitmapFont bitmapFont) {
|
||||
if (bitmapFont == null)
|
||||
return 0;
|
||||
|
||||
@@ -360,7 +360,7 @@ public class FSkinFont {
|
||||
return langUniqueCharacterSet.get(langCode);
|
||||
}
|
||||
StringBuilder characters = new StringBuilder(FreeTypeFontGenerator.DEFAULT_CHARS);
|
||||
characters.append("•");//add bullet to default characters
|
||||
characters.append("•").append("—");//add bullet and long dash to default characters
|
||||
IntSet characterSet = new IntSet();
|
||||
for (int offset = 0; offset < FreeTypeFontGenerator.DEFAULT_CHARS.length();) {
|
||||
final int codePoint = FreeTypeFontGenerator.DEFAULT_CHARS.codePointAt(offset);
|
||||
|
||||
Reference in New Issue
Block a user