diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-03 18:25:32 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-03 18:25:32 +0200 |
commit | a0ff501947a84b268e099524a06b56a6b900dad2 (patch) | |
tree | db27ca1b28dbc7e57b8c99f54c80732d3042e856 /src/main/java/io/polyfrost/oneconfig/hud/interfaces | |
parent | b798930b21b89b81be05a31281f768667a6dd7f3 (diff) | |
download | OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.gz OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.bz2 OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.zip |
move to cc.polyfrost
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/hud/interfaces')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java | 111 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java | 94 |
2 files changed, 0 insertions, 205 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java deleted file mode 100644 index e9e3a59..0000000 --- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java +++ /dev/null @@ -1,111 +0,0 @@ -package io.polyfrost.oneconfig.hud.interfaces; - -import io.polyfrost.oneconfig.lwjgl.RenderManager; - -import java.awt.*; - -public abstract class BasicHud { - public double xUnscaled = 0; - public double yUnscaled = 0; - public float scale = 1; - public int paddingX = 5; - public int paddingY = 5; - public boolean background = true; - public boolean rounded = false; - public BasicHud parent; - public BasicHud childRight; - public BasicHud childBottom; - - public abstract int getWidth(float scale); - - public abstract int getHeight(float scale); - - public abstract void draw(int x, int y, float scale); - - public int getExampleWidth(float scale) { - return getWidth(scale); - } - - public int getExampleHeight(float scale) { - return getHeight(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.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, 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.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) { - draw(x, y, scale); - } - - private void drawBackground(float x, float y, float width, float height, float 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) { - if (parent != null && parent.childRight == this) { - return parent.getXScaled(screenWidth) + parent.getWidth(parent.scale) + parent.paddingX * parent.scale / 2f; - } else if (parent != null) { - return parent.getXScaled(screenWidth); - } - if (xUnscaled <= 0.5) { - return (int) (screenWidth * xUnscaled); - } - return (float) (screenWidth - (1d - xUnscaled) * screenWidth - (getWidth(scale) + paddingX * scale)); - } - - public float getYScaled(int screenHeight) { - if (parent != null && parent.childBottom == this) { - return parent.getYScaled(screenHeight) + parent.getHeight(parent.scale) + parent.paddingY * parent.scale / 2f; - } else if (parent != null) { - return parent.getYScaled(screenHeight); - } - if (yUnscaled <= 0.5) { - return (int) (screenHeight * yUnscaled); - } - return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale)); - } - - public float getTotalWidth(float scale) { - float width = getWidth(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(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 (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(childBottom.scale) + paddingY * scale / 2f; - if (childRight != null) height = Math.max(childRight.getTotalExampleHeight(childRight.scale), height); - return height; - } -}
\ No newline at end of file diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java deleted file mode 100644 index 299e7b8..0000000 --- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.polyfrost.oneconfig.hud.interfaces; - -import io.polyfrost.oneconfig.lwjgl.RenderManager; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -import java.util.List; - -public class TextHud extends BasicHud { - /** - * Currently doesn't work because of double extend, will have to be redone somehow (I have no idea how yet) - */ - private final FontRenderer fb = Minecraft.getMinecraft().fontRendererObj; - boolean shadow = false; - boolean doExample = false; - private List<String> cachedLines; - private int cachedWidth; - private int cachedHeight; - private List<String> cachedExampleLines; - private int cachedExampleWidth; - private int cachedExampleHeight; - - protected List<String> update() { - return null; - } - - @SubscribeEvent - private void onTick(TickEvent.ClientTickEvent event) { - if (event.phase != TickEvent.Phase.START) return; - cachedLines = update(); - if (cachedLines != null) { - cachedHeight = cachedLines.size() * (fb.FONT_HEIGHT + 3); - cachedWidth = 0; - for (String line : cachedLines) { - int width = fb.getStringWidth(line); - if (width > cachedWidth) cachedWidth = width; - } - } - if (doExample) { - cachedExampleLines = updateExample(); - if (cachedExampleLines != null) { - cachedExampleHeight = cachedExampleLines.size() * 12; - cachedExampleWidth = 0; - for (String line : cachedExampleLines) { - int width = fb.getStringWidth(line); - if (width > cachedExampleWidth) cachedExampleWidth = width; - } - } - } - } - - protected List<String> updateExample() { - return update(); - } - - @Override - public void draw(int x, int y, float scale) { - if (cachedLines != null) drawText(cachedLines, x, y, scale); - } - - @Override - public void drawExample(int x, int y, float scale) { - doExample = true; - if (cachedExampleLines != null) drawText(cachedExampleLines, x, y, scale); - } - - private void drawText(List<String> lines, int x, int y, float scale) { - for (int i = 0; i < lines.size(); i++) { - RenderManager.drawScaledString(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale); - } - } - - @Override - public int getWidth(float scale) { - return (int) (cachedWidth * scale); - } - - @Override - public int getHeight(float scale) { - return (int) (cachedHeight * scale); - } - - @Override - public int getExampleWidth(float scale) { - return (int) (cachedExampleWidth * scale); - } - - @Override - public int getExampleHeight(float scale) { - return (int) (cachedExampleHeight * scale); - } -} |