diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-06-30 06:21:50 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-06-30 06:21:50 +0200 |
commit | d74bcf9bf390418df35d94b54d59df0170033f65 (patch) | |
tree | 2ceae1bd287c42b4f109c47d2360199d6076a156 /core/src/ch/asynk/tankontank/ui | |
parent | 06868b70f82ed30e46ea3fd012a0befc8380bbad (diff) | |
download | RustAndDust-d74bcf9bf390418df35d94b54d59df0170033f65.zip RustAndDust-d74bcf9bf390418df35d94b54d59df0170033f65.tar.gz |
TankOnTank -> CreepingArmor
Diffstat (limited to 'core/src/ch/asynk/tankontank/ui')
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Bg.java | 28 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Label.java | 72 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/LabelImage.java | 72 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/LabelStack.java | 72 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Menu.java | 93 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Msg.java | 79 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/OkCancel.java | 115 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Patch.java | 28 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Position.java | 239 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Widget.java | 93 |
10 files changed, 0 insertions, 891 deletions
diff --git a/core/src/ch/asynk/tankontank/ui/Bg.java b/core/src/ch/asynk/tankontank/ui/Bg.java deleted file mode 100644 index 7a87c26..0000000 --- a/core/src/ch/asynk/tankontank/ui/Bg.java +++ /dev/null @@ -1,28 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -public class Bg extends Widget -{ - private TextureRegion region; - - public Bg(TextureRegion region) - { - super(); - this.region = region; - setPosition(0, 0, region.getRegionWidth(), region.getRegionHeight()); - } - - @Override - public void dispose() - { - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - batch.draw(region, rect.x, rect.y, rect.width, rect.height); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Label.java b/core/src/ch/asynk/tankontank/ui/Label.java deleted file mode 100644 index 041f44d..0000000 --- a/core/src/ch/asynk/tankontank/ui/Label.java +++ /dev/null @@ -1,72 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.GlyphLayout; - -public class Label extends Widget -{ - private BitmapFont font; - private GlyphLayout layout; - private float dx; - private float dy; - protected String text; - - public Label(BitmapFont font) - { - this(font, 0f); - } - - public Label(BitmapFont font, float padding) - { - this(font, padding, Position.MIDDLE_CENTER); - } - - public Label(BitmapFont font, float padding, Position position) - { - super(); - this.font = font; - this.padding = padding; - this.position = position; - this.layout = new GlyphLayout(); - } - - @Override - public void dispose() - { - } - - @Override - public void translate(float dx, float dy) - { - setPosition((rect.x + dx), (rect.y + dy)); - } - - @Override - public void setPosition(float x, float y) - { - this.layout.setText(font, (text == null) ? "" : text); - setPosition(x, y, (layout.width + (2 * padding)), (layout.height + (2 * padding))); - this.dx = (x + padding); - this.dy = (y + padding + layout.height); - } - - public void write(String text) - { - this.text = text; - setPosition(position); - } - - public void write(String text, float x, float y) - { - this.text = text; - setPosition(x, y); - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - font.draw(batch, layout, dx, dy); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/LabelImage.java b/core/src/ch/asynk/tankontank/ui/LabelImage.java deleted file mode 100644 index 4f28924..0000000 --- a/core/src/ch/asynk/tankontank/ui/LabelImage.java +++ /dev/null @@ -1,72 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -public class LabelImage extends Bg -{ - private Label label; - - public LabelImage(TextureRegion region, BitmapFont font) - { - this(region, font, 0f); - } - - public LabelImage(TextureRegion region, BitmapFont font, float padding) - { - this(region, font, padding, Position.MIDDLE_CENTER); - } - - public LabelImage(TextureRegion region, BitmapFont font, float padding, Position position) - { - super(region); - this.label = new Label(font, padding, position); - } - - @Override - public void dispose() - { - label.dispose(); - } - - @Override - public void translate(float dx, float dy) - { - super.translate(dx, dy); - label.translate(dx, dy); - } - - public void setPosition(float x, float y) - { - super.setPosition(x, y); - label.setPosition(x, y); - } - - public void setLabelPosition(Position position) - { - label.setPosition(position, this); - } - - public void write(String text) - { - this.label.write(text); - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - super.draw(batch); - label.draw(batch); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!visible) return; - super.drawDebug(shapes); - label.drawDebug(shapes); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/LabelStack.java b/core/src/ch/asynk/tankontank/ui/LabelStack.java deleted file mode 100644 index f730d0d..0000000 --- a/core/src/ch/asynk/tankontank/ui/LabelStack.java +++ /dev/null @@ -1,72 +0,0 @@ -package ch.asynk.tankontank.ui; - -import java.util.ArrayDeque; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; - -import ch.asynk.tankontank.engine.gfx.Animation; - -public class LabelStack extends Label implements Animation -{ - class MsgInfo - { - String text; - float duration; - Position position; - MsgInfo(String text, float duration, Position position) - { - this.text = text; - this.duration = duration; - this.position = position; - } - } - - private float duration; - private float elapsed; - private ArrayDeque<MsgInfo> stack; - - public LabelStack(BitmapFont font, float padding) - { - super(font, padding); - this.visible = false; - this.stack = new ArrayDeque<MsgInfo>(); - } - - public void pushWrite(String text, float duration, Position position) - { - if (visible) - stack.push(new MsgInfo(text, duration, position)); - else - write(text, duration, position); - } - - public void write(String text, float duration, Position position) - { - this.position = position; - write(text, duration); - } - - public void write(String text, float duration) - { - this.duration = duration; - this.visible = true; - this.elapsed = 0f; - write(text); - } - - @Override - public boolean animate(float delta) - { - if (!visible) return true; - elapsed += delta; - if (elapsed >= duration) { - visible = false; - if (stack.size() > 0) { - MsgInfo info = stack.pop(); - write(info.text, info.duration, info.position); - } - } - return false; - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Menu.java b/core/src/ch/asynk/tankontank/ui/Menu.java deleted file mode 100644 index 1cd61ca..0000000 --- a/core/src/ch/asynk/tankontank/ui/Menu.java +++ /dev/null @@ -1,93 +0,0 @@ -package ch.asynk.tankontank.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); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Msg.java b/core/src/ch/asynk/tankontank/ui/Msg.java deleted file mode 100644 index c2069b7..0000000 --- a/core/src/ch/asynk/tankontank/ui/Msg.java +++ /dev/null @@ -1,79 +0,0 @@ -package ch.asynk.tankontank.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.glutils.ShapeRenderer; - -public class Msg extends Patch -{ - private LabelStack label; - - public Msg(BitmapFont font, TextureAtlas atlas) - { - super(atlas.createPatch("typewriter")); - label = new LabelStack(font, 20f); - } - - @Override - public void dispose() - { - super.dispose(); - label.dispose(); - } - - 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); - label.translate(dx, dy); - } - - public void write(String text, float duration) - { - label.write(text, duration); - resize(); - } - - public void write(String text, float duration, Position position) - { - this.position = position; - label.write(text, duration, position); - resize(); - } - - public void pushWrite(String text, float duration, Position position) - { - this.position = position; - label.pushWrite(text, duration, position); - resize(); - } - - private void resize() - { - setPosition(label.getX(), label.getY(), label.getWidth(), label.getHeight()); - } - - public boolean animate(float delta) - { - return label.animate(delta); - } - - @Override - public void draw(Batch batch) - { - if (!label.visible) return; - super.draw(batch); - label.draw(batch); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!label.visible) return; - super.drawDebug(shapes); - label.drawDebug(shapes); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/OkCancel.java b/core/src/ch/asynk/tankontank/ui/OkCancel.java deleted file mode 100644 index ba61642..0000000 --- a/core/src/ch/asynk/tankontank/ui/OkCancel.java +++ /dev/null @@ -1,115 +0,0 @@ -package ch.asynk.tankontank.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.glutils.ShapeRenderer; - -public class OkCancel extends Patch -{ - public static int PADDING = 20; - public static int VSPACING = 10; - public static int HSPACING = 10; - - public boolean ok; - protected Label label; - protected Bg okBtn; - protected Bg cancelBtn; - - public OkCancel(BitmapFont font, TextureAtlas atlas) - { - super(atlas.createPatch("typewriter")); - this.label = new Label(font); - this.okBtn = new Bg(atlas.findRegion("ok")); - this.cancelBtn = new Bg(atlas.findRegion("cancel")); - this.visible = false; - } - - 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); - label.translate(dx, dy); - okBtn.translate(dx, dy); - cancelBtn.translate(dx, dy); - } - - public void show(String msg) - { - show(msg, Position.MIDDLE_CENTER); - } - - public void show(String msg, Position position) - { - label.write(msg); - - float height = (label.getHeight() + okBtn.getHeight() + (2 * PADDING) + (2 * VSPACING)); - float width = (label.getWidth() + (2 * PADDING)); - float w2 = (okBtn.getWidth() + cancelBtn.getWidth() + (2 * PADDING) + (1 * HSPACING)); - 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() - PADDING), (y + PADDING)); - cancelBtn.setPosition((x + PADDING), okBtn.getY()); - label.setPosition((x + PADDING), (y + PADDING + okBtn.getHeight() + VSPACING)); - cancelBtn.visible = true; - visible = true; - ok = false; - } - - public void noCancel() - { - cancelBtn.visible = false; - } - - @Override - public boolean hit(float x, float y) - { - if (!cancelBtn.visible && super.hit(x, y)) { - ok = true; - return true; - } - if (okBtn.hit(x, y)) { - ok = true; - return true; - } else if (cancelBtn.hit(x, y)) { - ok = false; - return true; - } - return false; - } - - @Override - public void dispose() - { - super.dispose(); - label.dispose(); - okBtn.dispose(); - cancelBtn.dispose(); - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - super.draw(batch); - label.draw(batch); - okBtn.draw(batch); - cancelBtn.draw(batch); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!visible) return; - super.drawDebug(shapes); - label.drawDebug(shapes); - okBtn.drawDebug(shapes); - cancelBtn.drawDebug(shapes); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Patch.java b/core/src/ch/asynk/tankontank/ui/Patch.java deleted file mode 100644 index 4056a3c..0000000 --- a/core/src/ch/asynk/tankontank/ui/Patch.java +++ /dev/null @@ -1,28 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.NinePatch; - -public class Patch extends Widget -{ - private NinePatch patch; - - public Patch(NinePatch patch) - { - super(); - this.patch = patch; - setPosition(0, 0, patch.getTotalWidth(), patch.getTotalHeight()); - } - - @Override - public void dispose() - { - } - - @Override - public void draw(Batch batch) - { - if (!visible) return; - patch.draw(batch, rect.x, rect.y, rect.width, rect.height); - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Position.java b/core/src/ch/asynk/tankontank/ui/Position.java deleted file mode 100644 index 1257cb6..0000000 --- a/core/src/ch/asynk/tankontank/ui/Position.java +++ /dev/null @@ -1,239 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.Gdx; -import ch.asynk.tankontank.game.Hud; - -public enum Position -{ - TOP_LEFT, - TOP_RIGHT, - TOP_CENTER, - MIDDLE_LEFT, - MIDDLE_RIGHT, - MIDDLE_CENTER, - BOTTOM_LEFT, - BOTTOM_RIGHT, - BOTTOM_CENTER; - - public Position verticalMirror() - { - Position p = this; - switch(this) { - case TOP_LEFT: - p = TOP_RIGHT; - break; - case MIDDLE_LEFT: - p = MIDDLE_RIGHT; - break; - case BOTTOM_LEFT: - p = BOTTOM_RIGHT; - break; - case TOP_RIGHT: - p = TOP_LEFT; - break; - case MIDDLE_RIGHT: - p = MIDDLE_LEFT; - break; - case BOTTOM_RIGHT: - p = BOTTOM_LEFT; - break; - } - return p; - } - - public Position horizontalMirror() - { - Position p = this; - switch(this) { - case TOP_LEFT: - p = BOTTOM_LEFT; - break; - case TOP_CENTER: - p = BOTTOM_CENTER; - break; - case TOP_RIGHT: - p = BOTTOM_RIGHT; - break; - case BOTTOM_LEFT: - p = TOP_LEFT; - break; - case BOTTOM_CENTER: - p = TOP_CENTER; - break; - case BOTTOM_RIGHT: - p = TOP_RIGHT; - break; - } - return p; - } - - public boolean isLeft() - { - boolean r = false; - switch(this) { - case TOP_LEFT: - case MIDDLE_LEFT: - case BOTTOM_LEFT: - r = true; - break; - default: - r = false; - break; - } - return r; - } - - public boolean isRight() - { - boolean r = false; - switch(this) { - case TOP_RIGHT: - case MIDDLE_RIGHT: - case BOTTOM_RIGHT: - r = true; - break; - default: - r = false; - break; - } - return r; - } - - public boolean isCenter() - { - boolean r = false; - switch(this) { - case TOP_CENTER: - case MIDDLE_CENTER: - case BOTTOM_CENTER: - r = true; - break; - default: - r = false; - break; - } - return r; - } - - private static int hudLeft = 0; - private static int hudBottom = 0; - private static int hudWidth = Gdx.graphics.getWidth(); - private static int hudHeight = Gdx.graphics.getHeight(); - - public static void update(int width, int height) - { - update(0, 0, width, height); - } - - public static void update(int left, int bottom, int width, int height) - { - hudLeft = left; - hudBottom = bottom; - hudWidth = width; - hudHeight = height; - } - - public float getX(float width) - { - float x = hudLeft; - switch(this) { - case TOP_LEFT: - case MIDDLE_LEFT: - case BOTTOM_LEFT: - x += Hud.OFFSET; - break; - case TOP_CENTER: - case MIDDLE_CENTER: - case BOTTOM_CENTER: - x += ((hudWidth - width) / 2); - break; - case TOP_RIGHT: - case MIDDLE_RIGHT: - case BOTTOM_RIGHT: - x += (hudWidth - width - Hud.OFFSET); - break; - default: - x += ((hudWidth - width) / 2); - break; - } - return x; - } - - public float getY(float height) - { - float y = hudBottom; - switch(this) { - case TOP_LEFT: - case TOP_CENTER: - case TOP_RIGHT: - y += (hudHeight - height - Hud.OFFSET); - break; - case MIDDLE_LEFT: - case MIDDLE_CENTER: - case MIDDLE_RIGHT: - y += ((hudHeight - height) / 2); - break; - case BOTTOM_LEFT: - case BOTTOM_CENTER: - case BOTTOM_RIGHT: - y += Hud.OFFSET; - break; - default: - y += ((hudHeight - height) / 2); - break; - } - return y; - } - - public float getX(Widget widget, float width) - { - float x = 0; - switch(this) { - case TOP_LEFT: - case MIDDLE_LEFT: - case BOTTOM_LEFT: - x = widget.getX(); - break; - case TOP_CENTER: - case MIDDLE_CENTER: - case BOTTOM_CENTER: - x = (widget.getX() + ((widget.getWidth() - width) / 2)); - break; - case TOP_RIGHT: - case MIDDLE_RIGHT: - case BOTTOM_RIGHT: - x = (widget.getX() + widget.getWidth() - width); - break; - default: - x = (widget.getX() + ((widget.getWidth() - width) / 2)); - break; - } - return x; - } - - public float getY(Widget widget, float height) - { - float y = 0; - switch(this) { - case TOP_LEFT: - case TOP_CENTER: - case TOP_RIGHT: - y = (widget.getY() + widget.getHeight() - height); - break; - case MIDDLE_LEFT: - case MIDDLE_CENTER: - case MIDDLE_RIGHT: - y = (widget.getY() + ((widget.getHeight() - height) / 2)); - break; - case BOTTOM_LEFT: - case BOTTOM_CENTER: - case BOTTOM_RIGHT: - y = widget.getY(); - break; - default: - y = (widget.getY() + ((widget.getHeight() - height) / 2)); - break; - } - return y; - } -} diff --git a/core/src/ch/asynk/tankontank/ui/Widget.java b/core/src/ch/asynk/tankontank/ui/Widget.java deleted file mode 100644 index e49833a..0000000 --- a/core/src/ch/asynk/tankontank/ui/Widget.java +++ /dev/null @@ -1,93 +0,0 @@ -package ch.asynk.tankontank.ui; - -import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.math.Rectangle; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -import ch.asynk.tankontank.engine.gfx.Drawable; - -public abstract class Widget implements Disposable, Drawable -{ - public boolean blocked; - public boolean visible; - protected float padding; - protected Rectangle rect; - protected Position position; - protected Widget parent; - - protected Widget() - { - this.parent = null; - this.blocked = false; - this.visible = true; - this.padding = 0f; - this.rect = new Rectangle(0, 0, 0, 0); - this.position = Position.MIDDLE_CENTER; - } - - public float getX() { return rect.x; } - public float getY() { return rect.y; } - public float getWidth() { return rect.width; } - public float getHeight() { return rect.height; } - - public void translate(float dx, float dy) - { - rect.x += dx; - rect.y += dy; - } - - public void setPosition(Rectangle r) - { - rect.set(r); - } - - public void setPosition(float x, float y) - { - rect.x = x; - rect.y = y; - } - - public void setPosition(float x, float y, float w, float h) - { - rect.set(x, y, w, h); - } - - public void setPosition(Position position) - { - this.position = position; - setParent(this.parent); - } - - public void setPosition(Position position, Widget parent) - { - this.position = position; - setParent(parent); - } - - public void setParent(Widget parent) - { - this.parent = parent; - if (parent == null) { - rect.x = position.getX(rect.width); - rect.y = position.getY(rect.height); - } else { - rect.x = position.getX(parent, rect.width); - rect.y = position.getY(parent, rect.height); - } - // might trigger something if overriden - setPosition(rect.x, rect.y); - } - - public boolean hit(float x, float y) - { - if (blocked || !visible) return false; - return rect.contains(x, y); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!visible) return; - shapes.rect(rect.x, rect.y, rect.width, rect.height); - } -} |