summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-18 11:10:21 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-18 11:10:21 +0100
commitcb81f0a8a194ceebaea880f9027635e6a27df69e (patch)
treea64e55aaa5f45d8329737af6633a6d3fe9f3a3ff /core/src/ch/asynk
parent75ff89304eaf9052ab889bb7ec81c96de4fa7908 (diff)
downloadRustAndDust-cb81f0a8a194ceebaea880f9027635e6a27df69e.zip
RustAndDust-cb81f0a8a194ceebaea880f9027635e6a27df69e.tar.gz
UI: merge menu and ui assets, AtlasRegion are known and provided by RustAndDust
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/RustAndDust.java29
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hud.java4
-rw-r--r--core/src/ch/asynk/rustanddust/menu/MainMenu.java7
-rw-r--r--core/src/ch/asynk/rustanddust/menu/OptionsMenu.java13
-rw-r--r--core/src/ch/asynk/rustanddust/menu/PlayMenu.java24
-rw-r--r--core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java10
-rw-r--r--core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java14
-rw-r--r--core/src/ch/asynk/rustanddust/screens/MenuScreen.java26
-rw-r--r--core/src/ch/asynk/rustanddust/ui/Msg.java8
-rw-r--r--core/src/ch/asynk/rustanddust/ui/OkCancel.java11
10 files changed, 75 insertions, 71 deletions
diff --git a/core/src/ch/asynk/rustanddust/RustAndDust.java b/core/src/ch/asynk/rustanddust/RustAndDust.java
index 3985379..5a63c70 100644
--- a/core/src/ch/asynk/rustanddust/RustAndDust.java
+++ b/core/src/ch/asynk/rustanddust/RustAndDust.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.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
@@ -20,9 +21,9 @@ import ch.asynk.rustanddust.ui.Bg;
public class RustAndDust extends Game
{
+ public static final String NINEPATCH = "typewriter";
public static final String TTF_FONT = "skin/veteran-typewriter.ttf";
public static final String ATLAS_UI = "data/ui.atlas";
- public static final String ATLAS_MENU = "data/menu.atlas";
public static final String ATLAS_HUD = "data/hud.atlas";
public static final String ATLAS_UNITS = "data/units%d.atlas";
public static final String ATLAS_UNIT_OVERLAYS = "data/unit-overlays%d.atlas";
@@ -44,6 +45,15 @@ public class RustAndDust extends Game
public static final String SND_PROMOTE_US = "sounds/promote_us.mp3";
public static final String SND_PROMOTE_GE = "sounds/promote_ge.mp3";
+ public static final String UI_OK = "ok";
+ public static final String UI_CANCEL = "cancel";
+ public static final String UI_FROM = "from";
+ public static final String UI_TO = "to";
+ public static final String UI_MOVE = "move";
+ public static final String UI_UNIT = "unit";
+ public static final String UI_US_FLAG = "us-flag";
+ public static final String UI_GE_FLAG = "ge-flag";
+
public AssetManager manager;
public Factory factory;
public Ctrl ctrl;
@@ -51,8 +61,8 @@ public class RustAndDust extends Game
public int hudCorrection;
public TextureAtlas uiAtlas;
- public TextureAtlas menuAtlas;
public BitmapFont font;
+ public NinePatch ninePatch;
public enum State
{
@@ -72,6 +82,11 @@ public class RustAndDust extends Game
Gdx.app.debug(dom, msg);
}
+ public TextureAtlas.AtlasRegion getUiRegion(String s)
+ {
+ return uiAtlas.findRegion(s);
+ }
+
@Override
public void create ()
{
@@ -115,7 +130,7 @@ public class RustAndDust extends Game
if (config.battle.getMapType() == Factory.MapType.MAP_00)
manager.load(PNG_MAP_00, Texture.class);
int i = config.graphics.i;
- manager.load(String.format(ATLAS_UNITS,i), TextureAtlas.class);
+ manager.load(String.format(ATLAS_UNITS, i), TextureAtlas.class);
manager.load(String.format(ATLAS_UNIT_OVERLAYS, i), TextureAtlas.class);
manager.load(ATLAS_HUD, TextureAtlas.class);
manager.load(ATLAS_HEX_OVERLAYS, TextureAtlas.class);
@@ -142,8 +157,8 @@ public class RustAndDust extends Game
if (config.battle.getMapType() == Factory.MapType.MAP_00)
manager.unload(PNG_MAP_00);
int i = config.graphics.i;
- manager.unload(String.format(ATLAS_UNITS,i));
- manager.unload(String.format(ATLAS_UNIT_OVERLAYS));
+ manager.unload(String.format(ATLAS_UNITS, i));
+ manager.unload(String.format(ATLAS_UNIT_OVERLAYS, i));
manager.unload(ATLAS_HUD);
manager.unload(ATLAS_HEX_OVERLAYS);
manager.unload(PNG_SELECTED);
@@ -177,6 +192,7 @@ public class RustAndDust extends Game
parameter.size = Math.max((int) (h * 0.04f), 16);
parameter.color = Color.BLACK;
font = generator.generateFont(parameter);
+ ninePatch = uiAtlas.createPatch(NINEPATCH);
}
private void unloadUiAssets()
@@ -188,15 +204,12 @@ public class RustAndDust extends Game
private void loadMenuAssets()
{
manager.load(PNG_MAP_00, Texture.class);
- manager.load(ATLAS_MENU, TextureAtlas.class);
manager.finishLoading();
- menuAtlas = manager.get(ATLAS_MENU, TextureAtlas.class);
}
private void unloadMenuAssets()
{
manager.unload(PNG_MAP_00);
- manager.unload(ATLAS_MENU);
}
// @Override
diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java
index bd2d600..a60d125 100644
--- a/core/src/ch/asynk/rustanddust/game/Hud.java
+++ b/core/src/ch/asynk/rustanddust/game/Hud.java
@@ -65,8 +65,8 @@ public class Hud implements Disposable, Animation
playerInfo = new PlayerInfo(ctrl, game.font, game.uiAtlas, hudAtlas);
actionButtons = new ActionButtons(ctrl, game.uiAtlas, hudAtlas);
actionButtons.hide();
- msg = new Msg(game.font, game.uiAtlas);
- okCancel = new OkCancel(game.font, game.uiAtlas);
+ msg = new Msg(game.font, game.ninePatch, 20f);
+ okCancel = new OkCancel(game.font, game.ninePatch, game.getUiRegion(game.UI_OK), game.getUiRegion(game.UI_CANCEL));
stats = new StatisticsPanel(game.font, game.uiAtlas, hudAtlas);
engagement = new EngagementPanel(game.font, game.uiAtlas, hudAtlas);
}
diff --git a/core/src/ch/asynk/rustanddust/menu/MainMenu.java b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
index ff65d50..620205a 100644
--- a/core/src/ch/asynk/rustanddust/menu/MainMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
@@ -1,9 +1,8 @@
package ch.asynk.rustanddust.menu;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.ui.Menu;
public class MainMenu extends Menu
@@ -24,9 +23,9 @@ public class MainMenu extends Menu
public int last() { return NONE.i; }
};
- public MainMenu(BitmapFont font, TextureAtlas atlas)
+ public MainMenu(RustAndDust game)
{
- super(Items.NONE, font, atlas.createPatch("typewriter"));
+ super(Items.NONE, game.font, game.ninePatch);
label(Items.PLAY).write("Play");
label(Items.TUTORIALS).write("Tutorials");
diff --git a/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
index e2b3b1e..4499405 100644
--- a/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
@@ -3,7 +3,6 @@ package ch.asynk.rustanddust.menu;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import ch.asynk.rustanddust.ui.Label;
import ch.asynk.rustanddust.ui.Bg;
@@ -44,14 +43,14 @@ public class OptionsMenu extends Patch
protected Bg okBtn;
protected Bg cancelBtn;
- public OptionsMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ public OptionsMenu(RustAndDust game)
{
- super(atlas.createPatch("typewriter"));
+ super(game.ninePatch);
this.game = game;
- this.font = font;
- this.okCancel = new OkCancel(font, atlas);
- this.okBtn = new Bg(atlas.findRegion("ok"));
- this.cancelBtn = new Bg(atlas.findRegion("cancel"));
+ this.font = game.font;
+ this.okCancel = new OkCancel(font, game.ninePatch, game.getUiRegion(game.UI_OK), game.getUiRegion(game.UI_CANCEL));
+ this.okBtn = new Bg(game.getUiRegion(game.UI_OK));
+ this.cancelBtn = new Bg(game.getUiRegion(game.UI_CANCEL));
this.title = new Label(font);
this.title.write("- Options");
this.fxVolume = new Label(font);
diff --git a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
index cbf182d..866a647 100644
--- a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
@@ -1,8 +1,6 @@
package ch.asynk.rustanddust.menu;
import com.badlogic.gdx.graphics.g2d.Batch;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import ch.asynk.rustanddust.ui.Label;
import ch.asynk.rustanddust.ui.Bg;
@@ -17,7 +15,6 @@ public class PlayMenu extends Patch
public static int VSPACING = 30;
private final RustAndDust game;
- private final BitmapFont font;
private Label title;
private Label gameMode;
@@ -32,22 +29,21 @@ public class PlayMenu extends Patch
public boolean launch;
- public PlayMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ public PlayMenu(RustAndDust game)
{
- super(atlas.createPatch("typewriter"));
+ super(game.ninePatch);
this.game = game;
- this.font = font;
- this.title = new Label(font);
+ this.title = new Label(game.font);
this.title.write("- Play");
- this.gameMode = new Label(font);
+ this.gameMode = new Label(game.font);
this.gameMode.write("Game mode : ");
- this.gameModeValue = new Label(font);
- this.okBtn = new Bg(atlas.findRegion("ok"));
- this.cancelBtn = new Bg(atlas.findRegion("cancel"));
- this.battle = new Label(font);
+ this.gameModeValue = new Label(game.font);
+ this.okBtn = new Bg(game.getUiRegion(game.UI_OK));
+ this.cancelBtn = new Bg(game.getUiRegion(game.UI_CANCEL));
+ this.battle = new Label(game.font);
this.battle.write("Scenario : ");
- this.battleValue = new Label(font);
- this.okCancel = new OkCancel(font, atlas);
+ this.battleValue = new Label(game.font);
+ this.okCancel = new OkCancel(game.font, game.ninePatch, game.getUiRegion(game.UI_OK), game.getUiRegion(game.UI_CANCEL));
if (game.config.battle == null) {
battleIdx = 0;
diff --git a/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java b/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java
index 7140e48..cb1fcef 100644
--- a/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java
@@ -31,13 +31,13 @@ public class ScenariosMenu extends Patch
public boolean launch;
- public ScenariosMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ public ScenariosMenu(RustAndDust game)
{
- super(atlas.createPatch("typewriter"));
+ super(game.ninePatch);
this.game = game;
- this.font = font;
- this.okBtn = new Bg(atlas.findRegion("ok"));
- this.cancelBtn = new Bg(atlas.findRegion("cancel"));
+ this.font = game.font;
+ this.okBtn = new Bg(game.getUiRegion(game.UI_OK));
+ this.cancelBtn = new Bg(game.getUiRegion(game.UI_CANCEL));
this.title = new Label(font);
this.title.write("- Scenarios");
this.battleLabels = new Label[game.factory.battles.length];
diff --git a/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
index 53dd29f..87e2765 100644
--- a/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
@@ -1,8 +1,6 @@
package ch.asynk.rustanddust.menu;
import com.badlogic.gdx.graphics.g2d.Batch;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import ch.asynk.rustanddust.ui.Label;
import ch.asynk.rustanddust.ui.Bg;
@@ -15,21 +13,19 @@ public class TutorialsMenu extends Patch
public static int TITLE_PADDING = 30;
private final RustAndDust game;
- private final BitmapFont font;
private Label title;
private Label msg;
protected Bg okBtn;
- public TutorialsMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ public TutorialsMenu(RustAndDust game)
{
- super(atlas.createPatch("typewriter"));
+ super(game.ninePatch);
this.game = game;
- this.font = font;
- this.okBtn = new Bg(atlas.findRegion("ok"));
- this.title = new Label(font);
+ this.okBtn = new Bg(game.getUiRegion(game.UI_OK));
+ this.title = new Label(game.font);
this.title.write("- Tutorials");
- this.msg = new Label(font);
+ this.msg = new Label(game.font);
this.msg.write("Not implemented yet.");
this.visible = false;
diff --git a/core/src/ch/asynk/rustanddust/screens/MenuScreen.java b/core/src/ch/asynk/rustanddust/screens/MenuScreen.java
index d9d2221..48f9656 100644
--- a/core/src/ch/asynk/rustanddust/screens/MenuScreen.java
+++ b/core/src/ch/asynk/rustanddust/screens/MenuScreen.java
@@ -69,19 +69,19 @@ public class MenuScreen implements Screen
this.gameAssetsLoading = false;
- this.bg = game.manager.get("data/map_00.png", Texture.class);
-
- this.unit = new Sprite(game.menuAtlas.findRegion("unit"));
- this.move = new Sprite(game.menuAtlas.findRegion("move"));
- this.from = new Sprite(game.menuAtlas.findRegion("from"));
- this.to = new Sprite(game.menuAtlas.findRegion("to"));
- this.usFlag = new Sprite(game.menuAtlas.findRegion("us-flag"));
- this.geFlag = new Sprite(game.menuAtlas.findRegion("ge-flag"));
-
- this.mainMenu = new MainMenu(game.font, game.uiAtlas);
- this.playMenu = new PlayMenu(game, game.font, game.uiAtlas);
- this.optionsMenu = new OptionsMenu(game, game.font, game.uiAtlas);
- this.tutorialsMenu = new TutorialsMenu(game, game.font, game.uiAtlas);
+ this.bg = game.manager.get(game.PNG_MAP_00, Texture.class);
+
+ this.unit = new Sprite(game.getUiRegion(game.UI_UNIT));
+ this.move = new Sprite(game.getUiRegion(game.UI_MOVE));
+ this.from = new Sprite(game.getUiRegion(game.UI_FROM));
+ this.to = new Sprite(game.getUiRegion(game.UI_TO));
+ this.usFlag = new Sprite(game.getUiRegion(game.UI_US_FLAG));
+ this.geFlag = new Sprite(game.getUiRegion(game.UI_GE_FLAG));
+
+ this.mainMenu = new MainMenu(game);
+ this.playMenu = new PlayMenu(game);
+ this.optionsMenu = new OptionsMenu(game);
+ this.tutorialsMenu = new TutorialsMenu(game);
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
diff --git a/core/src/ch/asynk/rustanddust/ui/Msg.java b/core/src/ch/asynk/rustanddust/ui/Msg.java
index e1e7c13..16c4e2d 100644
--- a/core/src/ch/asynk/rustanddust/ui/Msg.java
+++ b/core/src/ch/asynk/rustanddust/ui/Msg.java
@@ -2,17 +2,17 @@ package ch.asynk.rustanddust.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
public class Msg extends Patch
{
private LabelStack label;
- public Msg(BitmapFont font, TextureAtlas atlas)
+ public Msg(BitmapFont font, NinePatch patch, float fontSize)
{
- super(atlas.createPatch("typewriter"));
- label = new LabelStack(font, 20f);
+ super(patch);
+ label = new LabelStack(font, fontSize);
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/ui/OkCancel.java b/core/src/ch/asynk/rustanddust/ui/OkCancel.java
index c064102..7b0bd1c 100644
--- a/core/src/ch/asynk/rustanddust/ui/OkCancel.java
+++ b/core/src/ch/asynk/rustanddust/ui/OkCancel.java
@@ -1,8 +1,9 @@
package ch.asynk.rustanddust.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
public class OkCancel extends Patch
@@ -16,12 +17,12 @@ public class OkCancel extends Patch
protected Bg okBtn;
protected Bg cancelBtn;
- public OkCancel(BitmapFont font, TextureAtlas atlas)
+ public OkCancel(BitmapFont font, NinePatch patch, AtlasRegion okRegion, AtlasRegion cancelRegion)
{
- super(atlas.createPatch("typewriter"));
+ super(patch);
this.label = new Label(font);
- this.okBtn = new Bg(atlas.findRegion("ok"));
- this.cancelBtn = new Bg(atlas.findRegion("cancel"));
+ this.okBtn = new Bg(okRegion);
+ this.cancelBtn = new Bg(cancelRegion);
this.visible = false;
}