More progress on Guis themselves

This commit is contained in:
Speiger 2024-06-06 22:44:27 +02:00
parent 9526fe42b9
commit 4a123c08d6
10 changed files with 31 additions and 22 deletions

View File

@ -44,7 +44,7 @@ public class GuiAnimator implements ObjectFloatConsumer<Target> {
private void reset() { private void reset() {
if(changeState == 0) return; 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; xDiff = 0F;
yDiff = 0F; yDiff = 0F;
widthDiff = 0F; widthDiff = 0F;
@ -56,7 +56,7 @@ public class GuiAnimator implements ObjectFloatConsumer<Target> {
public void apply() { public void apply() {
if(changeState == 0) return; 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) { public boolean update(float partialTime) {

View File

@ -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_MANUAL_MANAGED = 1 << 3;
private static final int FLAG_SCISSORED = 1 << 4; private static final int FLAG_SCISSORED = 1 << 4;
final IGuiBox box; final IGuiBox box;
IComponentScreen screen;
ConstraintContainer constraints; ConstraintContainer constraints;
GuiAnimator animator; GuiAnimator animator;
GuiComponent parent; 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 abstract void init();
public void close() { public void close() {
notifyListeners(LISTENER_CLOSED); notifyListeners(LISTENER_CLOSED);
@ -103,6 +111,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
children.add(child); children.add(child);
box.addChild(child.getBox()); box.addChild(child.getBox());
interactions.add(child.interactions); interactions.add(child.interactions);
child.screen = screen;
child.init(); child.init();
return child; return child;
} }
@ -141,7 +150,6 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
} }
public void onChanged(boolean repaint) { public void onChanged(boolean repaint) {
// TODO implement changes xD
if(constraints != null) constraints.apply(this, parent); if(constraints != null) constraints.apply(this, parent);
if(animator != null) animator.apply(); if(animator != null) animator.apply();
box.onChanged(); box.onChanged();
@ -155,6 +163,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
protected void repaint() {} protected void repaint() {}
public IComponentScreen screen() { return screen; }
@Override @Override
public IGuiBox getBox() { return box; } public IGuiBox getBox() { return box; }
@ -179,7 +188,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
@Override @Override
public GuiComponent resize(float width, float height) { public GuiComponent resize(float width, float height) {
if(width != 0F || height != 0F) { if(width != 0F || height != 0F) {
box.grow(width, height); box.resize(width, height);
onChanged(true); onChanged(true);
} }
return this; return this;

View File

@ -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();
}

View File

@ -56,12 +56,11 @@ public class Constraints {
} }
public static record Conditional(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) implements IConstraint { 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); } public static Conditional of(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return new Conditional(supplier, onTrue, onFalse); }
@Override @Override
public void apply(GuiComponent owner, GuiComponent child, Target target) { public void apply(GuiComponent owner, GuiComponent parent, Target target) {
(supplier.getAsBoolean() ? onTrue : onFalse).apply(owner, child, target); (supplier.getAsBoolean() ? onTrue : onFalse).apply(owner, parent, target);
} }
} }
} }

View File

@ -26,11 +26,11 @@ public interface IConstraint {
public static IConstraint relative(float value, float padding) { return Relative.of(value, padding); } public static IConstraint relative(float value, float padding) { return Relative.of(value, padding); }
public static IConstraint center() { return Center.of(); } 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 { public static interface ISimpleConstraint extends IConstraint {
@Override @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); public void apply(IGuiBox owner, IGuiBox parent, Target target);
} }

View File

@ -751,7 +751,7 @@ public abstract class GuiComponent extends FlagHolder
public GuiComponent resize(float moveX, float moveY) public GuiComponent resize(float moveX, float moveY)
{ {
if(moveX == 0F && moveY == 0F || constraints != null) return this; if(moveX == 0F && moveY == 0F || constraints != null) return this;
box.grow(moveX, moveY); box.resize(moveX, moveY);
onChanged(true); onChanged(true);
return this; return this;
} }

View File

@ -82,7 +82,7 @@ public class Animator
private void resetValues() private void resetValues()
{ {
if(!changed) return; 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); else owner.changeVisibility(1F / visibilityMod).getBox().scale(1F / scaleMod);
xMod = 0F; xMod = 0F;
yMod = 0F; yMod = 0F;
@ -100,7 +100,7 @@ public class Animator
{ {
return; 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);
} }

View File

@ -162,7 +162,7 @@ public class GuiBox implements IGuiBox
@Override @Override
public IGuiBox move(float xOffset, float yOffset) { return setXY(baseX + xOffset, baseY + yOffset); } public IGuiBox move(float xOffset, float yOffset) { return setXY(baseX + xOffset, baseY + yOffset); }
@Override @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 @Override
public IGuiBox scale(float scale) { return setScale(scale * baseScale); } public IGuiBox scale(float scale) { return setScale(scale * baseScale); }
@Override @Override

View File

@ -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.Facing;
import speiger.src.coreengine.math.misc.FacingList; 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 public interface IGuiBox extends IScreenBox
{ {
@ -57,17 +55,12 @@ public interface IGuiBox extends IScreenBox
public IGuiBox setScale(float scale); public IGuiBox setScale(float scale);
public IGuiBox move(float xOffset, float yOffset); 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 IGuiBox scale(float scale);
public default IGuiBox setXY(float x, float y) { return setX(x).setY(y); } 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(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(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; } public default boolean isColiding(float x, float y) { return getMinX() <= x && getMaxX() >= x && getMinY() <= y && getMaxY() >= y; }

View File

@ -121,7 +121,7 @@ public class ParentBox implements IGuiBox
@Override @Override
public IGuiBox move(float xOffset, float yOffset) { throw new UnsupportedOperationException(); } public IGuiBox move(float xOffset, float yOffset) { throw new UnsupportedOperationException(); }
@Override @Override
public IGuiBox grow(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); } public IGuiBox resize(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); }
@Override @Override
public IGuiBox scale(float scale) { throw new UnsupportedOperationException(); } public IGuiBox scale(float scale) { throw new UnsupportedOperationException(); }
@Override @Override