From 40d71e35fb9df85dc13c0b694f59d9234f5323fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Latner?= <matyas.latner@nic.cz> Date: Fri, 27 Feb 2015 13:20:40 +0100 Subject: [PATCH] #1 Font loader refactor --- .../game/games/robbery/RobberyScreen.java | 15 +++++++++++++++ .../tablexia/game/games/robbery/RuleScreen.java | 5 +---- .../application/ApplicationFontManager.java | 8 ++++++++ .../nic/tablexia/loader/zip/ZipAssetLoader.java | 2 +- core/src/cz/nic/tablexia/menu/MainMenu.java | 2 +- .../tablexia/screen/AbstractTablexiaScreen.java | 10 ++++++++++ .../cz/nic/tablexia/screen/about/AboutScreen.java | 4 +--- .../screen/encyclopedia/EncyclopediaScreen.java | 4 +--- .../screen/halloffame/HallOfFameScreen.java | 4 +--- .../screen/preferences/PreferencesScreen.java | 3 +-- .../screen/statistics/StatisticsScreen.java | 4 +--- 11 files changed, 41 insertions(+), 20 deletions(-) diff --git a/core/src/cz/nic/tablexia/game/games/robbery/RobberyScreen.java b/core/src/cz/nic/tablexia/game/games/robbery/RobberyScreen.java index d2775547c..68888e9e0 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/RobberyScreen.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/RobberyScreen.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -383,6 +384,20 @@ public class RobberyScreen extends AbstractTablexiaScreen<GameRule> { } return null; } + + public static BitmapFont getRobberyRegularFont() { + if (instance != null) { + return instance.getDefaultRegularFont(); + } + return null; + } + + public static BitmapFont getRobberyBoldFont() { + if (instance != null) { + return instance.getDefaultBoldFont(); + } + return null; + } public static GameRule getRobberyData() { if (instance != null) { diff --git a/core/src/cz/nic/tablexia/game/games/robbery/RuleScreen.java b/core/src/cz/nic/tablexia/game/games/robbery/RuleScreen.java index e247cb525..ddc059408 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/RuleScreen.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/RuleScreen.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; @@ -12,7 +11,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import cz.nic.tablexia.game.games.robbery.assets.RobberyAssets; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.loader.application.ApplicationTextureManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; @@ -94,8 +92,7 @@ public class RuleScreen extends AbstractTablexiaScreen<Void> { } }); - BitmapFont font = ApplicationFontManager.getInstance().<BitmapFont>get(ApplicationFontManager.FONT_ROBOTO_REGULAR); - label = new Label(RobberyScreen.getRobberyData().getRuleMessageText(), new LabelStyle(font, TEXT_COLOR)); + label = new Label(RobberyScreen.getRobberyData().getRuleMessageText(), new LabelStyle(RobberyScreen.getRobberyRegularFont(), TEXT_COLOR)); label.setWrap(true); getStage().addActor(background); diff --git a/core/src/cz/nic/tablexia/loader/application/ApplicationFontManager.java b/core/src/cz/nic/tablexia/loader/application/ApplicationFontManager.java index 84731e889..ed42a3602 100644 --- a/core/src/cz/nic/tablexia/loader/application/ApplicationFontManager.java +++ b/core/src/cz/nic/tablexia/loader/application/ApplicationFontManager.java @@ -1,4 +1,5 @@ package cz.nic.tablexia.loader.application; + import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.loaders.FileHandleResolver; import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; @@ -24,6 +25,9 @@ public class ApplicationFontManager extends AssetManager implements IApplication private static final String FONT_PATH = "font/"; public static final String FONT_ROBOTO_REGULAR = FONT_PATH + "Roboto-Regular.ttf"; public static final String FONT_ROBOTO_BOLD = FONT_PATH + "Roboto-Bold.ttf"; + + public static final String APPLICATION_DEFAULT_FONT_REGULAR = FONT_ROBOTO_REGULAR; + public static final String APPLICATION_DEFAULT_FONT_BOLD = FONT_ROBOTO_BOLD; private static ApplicationFontManager instance; @@ -60,4 +64,8 @@ public class ApplicationFontManager extends AssetManager implements IApplication fontParams.fontParameters.magFilter = TextureFilter.Linear; load(fontFile, BitmapFont.class, fontParams); } + + public BitmapFont getFont(String fontName) { + return get(fontName, BitmapFont.class); + } } \ No newline at end of file diff --git a/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java b/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java index 38482dd6a..b541e354e 100644 --- a/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java +++ b/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java @@ -20,7 +20,7 @@ import cz.nic.tablexia.loader.TablexiaDataManager; /** * Zip assets content loader - * + * * @author Matyáš Latner * */ diff --git a/core/src/cz/nic/tablexia/menu/MainMenu.java b/core/src/cz/nic/tablexia/menu/MainMenu.java index 6c1b076f1..72d7a11c5 100644 --- a/core/src/cz/nic/tablexia/menu/MainMenu.java +++ b/core/src/cz/nic/tablexia/menu/MainMenu.java @@ -62,7 +62,7 @@ public class MainMenu extends Stack { // menu button style menuButtonStyle = new TextButtonStyle(); - menuButtonStyle.font = ApplicationFontManager.getInstance().<BitmapFont>get(ApplicationFontManager.FONT_ROBOTO_REGULAR); + menuButtonStyle.font = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FONT_ROBOTO_REGULAR); menuButtonStyle.fontColor = MENU_TEXT_COLOR; menuButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new ColorTexture(50, 50, Color.BLUE))); diff --git a/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java b/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java index d8edc0288..f90c004b3 100644 --- a/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java +++ b/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.Action; import com.badlogic.gdx.scenes.scene2d.Stage; @@ -24,6 +25,7 @@ import cz.nic.tablexia.loader.TablexiaAssetManager; import cz.nic.tablexia.loader.TablexiaDataManager; import cz.nic.tablexia.loader.TablexiaSoundManager; import cz.nic.tablexia.loader.TablexiaTextureManager; +import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.util.Log; import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveTo; @@ -305,6 +307,14 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter { public String getText(String key) { return textManager.getResult().get(key); } + + public BitmapFont getDefaultRegularFont() { + return ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_REGULAR); + } + + public BitmapFont getDefaultBoldFont() { + return ApplicationFontManager.getInstance().getFont(ApplicationFontManager.APPLICATION_DEFAULT_FONT_BOLD); + } public String getFormattedText(String key, Object... args) { return textManager.getResult().format(key, args); diff --git a/core/src/cz/nic/tablexia/screen/about/AboutScreen.java b/core/src/cz/nic/tablexia/screen/about/AboutScreen.java index 2ed436b28..b746749e0 100644 --- a/core/src/cz/nic/tablexia/screen/about/AboutScreen.java +++ b/core/src/cz/nic/tablexia/screen/about/AboutScreen.java @@ -1,19 +1,17 @@ package cz.nic.tablexia.screen.about; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Table; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; public class AboutScreen extends AbstractTablexiaScreen<Void> { @Override protected void screenLoaded() { - Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE)); + Label label = new Label(getClass().getSimpleName(), new LabelStyle(getDefaultRegularFont(), Color.WHITE)); Table table = new Table(); table.add(label); label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2); diff --git a/core/src/cz/nic/tablexia/screen/encyclopedia/EncyclopediaScreen.java b/core/src/cz/nic/tablexia/screen/encyclopedia/EncyclopediaScreen.java index ec70a7105..5f8f71ad8 100644 --- a/core/src/cz/nic/tablexia/screen/encyclopedia/EncyclopediaScreen.java +++ b/core/src/cz/nic/tablexia/screen/encyclopedia/EncyclopediaScreen.java @@ -1,19 +1,17 @@ package cz.nic.tablexia.screen.encyclopedia; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Table; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> { @Override protected void screenLoaded() { - Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE)); + Label label = new Label(getClass().getSimpleName(), new LabelStyle(getDefaultRegularFont(), Color.WHITE)); Table table = new Table(); table.add(label); label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2); diff --git a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java index 040093558..41990f5df 100644 --- a/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java +++ b/core/src/cz/nic/tablexia/screen/halloffame/HallOfFameScreen.java @@ -1,19 +1,17 @@ package cz.nic.tablexia.screen.halloffame; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Table; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; public class HallOfFameScreen extends AbstractTablexiaScreen<Void> { @Override protected void screenLoaded() { - Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE)); + Label label = new Label(getClass().getSimpleName(), new LabelStyle(getDefaultRegularFont(), Color.WHITE)); Table table = new Table(); table.add(label); label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2); diff --git a/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java b/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java index c84f33ec2..e70f383ab 100644 --- a/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java +++ b/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java @@ -15,7 +15,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.graphics.ColorTexture; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.loader.application.ApplicationTextureManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; @@ -39,7 +38,7 @@ public class PreferencesScreen extends AbstractTablexiaScreen<Void> { @Override protected void screenLoaded() { - BitmapFont font = ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class); + BitmapFont font = getDefaultRegularFont(); Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); preferencesContainer = new Container<Table>(); diff --git a/core/src/cz/nic/tablexia/screen/statistics/StatisticsScreen.java b/core/src/cz/nic/tablexia/screen/statistics/StatisticsScreen.java index a9234c33a..3afe4bd32 100644 --- a/core/src/cz/nic/tablexia/screen/statistics/StatisticsScreen.java +++ b/core/src/cz/nic/tablexia/screen/statistics/StatisticsScreen.java @@ -1,7 +1,6 @@ package cz.nic.tablexia.screen.statistics; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.ui.Container; import com.badlogic.gdx.scenes.scene2d.ui.Label; @@ -11,7 +10,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import java.util.List; import cz.nic.tablexia.TablexiaSettings; -import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.loader.application.ApplicationTextureManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; @@ -29,7 +27,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> { backgroundLayout = new Container<Label>(); backgroundLayout.setBackground(new TextureRegionDrawable(new TextureRegion(getTexture(ApplicationTextureManager.UniversalAssets.BACKGROUND_WOODEN)))); - Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE)); + Label label = new Label(getClass().getSimpleName(), new LabelStyle(getDefaultRegularFont(), Color.WHITE)); label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2); backgroundLayout.setActor(label); -- GitLab