From c01d317fdbf014966419b11481d9421d3fbf4391 Mon Sep 17 00:00:00 2001 From: Speiger Date: Sat, 15 Jun 2024 23:48:10 +0200 Subject: [PATCH] Progress on Guis and start on Fontrendering --- .../rendering/gui/animation/GuiAnimator.java | 1 - .../gui/components/base/GuiComponent.java | 13 +++-- .../gui/components/base/IComponentScreen.java | 1 + .../rendering/gui/font/FontGroup.java | 49 +++++++++++++++++++ .../rendering/gui/font/FontManager.java | 5 ++ .../rendering/gui/font/glyth/Glyth.java | 3 ++ .../rendering/gui/font/glyth/GlythData.java | 7 +++ .../gui/font/providers/IFontProvider.java | 7 +++ .../rendering/gui/screen/GuiContainer.java | 46 ++++++++++++++--- 9 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/FontGroup.java create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/FontManager.java create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/Glyth.java create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/GlythData.java create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/providers/IFontProvider.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 82ad620..75fd264 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 @@ -51,7 +51,6 @@ public class GuiAnimator implements ObjectFloatConsumer { heightDiff = 0F; scaleDiff = 1F; changeState = 0; - } public void apply() { 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 dc6df0c..9990b4f 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 @@ -102,17 +102,21 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas return true; } - public GuiComponent addChild(GuiComponent child) { return addChild(child, null); } + public GuiComponent withConstraints(ConstraintContainer container) { + this.constraints = container; + if((screen != null || parent != null) && constraints != null) constraints.apply(this, parent); + return this; + } - public GuiComponent addChild(GuiComponent child, ConstraintContainer constraints) { + public GuiComponent addChild(GuiComponent child) { if(child.parent != null) throw new IllegalArgumentException("A Child can not have multiple parents"); - child.constraints = constraints; child.parent = this; children.add(child); box.addChild(child.getBox()); interactions.add(child.interactions); - child.screen = screen; + child.setScreen(screen); child.init(); + child.onChanged(true); return child; } @@ -124,6 +128,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas if(child.parent != this) throw new IllegalArgumentException("Child isn't owned by this Component"); child.close(); child.parent = null; + child.screen = null; children.remove(child); box.removeChild(child.getBox()); interactions.remove(child.interactions); 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 index e88fe54..aee9baa 100644 --- 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 @@ -10,5 +10,6 @@ public interface IComponentScreen { public void pushLayer(); public void popLayer(); public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints); + public boolean hasComponent(GuiComponent component); public boolean removeComponent(GuiComponent component); } diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontGroup.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontGroup.java new file mode 100644 index 0000000..818b0a2 --- /dev/null +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontGroup.java @@ -0,0 +1,49 @@ +package speiger.src.coreengine.rendering.gui.font; + +import java.util.List; + +import speiger.src.collections.ints.maps.impl.hash.Int2ObjectOpenHashMap; +import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap; +import speiger.src.coreengine.assets.AssetLocation; +import speiger.src.coreengine.rendering.gui.font.glyth.Glyth; +import speiger.src.coreengine.rendering.gui.font.glyth.GlythData; +import speiger.src.coreengine.rendering.gui.font.providers.IFontProvider; + +public class FontGroup { + private static final int BOLD_FLAG = 1<<31; + AssetLocation locations; + List providers; + Int2ObjectMap bakedGlyths = new Int2ObjectOpenHashMap<>(); + Int2ObjectMap dataGlyths = new Int2ObjectOpenHashMap<>(); + + public FontGroup(AssetLocation locations, List providers) { + this.locations = locations; + this.providers = providers; + } + + public GlythData data(int codepoint) { + return dataGlyths.computeIfAbsent(codepoint, this::compute); + } + + public Glyth glyth(int codepoint, boolean bold) { + return bakedGlyths.computeIfAbsent(codepoint | (bold ? 0 : BOLD_FLAG), this::bake); + } + + private GlythData compute(int codepoint) { + for(int i = 0,m=providers.size();i entry : container) { + boolean keepMouse = entry.getBooleanValue(); + GuiComponent.renderComponent(entry.getKey(), renderer, keepMouse ? mouseX : -1, keepMouse ? mouseY : -1, partialTicks); + } + } + + public void tick() { + for(Object2BooleanMap.Entry entry : container) { + entry.getKey().updateComponent(); + } + } + public static class LayeredContainer implements Iterable> { List> components = new ObjectArrayList<>(); List> interactables = new ObjectArrayList<>(); @@ -89,8 +112,15 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer { interactables().add(component.interactContainer()); } - public boolean removeChild(GuiComponent component) { - for(int i = components.size()-1;i>=0;i--) { + public boolean contains(GuiComponent component) { + for(int i = layer;i>=0;i--) { + if(components.get(i).contains(component)) return true; + } + return false; + } + + public boolean remove(GuiComponent component) { + for(int i = layer;i>=0;i--) { if(components.get(i).remove(component)) { interactables.get(i).remove(component.interactContainer()); clearEmptyLayers();