summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2019-12-27 01:44:36 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2019-12-27 01:44:36 +0100
commit8b7743eececa744c66d4dab6ba863e7c988570c2 (patch)
treeae1d901624dfe87305e11d930bd0caa3a9a9b124
parent97caa84105cceb98ec1253426e200858b4bcb9da (diff)
downloadgdx-boardgame-8b7743eececa744c66d4dab6ba863e7c988570c2.zip
gdx-boardgame-8b7743eececa744c66d4dab6ba863e7c988570c2.tar.gz
ui : Element swallows chidren out of Assembly's mouth
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Assembly.java15
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Element.java21
2 files changed, 21 insertions, 15 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
index 866c3dd..28a7597 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
@@ -7,7 +7,6 @@ import ch.asynk.gdx.boardgame.utils.IterableSet;
public abstract class Assembly extends Element
{
- protected IterableSet<Element> children;
private Element touched;
public Assembly(int c)
@@ -15,20 +14,6 @@ public abstract class Assembly extends Element
this.children = new IterableSet<Element>(c);
}
- public void add(Element e)
- {
- if (children.add(e)) {
- e.setParent(this);
- }
- }
-
- public void remove(Element e)
- {
- if (children.remove(e)) {
- e.setParent(null);
- }
- }
-
public void taintChildren()
{
children.forEach( c -> c.taint() );
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
index 9885b59..73d068f 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
@@ -7,10 +7,12 @@ import ch.asynk.gdx.boardgame.Drawable;
import ch.asynk.gdx.boardgame.Paddable;
import ch.asynk.gdx.boardgame.Positionable;
import ch.asynk.gdx.boardgame.Touchable;
+import ch.asynk.gdx.boardgame.utils.IterableSet;
public abstract class Element implements Drawable, Paddable, Positionable, Touchable
{
public static boolean DEBUG_GEOMETRY = false;
+ public static int DEFAULT_CHILD_COUNT = 2;
public boolean blocked;
public boolean visible;
@@ -23,6 +25,8 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
protected boolean tainted; // geometry must be computed
public boolean taintParent; // propagate tainted state up the tree
+ protected IterableSet<Element> children;
+
protected Element()
{
this(false);
@@ -40,6 +44,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
this.x = this.y = 0;
this.tainted = true;
this.taintParent = taintParent;
+ this.children = null;
}
@Override public final float getX() { return rect.x; }
@@ -78,6 +83,22 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
return r;
}
+ public void add(Element e)
+ {
+ if (children == null)
+ children = new IterableSet<Element>(DEFAULT_CHILD_COUNT);
+ if (children.add(e)) {
+ e.setParent(this);
+ }
+ }
+
+ public void remove(Element e)
+ {
+ if (children.remove(e)) {
+ e.setParent(null);
+ }
+ }
+
@Override public void drawDebug(ShapeRenderer shapeRenderer)
{
shapeRenderer.rect(getX(), getY(), getWidth(), getHeight());