Skip to content
Snippets Groups Projects
Commit ff419781 authored by Magnus Segtnan Skjølberg's avatar Magnus Segtnan Skjølberg
Browse files

(#18): use ResourceManager for loading gameplay skin

parent 8432b1c1
No related branches found
No related tags found
3 merge requests!51Resolve "Adjust cannon angle from touch input",!35Draft: Resolve "Adjust cannon angle from touch input",!32Combine hud with gameplay
Pipeline #214171 failed
......@@ -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
*/
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment