diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-18 20:09:08 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-18 20:09:08 +0200 |
commit | 01f85e9e40e3c065807ef9020ecf62266c2eec8a (patch) | |
tree | 289c3a72841e2f723f6ae190e481305b288d0df9 /src/main/java/io/polyfrost/oneconfig/hud | |
parent | 420ca8641b6204b011ee74916c839de54d0b2104 (diff) | |
download | OneConfig-01f85e9e40e3c065807ef9020ecf62266c2eec8a.tar.gz OneConfig-01f85e9e40e3c065807ef9020ecf62266c2eec8a.tar.bz2 OneConfig-01f85e9e40e3c065807ef9020ecf62266c2eec8a.zip |
hud childing start
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/hud')
3 files changed, 32 insertions, 24 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java index a532ebd..a4172a2 100644 --- a/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java +++ b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java @@ -15,8 +15,9 @@ public class HudCore { @SubscribeEvent public void onRender(RenderGameOverlayEvent.Post event) { if (event.type != RenderGameOverlayEvent.ElementType.ALL || editing) return; + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); for (BasicHud hud : huds) { - hud.drawAll(hud.getXScaled(Minecraft.getMinecraft().displayWidth), hud.getYScaled(Minecraft.getMinecraft().displayHeight), hud.scale); + hud.drawAll(hud.getXScaled(sr.getScaledWidth()), hud.getYScaled(sr.getScaledHeight()), hud.scale, true); } } } diff --git a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java index 884a1bb..22121b7 100644 --- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java +++ b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java @@ -4,6 +4,7 @@ import io.polyfrost.oneconfig.hud.HudCore; import io.polyfrost.oneconfig.hud.interfaces.BasicHud; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.test.TestHud; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import org.lwjgl.input.Keyboard; @@ -26,6 +27,8 @@ public class HudGui extends GuiScreen { for (BasicHud hud : HudCore.huds) { hud.childBottom = new TestHud(); hud.childBottom.parent = hud; + hud.childRight = new TestHud(); + hud.childRight.parent = hud; } } @@ -61,7 +64,7 @@ public class HudGui extends GuiScreen { int x = (int) hud.getXScaled(this.width); int y = (int) hud.getYScaled(this.height); - hud.drawExampleAll(x, y, hud.scale); + hud.drawExampleAll(x, y, hud.scale, true); int color = new Color(215, 224, 235).getRGB(); if (editingHud == hud) { color = new Color(43, 159, 235).getRGB(); @@ -70,10 +73,10 @@ public class HudGui extends GuiScreen { } int finalColor = color; RenderManager.setupAndDraw(true, (vg) -> { - RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 2, finalColor); - RenderManager.drawLine(vg, x, y, x, y + height, 2, finalColor); - RenderManager.drawLine(vg, x + width, y, x + width, y + height, 2, finalColor); - RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 2, finalColor); + RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 1, finalColor); + RenderManager.drawLine(vg, x, y, x, y + height, 1, finalColor); + RenderManager.drawLine(vg, x + width, y, x + width, y + height, 1, finalColor); + RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 1, finalColor); }); if (hud == editingHud && !isDragging) { diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java index f43a79e..5044421 100644 --- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java +++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java @@ -30,18 +30,22 @@ public abstract class BasicHud { return getHeight(scale); } - public void drawAll(float x, float y, float scale) { - drawBackground(x, y, getTotalWidth(scale), getTotalHeight(scale), scale); + public void drawAll(float x, float y, float scale, boolean background) { + if (background) drawBackground(x, y, getTotalWidth(scale), getTotalHeight(scale), scale); draw((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); - if (childRight != null) childRight.draw((int) x, (int) y, scale); - if (childBottom != null) childBottom.draw((int) x, (int) y, scale); + if (childRight != null) + childRight.drawAll((int) x + paddingX * scale / 2f + getWidth(scale), (int) y, childRight.scale, false); + if (childBottom != null) + childBottom.drawAll((int) x, (int) y + paddingY * scale / 2f + getHeight(scale), childBottom.scale, false); } - public void drawExampleAll(float x, float y, float scale) { - drawBackground(x, y, getTotalExampleWidth(scale), getTotalHeight(scale), scale); + public void drawExampleAll(float x, float y, float scale, boolean background) { + if (background) drawBackground(x, y, getTotalExampleWidth(scale), getTotalExampleHeight(scale), scale); drawExample((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); - if (childRight != null) childRight.drawExample((int) x, (int) y, scale); - if (childBottom != null) childBottom.drawExample((int) x, (int) y, scale); + if (childRight != null) + childRight.drawExampleAll((int) x + paddingX * scale / 2f + getWidth(scale), (int) y, childRight.scale, false); + if (childBottom != null) + childBottom.drawExampleAll((int) x, (int) y + paddingY * scale / 2f + getHeight(scale), childBottom.scale, false); } public void drawExample(int x, int y, float scale) { @@ -49,8 +53,8 @@ public abstract class BasicHud { } private void drawBackground(float x, float y, float width, float height, float scale) { - RenderManager.setupAndDraw((vg) -> RenderManager.drawRoundedRect(vg, x, y, width + paddingX * scale, - height + paddingY * scale, new Color(0, 0, 0, 120).getRGB(), 2 * scale)); + RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), + (height + paddingY * scale), new Color(0, 0, 0, 120).getRGB(), 2 * scale)); } public float getXScaled(int screenWidth) { @@ -69,29 +73,29 @@ public abstract class BasicHud { public float getTotalWidth(float scale) { float width = getWidth(scale); - if (childBottom != null) width += childBottom.getTotalWidth(scale); - if (childRight != null) width += childRight.getTotalWidth(scale); + if (childRight != null) width += childRight.getTotalWidth(childRight.scale) + paddingY * scale / 2f; + if (childBottom != null) width = Math.max(childBottom.getTotalWidth(childBottom.scale), width); return width; } public float getTotalHeight(float scale) { float height = getHeight(scale); - if (childBottom != null) height += childBottom.getTotalHeight(scale); - if (childRight != null) height += childRight.getTotalHeight(scale); + if (childBottom != null) height += childBottom.getTotalHeight(childBottom.scale) + paddingY * scale / 2f; + if (childRight != null) height = Math.max(childRight.getTotalHeight(childRight.scale), height); return height; } public float getTotalExampleWidth(float scale) { float width = getExampleWidth(scale); - if (childBottom != null) width += childBottom.getTotalExampleWidth(scale); - if (childRight != null) width += childRight.getTotalExampleWidth(scale); + if (childRight != null) width += childRight.getTotalExampleWidth(childRight.scale) + paddingX * scale / 2f; + if (childBottom != null) width = Math.max(childBottom.getTotalExampleWidth(childBottom.scale), width); return width; } public float getTotalExampleHeight(float scale) { float height = getExampleHeight(scale); - if (childBottom != null) height += childBottom.getTotalExampleHeight(scale); - if (childRight != null) height += childRight.getTotalExampleHeight(scale); + if (childBottom != null) height += childBottom.getTotalExampleHeight(childBottom.scale) + paddingY * scale / 2f; + if (childRight != null) height = Math.max(childRight.getTotalExampleHeight(childRight.scale), height); return height; } }
\ No newline at end of file |