From 8b7743eececa744c66d4dab6ba863e7c988570c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 27 Dec 2019 01:44:36 +0100 Subject: ui : Element swallows chidren out of Assembly's mouth --- core/src/ch/asynk/gdx/boardgame/ui/Assembly.java | 15 --------------- core/src/ch/asynk/gdx/boardgame/ui/Element.java | 21 +++++++++++++++++++++ 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 children; private Element touched; public Assembly(int c) @@ -15,20 +14,6 @@ public abstract class Assembly extends Element this.children = new IterableSet(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 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(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()); -- cgit v1.1-2-g2b99