diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
5 files changed, 34 insertions, 20 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 3ca029e..8a5608e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -139,7 +139,7 @@ public class Config { if (optionPage.location() == PageLocation.TOP) subcategory.topButtons.add(button); else subcategory.bottomButtons.add(button); } else if (field.isAnnotationPresent(HUD.class)) { - HUDUtils.addHudOptions(page, field, instance); + HUDUtils.addHudOptions(page, field, instance, this); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index f5b1d3f..fc90c01 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -1,13 +1,13 @@ package cc.polyfrost.oneconfig.gui; -import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; import cc.polyfrost.oneconfig.hud.Hud; +import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; import cc.polyfrost.oneconfig.internal.hud.HudCore; -import cc.polyfrost.oneconfig.libs.universal.UResolution; -import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +44,7 @@ public class HudGui extends UScreen implements GuiPause { } for (Hud hud : HudCore.huds) { - if (hud.enabled) processHud(matrixStack, hud, mouseX); + if (hud.isEnabled()) processHud(matrixStack, hud, mouseX); } } @@ -128,7 +128,7 @@ public class HudGui extends UScreen implements GuiPause { float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; ArrayList<Float> verticalLines = new ArrayList<>(); for (Hud hud : HudCore.huds) { - if (!hud.enabled) continue; + if (!hud.isEnabled()) continue; verticalLines.addAll(getXSnappingHud(hud)); } getSpaceSnapping(verticalLines); @@ -167,7 +167,7 @@ public class HudGui extends UScreen implements GuiPause { float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; ArrayList<Float> horizontalLines = new ArrayList<>(); for (Hud hud : HudCore.huds) { - if (!hud.enabled) continue; + if (!hud.isEnabled()) continue; horizontalLines.addAll(getYSnappingHud(hud)); } getSpaceSnapping(horizontalLines); @@ -229,7 +229,7 @@ public class HudGui extends UScreen implements GuiPause { } editingHud = null; for (Hud hud : HudCore.huds) { - if (!hud.enabled) continue; + if (!hud.isEnabled()) continue; if (mouseClickedHud(hud, (int) mouseX, (int) mouseY)) break; } 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; * * }</pre> */ 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" ) 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 2bbd3b7..31604ed 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java @@ -15,8 +15,8 @@ public class HudCore { public void onRender(HudRenderEvent event) { if (editing) return; for (Hud hud : huds) { - if (hud.enabled) - hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); + if (!hud.isEnabled()) continue; + hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); } } } |