aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/hud
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-07-04 15:33:26 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-07-04 15:33:26 +0200
commit76c85b82bd0dba4dfdffc136a4d4f8cb45cb45f3 (patch)
tree6f8cf9be5e0bfd672b92ad0bc87b3c40ff1ada36 /src/main/java/cc/polyfrost/oneconfig/hud
parent5c51b22ee6ebd2b286603ff2f0dc5799963ab4c3 (diff)
downloadOneConfig-76c85b82bd0dba4dfdffc136a4d4f8cb45cb45f3.tar.gz
OneConfig-76c85b82bd0dba4dfdffc136a4d4f8cb45cb45f3.tar.bz2
OneConfig-76c85b82bd0dba4dfdffc136a4d4f8cb45cb45f3.zip
hud stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/hud')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java20
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Hud.java14
2 files changed, 24 insertions, 10 deletions
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"
)