aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/java/kr
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2023-01-17 15:57:51 +0900
committersyeyoung <cyoung06@naver.com>2023-01-17 15:57:51 +0900
commitbaa1b1476bbca91d1a5b6c89bd7b3c39a3efae15 (patch)
tree22f541a634b7a5268833e707e0765881f3c6fe80 /mod/src/main/java/kr
parent5553298dc18b89767ba99977545c9f7a284a76d8 (diff)
downloadSkyblock-Dungeons-Guide-baa1b1476bbca91d1a5b6c89bd7b3c39a3efae15.tar.gz
Skyblock-Dungeons-Guide-baa1b1476bbca91d1a5b6c89bd7b3c39a3efae15.tar.bz2
Skyblock-Dungeons-Guide-baa1b1476bbca91d1a5b6c89bd7b3c39a3efae15.zip
- Intrinsics
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr')
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/ImageTexture.java74
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java4
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java10
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java13
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java10
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Border.java32
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Column.java55
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Flexible.java15
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicHeight.java65
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicWidth.java65
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Line.java9
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Measure.java10
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Padding.java15
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Row.java57
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Scaler.java14
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/SizedBox.java10
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Stack.java18
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java14
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/TextField.java9
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/UnconstrainedBox.java11
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/image/URLImage.java103
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/layouter/Layouter.java7
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/layouter/SingleChildPassingLayouter.java11
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java5
24 files changed, 604 insertions, 32 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/ImageTexture.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/ImageTexture.java
index 3a4c226a..df3b4043 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/ImageTexture.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/ImageTexture.java
@@ -19,6 +19,7 @@
package kr.syeyoung.dungeonsguide.mod.features.impl.discord.inviteViewer;
+import kr.syeyoung.dungeonsguide.mod.DungeonsGuide;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@@ -30,16 +31,26 @@ import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Consumer;
@Data
public class ImageTexture {
@@ -53,8 +64,9 @@ public class ImageTexture {
private int frames;
private int size;
- @Getter @Setter
- private int lastFrame = 0;
+ private long startedPlayingAt = -1;
+
+ private int delayTime;
public void buildGLThings() {
previewTexture = new DynamicTexture(image);
@@ -76,6 +88,15 @@ public class ImageTexture {
BufferedImage dummyFrame = reader.read(0);
width = dummyFrame.getWidth(); height = dummyFrame.getHeight();
+ IIOMetadata imageMetaData = reader.getImageMetadata(0);
+ String metaFormatName = imageMetaData.getNativeMetadataFormatName();
+
+ IIOMetadataNode root = (IIOMetadataNode)imageMetaData.getAsTree(metaFormatName);
+
+ IIOMetadataNode graphicsControlExtensionNode = getNode(root, "GraphicControlExtension");
+
+ delayTime = Integer.parseInt(graphicsControlExtensionNode.getAttribute("delayTime"));
+
image = new BufferedImage(width, height * frames, dummyFrame.getType());
Graphics2D graphics2D = image.createGraphics();
@@ -87,9 +108,25 @@ public class ImageTexture {
reader.dispose(); imageInputStream.close(); huc.disconnect();
}
- public void drawFrame(int frame, int x, int y, int width, int height) {
+
+ private static IIOMetadataNode getNode(IIOMetadataNode rootNode, String nodeName) {
+ int nNodes = rootNode.getLength();
+ for (int i = 0; i < nNodes; i++) {
+ if (rootNode.item(i).getNodeName().compareToIgnoreCase(nodeName)== 0) {
+ return((IIOMetadataNode) rootNode.item(i));
+ }
+ }
+ IIOMetadataNode node = new IIOMetadataNode(nodeName);
+ rootNode.appendChild(node);
+ return(node);
+ }
+
+ public void drawFrame(double x, double y, double width, double height) {
if (getResourceLocation() == null)
buildGLThings();
+ if (startedPlayingAt == -1) startedPlayingAt = System.currentTimeMillis();
+
+ int frame = (int) (((System.currentTimeMillis() - startedPlayingAt) / delayTime) % frames);
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
textureManager.bindTexture(getResourceLocation());
@@ -99,20 +136,35 @@ public class ImageTexture {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
- worldrenderer.pos((double)x, (double)(y + height), 0.0D)
+ worldrenderer.pos(x, (y + height), 0.0D)
.tex(0,((frame+1) * height)/ ((double)frames * height)).endVertex();
- worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D)
+ worldrenderer.pos((x + width), (y + height), 0.0D)
.tex(1, ((frame+1) * height)/ ((double)frames * height)).endVertex();
- worldrenderer.pos((double)(x + width), (double)y, 0.0D)
+ worldrenderer.pos((x + width), y, 0.0D)
.tex(1,(frame * height)/ ((double)frames * height)).endVertex();
- worldrenderer.pos((double)x, (double)y, 0.0D)
+ worldrenderer.pos(x, y, 0.0D)
.tex(0, (frame * height) / ((double)frames * height)).endVertex();
tessellator.draw();
}
- public void drawFrameAndIncrement(int x, int y, int width, int height) {
- drawFrame(lastFrame, x,y,width,height);
- lastFrame++;
- if (lastFrame >= frames) lastFrame = 0;
+ public static final ExecutorService executorService = Executors.newFixedThreadPool(3, DungeonsGuide.THREAD_FACTORY);
+ public static final Map<String, ImageTexture> imageMap = new HashMap<>();
+ public static final Logger logger = LogManager.getLogger("DG-ImageLoader");
+ public static void loadImage(String url, Consumer<ImageTexture> callback) {
+ if (imageMap.containsKey(url)) {
+ callback.accept(imageMap.get(url));
+ return;
+ }
+ if (url.isEmpty()) callback.accept(null);
+ executorService.submit(() -> {
+ try {
+ ImageTexture imageTexture = new ImageTexture(url);
+ imageMap.put(url, imageTexture);
+ callback.accept(imageTexture);
+ } catch (Exception e) {
+ callback.accept(null);
+ logger.log(Level.WARN, "An error occured while loading image from: "+url, e);
+ }
+ });
}
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
index 42ea79c1..e537c311 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
@@ -47,6 +47,8 @@ import java.util.concurrent.*;
public class PartyInviteViewer extends SimpleFeature {
public PartyInviteViewer() {
super("Discord", "Party Invite Viewer","Simply type /dg asktojoin or /dg atj to toggle whether ask-to-join would be presented as option on discord!\n\nRequires Discord RPC to be enabled", "discord.party_invite_viewer");
+
+
}
@Override
@@ -222,7 +224,7 @@ public class PartyInviteViewer extends SimpleFeature {
}
}
if (loadedImage != null) {
- loadedImage.drawFrameAndIncrement( 7,7,height-14,height-14);
+ loadedImage.drawFrame( 7,7,height-14,height-14);
} else {
Gui.drawRect(7, 7, height - 7, height-7, 0xFF4E4E4E);
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java
index eb9b07da..ecfb9883 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java
@@ -62,6 +62,16 @@ public class AbsXY extends AnnotatedExportOnlyWidget implements Layouter {
return new Size(constraintBox.getMaxWidth(), constraintBox.getMaxHeight());
}
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicWidth(buildContext.getChildren().get(0), height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicHeight(buildContext.getChildren().get(0), width);
+ }
@Override
public List<Widget> build(DomElement buildContext) {
return Collections.singletonList(child.getValue());
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java
index 5c1bce11..921ad522 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java
@@ -50,7 +50,7 @@ public class Align extends AnnotatedExportOnlyWidget implements Layouter {
@Override
public Size layout(DomElement buildContext, ConstraintBox constraintBox) {
- DomElement theOnly = getDomElement().getChildren().get(0);
+ DomElement theOnly = buildContext.getChildren().get(0);
Size size = theOnly.getLayouter().layout(theOnly, new ConstraintBox(
0, constraintBox.getMaxWidth(), 0, constraintBox.getMaxHeight()
));
@@ -61,4 +61,15 @@ public class Align extends AnnotatedExportOnlyWidget implements Layouter {
));
return new Size(constraintBox.getMaxWidth(), constraintBox.getMaxHeight());
}
+
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicWidth(buildContext.getChildren().get(0), height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicHeight(buildContext.getChildren().get(0), width);
+ }
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java
index 6984bf32..873c0640 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java
@@ -81,6 +81,16 @@ public class AspectRatioFitter extends AnnotatedExportOnlyWidget implements Layo
}
@Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ return height * this.width.getValue() / this.height.getValue();
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ return width * this.height.getValue() / this.width.getValue();
+ }
+
+ @Override
public boolean canCutRequest() {
return Flexible.FlexFit.TIGHT == fit.getValue();
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Border.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Border.java
index e743a8af..e4ce27ea 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Border.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Border.java
@@ -118,6 +118,38 @@ public class Border extends AnnotatedExportOnlyWidget implements Layouter {
return new Size(dimension.getWidth() + lw + rw, dimension.getHeight() + th + bh);
}
+
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ DomElement top = null, bottom = null, left = null, right = null, content = null;
+ for (DomElement child : buildContext.getChildren()) {
+ if (child.getWidget() == this.top.getValue()) top = child;
+ if (child.getWidget() == this.bottom.getValue()) bottom = child;
+ if (child.getWidget() == this.left.getValue()) left = child;
+ if (child.getWidget() == this.right.getValue()) right = child;
+ if (child.getWidget() == this.content.getValue()) content = child;
+ }
+ return content.getLayouter().getMaxIntrinsicWidth(content, height)
+ + left.getLayouter().getMaxIntrinsicWidth(left, height)
+ + right.getLayouter().getMaxIntrinsicWidth(right, height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ DomElement top = null, bottom = null, left = null, right = null, content = null;
+ for (DomElement child : buildContext.getChildren()) {
+ if (child.getWidget() == this.top.getValue()) top = child;
+ if (child.getWidget() == this.bottom.getValue()) bottom = child;
+ if (child.getWidget() == this.left.getValue()) left = child;
+ if (child.getWidget() == this.right.getValue()) right = child;
+ if (child.getWidget() == this.content.getValue()) content = child;
+ }
+ return content.getLayouter().getMaxIntrinsicHeight(content, width)
+ + top.getLayouter().getMaxIntrinsicHeight(top, width)
+ + bottom.getLayouter().getMaxIntrinsicHeight(bottom, width);
+ }
+
@Override
protected Renderer createRenderer() {
return OnlyChildrenRenderer.INSTANCE;
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Column.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Column.java
index f61838ee..b310e6cf 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Column.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Column.java
@@ -93,7 +93,7 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
CrossAxisAlignment crossAxisAlignment = hAlign.getValue();
MainAxisAlignment mainAxisAlignment = vAlign.getValue();
Map<DomElement, Size> saved = new HashMap<>();
- for (DomElement child : getDomElement().getChildren()) {
+ for (DomElement child : buildContext.getChildren()) {
if (!(child.getWidget() instanceof Flexible)) {
Size requiredSize = child.getLayouter().layout(child, new ConstraintBox(
crossAxisAlignment == CrossAxisAlignment.STRETCH
@@ -109,7 +109,7 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
boolean flexFound = false;
int sumFlex = 0;
- for (DomElement child : getDomElement().getChildren()) {
+ for (DomElement child : buildContext.getChildren()) {
if (child.getWidget() instanceof Flexible) {
sumFlex += Math.min(1, ((Flexible) child.getWidget()).flex.getValue());
flexFound = true;
@@ -123,7 +123,7 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
double remainingHeight = effheight - height;
double heightPer = remainingHeight / sumFlex;
- for (DomElement child : getDomElement().getChildren()) {
+ for (DomElement child : buildContext.getChildren()) {
if (child.getWidget() instanceof Flexible) {
Size requiredSize = child.getLayouter().layout(child, new ConstraintBox(
crossAxisAlignment == CrossAxisAlignment.STRETCH
@@ -150,14 +150,14 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
double remaining = effheight - height;
if (remaining > 0) {
starty = 0;
- heightDelta = remaining / (getDomElement().getChildren().size()-1);
+ heightDelta = remaining / (buildContext.getChildren().size()-1);
} else {
starty = (effheight - height) / 2;
}
} else if (mainAxisAlignment == MainAxisAlignment.SPACE_EVENLY) {
double remaining = effheight - height;
if (remaining > 0) {
- heightDelta = remaining / (getDomElement().getChildren().size()+1);
+ heightDelta = remaining / (buildContext.getChildren().size()+1);
starty = heightDelta;
} else {
starty= (effheight - height) / 2;
@@ -165,14 +165,14 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
} else if (mainAxisAlignment == MainAxisAlignment.SPACE_AROUND) {
double remaining = effheight - height;
if (remaining > 0) {
- heightDelta = 2 * remaining / getDomElement().getChildren().size();
+ heightDelta = 2 * remaining / buildContext.getChildren().size();
starty = heightDelta / 2;
} else {
starty = (effheight - height / 2);
}
}
- for (DomElement child : getDomElement().getChildren()) {
+ for (DomElement child : buildContext.getChildren()) {
Size size = saved.get(child);
child.setRelativeBound(new Rect(
@@ -190,4 +190,45 @@ public class Column extends AnnotatedExportOnlyWidget implements Layouter {
effheight
);
}
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ double height = 0;
+ double flex = 0;
+ double maxPer = 0;
+ for (DomElement child : buildContext.getChildren()) {
+ if (child.getWidget() instanceof Flexible) {
+ flex += ((Flexible) child.getWidget()).flex.getValue();
+ maxPer = Double.max(maxPer, child.getLayouter().getMaxIntrinsicHeight(buildContext, width) /
+ ((Flexible) child.getWidget()).flex.getValue());
+ } else {
+ height += child.getLayouter().getMaxIntrinsicHeight(buildContext, width);
+ }
+ }
+ return height + maxPer * flex;
+ }
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ double maxWidth = 0;
+ double heightTaken = 0;
+ int sumFlex = 0;
+ for (DomElement child : buildContext.getChildren()) {
+ if (!(child.getWidget() instanceof Flexible)) {
+ heightTaken += child.getLayouter().getMaxIntrinsicWidth(buildContext, Double.POSITIVE_INFINITY);
+ maxWidth = Double.max(maxWidth, child.getLayouter().getMaxIntrinsicWidth(buildContext, 0));
+ } else {
+ sumFlex += ((Flexible) child.getWidget()).flex.getValue();
+ }
+ }
+ double leftOver = height - heightTaken;
+ if (sumFlex > 0) {
+ double per = leftOver / sumFlex;
+ for (DomElement child : buildContext.getChildren()) {
+ if (child.getWidget() instanceof Flexible) {
+ maxWidth = Double.max(maxWidth, child.getLayouter().getMaxIntrinsicWidth(buildContext, per * ((Flexible) child.getWidget()).flex.getValue()));
+ }
+ }
+ }
+ return maxWidth;
+ }
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Flexible.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Flexible.java
index 5585395a..09c1dcaf 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Flexible.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Flexible.java
@@ -67,14 +67,25 @@ public class Flexible extends AnnotatedExportOnlyWidget implements Layouter {
new ConstraintBox(constraintBox.getMaxWidth() == Integer.MAX_VALUE ? 0 : constraintBox.getMaxWidth(), constraintBox.getMaxWidth()
, constraintBox.getMaxHeight() == Integer.MAX_VALUE ? 0 : constraintBox.getMaxHeight(), constraintBox.getMaxHeight())
: ConstraintBox.loose(constraintBox.getMaxWidth(), constraintBox.getMaxHeight());
- DomElement child = getDomElement().getChildren().get(0);
+ DomElement child = buildContext.getChildren().get(0);
Size dim = child.getLayouter().layout(child, box);
- getDomElement().getChildren().get(0).setRelativeBound(new Rect(0,0, dim.getWidth(),dim.getHeight()));
+ buildContext.getChildren().get(0).setRelativeBound(new Rect(0,0, dim.getWidth(),dim.getHeight()));
return dim;
}
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicWidth(buildContext.getChildren().get(0), height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ return buildContext.getChildren().isEmpty() ? 0 : buildContext.getChildren().get(0).getLayouter().getMaxIntrinsicHeight(buildContext.getChildren().get(0), width);
+ }
+
@Override
public boolean canCutRequest() {
return Flexible.FlexFit.TIGHT == fit.getValue();
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicHeight.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicHeight.java
new file mode 100644
index 00000000..484e46f7
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicHeight.java
@@ -0,0 +1,65 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2023 cyoung06 (syeyoung)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.mod.guiv2.elements;
+
+import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute;
+import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement;
+import kr.syeyoung.dungeonsguide.mod.guiv2.Widget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.layouter.Layouter;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.ConstraintBox;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Rect;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Size;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Export;
+
+import java.util.Collections;
+import java.util.List;
+
+public class IntrinsicHeight extends AnnotatedExportOnlyWidget implements Layouter {
+ @Export(attributeName = "$")
+ public final BindableAttribute<Widget> widget = new BindableAttribute<>(Widget.class);
+
+ @Override
+ public List<Widget> build(DomElement buildContext) {
+ return Collections.singletonList(widget.getValue());
+ }
+
+ @Override
+ public Size layout(DomElement buildContext, ConstraintBox constraintBox) {
+ DomElement elem = buildContext.getChildren().get(0);
+ double height = elem.getLayouter().getMaxIntrinsicHeight(elem, constraintBox.getMaxWidth() == Double.POSITIVE_INFINITY ? 0 : constraintBox.getMaxWidth());
+ Size size = elem.getLayouter().layout(buildContext, new ConstraintBox(
+ constraintBox.getMinWidth(), constraintBox.getMaxWidth(), height, height
+ ));
+ elem.setRelativeBound(new Rect(0,0,size.getWidth(), size.getHeight()));
+ return size;
+ }
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ DomElement elem = buildContext.getChildren().get(0);
+ return elem.getLayouter().getMaxIntrinsicWidth(elem, height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ DomElement elem = buildContext.getChildren().get(0);
+ return elem.getLayouter().getMaxIntrinsicHeight(elem, width);
+ }
+}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicWidth.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicWidth.java
new file mode 100644
index 00000000..9754ec1c
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/IntrinsicWidth.java
@@ -0,0 +1,65 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2023 cyoung06 (syeyoung)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.mod.guiv2.elements;
+
+import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute;
+import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement;
+import kr.syeyoung.dungeonsguide.mod.guiv2.Widget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.layouter.Layouter;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.ConstraintBox;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Rect;
+import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Size;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Export;
+
+import java.util.Collections;
+import java.util.List;
+
+public class IntrinsicWidth extends AnnotatedExportOnlyWidget implements Layouter {
+ @Export(attributeName = "$")
+ public final BindableAttribute<Widget> widget = new BindableAttribute<>(Widget.class);
+
+ @Override
+ public List<Widget> build(DomElement buildContext) {
+ return Collections.singletonList(widget.getValue());
+ }
+
+ @Override
+ public Size layout(DomElement buildContext, ConstraintBox constraintBox) {
+ DomElement elem = buildContext.getChildren().get(0);
+ double width = elem.getLayouter().getMaxIntrinsicWidth(elem, constraintBox.getMaxHeight() == Double.POSITIVE_INFINITY ? 0 : constraintBox.getMaxHeight());
+ Size size = elem.getLayouter().layout(buildContext, new ConstraintBox(
+ width, width, constraintBox.getMinHeight(), constraintBox.getMaxHeight()
+ ));
+ elem.setRelativeBound(new Rect(0,0,size.getWidth(), size.getHeight()));
+ return size;
+ }
+
+ @Override
+ public double getMaxIntrinsicWidth(DomElement buildContext, double height) {
+ DomElement elem = buildContext.getChildren().get(0);
+ return elem.getLayouter().getMaxIntrinsicWidth(elem, height);
+ }
+
+ @Override
+ public double getMaxIntrinsicHeight(DomElement buildContext, double width) {
+ DomElement elem = buildContext.getChildren().get(0);
+ return elem.getLayouter().getMaxIntrinsicHeight(elem, width);
+ }
+}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Line.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Line.java
index d84cfa46..5f0d0395 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Line.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Line.java