move skin and adventure fonts to Assets

This commit is contained in:
Anthony Calosa
2022-07-10 07:49:31 +08:00
parent 6915b0d7a4
commit 2d607bf289
2 changed files with 22 additions and 23 deletions

View File

@@ -11,6 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import forge.Forge;
import java.util.function.Function; import java.util.function.Function;
@@ -18,15 +19,10 @@ import java.util.function.Function;
* Class to create ui elements in the correct style * Class to create ui elements in the correct style
*/ */
public class Controls { public class Controls {
private static Skin SelectedSkin = null;
private static BitmapFont defaultfont, bigfont;
static public TextButton newTextButton(String text) { static public TextButton newTextButton(String text) {
return new TextButton(text, GetSkin()); return new TextButton(text, GetSkin());
} }
static public Rectangle getBoundingRect(Actor actor) { static public Rectangle getBoundingRect(Actor actor) {
return new Rectangle(actor.getX(),actor.getY(),actor.getWidth(),actor.getHeight()); return new Rectangle(actor.getX(),actor.getY(),actor.getWidth(),actor.getHeight());
} }
static public boolean actorContainsVector (Actor actor, Vector2 point) { static public boolean actorContainsVector (Actor actor, Vector2 point) {
@@ -56,8 +52,6 @@ public class Controls {
return ret; return ret;
} }
static public TextField newTextField(String text) { static public TextField newTextField(String text) {
return new TextField(text, GetSkin()); return new TextField(text, GetSkin());
} }
@@ -108,32 +102,28 @@ public class Controls {
switch (fontName) { switch (fontName) {
case "blackbig": case "blackbig":
case "big": case "big":
return bigfont; return Forge.getAssets().advBigFont;
default: default:
return defaultfont; return Forge.getAssets().advDefaultFont;
} }
} }
static public Skin GetSkin() { static public Skin GetSkin() {
if (Forge.getAssets().skin == null) {
if (SelectedSkin == null) { Forge.getAssets().skin = new Skin();
SelectedSkin = new Skin();
FileHandle skinFile = Config.instance().getFile(Paths.SKIN); FileHandle skinFile = Config.instance().getFile(Paths.SKIN);
FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas"); FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas");
TextureAtlas atlas = new TextureAtlas(atlasFile); TextureAtlas atlas = new TextureAtlas(atlasFile);
//font //font
defaultfont = new BitmapFont(Config.instance().getFile(Paths.SKIN).sibling("LanaPixel.fnt")); Forge.getAssets().advDefaultFont = new BitmapFont(Config.instance().getFile(Paths.SKIN).sibling("LanaPixel.fnt"));
bigfont = new BitmapFont(Config.instance().getFile(Paths.SKIN).sibling("LanaPixel.fnt")); Forge.getAssets().advBigFont = new BitmapFont(Config.instance().getFile(Paths.SKIN).sibling("LanaPixel.fnt"));
bigfont.getData().setScale(2, 2); Forge.getAssets().advBigFont.getData().setScale(2, 2);
SelectedSkin.add("default", defaultfont); Forge.getAssets().skin.add("default", Forge.getAssets().advDefaultFont);
SelectedSkin.add("big", bigfont); Forge.getAssets().skin.add("big", Forge.getAssets().advBigFont);
SelectedSkin.addRegions(atlas); Forge.getAssets().skin.addRegions(atlas);
SelectedSkin.load(skinFile); Forge.getAssets().skin.load(skinFile);
} }
return SelectedSkin; return Forge.getAssets().skin;
} }
public static Label newLabel(String name) { public static Label newLabel(String name) {

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver; import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import forge.gui.GuiBase; import forge.gui.GuiBase;
@@ -19,6 +20,8 @@ public class Assets implements Disposable {
public ObjectMap<String, Texture> generatedCards = new ObjectMap<>(512); public ObjectMap<String, Texture> generatedCards = new ObjectMap<>(512);
public ObjectMap<Integer, Texture> fallback_skins = new ObjectMap<>(); public ObjectMap<Integer, Texture> fallback_skins = new ObjectMap<>();
public ObjectMap<String, Texture> tmxMap = new ObjectMap<String, Texture>(); public ObjectMap<String, Texture> tmxMap = new ObjectMap<String, Texture>();
public Skin skin;
public BitmapFont advDefaultFont, advBigFont;
public Assets() { public Assets() {
//init titlebg fallback //init titlebg fallback
fallback_skins.put(0, new Texture(GuiBase.isAndroid() fallback_skins.put(0, new Texture(GuiBase.isAndroid()
@@ -43,5 +46,11 @@ public class Assets implements Disposable {
texture.dispose(); texture.dispose();
for (Texture texture : tmxMap.values()) for (Texture texture : tmxMap.values())
texture.dispose(); texture.dispose();
if (advDefaultFont != null)
advDefaultFont.dispose();
if (advBigFont != null)
advBigFont.dispose();
if (skin != null)
skin.dispose();
} }
} }