More Progress on GUIContainer
This commit is contained in:
parent
3139dff800
commit
94f371b4a3
|
@ -1,16 +1,19 @@
|
||||||
package speiger.src.coreengine.rendering.gui.screen;
|
package speiger.src.coreengine.rendering.gui.screen;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import speiger.src.collections.ints.sets.IntOpenHashSet;
|
import speiger.src.collections.ints.sets.IntOpenHashSet;
|
||||||
import speiger.src.collections.ints.sets.IntSet;
|
import speiger.src.collections.ints.sets.IntSet;
|
||||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
import speiger.src.collections.objects.utils.ObjectIterables;
|
import speiger.src.collections.objects.maps.abstracts.AbstractObject2BooleanMap.BasicEntry;
|
||||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
import speiger.src.collections.objects.maps.interfaces.Object2BooleanMap;
|
||||||
|
import speiger.src.collections.objects.maps.interfaces.Object2BooleanMap.Entry;
|
||||||
import speiger.src.coreengine.rendering.gui.components.base.GuiComponent;
|
import speiger.src.coreengine.rendering.gui.components.base.GuiComponent;
|
||||||
import speiger.src.coreengine.rendering.gui.components.base.IComponentScreen;
|
import speiger.src.coreengine.rendering.gui.components.base.IComponentScreen;
|
||||||
import speiger.src.coreengine.rendering.gui.components.base.IInteractable;
|
import speiger.src.coreengine.rendering.gui.components.base.IInteractable;
|
||||||
import speiger.src.coreengine.rendering.gui.components.base.IInteractableContainer;
|
import speiger.src.coreengine.rendering.gui.components.base.IInteractableContainer;
|
||||||
|
import speiger.src.coreengine.rendering.gui.layout.constraints.ConstraintContainer;
|
||||||
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||||
|
|
||||||
public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
|
@ -41,7 +44,27 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
@Override
|
@Override
|
||||||
public IntSet getActiveButtons() { return activeButtons; }
|
public IntSet getActiveButtons() { return activeButtons; }
|
||||||
|
|
||||||
public static class LayeredContainer {
|
@Override
|
||||||
|
public void pushLayer() { container.pushLayer(); }
|
||||||
|
@Override
|
||||||
|
public void popLayer() { container.popLayer(); }
|
||||||
|
@Override
|
||||||
|
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints) {
|
||||||
|
//TODO change constraints
|
||||||
|
container.add(component);
|
||||||
|
component.setScreen(this);
|
||||||
|
component.init();
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean removeComponent(GuiComponent component) {
|
||||||
|
return container.removeChild(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class LayeredContainer implements Iterable<Object2BooleanMap.Entry<GuiComponent>> {
|
||||||
List<List<GuiComponent>> components = new ObjectArrayList<>();
|
List<List<GuiComponent>> components = new ObjectArrayList<>();
|
||||||
List<List<IInteractable>> interactables = new ObjectArrayList<>();
|
List<List<IInteractable>> interactables = new ObjectArrayList<>();
|
||||||
int layer = -1;
|
int layer = -1;
|
||||||
|
@ -66,6 +89,48 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
interactables().add(component.interactContainer());
|
interactables().add(component.interactContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean removeChild(GuiComponent component) {
|
||||||
|
for(int i = components.size()-1;i>=0;i--) {
|
||||||
|
if(components.get(i).remove(component)) {
|
||||||
|
interactables.get(i).remove(component.interactContainer());
|
||||||
|
clearEmptyLayers();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearEmptyLayers() {
|
||||||
|
while(components.getLast().isEmpty() && layer > 0) {
|
||||||
|
popLayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Object2BooleanMap.Entry<GuiComponent>> iterator() {
|
||||||
|
return new Iterator<>() {
|
||||||
|
BasicEntry<GuiComponent> entry = new BasicEntry<>();
|
||||||
|
int myLayer = layer;
|
||||||
|
Iterator<GuiComponent> childIterator = components.getLast().iterator();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return childIterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<GuiComponent> next() {
|
||||||
|
if(!hasNext()) throw new IllegalStateException("Out of Elements to poll");
|
||||||
|
entry.set(childIterator.next(), myLayer == layer);
|
||||||
|
if(!childIterator.hasNext() && myLayer > 0) {
|
||||||
|
childIterator = components.get(--myLayer).iterator();
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public List<GuiComponent> children() {
|
public List<GuiComponent> children() {
|
||||||
return components.get(layer);
|
return components.get(layer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue