Store the used font on the game skin

This commit is contained in:
Lonami Exo 2017-01-31 09:54:30 +01:00
parent 43f4ca68c6
commit dd76e119df
5 changed files with 16 additions and 15 deletions

View file

@ -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"));

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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