From dd76e119dfdecf14b81b70cee3fc35134f601b86 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 31 Jan 2017 09:54:30 +0100 Subject: [PATCH] Store the used font on the game skin --- core/src/io/github/lonamiwebs/klooni/Klooni.java | 3 +++ .../io/github/lonamiwebs/klooni/actors/Band.java | 13 ++++++------- .../io/github/lonamiwebs/klooni/game/Scorer.java | 11 +++++------ .../lonamiwebs/klooni/screens/GameScreen.java | 2 +- .../lonamiwebs/klooni/screens/PauseMenuStage.java | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/src/io/github/lonamiwebs/klooni/Klooni.java b/core/src/io/github/lonamiwebs/klooni/Klooni.java index 3dce17f..bf814f5 100644 --- a/core/src/io/github/lonamiwebs/klooni/Klooni.java +++ b/core/src/io/github/lonamiwebs/klooni/Klooni.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.scenes.scene2d.ui.Skin; @@ -49,6 +50,8 @@ public class Klooni extends Game { skin.add("web_texture", new Texture(Gdx.files.internal("ui/web.png"))); skin.add("back_texture", new Texture(Gdx.files.internal("ui/back.png"))); + skin.add("font", new BitmapFont(Gdx.files.internal("font/geosans-light.fnt"))); + // Use only one instance for the theme, so anyone using it uses the most up-to-date Theme.skin = skin; // Not the best idea theme = Theme.getTheme(prefs.getString("themeName", "default")); diff --git a/core/src/io/github/lonamiwebs/klooni/actors/Band.java b/core/src/io/github/lonamiwebs/klooni/actors/Band.java index ff4e822..4636926 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/Band.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/Band.java @@ -1,17 +1,16 @@ package io.github.lonamiwebs.klooni.actors; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; 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.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.utils.Align; +import io.github.lonamiwebs.klooni.Klooni; import io.github.lonamiwebs.klooni.game.GameLayout; import io.github.lonamiwebs.klooni.game.Scorer; @@ -33,7 +32,7 @@ public class Band extends Actor { //region Constructor - public Band(final GameLayout layout, final Scorer scorer, final Color bandColor) { + public Band(final Klooni game, final GameLayout layout, final Scorer scorer, final Color bandColor) { this.scorer = scorer; // A 1x1 pixel map will be enough since the band texture will then be expanded @@ -43,12 +42,12 @@ public class Band extends Actor { bandTexture = new Texture(pixmap); pixmap.dispose(); - Label.LabelStyle scoreStyle = new Label.LabelStyle(); - scoreStyle.font = new BitmapFont(Gdx.files.internal("font/geosans-light.fnt")); + Label.LabelStyle labelStyle = new Label.LabelStyle(); + labelStyle.font = game.skin.getFont("font"); - scoreLabel = new Label("", scoreStyle); + scoreLabel = new Label("", labelStyle); scoreLabel.setAlignment(Align.center); - infoLabel = new Label("pause menu", scoreStyle); + infoLabel = new Label("pause menu", labelStyle); infoLabel.setAlignment(Align.center); scoreBounds = new Rectangle(); diff --git a/core/src/io/github/lonamiwebs/klooni/game/Scorer.java b/core/src/io/github/lonamiwebs/klooni/game/Scorer.java index 3522b38..3ec8f21 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/Scorer.java +++ b/core/src/io/github/lonamiwebs/klooni/game/Scorer.java @@ -3,7 +3,6 @@ package io.github.lonamiwebs.klooni.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.MathUtils; @@ -39,21 +38,21 @@ public class Scorer { //region Constructor // The board size is required when calculating the score - public Scorer(GameLayout layout) { + public Scorer(final Klooni game, GameLayout layout) { currentScore = 0; maxScore = Klooni.getMaxScore(); cupTexture = new Texture(Gdx.files.internal("ui/cup.png")); cupArea = new Rectangle(); - Label.LabelStyle scoreStyle = new Label.LabelStyle(); - scoreStyle.font = new BitmapFont(Gdx.files.internal("font/geosans-light.fnt")); + Label.LabelStyle labelStyle = new Label.LabelStyle(); + labelStyle.font = game.skin.getFont("font"); - currentScoreLabel = new Label("0", scoreStyle); + currentScoreLabel = new Label("0", labelStyle); currentScoreLabel.setColor(Color.GOLD); currentScoreLabel.setAlignment(Align.right); - maxScoreLabel = new Label(Integer.toString(maxScore), scoreStyle); + maxScoreLabel = new Label(Integer.toString(maxScore), labelStyle); maxScoreLabel.setColor(new Color(0x65D681FF)); layout.update(this); diff --git a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java index c2a03b8..c612e81 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java @@ -44,7 +44,7 @@ class GameScreen implements Screen, InputProcessor { batch = new SpriteBatch(); final GameLayout layout = new GameLayout(); - scorer = new Scorer(layout); + scorer = new Scorer(game, layout); board = new Board(layout, BOARD_SIZE); holder = new PieceHolder(layout, HOLDER_PIECE_COUNT, board.cellSize); pauseMenu = new PauseMenuStage(layout, game, scorer); diff --git a/core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java b/core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java index 8d53369..b94d597 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java @@ -52,7 +52,7 @@ class PauseMenuStage extends Stage { // Current and maximum score band. // Do not add it to the table not to over-complicate things. - band = new Band(layout, this.scorer, Color.SKY); + band = new Band(game, layout, this.scorer, Color.SKY); addActor(band); // Home screen button