From 76c85b82bd0dba4dfdffc136a4d4f8cb45cb45f3 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:33:26 +0200 Subject: hud stuff --- .../java/cc/polyfrost/oneconfig/hud/HUDUtils.java | 20 +++++++++++--------- src/main/java/cc/polyfrost/oneconfig/hud/Hud.java | 14 +++++++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/hud') diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java index e91a7ce..a67177c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.hud; +import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.annotations.HUD; import cc.polyfrost.oneconfig.config.core.ConfigUtils; import cc.polyfrost.oneconfig.config.elements.BasicOption; @@ -11,10 +12,11 @@ import java.lang.reflect.Field; import java.util.ArrayList; public class HUDUtils { - public static void addHudOptions(OptionPage page, Field field, Object instance) { + public static void addHudOptions(OptionPage page, Field field, Object instance, Config config) { HUD hudAnnotation = field.getAnnotation(HUD.class); Hud hud = (Hud) ConfigUtils.getField(field, instance); if (hud == null) return; + hud.setConfig(config); HudCore.huds.add(hud); String category = hudAnnotation.category(); String subcategory = hudAnnotation.subcategory(); @@ -24,21 +26,21 @@ public class HUDUtils { options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", category, subcategory, 2)); options.addAll(ConfigUtils.getClassOptions(hud)); options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", category, subcategory, 1)); - options.get(options.size() - 1).addDependency(() -> hud.enabled); + options.get(options.size() - 1).addDependency(hud::isEnabled); options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", category, subcategory, 1)); - options.get(options.size() - 1).addDependency(() -> hud.enabled); + options.get(options.size() - 1).addDependency(hud::isEnabled); options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", category, subcategory, 1, true)); - options.get(options.size() - 1).addDependency(() -> hud.enabled); + options.get(options.size() - 1).addDependency(hud::isEnabled); options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", category, subcategory, 1, true)); - options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.border); + options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border); options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0)); - options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.rounded); + options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.rounded); options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0)); - options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.border); + options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border); options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0)); - options.get(options.size() - 1).addDependency(() -> hud.enabled); + options.get(options.size() - 1).addDependency(hud::isEnabled); options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0)); - options.get(options.size() - 1).addDependency(() -> hud.enabled); + options.get(options.size() - 1).addDependency(hud::isEnabled); } catch (NoSuchFieldException ignored) { } } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java index 982bee9..2d6c451 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java @@ -39,7 +39,8 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * * } */ public abstract class Hud { - public boolean enabled; + private boolean enabled; + transient private Config config; public boolean rounded; public boolean border; public OneColor bgColor; @@ -236,6 +237,17 @@ public abstract class Hud { return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale)); } + /** + * @return If the hud is enabled + */ + public boolean isEnabled() { + return enabled && (config == null || config.enabled); + } + + public void setConfig(Config config) { + this.config = config; + } + @Switch( name = "Show in Chat" ) -- cgit