From 3801826023cfa8afc43f155e3f32d2f2ede47cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 10 Feb 2015 17:22:22 +0100 Subject: Statistics -> StatisticsPanel --- core/src/ch/asynk/tankontank/game/Hud.java | 6 +- .../ch/asynk/tankontank/game/hud/Statistics.java | 120 --------------------- .../asynk/tankontank/game/hud/StatisticsPanel.java | 120 +++++++++++++++++++++ 3 files changed, 123 insertions(+), 123 deletions(-) delete mode 100644 core/src/ch/asynk/tankontank/game/hud/Statistics.java create mode 100644 core/src/ch/asynk/tankontank/game/hud/StatisticsPanel.java diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 0afc999..0e0a3a2 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -19,7 +19,7 @@ import ch.asynk.tankontank.ui.OkCancel; import ch.asynk.tankontank.ui.Widget; import ch.asynk.tankontank.game.hud.PlayerInfo; import ch.asynk.tankontank.game.hud.ActionButtons; -import ch.asynk.tankontank.game.hud.Statistics; +import ch.asynk.tankontank.game.hud.StatisticsPanel; import ch.asynk.tankontank.game.hud.Engagement; import ch.asynk.tankontank.TankOnTank; @@ -38,7 +38,7 @@ public class Hud implements Disposable, Animation public ActionButtons actionButtons; private Msg msg; - private Statistics stats; + private StatisticsPanel stats; private Engagement engagement; private OkCancel okCancel; private LinkedList dialogs = new LinkedList(); @@ -54,7 +54,7 @@ public class Hud implements Disposable, Animation actionButtons.hide(); msg = new Msg(game.fontB, game.uiAtlas); okCancel = new OkCancel(game.fontB, game.uiAtlas); - stats = new Statistics(game.fontB, game.uiAtlas); + stats = new StatisticsPanel(game.fontB, game.uiAtlas); engagement = new Engagement(game.fontB, game.uiAtlas, hudAtlas); } diff --git a/core/src/ch/asynk/tankontank/game/hud/Statistics.java b/core/src/ch/asynk/tankontank/game/hud/Statistics.java deleted file mode 100644 index 9517b8c..0000000 --- a/core/src/ch/asynk/tankontank/game/hud/Statistics.java +++ /dev/null @@ -1,120 +0,0 @@ -package ch.asynk.tankontank.game.hud; - -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.glutils.ShapeRenderer; - -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.ui.Bg; -import ch.asynk.tankontank.ui.Label; -import ch.asynk.tankontank.ui.Patch; -import ch.asynk.tankontank.ui.Position; - -public class Statistics extends Patch -{ - public static int OK_OFFSET = 10; - public static int PADDING = 20; - public static int VSPACING = 10; - public static int HSPACING = 10; - - private Label title; - private Label header; - private Label stats1; - private Label stats2; - private Bg okBtn; - - public Statistics(BitmapFont font, TextureAtlas atlas) - { - super(atlas.createPatch("typewriter")); - this.title = new Label(font); - this.header = new Label(font); - this.stats1 = new Label(font); - this.stats2 = new Label(font); - this.okBtn = new Bg(atlas.findRegion("ok")); - this.visible = false; - this.header.write("\nActions\nUnits Left\nUnits Withrawed\nCasualties\nWon Attacks\nLost Attacks"); - } - - public void updatePosition() - { - if (!visible) return; - float dx = (position.getX(rect.width) - rect.x); - float dy = (position.getY(rect.height) - rect.y); - translate(dx, dy); - title.translate(dx, dy); - header.translate(dx, dy); - stats1.translate(dx, dy); - stats2.translate(dx, dy); - okBtn.translate(dx, dy); - } - - public void show(Player winner, Player loser, Position position) - { - title.write(winner.getName() + " player won the battle in " + winner.getTurnDone() + " turns."); - stats1.write(winner.getStats()); - stats2.write(loser.getStats()); - - float height = (title.getHeight() + header.getHeight() + (2 * PADDING) + (1 * VSPACING)); - float width = (header.getWidth() + stats1.getWidth() + stats2.getWidth() + (2 * PADDING) + (4 * HSPACING)); - float w2 = (title.getWidth() + (2 * PADDING)); - if (w2 > width) width = w2; - float x = position.getX(width); - float y = position.getY(height); - setPosition(x, y, width, height); - - okBtn.setPosition((x + width - okBtn.getWidth() + OK_OFFSET), (y - OK_OFFSET)); - - y += PADDING; - x += PADDING; - header.setPosition(x, y); - stats1.setPosition((x + header.getWidth() + (2 * HSPACING)), y); - stats2.setPosition((stats1.getX() + stats1.getWidth() + (2 * HSPACING)), y); - y += (header.getHeight() + VSPACING); - title.setPosition(x, y); - visible = true; - } - - @Override - public boolean hit(float x, float y) - { - if (okBtn.hit(x, y)) - return true; - return false; - } - - @Override - public void dispose() - { - super.dispose(); - title.dispose(); - header.dispose(); - stats1.dispose(); - stats2.dispose(); - okBtn.dispose(); - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - super.draw(batch); - title.draw(batch); - header.draw(batch); - stats1.draw(batch); - stats2.draw(batch); - okBtn.draw(batch); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!visible) return; - super.drawDebug(shapes); - title.drawDebug(shapes); - header.drawDebug(shapes); - stats1.drawDebug(shapes); - stats2.drawDebug(shapes); - okBtn.drawDebug(shapes); - } -} diff --git a/core/src/ch/asynk/tankontank/game/hud/StatisticsPanel.java b/core/src/ch/asynk/tankontank/game/hud/StatisticsPanel.java new file mode 100644 index 0000000..9ad75a6 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/StatisticsPanel.java @@ -0,0 +1,120 @@ +package ch.asynk.tankontank.game.hud; + +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.glutils.ShapeRenderer; + +import ch.asynk.tankontank.game.Player; +import ch.asynk.tankontank.ui.Bg; +import ch.asynk.tankontank.ui.Label; +import ch.asynk.tankontank.ui.Patch; +import ch.asynk.tankontank.ui.Position; + +public class StatisticsPanel extends Patch +{ + public static int OK_OFFSET = 10; + public static int PADDING = 20; + public static int VSPACING = 10; + public static int HSPACING = 10; + + private Label title; + private Label header; + private Label stats1; + private Label stats2; + private Bg okBtn; + + public StatisticsPanel(BitmapFont font, TextureAtlas atlas) + { + super(atlas.createPatch("typewriter")); + this.title = new Label(font); + this.header = new Label(font); + this.stats1 = new Label(font); + this.stats2 = new Label(font); + this.okBtn = new Bg(atlas.findRegion("ok")); + this.visible = false; + this.header.write("\nActions\nUnits Left\nUnits Withrawed\nCasualties\nWon Attacks\nLost Attacks"); + } + + public void updatePosition() + { + if (!visible) return; + float dx = (position.getX(rect.width) - rect.x); + float dy = (position.getY(rect.height) - rect.y); + translate(dx, dy); + title.translate(dx, dy); + header.translate(dx, dy); + stats1.translate(dx, dy); + stats2.translate(dx, dy); + okBtn.translate(dx, dy); + } + + public void show(Player winner, Player loser, Position position) + { + title.write(winner.getName() + " player won the battle in " + winner.getTurnDone() + " turns."); + stats1.write(winner.getStats()); + stats2.write(loser.getStats()); + + float height = (title.getHeight() + header.getHeight() + (2 * PADDING) + (1 * VSPACING)); + float width = (header.getWidth() + stats1.getWidth() + stats2.getWidth() + (2 * PADDING) + (4 * HSPACING)); + float w2 = (title.getWidth() + (2 * PADDING)); + if (w2 > width) width = w2; + float x = position.getX(width); + float y = position.getY(height); + setPosition(x, y, width, height); + + okBtn.setPosition((x + width - okBtn.getWidth() + OK_OFFSET), (y - OK_OFFSET)); + + y += PADDING; + x += PADDING; + header.setPosition(x, y); + stats1.setPosition((x + header.getWidth() + (2 * HSPACING)), y); + stats2.setPosition((stats1.getX() + stats1.getWidth() + (2 * HSPACING)), y); + y += (header.getHeight() + VSPACING); + title.setPosition(x, y); + visible = true; + } + + @Override + public boolean hit(float x, float y) + { + if (okBtn.hit(x, y)) + return true; + return false; + } + + @Override + public void dispose() + { + super.dispose(); + title.dispose(); + header.dispose(); + stats1.dispose(); + stats2.dispose(); + okBtn.dispose(); + } + + @Override + public void draw(Batch batch) + { + if (!visible) return; + super.draw(batch); + title.draw(batch); + header.draw(batch); + stats1.draw(batch); + stats2.draw(batch); + okBtn.draw(batch); + } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!visible) return; + super.drawDebug(shapes); + title.drawDebug(shapes); + header.drawDebug(shapes); + stats1.drawDebug(shapes); + stats2.drawDebug(shapes); + okBtn.drawDebug(shapes); + } +} -- cgit v1.1-2-g2b99