From 424755c868b5519d1f73ada82666071a9fa54f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 23 Nov 2014 12:33:21 +0100 Subject: HUd: regroup dialogs into a Widget[] --- core/src/ch/asynk/tankontank/game/Hud.java | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index abaa112..4738c06 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -15,6 +15,7 @@ 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.game.hud.Widget; import ch.asynk.tankontank.TankOnTank; @@ -37,6 +38,7 @@ public class Hud implements Disposable private Engagement engagement; private OkCancel okCancel; private DialogAction dialogAction; + private Widget[] dialogs; enum DialogAction { @@ -64,6 +66,7 @@ public class Hud implements Disposable 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); + dialogs = new Widget[] { okCancel, stats, engagement}; } @Override @@ -131,22 +134,18 @@ public class Hud implements Disposable { hit = null; - if (okCancel.visible) { - if (okCancel.hit(x, y)) - hit = okCancel; - } - else if (stats.visible) { - if (stats.hit(x, y)) - hit = stats; + for (Widget w : dialogs) { + if (w.visible && w.hit(x, y)) { + hit = w; + break; + } } - else if (engagement.visible) { - if (engagement.hit(x, y)) - hit = engagement; + if (hit == null) { + if (actionButtons.touchDown(x, y)) + hit = actionButtons; + else if (playerInfo.touchDown(x, y)) + hit = playerInfo; } - else if (actionButtons.touchDown(x, y)) - hit = actionButtons; - else if (playerInfo.touchDown(x, y)) - hit = playerInfo; return (hit != null); } -- cgit v1.1-2-g2b99