74 lines
1.8 KiB
Java
74 lines
1.8 KiB
Java
package speiger.src.coreengine.rendering.newGui.components.base;
|
|
|
|
import java.util.List;
|
|
import java.util.function.BooleanSupplier;
|
|
|
|
import speiger.src.collections.ints.sets.IntOpenHashSet;
|
|
import speiger.src.collections.ints.sets.IntSet;
|
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
|
import speiger.src.collections.objects.utils.ObjectLists;
|
|
import speiger.src.coreengine.rendering.newGui.components.base.IInteractableContainer.IRecursiveInteractionContainer;
|
|
|
|
public class InteractionContainer implements IRecursiveInteractionContainer {
|
|
List<IInteractable> children = new ObjectArrayList<>();
|
|
IInteractable focused;
|
|
IntSet activeButtons = new IntOpenHashSet();
|
|
BooleanSupplier active;
|
|
|
|
public InteractionContainer() {
|
|
this(() -> true);
|
|
}
|
|
|
|
public InteractionContainer(BooleanSupplier active) {
|
|
this.active = active;
|
|
}
|
|
|
|
public void add(IInteractable child) {
|
|
children.add(child);
|
|
}
|
|
|
|
public void remove(IInteractable child) {
|
|
children.remove(child);
|
|
}
|
|
|
|
public boolean contains(IInteractable child) {
|
|
return children.contains(child);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFocused() {
|
|
return getFocusedChild() != null;
|
|
}
|
|
|
|
@Override
|
|
public void setFocused(boolean value) {
|
|
}
|
|
|
|
@Override
|
|
public List<? extends IInteractable> getChildren() {
|
|
return active.getAsBoolean() ? children : ObjectLists.empty();
|
|
}
|
|
|
|
@Override
|
|
public boolean isMouseColliding(int mouseX, int mouseY) {
|
|
return active.getAsBoolean();
|
|
}
|
|
|
|
@Override
|
|
public void setFocusedChild(IInteractable child) {
|
|
if(focused != null) focused.setFocused(false);
|
|
this.focused = child;
|
|
if(focused != null) focused.setFocused(true);
|
|
}
|
|
|
|
@Override
|
|
public IInteractable getFocusedChild() {
|
|
return focused;
|
|
}
|
|
|
|
@Override
|
|
public IntSet getActiveButtons() {
|
|
return activeButtons;
|
|
}
|
|
}
|