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 --- api/OneConfig.api | 13 ++++++++++--- gradle.properties | 2 +- .../java/cc/polyfrost/oneconfig/config/Config.java | 2 +- src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java | 14 +++++++------- .../java/cc/polyfrost/oneconfig/hud/HUDUtils.java | 20 +++++++++++--------- src/main/java/cc/polyfrost/oneconfig/hud/Hud.java | 14 +++++++++++++- .../cc/polyfrost/oneconfig/internal/hud/HudCore.java | 4 ++-- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/api/OneConfig.api b/api/OneConfig.api index 55cd208..304003f 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -1,5 +1,6 @@ public class cc/polyfrost/oneconfig/config/Config { protected final field configFile Ljava/lang/String; + protected final field defaults Ljava/util/HashMap; public field enabled Z protected final field gson Lcom/google/gson/Gson; public field hasBeenInitialized Z @@ -15,6 +16,7 @@ public class cc/polyfrost/oneconfig/config/Config { protected fun deserializePart (Lcom/google/gson/JsonObject;Ljava/lang/Object;)V protected fun generateOptionList (Ljava/lang/Object;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)V protected fun getCustomOption (Ljava/lang/reflect/Field;Lcc/polyfrost/oneconfig/config/annotations/CustomOption;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)Lcc/polyfrost/oneconfig/config/elements/BasicOption; + public fun getDefault (Ljava/lang/reflect/Field;)Ljava/lang/Object; protected fun hideIf (Ljava/lang/String;Ljava/lang/String;)V protected fun hideIf (Ljava/lang/String;Ljava/util/function/Supplier;)V protected fun hideIf (Ljava/lang/String;Z)V @@ -22,7 +24,7 @@ public class cc/polyfrost/oneconfig/config/Config { public fun load ()V public fun openGui ()V protected fun registerKeyBind (Lcc/polyfrost/oneconfig/config/core/OneKeyBind;Ljava/lang/Runnable;)V - public fun reset ()Z + public fun reset ()V public fun save ()V } @@ -281,12 +283,14 @@ public abstract class cc/polyfrost/oneconfig/config/elements/BasicOption { public fun isEnabled ()Z public fun isHidden ()Z public fun keyTyped (CI)V + public fun reset (Lcc/polyfrost/oneconfig/config/Config;)V protected fun set (Ljava/lang/Object;)V } public class cc/polyfrost/oneconfig/config/elements/OptionCategory { public final field subcategories Ljava/util/ArrayList; public fun ()V + public fun reset (Lcc/polyfrost/oneconfig/config/Config;)V } public class cc/polyfrost/oneconfig/config/elements/OptionPage { @@ -294,6 +298,7 @@ public class cc/polyfrost/oneconfig/config/elements/OptionPage { public final field mod Lcc/polyfrost/oneconfig/config/data/Mod; public final field name Ljava/lang/String; public fun (Ljava/lang/String;Lcc/polyfrost/oneconfig/config/data/Mod;)V + public fun reset (Lcc/polyfrost/oneconfig/config/Config;)V } public class cc/polyfrost/oneconfig/config/elements/OptionSubcategory { @@ -304,6 +309,7 @@ public class cc/polyfrost/oneconfig/config/elements/OptionSubcategory { public fun draw (JII)I public fun drawLast (JI)V public fun getName ()Ljava/lang/String; + public fun reset (Lcc/polyfrost/oneconfig/config/Config;)V } public class cc/polyfrost/oneconfig/config/gson/ExclusionUtils { @@ -839,7 +845,7 @@ public abstract class cc/polyfrost/oneconfig/gui/pages/Page { public class cc/polyfrost/oneconfig/hud/HUDUtils { public fun ()V - public static fun addHudOptions (Lcc/polyfrost/oneconfig/config/elements/OptionPage;Ljava/lang/reflect/Field;Ljava/lang/Object;)V + public static fun addHudOptions (Lcc/polyfrost/oneconfig/config/elements/OptionPage;Ljava/lang/reflect/Field;Ljava/lang/Object;Lcc/polyfrost/oneconfig/config/Config;)V } public abstract class cc/polyfrost/oneconfig/hud/Hud { @@ -848,7 +854,6 @@ public abstract class cc/polyfrost/oneconfig/hud/Hud { public field borderColor Lcc/polyfrost/oneconfig/config/core/OneColor; public field borderSize F public field cornerRadius F - public field enabled Z public field paddingX F public field paddingY F public field rounded Z @@ -873,6 +878,8 @@ public abstract class cc/polyfrost/oneconfig/hud/Hud { public abstract fun getWidth (F)I public fun getXScaled (I)F public fun getYScaled (I)F + public fun isEnabled ()Z + public fun setConfig (Lcc/polyfrost/oneconfig/config/Config;)V } public abstract class cc/polyfrost/oneconfig/hud/SingleTextHud : cc/polyfrost/oneconfig/hud/TextHud { diff --git a/gradle.properties b/gradle.properties index de53850..5441beb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ mod_name = OneConfig mod_id = oneconfig -mod_version = 0.1.0-alpha43 +mod_version = 0.1.0-alpha45 essential.defaults.loom=0 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 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 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; * * } */ 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); } } } -- cgit