From 4a123c08d64e3566d60431124933ce699e90b045 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 6 Jun 2024 22:44:27 +0200 Subject: [PATCH] More progress on Guis themselves --- .../rendering/gui/animation/GuiAnimator.java | 4 ++-- .../rendering/gui/components/base/GuiComponent.java | 13 +++++++++++-- .../gui/components/base/IComponentScreen.java | 8 ++++++++ .../gui/layout/constraints/Constraints.java | 5 ++--- .../gui/layout/constraints/IConstraint.java | 4 ++-- .../coreengine/rendering/guiOld/GuiComponent.java | 2 +- .../guiOld/helper/animations/Animator.java | 4 ++-- .../rendering/guiOld/helper/box/GuiBox.java | 2 +- .../rendering/guiOld/helper/box/IGuiBox.java | 9 +-------- .../rendering/guiOld/helper/box/ParentBox.java | 2 +- 10 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/components/base/IComponentScreen.java diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/animation/GuiAnimator.java b/src/main/java/speiger/src/coreengine/rendering/gui/animation/GuiAnimator.java index f2cdc25..82ad620 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/animation/GuiAnimator.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/animation/GuiAnimator.java @@ -44,7 +44,7 @@ public class GuiAnimator implements ObjectFloatConsumer { 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 { 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) { diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/components/base/GuiComponent.java b/src/main/java/speiger/src/coreengine/rendering/gui/components/base/GuiComponent.java index 12abc5d..b55ae47 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/components/base/GuiComponent.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/components/base/GuiComponent.java @@ -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; diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/components/base/IComponentScreen.java b/src/main/java/speiger/src/coreengine/rendering/gui/components/base/IComponentScreen.java new file mode 100644 index 0000000..074867c --- /dev/null +++ b/src/main/java/speiger/src/coreengine/rendering/gui/components/base/IComponentScreen.java @@ -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(); +} diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/Constraints.java b/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/Constraints.java index 7b4c0ae..5e5ec37 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/Constraints.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/Constraints.java @@ -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); } } } diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/IConstraint.java b/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/IConstraint.java index 9da5f5c..8d97cd0 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/IConstraint.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/layout/constraints/IConstraint.java @@ -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); } diff --git a/src/main/java/speiger/src/coreengine/rendering/guiOld/GuiComponent.java b/src/main/java/speiger/src/coreengine/rendering/guiOld/GuiComponent.java index 77f2700..0d74d39 100644 --- a/src/main/java/speiger/src/coreengine/rendering/guiOld/GuiComponent.java +++ b/src/main/java/speiger/src/coreengine/rendering/guiOld/GuiComponent.java @@ -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; } diff --git a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/animations/Animator.java b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/animations/Animator.java index b9ebc4e..0e9eb9d 100644 --- a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/animations/Animator.java +++ b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/animations/Animator.java @@ -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); } diff --git a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/GuiBox.java b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/GuiBox.java index 69101ae..6a62c15 100644 --- a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/GuiBox.java +++ b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/GuiBox.java @@ -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 diff --git a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/IGuiBox.java b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/IGuiBox.java index 34fe86a..e191630 100644 --- a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/IGuiBox.java +++ b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/IGuiBox.java @@ -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; } diff --git a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/ParentBox.java b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/ParentBox.java index 461664b..9028d3c 100644 --- a/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/ParentBox.java +++ b/src/main/java/speiger/src/coreengine/rendering/guiOld/helper/box/ParentBox.java @@ -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