aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/hud
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/hud')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Hud.java (renamed from src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java)47
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java66
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java97
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java59
5 files changed, 234 insertions, 39 deletions
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/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
index 445b2ad..71c6c38 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
@@ -2,8 +2,39 @@ package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.renderer.RenderManager;
+import cc.polyfrost.oneconfig.config.Config;
-public abstract class BasicHud {
+/**
+ * Represents a HUD element in OneConfig.
+ * A HUD element can be used to display useful information to the user, like FPS or CPS.
+ * <p>
+ * If you simply want to display text, extend {@link SingleTextHud} or {@link MultiTextHud},
+ * whichever applies to the use case. Then, override the required methods.
+ * <p>
+ * 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.
+ * </p>
+ * <p>
+ * It should also be noted that additional options to the HUD can be added simply by declaring them.
+ * <pre>{@code
+ * public class TestHud extends SingleTextHud {
+ * @literal @Switch(
+ * name = "Additional Option"
+ * )
+ * public boolean additionalOption = true;
+ * }
+ * }</pre>
+ * </p>
+ * To register an element, add it to your OneConfig {@link Config}.
+ * <pre>{@code
+ * * public class YourConfig extends Config {
+ * * @literal @HUD(
+ * * name = "HUD Element"
+ * * )
+ * * public YourHudElement hudElement = new YourHudElement(false);
+ * * }
+ * * }</pre>
+ */
+public abstract class Hud {
public boolean enabled;
public boolean rounded;
public boolean border;
@@ -16,9 +47,9 @@ public abstract class BasicHud {
public float scale;
public float paddingX;
public float paddingY;
- public BasicHud parent;
- public BasicHud childRight;
- public BasicHud childBottom;
+ public Hud parent;
+ public Hud childRight;
+ public Hud childBottom;
/**
* @param enabled If the hud is enabled
@@ -34,7 +65,7 @@ public abstract class BasicHud {
* @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) {
+ 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;
@@ -57,7 +88,7 @@ public abstract class BasicHud {
* @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) {
+ 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));
}
@@ -66,14 +97,14 @@ public abstract class BasicHud {
* @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) {
+ 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 BasicHud(boolean 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));
}
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<String> getLines();
+
+ public List<String> 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<String> getLines();
+ public TextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
}