summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assets/data/ui-selected.pngbin0 -> 904 bytes
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/Assets.java3
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/UiScreen.java126
3 files changed, 113 insertions, 16 deletions
diff --git a/assets/data/ui-selected.png b/assets/data/ui-selected.png
new file mode 100644
index 0000000..57cfd1d
--- /dev/null
+++ b/assets/data/ui-selected.png
Binary files differ
diff --git a/test/src/ch/asynk/gdx/boardgame/test/Assets.java b/test/src/ch/asynk/gdx/boardgame/test/Assets.java
index 2bdad29..b3a56b9 100644
--- a/test/src/ch/asynk/gdx/boardgame/test/Assets.java
+++ b/test/src/ch/asynk/gdx/boardgame/test/Assets.java
@@ -23,6 +23,7 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets
public static final String FONT_20 = "size20.ttf";
public static final String FONT_25 = "size25.ttf";
public static final String PATCH = "ui-patch.png";
+ public static final String SELECTED = "ui-selected.png";
public static final String PANZER = "panzer.png";
public static final String ENGINEER = "engineer.png";
public static final String HEX_OVERLAYS = "hex-overlays.atlas";
@@ -78,6 +79,7 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets
load(TRI, Texture.class);
load(CORNER, Texture.class);
load(PATCH, Texture.class);
+ load(SELECTED, Texture.class);
load(PANZER, Texture.class);
load(ENGINEER, Texture.class);
load(FONT_20, BitmapFont.class, params20);
@@ -102,6 +104,7 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets
unload(TRI);
unload(CORNER);
unload(PATCH);
+ unload(SELECTED);
unload(PANZER);
unload(ENGINEER);
unload(FONT_20);
diff --git a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java
index 14d282c..a0167dc 100644
--- a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java
+++ b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java
@@ -1,40 +1,36 @@
package ch.asynk.gdx.boardgame.test;
+import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.OrthographicCamera;
import ch.asynk.gdx.boardgame.ui.Alignment;
import ch.asynk.gdx.boardgame.ui.Button;
-
-class MyButton extends Button
-{
- public MyButton(BitmapFont font, NinePatch patch, float padding, float spacing)
- {
- super(font, patch, padding, spacing);
- }
-
- @Override public void computeGeometry()
- {
- super.computeGeometry();
- label.write(String.format("%04d;%04d", (int)getX(), (int)getY()));
- }
-}
+import ch.asynk.gdx.boardgame.ui.Label;
+import ch.asynk.gdx.boardgame.ui.List;
+import ch.asynk.gdx.boardgame.ui.Patch;
+import ch.asynk.gdx.boardgame.utils.Collection;
+import ch.asynk.gdx.boardgame.utils.IterableArray;
public class UiScreen extends AbstractScreen
{
private final Button next;
private final Button[] buttons = new Button[8];
+ private final MyList list;
public enum State
{
- POSITIONS, DONE;
+ POSITIONS, SCROLL, DONE;
public State next()
{
switch(this) {
case POSITIONS:
+ return SCROLL;
+ case SCROLL:
return DONE;
default:
return POSITIONS;
@@ -60,6 +56,9 @@ public class UiScreen extends AbstractScreen
this.buttons[6] = buildButton(font, patch, 10, 15, Alignment.BOTTOM_LEFT, Alignment.TOP_RIGHT);
this.buttons[7] = buildButton(font, patch, 10, 15, Alignment.BOTTOM_CENTER, Alignment.TOP_CENTER);
+ this.list = new MyList(font, patch, app.assets.getTextureRegion(app.assets.SELECTED));
+ this.list.setAlignment(Alignment.MIDDLE_CENTER);
+
this.next = new Button(font, patch, 10, 15);
this.next.write("Next");
this.next.setAlignment(Alignment.BOTTOM_RIGHT);
@@ -86,8 +85,12 @@ public class UiScreen extends AbstractScreen
case POSITIONS:
setButtons(true);
break;
- case DONE:
+ case SCROLL:
setButtons(false);
+ root.add(list);
+ break;
+ case DONE:
+ root.remove(list);
app.switchToMenu();
break;
}
@@ -131,3 +134,94 @@ public class UiScreen extends AbstractScreen
}
}
}
+
+class MyButton extends Button
+{
+ public MyButton(BitmapFont font, NinePatch patch, float padding, float spacing)
+ {
+ super(font, patch, padding, spacing);
+ }
+
+ @Override public void computeGeometry()
+ {
+ super.computeGeometry();
+ label.write(String.format("%04d;%04d", (int)getX(), (int)getY()));
+ }
+}
+
+class MyList extends Patch
+{
+ private Label title;
+ private List list;
+
+ class Item implements List.Item
+ {
+ private String s;
+ public Item(String s)
+ {
+ this.s = s;
+ }
+ public String s() { return s; }
+ }
+
+ public MyList(BitmapFont font, NinePatch patch, TextureRegion textureRegion)
+ {
+ super(patch);
+ this.padding = 10;
+ this.title = new Label(font, 10);
+ this.title.write("My List Title");
+ this.title.setAlignment(alignment.TOP_CENTER);
+ this.title.setParent(this);
+
+ Collection<List.Item> items = new IterableArray<List.Item>(15);
+ for (int i = 0; i < 15; i++) {
+ items.add(new Item(String.format("%02d : is just another list item", i)));
+ }
+ this.list = new List(font, textureRegion, 10, 15);
+ this.list.setItems(items);
+ this.list.setParent(this);
+ }
+
+ @Override public void computeGeometry()
+ {
+ float pp = (2 * padding);
+
+ // update dimensions
+ title.computeGeometry();
+ rect.width = title.getWidth() + pp;
+ rect.height = title.getHeight() + pp + list.getHeight() + 15;
+ if ((list.getWidth() + pp) > rect.width) rect.width = list.getWidth() + pp;
+
+ // update position
+ super.computeGeometry();
+ title.computeGeometry();
+ list.computeGeometry();
+ }
+
+ @Override public boolean touch(float x, float y)
+ {
+ if (super.touch(x, y)) {
+ if (list.touch(x, y)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override public void draw(Batch batch)
+ {
+ if (!visible) return;
+ if (tainted) computeGeometry();
+ super.draw(batch);
+ title.draw(batch);
+ list.draw(batch);
+ }
+
+ @Override public void drawDebug(ShapeRenderer shapeRenderer)
+ {
+ if (!visible) return;
+ super.drawDebug(shapeRenderer);
+ title.drawDebug(shapeRenderer);
+ list.drawDebug(shapeRenderer);
+ }
+}