More progress on Guis themselves
This commit is contained in:
parent
9526fe42b9
commit
4a123c08d6
|
@ -44,7 +44,7 @@ public class GuiAnimator implements ObjectFloatConsumer<Target> {
|
|||
|
||||
private void reset() {
|
||||
if(changeState == 0) return;
|
||||
owner.getBox().move(-xDiff, -yDiff).grow(-widthDiff, -heightDiff).scale(1F / scaleDiff);
|
||||
owner.getBox().move(-xDiff, -yDiff).resize(-widthDiff, -heightDiff).scale(1F / scaleDiff);
|
||||
xDiff = 0F;
|
||||
yDiff = 0F;
|
||||
widthDiff = 0F;
|
||||
|
@ -56,7 +56,7 @@ public class GuiAnimator implements ObjectFloatConsumer<Target> {
|
|||
|
||||
public void apply() {
|
||||
if(changeState == 0) return;
|
||||
owner.getBox().move(xDiff, yDiff).grow(widthDiff, heightDiff).scale(scaleDiff);
|
||||
owner.getBox().move(xDiff, yDiff).resize(widthDiff, heightDiff).scale(scaleDiff);
|
||||
}
|
||||
|
||||
public boolean update(float partialTime) {
|
||||
|
|
|
@ -19,6 +19,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
private static final int FLAG_MANUAL_MANAGED = 1 << 3;
|
||||
private static final int FLAG_SCISSORED = 1 << 4;
|
||||
final IGuiBox box;
|
||||
IComponentScreen screen;
|
||||
ConstraintContainer constraints;
|
||||
GuiAnimator animator;
|
||||
GuiComponent parent;
|
||||
|
@ -48,6 +49,13 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
}
|
||||
}
|
||||
|
||||
public void setScreen(IComponentScreen screen) {
|
||||
this.screen = screen;
|
||||
for(GuiComponent child : children) {
|
||||
child.setScreen(screen);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
public void close() {
|
||||
notifyListeners(LISTENER_CLOSED);
|
||||
|
@ -103,6 +111,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
children.add(child);
|
||||
box.addChild(child.getBox());
|
||||
interactions.add(child.interactions);
|
||||
child.screen = screen;
|
||||
child.init();
|
||||
return child;
|
||||
}
|
||||
|
@ -141,7 +150,6 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
}
|
||||
|
||||
public void onChanged(boolean repaint) {
|
||||
// TODO implement changes xD
|
||||
if(constraints != null) constraints.apply(this, parent);
|
||||
if(animator != null) animator.apply();
|
||||
box.onChanged();
|
||||
|
@ -155,6 +163,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
|
||||
protected void repaint() {}
|
||||
|
||||
public IComponentScreen screen() { return screen; }
|
||||
@Override
|
||||
public IGuiBox getBox() { return box; }
|
||||
|
||||
|
@ -179,7 +188,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
|||
@Override
|
||||
public GuiComponent resize(float width, float height) {
|
||||
if(width != 0F || height != 0F) {
|
||||
box.grow(width, height);
|
||||
box.resize(width, height);
|
||||
onChanged(true);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package speiger.src.coreengine.rendering.gui.components.base;
|
||||
|
||||
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||
|
||||
public interface IComponentScreen {
|
||||
public IGuiBox getBox();
|
||||
public long clock();
|
||||
}
|
|
@ -56,12 +56,11 @@ public class Constraints {
|
|||
}
|
||||
|
||||
public static record Conditional(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) implements IConstraint {
|
||||
|
||||
public static Conditional of(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return new Conditional(supplier, onTrue, onFalse); }
|
||||
|
||||
@Override
|
||||
public void apply(GuiComponent owner, GuiComponent child, Target target) {
|
||||
(supplier.getAsBoolean() ? onTrue : onFalse).apply(owner, child, target);
|
||||
public void apply(GuiComponent owner, GuiComponent parent, Target target) {
|
||||
(supplier.getAsBoolean() ? onTrue : onFalse).apply(owner, parent, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,11 @@ public interface IConstraint {
|
|||
public static IConstraint relative(float value, float padding) { return Relative.of(value, padding); }
|
||||
|
||||
public static IConstraint center() { return Center.of(); }
|
||||
public static IConstraint conditiojnal(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return Conditional.of(supplier, onTrue, onFalse); }
|
||||
public static IConstraint conditional(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return Conditional.of(supplier, onTrue, onFalse); }
|
||||
|
||||
public static interface ISimpleConstraint extends IConstraint {
|
||||
@Override
|
||||
default void apply(GuiComponent owner, GuiComponent parent, Target target) { apply(owner.getBox(), parent.getBox(), target); }
|
||||
default void apply(GuiComponent owner, GuiComponent parent, Target target) { apply(owner.getBox(), parent == null ? owner.screen().getBox() : parent.getBox(), target); }
|
||||
public void apply(IGuiBox owner, IGuiBox parent, Target target);
|
||||
}
|
||||
|
||||
|
|
|
@ -751,7 +751,7 @@ public abstract class GuiComponent extends FlagHolder
|
|||
public GuiComponent resize(float moveX, float moveY)
|
||||
{
|
||||
if(moveX == 0F && moveY == 0F || constraints != null) return this;
|
||||
box.grow(moveX, moveY);
|
||||
box.resize(moveX, moveY);
|
||||
onChanged(true);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class Animator
|
|||
private void resetValues()
|
||||
{
|
||||
if(!changed) return;
|
||||
if(!owner.hasConstraints()) owner.changeVisibility(1F / visibilityMod).getBox().move(-xMod, -yMod).grow(-widthMod, -heightMod).scale(1F / scaleMod);
|
||||
if(!owner.hasConstraints()) owner.changeVisibility(1F / visibilityMod).getBox().move(-xMod, -yMod).resize(-widthMod, -heightMod).scale(1F / scaleMod);
|
||||
else owner.changeVisibility(1F / visibilityMod).getBox().scale(1F / scaleMod);
|
||||
xMod = 0F;
|
||||
yMod = 0F;
|
||||
|
@ -100,7 +100,7 @@ public class Animator
|
|||
{
|
||||
return;
|
||||
}
|
||||
owner.changeVisibility(visibilityMod).getBox().scale(scaleMod).move(xMod, yMod).grow(widthMod, heightMod);
|
||||
owner.changeVisibility(visibilityMod).getBox().scale(scaleMod).move(xMod, yMod).resize(widthMod, heightMod);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ public class GuiBox implements IGuiBox
|
|||
@Override
|
||||
public IGuiBox move(float xOffset, float yOffset) { return setXY(baseX + xOffset, baseY + yOffset); }
|
||||
@Override
|
||||
public IGuiBox grow(float xGrowth, float yGrowth) { return setBounds(baseWidth + xGrowth, baseHeight + yGrowth); }
|
||||
public IGuiBox resize(float xGrowth, float yGrowth) { return setBounds(baseWidth + xGrowth, baseHeight + yGrowth); }
|
||||
@Override
|
||||
public IGuiBox scale(float scale) { return setScale(scale * baseScale); }
|
||||
@Override
|
||||
|
|
|
@ -2,8 +2,6 @@ package speiger.src.coreengine.rendering.guiOld.helper.box;
|
|||
|
||||
import speiger.src.coreengine.math.misc.Facing;
|
||||
import speiger.src.coreengine.math.misc.FacingList;
|
||||
import speiger.src.coreengine.math.vector.floats.Vec2f;
|
||||
import speiger.src.coreengine.math.vector.floats.Vec4f;
|
||||
|
||||
public interface IGuiBox extends IScreenBox
|
||||
{
|
||||
|
@ -57,17 +55,12 @@ public interface IGuiBox extends IScreenBox
|
|||
public IGuiBox setScale(float scale);
|
||||
|
||||
public IGuiBox move(float xOffset, float yOffset);
|
||||
public IGuiBox grow(float xGrowth, float yGrowth);
|
||||
public IGuiBox resize(float xGrowth, float yGrowth);
|
||||
public IGuiBox scale(float scale);
|
||||
|
||||
public default IGuiBox setXY(float x, float y) { return setX(x).setY(y); }
|
||||
public default IGuiBox setXY(Vec2f pos) { return setX(pos.x()).setY(pos.y()); }
|
||||
|
||||
public default IGuiBox setBounds(float width, float height) { return setWidth(width).setHeight(height); }
|
||||
public default IGuiBox setBounds(Vec2f bounds) {return setWidth(bounds.x()).setHeight(bounds.y()); }
|
||||
|
||||
public default IGuiBox set(float x, float y, float width, float height) { return setX(x).setY(y).setWidth(width).setHeight(height); }
|
||||
public default IGuiBox set(Vec4f vec) { return setX(vec.x()).setY(vec.y()).setWidth(vec.z()).setHeight(vec.w()); }
|
||||
|
||||
public default boolean isColiding(float x, float y) { return getMinX() <= x && getMaxX() >= x && getMinY() <= y && getMaxY() >= y; }
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public class ParentBox implements IGuiBox
|
|||
@Override
|
||||
public IGuiBox move(float xOffset, float yOffset) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public IGuiBox grow(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); }
|
||||
public IGuiBox resize(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public IGuiBox scale(float scale) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue