diff --git a/frontend/core/src/com/game/tankwars/ResourceManager.java b/frontend/core/src/com/game/tankwars/ResourceManager.java index 021ebc389503f1de6624a29e835685f46776675e..7c9e4c8505f67512a4c460a7b36599adca359530 100644 --- a/frontend/core/src/com/game/tankwars/ResourceManager.java +++ b/frontend/core/src/com/game/tankwars/ResourceManager.java @@ -2,15 +2,8 @@ package com.game.tankwars; import com.badlogic.gdx.assets.AssetDescriptor; import com.badlogic.gdx.assets.AssetManager; -import com.badlogic.gdx.assets.loaders.FileHandleResolver; -import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; -import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader; -import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader; import com.badlogic.gdx.scenes.scene2d.ui.Skin; -import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.utils.GdxRuntimeException; import com.github.acanthite.gdx.graphics.g2d.FreeTypeSkinLoader; @@ -29,6 +22,8 @@ public class ResourceManager { new AssetDescriptor<>("menu-textures.atlas", TextureAtlas.class); private final AssetDescriptor<Skin> MENU_SKIN = new AssetDescriptor<>("menu-textures.json", Skin.class); + private final AssetDescriptor<Skin> GAMEPLAY_SKIN = + new AssetDescriptor<>("gameplay-skin.json", Skin.class); public ResourceManager() { manager = new AssetManager(); @@ -66,6 +61,21 @@ public class ResourceManager { return null; } + /** + * Loads the Skin for the gameplay, + * @return loaded Skin object with JSON file, null on loading error + */ + public Skin loadAndGetGameplayHudAssets() { + if (!manager.isLoaded(GAMEPLAY_SKIN)) manager.load(GAMEPLAY_SKIN); + try { + manager.finishLoading(); + return manager.get(GAMEPLAY_SKIN); + } catch(GdxRuntimeException error) { + System.out.println(error.getMessage()); + } + return null; + } + /** * Block until all currently loaded assets are finished loading */ diff --git a/frontend/core/src/com/game/tankwars/view/GameHud.java b/frontend/core/src/com/game/tankwars/view/GameHud.java index 2420b1ad099b2a886e11bbd5bba78fbb7f56f2d0..9526682da78562a8e535322effa5e728cb493ce1 100644 --- a/frontend/core/src/com/game/tankwars/view/GameHud.java +++ b/frontend/core/src/com/game/tankwars/view/GameHud.java @@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.utils.viewport.Viewport; +import com.game.tankwars.ResourceManager; import com.ray3k.stripe.FreeTypeSkin; public class GameHud { @@ -49,7 +50,7 @@ public class GameHud { stage.addActor(table); - skin = new FreeTypeSkin(Gdx.files.internal("gameplay-skin.json")); + skin = ResourceManager.getInstance().loadAndGetGameplayHudAssets(); healthProgressBarPlayer = new ProgressBar(0, 100, 1, false, skin); healthProgressBarPlayer.setValue(100); @@ -69,7 +70,7 @@ public class GameHud { fireButton = new TextButton("Fire!", skin); table.add(fireButton).expand().bottom().left().padLeft(10).padBottom(10); - powerLabel = new Label("Power", skin.get("roboto-black-white", Label.LabelStyle.class)); + powerLabel = new Label("Power", skin.get("large-white", Label.LabelStyle.class)); powerSlider = new Slider(0, 100, 1, false, skin); powerContainer = new HorizontalGroup().space(10);