aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java170
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestHud.java3
4 files changed, 159 insertions, 22 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index c31d2e1..a0f1e6c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -33,7 +33,7 @@ public class HudGui extends GuiScreen {
}
for (BasicHud hud : HudCore.huds) {
- processHud(hud, mouseX);
+ if (hud.enabled) processHud(hud, mouseX);
}
}
@@ -127,6 +127,7 @@ public class HudGui extends GuiScreen {
newX = snapX;
newY = snapY;
for (BasicHud hud : HudCore.huds) {
+ if (!hud.enabled) continue;
if (findParent(hud, snapX, snapY))
break;
}
@@ -166,6 +167,7 @@ public class HudGui extends GuiScreen {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
ArrayList<Float> verticalLines = new ArrayList<>();
for (BasicHud hud : HudCore.huds) {
+ if (!hud.enabled) continue;
verticalLines.addAll(getXSnappingHud(hud));
}
getSpaceSnapping(verticalLines);
@@ -205,6 +207,7 @@ public class HudGui extends GuiScreen {
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
ArrayList<Float> horizontalLines = new ArrayList<>();
for (BasicHud hud : HudCore.huds) {
+ if (!hud.enabled) continue;
horizontalLines.addAll(getYSnappingHud(hud));
}
getSpaceSnapping(horizontalLines);
@@ -266,6 +269,7 @@ public class HudGui extends GuiScreen {
}
editingHud = null;
for (BasicHud hud : HudCore.huds) {
+ if (!hud.enabled) continue;
if (mouseClickedHud(hud, mouseX, mouseY))
break;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
index b15300e..6c36256 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
@@ -3,39 +3,134 @@ package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.lwjgl.OneColor;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
-import java.awt.*;
-
public abstract class BasicHud {
- public boolean enabled = true;
- public boolean rounded = false;
- public boolean border = false;
- public OneColor bgColor = new OneColor(0, 0, 0, 120);
- public OneColor borderColor = new OneColor(0, 0, 0);
- public float cornerRadius = 2;
- public float borderSize = 2;
- public double xUnscaled = 0;
- public double yUnscaled = 0;
- public float scale = 1;
- public float paddingX = 5;
- public float paddingY = 5;
+ public boolean enabled;
+ public boolean rounded;
+ public boolean border;
+ public OneColor bgColor;
+ public OneColor borderColor;
+ public float cornerRadius;
+ public float borderSize;
+ public double xUnscaled;
+ public double yUnscaled;
+ public float scale;
+ public float paddingX;
+ public float paddingY;
public BasicHud parent;
public BasicHud childRight;
public BasicHud childBottom;
- public abstract int getWidth(float scale);
+ /**
+ * @param enabled If the hud is enabled
+ * @param x X-coordinate of hud on a 1080p display
+ * @param y Y-coordinate of hud on a 1080p display
+ * @param scale Scale of the hud
+ * @param rounded If the corner is rounded or not
+ * @param cornerRadius Radius of the corner
+ * @param paddingX Horizontal background padding
+ * @param paddingY Vertical background padding
+ * @param bgColor Background color
+ * @param border If the hud has a border or not
+ * @param borderSize Thickness of the border
+ * @param borderColor The color of the border
+ */
+ public BasicHud(boolean enabled, int x, int y, float scale, boolean rounded, int cornerRadius, int paddingX, int paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) {
+ this.enabled = enabled;
+ this.scale = scale;
+ this.rounded = rounded;
+ this.cornerRadius = cornerRadius;
+ this.paddingX = paddingX;
+ this.paddingY = paddingY;
+ this.bgColor = bgColor;
+ this.border = border;
+ this.borderSize = borderSize;
+ this.borderColor = borderColor;
+ if (x / 1920d <= 0.5d) xUnscaled = x / 1920d;
+ else xUnscaled = (x + getWidth(scale)) / 1920d;
+ if (y / 1080d <= 0.5d) yUnscaled = y / 1080d;
+ else yUnscaled = (y + getHeight(scale)) / 1090d;
+ }
- public abstract int getHeight(float scale);
+ /**
+ * @param enabled If the hud is enabled
+ * @param x X-coordinate of hud on a 1080p display
+ * @param y Y-coordinate of hud on a 1080p display
+ * @param scale Scale of the hud
+ */
+ public BasicHud(boolean enabled, int x, int y, int scale) {
+ this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
+ }
+ /**
+ * @param enabled If the hud is enabled
+ * @param x X-coordinate of hud on a 1080p display
+ * @param y Y-coordinate of hud on a 1080p display
+ */
+ public BasicHud(boolean enabled, int x, int y) {
+ this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
+ }
+
+ /**
+ * @param enabled If the hud is enabled
+ */
+ public BasicHud(boolean enabled) {
+ this(enabled, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
+ }
+
+ /**
+ * Function called when drawing the hud
+ * @param x Top left x-coordinate of the hud
+ * @param y Top left y-coordinate of the hud
+ * @param scale Scale of the hud
+ */
public abstract void draw(int x, int y, float scale);
+ /**
+ * Function called when drawing the example version of the hud.
+ * This is used in for example, the hud editor gui.
+ * @param x Top left x-coordinate of the hud
+ * @param y Top left y-coordinate of the hud
+ * @param scale Scale of the hud
+ */
+ public void drawExample(int x, int y, float scale) {
+ draw(x, y, scale);
+ }
+
+ /**
+ * @param scale Scale of the hud
+ * @return The width of the hud
+ */
+ public abstract int getWidth(float scale);
+
+ /**
+ * @param scale Scale of the hud
+ * @return The height of the hud
+ */
+ public abstract int getHeight(float scale);
+
+ /**
+ * @param scale Scale of the hud
+ * @return The width of the example version of the hud
+ */
public int getExampleWidth(float scale) {
return getWidth(scale);
}
+ /**
+ * @param scale Scale of the hud
+ * @return The height of the example version of the hud
+ */
public int getExampleHeight(float scale) {
return getHeight(scale);
}
+ /**
+ * Draw the background, the hud and all childed huds, used by HudCore
+ * @param x X-coordinate
+ * @param y Y-coordinate
+ * @param scale Scale of the hud
+ * @param background If background should be drawn or not
+ */
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);
@@ -45,6 +140,13 @@ public abstract class BasicHud {
childBottom.drawAll((int) x, (int) y + paddingY * scale / 2f + getHeight(scale), childBottom.scale, false);
}
+ /**
+ * Draw example version of the background, the hud and all childed huds, used by HudGui
+ * @param x X-coordinate
+ * @param y Y-coordinate
+ * @param scale Scale of the hud
+ * @param background If background should be drawn or not
+ */
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);
@@ -54,10 +156,14 @@ public abstract class BasicHud {
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);
- }
-
+ /**
+ * Draw example version of the background, the hud and all childed huds, used by HudGui
+ * @param x X-coordinate
+ * @param y Y-coordinate
+ * @param width Width of the hud
+ * @param height Height of the hud
+ * @param scale Scale of the hud
+ */
private void drawBackground(float x, float y, float width, float height, float scale) {
RenderManager.setupAndDraw(true, (vg) -> {
if (rounded) {
@@ -70,6 +176,10 @@ public abstract class BasicHud {
});
}
+ /**
+ * @param screenWidth width of the screen
+ * @return X-coordinate of the hud
+ */
public float getXScaled(int screenWidth) {
if (parent != null && parent.childRight == this) {
return parent.getXScaled(screenWidth) + parent.getWidth(parent.scale) + parent.paddingX * parent.scale / 2f;
@@ -82,6 +192,10 @@ public abstract class BasicHud {
return (float) (screenWidth - (1d - xUnscaled) * screenWidth - (getWidth(scale) + paddingX * scale));
}
+ /**
+ * @param screenHeight height of the screen
+ * @return Y-coordinate of the hud
+ */
public float getYScaled(int screenHeight) {
if (parent != null && parent.childBottom == this) {
return parent.getYScaled(screenHeight) + parent.getHeight(parent.scale) + parent.paddingY * parent.scale / 2f;
@@ -94,6 +208,10 @@ public abstract class BasicHud {
return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale));
}
+ /**
+ * @param scale Scale of the hud
+ * @return The width of the hud and all childed huds
+ */
public float getTotalWidth(float scale) {
float width = getWidth(scale);
if (childRight != null) width += childRight.getTotalWidth(childRight.scale) + paddingY * scale / 2f;
@@ -101,6 +219,10 @@ public abstract class BasicHud {
return width;
}
+ /**
+ * @param scale Scale of the hud
+ * @return The height of the hud and all childed huds
+ */
public float getTotalHeight(float scale) {
float height = getHeight(scale);
if (childBottom != null) height += childBottom.getTotalHeight(childBottom.scale) + paddingY * scale / 2f;
@@ -108,6 +230,10 @@ public abstract class BasicHud {
return height;
}
+ /**
+ * @param scale Scale of the hud
+ * @return The example width of the hud and all childed huds
+ */
public float getTotalExampleWidth(float scale) {
float width = getExampleWidth(scale);
if (childRight != null) width += childRight.getTotalExampleWidth(childRight.scale) + paddingX * scale / 2f;
@@ -115,6 +241,10 @@ public abstract class BasicHud {
return width;
}
+ /**
+ * @param scale Scale of the hud
+ * @return The example height of the hud and all childed huds
+ */
public float getTotalExampleHeight(float scale) {
float height = getExampleHeight(scale);
if (childBottom != null) height += childBottom.getTotalExampleHeight(childBottom.scale) + paddingY * scale / 2f;
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
index 9bf9e58..b5410de 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
@@ -16,7 +16,7 @@ public class TestConfig extends Config {
type = OptionType.HUD,
size = 2
)
- public static TestHud TestHud = new TestHud();
+ public static TestHud TestHud = new TestHud(true, 500, 500);
@Option(
name = "This is all still in beta",
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java b/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
index e225987..80f3bbc 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
@@ -5,6 +5,9 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import net.minecraft.client.Minecraft;
public class TestHud extends BasicHud {
+ public TestHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
@Override
public int getWidth(float scale) {