summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-23 12:28:15 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-23 12:28:15 +0100
commit364ddbeaf910a16052792d7246a196dd4518cd81 (patch)
treef0bc91d58852c1c14b9f7bde50c9b7a64c340715
parent377d1fe9058798584948b9e1ee17fe636d0ec8f8 (diff)
downloadRustAndDust-364ddbeaf910a16052792d7246a196dd4518cd81.zip
RustAndDust-364ddbeaf910a16052792d7246a196dd4518cd81.tar.gz
add hudEngagement dialog
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java27
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java10
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Engagement.java112
3 files changed, 139 insertions, 10 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index dd88f04..abaa112 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -14,6 +14,7 @@ import ch.asynk.tankontank.game.hud.PlayerInfo;
import ch.asynk.tankontank.game.hud.ActionButtons;
import ch.asynk.tankontank.game.hud.OkCancel;
import ch.asynk.tankontank.game.hud.Statistics;
+import ch.asynk.tankontank.game.hud.Engagement;
import ch.asynk.tankontank.TankOnTank;
@@ -33,6 +34,7 @@ public class Hud implements Disposable
private Msg msg;
private Statistics stats;
+ private Engagement engagement;
private OkCancel okCancel;
private DialogAction dialogAction;
@@ -43,6 +45,7 @@ public class Hud implements Disposable
END_TURN,
END_DEPLOYMENT,
END_GAME,
+ END_ENGAGEMENT,
NONE
}
@@ -60,6 +63,7 @@ public class Hud implements Disposable
msg = new Msg(font, atlas.findRegion("disabled"), 10f);
okCancel = new OkCancel(font, atlas.findRegion("disabled"), atlas, 10f);
stats = new Statistics(font, atlas.findRegion("disabled"), atlas, 10f);
+ engagement = new Engagement(font, atlas.findRegion("disabled"), atlas, 10f);
}
@Override
@@ -70,6 +74,7 @@ public class Hud implements Disposable
actionButtons.dispose();
msg.dispose();
okCancel.dispose();
+ engagement.dispose();
stats.dispose();
}
@@ -92,6 +97,7 @@ public class Hud implements Disposable
actionButtons.draw(batch);
msg.draw(batch);
okCancel.draw(batch);
+ engagement.draw(batch);
stats.draw(batch);
}
@@ -101,6 +107,7 @@ public class Hud implements Disposable
actionButtons.drawDebug(debugShapes);
msg.drawDebug(debugShapes);
okCancel.drawDebug(debugShapes);
+ engagement.drawDebug(debugShapes);
stats.drawDebug(debugShapes);
}
@@ -127,10 +134,15 @@ public class Hud implements Disposable
if (okCancel.visible) {
if (okCancel.hit(x, y))
hit = okCancel;
- } else if (stats.visible) {
+ }
+ else if (stats.visible) {
if (stats.hit(x, y))
hit = stats;
}
+ else if (engagement.visible) {
+ if (engagement.hit(x, y))
+ hit = engagement;
+ }
else if (actionButtons.touchDown(x, y))
hit = actionButtons;
else if (playerInfo.touchDown(x, y))
@@ -158,6 +170,10 @@ public class Hud implements Disposable
if (stats.hit(x, y))
closeDialog();
}
+ else if (hit == engagement) {
+ if (engagement.hit(x, y))
+ closeDialog();
+ }
hit = null;
@@ -188,6 +204,9 @@ public class Hud implements Disposable
stats.visible = false;
ctrl.endGame();
break;
+ case END_ENGAGEMENT:
+ engagement.visible = false;
+ break;
case NONE:
default:
break;
@@ -224,11 +243,11 @@ public class Hud implements Disposable
okCancel.show("Deployment unit count reached.\nEnd Deployment phase ?", Position.MIDDLE_CENTER);
}
- public void engagementSummary(String msg)
+ public void engagementSummary(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf, String msg)
{
ctrl.blockMap = true;
- dialogAction = DialogAction.NONE;
- okCancel.show(msg, Position.BOTTOM_CENTER, false);
+ dialogAction = DialogAction.END_ENGAGEMENT;
+ engagement.show(d1, d2, cnt, flk, def, tdf, wdf, msg, Position.BOTTOM_CENTER);
}
public void victory(Player winner, Player loser)
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index bd36a7f..537a48f 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -271,13 +271,12 @@ public abstract class Map extends Board
int d2 = d6();
int die = d1 + d2;
- String msg;
boolean success = false;
if (die == 2) {
- msg = "Die : 1 + 1 => Automatic failure";
+ ctrl.hud.engagementSummary(d1, d2, 0, 0, 0, 0, 0, target.toString() + " is destroyed");
success = false;
} else if (die == 12) {
- msg = "Die : 6 + 6 => Automatic success";
+ ctrl.hud.engagementSummary(d1, d2, 0, 0, 0, 0, 0, target.toString() + " resisted the assault");
success = true;
} else {
@@ -315,10 +314,9 @@ public abstract class Map extends Board
int s2 = (def + tdf + wdf);
success = (s1 >= s2);
- msg = String.format("die : %d + %d\nunits : +%d\nflank: +%d\n = %d\ndefense: %d\nterrain: +%d\nweather: +%d\n = %d\n%s",
- d1, d2, cnt, flk, s1, def, tdf, wdf, s2, (success ? "target destroyed" : "target missed"));
+ ctrl.hud.engagementSummary(d1, d2, cnt, flk, def, tdf, wdf,
+ target.toString() + (success ? " is destroyed" : " resisted the assault"));
}
- ctrl.hud.engagementSummary(msg);
return success;
}
diff --git a/core/src/ch/asynk/tankontank/game/hud/Engagement.java b/core/src/ch/asynk/tankontank/game/hud/Engagement.java
new file mode 100644
index 0000000..fbd835d
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/Engagement.java
@@ -0,0 +1,112 @@
+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.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import ch.asynk.tankontank.game.Player;
+
+public class Engagement extends Bg
+{
+ public float padding;
+ private Label attack;
+ private Label defense;
+ private Label attackV;
+ private Label defenseV;
+ private Label msg;
+ private Bg okBtn;
+
+ public Engagement(BitmapFont font, TextureRegion region, TextureAtlas atlas, float padding)
+ {
+ super(region);
+ this.attack = new Label(font);
+ this.defense = new Label(font);
+ this.attackV = new Label(font);
+ this.defenseV = new Label(font);
+ this.msg = new Label(font);
+ this.okBtn = new Bg(atlas.findRegion("ok"));
+ this.attack.write("Attack: \n die\n units\n flank");
+ this.defense.write("Defense: \n defense\n terrain \n weather");
+ this.visible = false;
+ this.padding = padding;
+ }
+
+ public void show(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf, String m, Position position)
+ {
+ int atk = (d1 + d2 + cnt + flk);
+ int df = (def + tdf + wdf);
+ attackV.write(String.format("%d\n%d + %d\n%d\n%d", atk, d1, d2, cnt, flk));
+ defenseV.write(String.format("%d\n%d\n%d\n%d", df, def, tdf, wdf));
+ msg.write(m);
+
+ float height = (attack.getHeight() + okBtn.getHeight() + msg.getHeight() + (4 * padding));
+ float width = (attack.getWidth() + defense.getWidth() + attackV.getWidth() + defenseV.getWidth() + (5 * padding));
+ float w2 = (msg.getWidth() + (2 * padding));
+ if (w2 > width) width = w2;
+ float x = position.getX(width);
+ float y = position.getY(height);
+ set(x, y, width, height);
+
+ x += padding;
+ y += padding;
+ okBtn.setPosition((x + width - okBtn.getWidth() - padding), y);
+ y += (okBtn.getHeight() + padding);
+ msg.setPosition(x, y);
+ y += msg.getHeight() + padding;
+ attack.setPosition(x, y);
+ x += attack.getWidth() + padding;
+ attackV.setPosition(x, y);
+ x += attackV.getWidth() + padding;
+ defense.setPosition(x, y);
+ x += defense.getWidth() + padding;
+ defenseV.setPosition(x, y);
+ visible = true;
+ }
+
+ public boolean hit(float x, float y)
+ {
+ if (okBtn.hit(x, y))
+ return true;
+ return false;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ attack.dispose();
+ defense.dispose();
+ attackV.dispose();
+ defenseV.dispose();
+ msg.dispose();
+ okBtn.dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ attack.draw(batch);
+ defense.draw(batch);
+ attackV.draw(batch);
+ defenseV.draw(batch);
+ msg.draw(batch);
+ okBtn.draw(batch);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer shapes)
+ {
+ if (!visible) return;
+ super.drawDebug(shapes);
+ attack.drawDebug(shapes);
+ defense.drawDebug(shapes);
+ attackV.drawDebug(shapes);
+ defenseV.drawDebug(shapes);
+ msg.drawDebug(shapes);
+ okBtn.drawDebug(shapes);
+ }
+}