summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/ui/Menu.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
commitde0463bcf0f76ef8b07f2719679c9e0d72745c5d (patch)
tree9a33df947ceeea16a3e20b400585b1d3c304e77e /core/src/ch/asynk/rustanddust/ui/Menu.java
parente66f9f2a61d3dab4545e996046486de0d44e2901 (diff)
downloadRustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip
RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/ui/Menu.java')
-rw-r--r--core/src/ch/asynk/rustanddust/ui/Menu.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/ui/Menu.java b/core/src/ch/asynk/rustanddust/ui/Menu.java
new file mode 100644
index 0000000..2fe93a7
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/ui/Menu.java
@@ -0,0 +1,93 @@
+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.NinePatch;
+
+public class Menu extends Patch
+{
+ public static int PADDING = 40;
+ public static int VSPACING = 8;
+
+ protected Label []labels;
+
+ public interface MenuItem
+ {
+ public int last();
+ public int i();
+ };
+
+ protected MenuItem menuItem;
+
+ public Menu(MenuItem menuItem, BitmapFont font, NinePatch ninePatch)
+ {
+ super(ninePatch);
+ this.menuItem = menuItem;
+ this.labels = new Label[menuItem.last()];
+ for (int i = 0; i< menuItem.last(); i ++)
+ labels[i] = new Label(font, 10);
+ }
+
+ protected Label label(MenuItem m)
+ {
+ return labels[m.i()];
+ }
+
+ protected float widestLabel()
+ {
+ float w = 0f;
+ for (int i = 0; i< menuItem.last(); i ++) {
+ float t = labels[i].getWidth();
+ if (t> w)
+ w = t;
+ }
+ return w;
+ }
+
+ protected float highestLabel()
+ {
+ float h = 0f;
+ for (int i = 0; i< menuItem.last(); i ++) {
+ float t = labels[i].getHeight();
+ if (t> h)
+ h = t;
+ }
+ return h;
+ }
+
+ public void setPosition()
+ {
+ float lh = highestLabel();
+ float h = ((menuItem.last() * lh) + (2 * PADDING) + ((menuItem.last() - 1) * VSPACING));
+ float w = (widestLabel() + (2 * PADDING));
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ y += PADDING;
+ x += PADDING;
+ float dy = (VSPACING + lh);
+
+ for (int i = 0; i< menuItem.last(); i ++) {
+ labels[i].setPosition(x, y);
+ y += dy;
+ }
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ for (int i = 0; i < menuItem.last(); i ++)
+ labels[i].dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ for (int i = 0; i < menuItem.last(); i ++)
+ labels[i].draw(batch);
+ }
+}