From f1830199d99b666f28c2b3b246f688f102adb427 Mon Sep 17 00:00:00 2001
From: Wyvest <45589059+Wyvest@users.noreply.github.com>
Date: Fri, 24 Jun 2022 23:44:58 +0700
Subject: TextHud revamp add docs to Hud fix config not saving when exiting
prematurely some new events
---
.../oneconfig/config/core/ConfigUtils.java | 15 +-
.../oneconfig/config/elements/BasicOption.java | 4 +-
.../oneconfig/events/event/PreShutdownEvent.java | 11 +
.../oneconfig/events/event/ShutdownEvent.java | 9 +
.../oneconfig/events/event/StartEvent.java | 7 +
.../java/cc/polyfrost/oneconfig/gui/HudGui.java | 24 +-
.../java/cc/polyfrost/oneconfig/hud/BasicHud.java | 261 ------------------
.../java/cc/polyfrost/oneconfig/hud/HUDUtils.java | 4 +-
src/main/java/cc/polyfrost/oneconfig/hud/Hud.java | 292 +++++++++++++++++++++
.../cc/polyfrost/oneconfig/hud/MultiTextHud.java | 66 +++++
.../cc/polyfrost/oneconfig/hud/SingleTextHud.java | 97 +++++++
.../java/cc/polyfrost/oneconfig/hud/TextHud.java | 59 +++--
.../cc/polyfrost/oneconfig/internal/OneConfig.java | 13 +
.../oneconfig/internal/config/core/ConfigCore.java | 10 +
.../polyfrost/oneconfig/internal/hud/HudCore.java | 6 +-
.../oneconfig/internal/mixin/MinecraftMixin.java | 11 +
.../oneconfig/renderer/RenderManager.java | 59 ++++-
.../cc/polyfrost/oneconfig/test/TestHud_Test.java | 31 +--
18 files changed, 648 insertions(+), 331 deletions(-)
create mode 100644 src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java
delete mode 100644 src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
(limited to 'src/main/java')
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
index aaa7cca..99b52e3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Arrays;
public class ConfigUtils {
public static BasicOption getOption(Option option, Field field, Object instance) {
@@ -42,9 +43,19 @@ public class ConfigUtils {
return null;
}
- public static ArrayList getClassOptions(Object object) {
+ public static ArrayList getClassOptions(Object object, Class> parentClass) {
ArrayList options = new ArrayList<>();
- for (Field field : object.getClass().getDeclaredFields()) {
+ ArrayList fields = new ArrayList<>(Arrays.asList(object.getClass().getDeclaredFields()));
+ Class> clazz = object.getClass();
+ while (true) {
+ clazz = clazz.getSuperclass();
+ if (clazz != null && clazz != parentClass) {
+ fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
+ } else {
+ break;
+ }
+ }
+ for (Field field : fields) {
Option option = findAnnotation(field, Option.class);
if (option == null) continue;
options.add(getOption(option, field, object));
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index eba2f9f..2bee982 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -37,7 +37,9 @@ public abstract class BasicOption {
* @param object Java object to set the variable to
*/
protected void set(Object object) throws IllegalAccessException {
- if (field == null) return;
+ if (field == null) {
+ return;
+ }
field.set(parent, object);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java
new file mode 100644
index 0000000..105cfbc
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java
@@ -0,0 +1,11 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the game is about to shut down.
+ * This can be used if anything needs to be done before the screen itself is fully closed
+ * or need to do something before another mod does something via {@link Runtime#addShutdownHook(Thread)}.
+ *
+ * @see ShutdownEvent
+ */
+public class PreShutdownEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java
new file mode 100644
index 0000000..3f8ee50
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java
@@ -0,0 +1,9 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the game is shutting down.
+ *
+ * @see PreShutdownEvent
+ */
+public class ShutdownEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java
new file mode 100644
index 0000000..2eea91c
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java
@@ -0,0 +1,7 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the Minecraft instance is starting.
+ */
+public class StartEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index 939bbaa..8364afe 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.gui;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
-import cc.polyfrost.oneconfig.hud.BasicHud;
+import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
@@ -14,7 +14,7 @@ import java.awt.*;
import java.util.ArrayList;
public class HudGui extends UScreen {
- private BasicHud editingHud;
+ private Hud editingHud;
private boolean isDragging;
private boolean isScaling;
private int xOffset;
@@ -35,12 +35,12 @@ public class HudGui extends UScreen {
setPosition(mouseX - xOffset, mouseY - yOffset, true);
}
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (hud.enabled) processHud(hud, mouseX);
}
}
- private void processHud(BasicHud hud, int mouseX) {
+ private void processHud(Hud hud, int mouseX) {
if (hud == editingHud && isScaling) {
float xFloat = hud.getXScaled(this.width);
float yFloat = hud.getYScaled(this.height);
@@ -127,7 +127,7 @@ public class HudGui extends UScreen {
if (snapX != newX || snapY != newY) {
newX = snapX;
newY = snapY;
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
if (findParent(hud, snapX, snapY))
break;
@@ -145,7 +145,7 @@ public class HudGui extends UScreen {
editingHud.yUnscaled = (newY + height) / (double) this.height;
}
- private boolean findParent(BasicHud hud, float snapX, float snapY) {
+ private boolean findParent(Hud hud, float snapX, float snapY) {
int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
int hudX = (int) hud.getXScaled(this.width);
int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
@@ -167,7 +167,7 @@ public class HudGui extends UScreen {
private float getXSnapping(float pos, boolean rightOnly) {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
ArrayList verticalLines = new ArrayList<>();
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
verticalLines.addAll(getXSnappingHud(hud));
}
@@ -193,7 +193,7 @@ public class HudGui extends UScreen {
return pos;
}
- private ArrayList getXSnappingHud(BasicHud hud) {
+ private ArrayList getXSnappingHud(Hud hud) {
ArrayList verticalLines = new ArrayList<>();
if (hud == editingHud) return verticalLines;
if (hud.childRight != null) verticalLines.addAll(getXSnappingHud(hud.childRight));
@@ -207,7 +207,7 @@ public class HudGui extends UScreen {
private float getYSnapping(float pos) {
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
ArrayList horizontalLines = new ArrayList<>();
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
horizontalLines.addAll(getYSnappingHud(hud));
}
@@ -233,7 +233,7 @@ public class HudGui extends UScreen {
return pos;
}
- private ArrayList getYSnappingHud(BasicHud hud) {
+ private ArrayList getYSnappingHud(Hud hud) {
ArrayList horizontalLines = new ArrayList<>();
if (hud == editingHud) return horizontalLines;
if (hud.childBottom != null) horizontalLines.addAll(getYSnappingHud(hud.childBottom));
@@ -270,7 +270,7 @@ public class HudGui extends UScreen {
}
}
editingHud = null;
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
if (mouseClickedHud(hud, (int) mouseX, (int) mouseY))
break;
@@ -278,7 +278,7 @@ public class HudGui extends UScreen {
}
}
- private boolean mouseClickedHud(BasicHud hud, int mouseX, int mouseY) {
+ private boolean mouseClickedHud(Hud hud, int mouseX, int mouseY) {
int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
float x = hud.getXScaled(this.width);
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
deleted file mode 100644
index 445b2ad..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
+++ /dev/null
@@ -1,261 +0,0 @@
-package cc.polyfrost.oneconfig.hud;
-
-import cc.polyfrost.oneconfig.config.core.OneColor;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
-
-public abstract class BasicHud {
- 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;
-
- /**
- * @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;
- }
-
- /**
- * @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);
- 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);
- }
-
- /**
- * 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);
- 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);
- }
-
- /**
- * 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) {
- RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale);
- if (border)
- RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale);
- } else {
- RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB());
- if (border)
- RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale);
- }
- });
- }
-
- /**
- * @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;
- } 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));
- }
-
- /**
- * @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;
- } 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));
- }
-
- /**
- * @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;
- if (childBottom != null) width = Math.max(childBottom.getTotalWidth(childBottom.scale), width);
- 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;
- if (childRight != null) height = Math.max(childRight.getTotalHeight(childRight.scale), height);
- 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;
- if (childBottom != null) width = Math.max(childBottom.getTotalExampleWidth(childBottom.scale), width);
- 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;
- 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/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
index 6b28835..fb42e9c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class HUDUtils {
public static void addHudOptions(OptionPage page, Field field, Object instance) {
HUD hudAnnotation = field.getAnnotation(HUD.class);
- BasicHud hud = (BasicHud) ConfigUtils.getField(field, instance);
+ Hud hud = (Hud) ConfigUtils.getField(field, instance);
if (hud == null) return;
HudCore.huds.add(hud);
String category = hudAnnotation.category();
@@ -22,7 +22,7 @@ public class HUDUtils {
try {
options.add(new ConfigHeader(field, hud, hudAnnotation.name(), category, subcategory, 2));
options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", category, subcategory, 2));
- options.addAll(ConfigUtils.getClassOptions(hud));
+ options.addAll(ConfigUtils.getClassOptions(hud, Hud.class));
options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", category, subcategory, 1));
options.get(options.size() - 1).addDependency(() -> hud.enabled);
options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", category, subcategory, 1));
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
new file mode 100644
index 0000000..71c6c38
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
@@ -0,0 +1,292 @@
+package cc.polyfrost.oneconfig.hud;
+
+import cc.polyfrost.oneconfig.config.core.OneColor;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import cc.polyfrost.oneconfig.config.Config;
+
+/**
+ * Represents a HUD element in OneConfig.
+ * A HUD element can be used to display useful information to the user, like FPS or CPS.
+ *
+ * If you simply want to display text, extend {@link SingleTextHud} or {@link MultiTextHud},
+ * whichever applies to the use case. Then, override the required methods.
+ *
+ * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(int, int, float)} with the width, height, and the drawing code respectively.
+ *
+ *
+ * It should also be noted that additional options to the HUD can be added simply by declaring them.
+ *
{@code
+ * public class TestHud extends SingleTextHud {
+ * @literal @Switch(
+ * name = "Additional Option"
+ * )
+ * public boolean additionalOption = true;
+ * }
+ * }
+ *
+ * To register an element, add it to your OneConfig {@link Config}.
+ * {@code
+ * * public class YourConfig extends Config {
+ * * @literal @HUD(
+ * * name = "HUD Element"
+ * * )
+ * * public YourHudElement hudElement = new YourHudElement(false);
+ * * }
+ * * }
+ */
+public abstract class Hud {
+ 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 Hud parent;
+ public Hud childRight;
+ public Hud childBottom;
+
+ /**
+ * @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 Hud(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;
+ }
+
+ /**
+ * @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 Hud(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 Hud(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 Hud(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);
+ 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);
+ }
+
+ /**
+ * 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);
+ 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);
+ }
+
+ /**
+ * 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) {
+ RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale);
+ if (border)
+ RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale);
+ } else {
+ RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB());
+ if (border)
+ RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale);
+ }
+ });
+ }
+
+ /**
+ * @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;
+ } 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));
+ }
+
+ /**
+ * @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;
+ } 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));
+ }
+
+ /**
+ * @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;
+ if (childBottom != null) width = Math.max(childBottom.getTotalWidth(childBottom.scale), width);
+ 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;
+ if (childRight != null) height = Math.max(childRight.getTotalHeight(childRight.scale), height);
+ 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;
+ if (childBottom != null) width = Math.max(childBottom.getTotalExampleWidth(childBottom.scale), width);
+ 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;
+ 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/cc/polyfrost/oneconfig/hud/MultiTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
new file mode 100644
index 0000000..5440f10
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
@@ -0,0 +1,66 @@
+package cc.polyfrost.oneconfig.hud;
+
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import net.minecraft.client.gui.GuiChat;
+
+import java.util.List;
+
+public abstract class MultiTextHud extends TextHud {
+ private transient int width = 100;
+ private transient int height;
+
+ public MultiTextHud(boolean enabled) {
+ this(enabled, 0, 0);
+ }
+
+ public MultiTextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (width * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (height * scale);
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ if (!showInGuis && UScreen.getCurrentScreen() != null && !(UScreen.getCurrentScreen() instanceof OneConfigGui)) return;
+ if (!showInChat && UScreen.getCurrentScreen() instanceof GuiChat) return;
+ if (!showInDebug && UMinecraft.getSettings().showDebugInfo) return;
+
+ int textY = y;
+ width = 0;
+ for (String line : getLines()) {
+ RenderManager.drawScaledString(line, x, textY, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
+ textY += 12 * scale;
+ }
+ height = (int) ((textY - y) / scale - 3);
+ }
+
+ @Override
+ public void drawExample(int x, int y, float scale) {
+ int textY = y;
+ width = 0;
+ for (String line : getExampleLines()) {
+ RenderManager.drawScaledString(line, x, textY, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
+ textY += 12 * scale;
+ }
+ height = (int) ((textY - y) / scale - 3);
+ }
+
+ public abstract List getLines();
+
+ public List getExampleLines() {
+ return getLines();
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
new file mode 100644
index 0000000..983047a
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
@@ -0,0 +1,97 @@
+package cc.polyfrost.oneconfig.hud;
+
+import cc.polyfrost.oneconfig.config.annotations.Dropdown;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
+import cc.polyfrost.oneconfig.config.annotations.Text;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import net.minecraft.client.gui.GuiChat;
+
+public abstract class SingleTextHud extends TextHud {
+
+ public SingleTextHud(boolean enabled) {
+ this(enabled, 0, 0);
+ }
+
+ public SingleTextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
+
+ @Switch(
+ name = "Brackets"
+ )
+ public boolean brackets = false;
+
+ @Text(
+ name = "Title"
+ )
+ public String title = getDefaultTitle();
+
+ @Dropdown(
+ name = "Title Location",
+ options = {"Left", "Right"}
+ )
+ public int titleLocation = 0;
+
+ public abstract String getDefaultTitle();
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(false)) * scale);
+ }
+
+ @Override
+ public int getExampleWidth(float scale) {
+ return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(true)) * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (UMinecraft.getFontRenderer().FONT_HEIGHT * scale);
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ if (!showInGuis && UScreen.getCurrentScreen() != null && !(UScreen.getCurrentScreen() instanceof OneConfigGui)) return;
+ if (!showInChat && UScreen.getCurrentScreen() instanceof GuiChat) return;
+ if (!showInDebug && UMinecraft.getSettings().showDebugInfo) return;
+
+ RenderManager.drawScaledString(getCompleteText(false), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ }
+
+ @Override
+ public void drawExample(int x, int y, float scale) {
+ RenderManager.drawScaledString(getCompleteText(true), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ }
+
+ protected final String getCompleteText(boolean example) {
+ boolean showTitle = !title.trim().isEmpty();
+ StringBuilder builder = new StringBuilder();
+ if (brackets) {
+ builder.append("[");
+ }
+
+ if (showTitle && titleLocation == 0) {
+ builder.append(title).append(": ");
+ }
+
+ builder.append(example ? getExampleText() : getText());
+
+ if (showTitle && titleLocation == 1) {
+ builder.append(" ").append(title);
+ }
+
+ if (brackets) {
+ builder.append("]");
+ }
+ return builder.toString();
+ }
+
+ public abstract String getText();
+
+ public String getExampleText() {
+ return getText();
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 738ed21..7a05ef7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -1,38 +1,39 @@
package cc.polyfrost.oneconfig.hud;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
-import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.config.annotations.Color;
+import cc.polyfrost.oneconfig.config.annotations.Dropdown;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
+import cc.polyfrost.oneconfig.config.core.OneColor;
-import java.util.List;
+abstract class TextHud extends Hud {
+ @Color(
+ name = "Text Color"
+ )
+ public OneColor color = new OneColor(255, 255, 255);
-public abstract class TextHud extends BasicHud {
- private transient int width = 100;
- private transient int height;
- public TextHud(boolean enabled, int x, int y) {
- super(enabled, x, y);
- }
+ @Switch(
+ name = "Show in Chat"
+ )
+ public boolean showInChat;
- @Override
- public int getWidth(float scale) {
- return (int) (width * scale);
- }
+ @Switch(
+ name = "Show in F3 (Debug)"
+ )
+ public boolean showInDebug;
- @Override
- public int getHeight(float scale) {
- return (int) (height * scale);
- }
+ @Switch(
+ name = "Show in GUIs"
+ )
+ public boolean showInGuis = true;
+
+ @Dropdown(
+ name = "Text Type",
+ options = {"No Shadow", "Shadow", "Full Shadow"}
+ )
+ public int textType = 0;
- @Override
- public void draw(int x, int y, float scale) {
- int textY = y;
- width = 0;
- for (String line : getLines()) {
- RenderManager.drawScaledString(line, x, textY, 0xffffff, false, scale);
- width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
- textY += 12 * scale;
- }
- height = (int) ((textY - y) / scale - 3);
- }
- public abstract List getLines();
+ public TextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index 479192d..c91b4e9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -1,6 +1,8 @@
package cc.polyfrost.oneconfig.internal;
import cc.polyfrost.oneconfig.events.EventManager;
+import cc.polyfrost.oneconfig.events.event.ShutdownEvent;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.internal.command.OneConfigCommand;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.config.Preferences;
@@ -8,6 +10,7 @@ import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.internal.gui.BlurHandler;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
@@ -21,6 +24,11 @@ import java.io.File;
*/
@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
+
+ public OneConfig() {
+ EventManager.INSTANCE.register(this);
+ }
+
public static final File oneConfigDir = new File("./OneConfig");
public static final Logger LOGGER = LogManager.getLogger("@NAME@");
public static OneConfigConfig config;
@@ -73,4 +81,9 @@ public class OneConfig {
public static boolean isObfuscated() {
return isObfuscated;
}
+
+ @Subscribe
+ private void onShutdown(ShutdownEvent event) {
+ ConfigCore.saveAll();
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
index 6b88afa..90c1062 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
@@ -7,9 +7,19 @@ import cc.polyfrost.oneconfig.internal.hud.HudCore;
import java.util.ArrayList;
import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.stream.Collectors;
public class ConfigCore {
+ static {
+ new Timer().scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ saveAll();
+ }
+ }, 30000, 30000);
+ }
public static List oneConfigMods = new ArrayList<>();
public static void saveAll() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
index 04a5e69..2d92b3c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -1,20 +1,20 @@
package cc.polyfrost.oneconfig.internal.hud;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
-import cc.polyfrost.oneconfig.hud.BasicHud;
+import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import java.util.ArrayList;
public class HudCore {
- public static ArrayList huds = new ArrayList<>();
+ public static ArrayList huds = new ArrayList<>();
public static boolean editing = false;
@Subscribe
public void onRender(HudRenderEvent event) {
if (editing) return;
- for (BasicHud hud : huds) {
+ for (Hud hud : huds) {
if (hud.enabled)
hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
index 6308fdb..5fb40f8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
@@ -20,6 +20,17 @@ public class MinecraftMixin {
@Shadow
private Timer timer;
+ @Inject(method = "shutdownMinecraftApplet", at = @At("HEAD"))
+ private void onShutdown(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new PreShutdownEvent());
+ }
+
+ @Inject(method = "startGame", at = @At("HEAD"))
+ private void onStart(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new StartEvent());
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent())));
+ }
+
@Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true)
private void onPreLaunch(CallbackInfo ci) {
OneConfig.preLaunch();
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
index d894d1e..b62d752 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
@@ -20,6 +20,7 @@ import org.lwjgl.nanovg.NVGPaint;
import org.lwjgl.opengl.GL11;
import java.util.function.LongConsumer;
+import java.util.regex.Pattern;
import static org.lwjgl.nanovg.NanoVG.*;
import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS;
@@ -740,14 +741,68 @@ public final class RenderManager {
// gl
- public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) {
+ private static final Pattern regex = Pattern.compile("(?i)\\\\u00A7[0-9a-f]");
+
+ public static int drawBorderedText(String text, float x, float y, int color, int opacity) {
+ String noColors = regex.matcher(text).replaceAll("\u00A7r");
+ int yes = 0;
+ if (opacity > 3) {
+ int xOff = -3;
+ while (xOff < 3) {
+ xOff++;
+ int yOff = -3;
+ while (yOff < 3) {
+ yOff++;
+ if (xOff * xOff != yOff * yOff) {
+ yes +=
+ //#if MODERN==0
+ UMinecraft.getFontRenderer().drawString(
+ noColors, (xOff / 2f) + x, (yOff / 2f) + y, (opacity) << 24, false
+ );
+ //#else
+ //$$ draw(
+ //$$ matrix.toMC(), noColors, (xOff / 2f) + x, (yOff / 2f) + y, (opacity) shl 24
+ //$$ )
+ //#endif
+ }
+ }
+ }
+ }
+ yes +=
+ //#if MODERN==0
+ UMinecraft.getFontRenderer().drawString(text, x, y, color, false);
+ //#else
+ //$$ draw(matrix.toMC(), text, x.toFloat(), y.toFloat(), color)
+ //#endif
+ return yes;
+ }
+
+ public static void drawScaledString(String text, float x, float y, int color, TextType type, float scale) {
UGraphics.GL.pushMatrix();
UGraphics.GL.scale(scale, scale, 1);
- UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
+ switch (type) {
+ case NONE:
+ UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, false);
+ break;
+ case SHADOW:
+ UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, true);
+ break;
+ case FULL:
+ drawBorderedText(text, x, y, color, 100);
+ break;
+ }
UGraphics.GL.popMatrix();
}
public static void drawGlRect(int x, int y, int width, int height, int color) {
Gui.drawRect(x, y, x + width, y + height, color);
}
+
+ public enum TextType {
+ NONE, SHADOW, FULL;
+
+ public static TextType toType(int type) {
+ return values()[type];
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
index 0de9d65..9982e7d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
@@ -1,33 +1,26 @@
package cc.polyfrost.oneconfig.test;
import cc.polyfrost.oneconfig.config.annotations.Switch;
-import cc.polyfrost.oneconfig.config.annotations.Text;
-import cc.polyfrost.oneconfig.hud.TextHud;
+import cc.polyfrost.oneconfig.hud.SingleTextHud;
import net.minecraft.client.Minecraft;
-import java.util.ArrayList;
-import java.util.List;
+public class TestHud_Test extends SingleTextHud {
+ @Switch(
+ name = "Custom Option"
+ )
+ public boolean yes;
-public class TestHud_Test extends TextHud {
public TestHud_Test(boolean enabled, int x, int y) {
super(enabled, x, y);
}
@Override
- public List getLines() {
- ArrayList lines = new ArrayList<>();
- lines.add("FPS: " + Minecraft.getDebugFPS());
- if (hasSecondLine) lines.add(secondLine);
- return lines;
+ public String getDefaultTitle() {
+ return "FPS";
}
- @Switch(
- name = "Has Second Line"
- )
- public boolean hasSecondLine = false;
-
- @Text(
- name = "Second Line Text"
- )
- public String secondLine = "Epic text";
+ @Override
+ public String getText() {
+ return Integer.toString(Minecraft.getDebugFPS());
+ }
}
--
cgit