aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-06 18:20:23 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-06 18:20:23 +0200
commit21d31344a151dfe94c79a20b503af55120c63b63 (patch)
tree6bae89e3532b2ed976a493ff8d6b5b7bfed94221 /src/main/java/cc/polyfrost/oneconfig/config
parent462d5976f3654f40229ff61391e7e55d0819d82d (diff)
downloadOneConfig-21d31344a151dfe94c79a20b503af55120c63b63.tar.gz
OneConfig-21d31344a151dfe94c79a20b503af55120c63b63.tar.bz2
OneConfig-21d31344a151dfe94c79a20b503af55120c63b63.zip
rewrite config system
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java101
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java26
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Header.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Info.java25
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java85
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java26
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java28
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java14
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java81
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java35
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java15
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java)4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java2
22 files changed, 371 insertions, 235 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index 2c51387..de6c575 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -1,24 +1,19 @@
package cc.polyfrost.oneconfig.config;
-import cc.polyfrost.oneconfig.config.annotations.ConfigPage;
-import cc.polyfrost.oneconfig.config.annotations.Option;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
-import cc.polyfrost.oneconfig.internal.config.ConfigCore;
+import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.config.data.*;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
-import cc.polyfrost.oneconfig.config.elements.OptionCategory;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
-import cc.polyfrost.oneconfig.config.elements.OptionSubcategory;
import cc.polyfrost.oneconfig.config.profiles.Profiles;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
-import cc.polyfrost.oneconfig.gui.elements.config.*;
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
-import cc.polyfrost.oneconfig.hud.BasicHud;
-import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import com.google.gson.*;
import java.io.*;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
@@ -87,89 +82,11 @@ public class Config {
* @param migrate whether the migrator should be run
*/
protected void generateOptionList(Object instance, OptionPage page, Mod mod, boolean migrate) {
- Class<?> clazz = instance.getClass();
- for (Field field : clazz.getDeclaredFields()) {
- String pagePrefix = page.equals(mod.defaultPage) ? "" : page.name + ".";
- if (!field.isAnnotationPresent(Option.class) && !field.isAnnotationPresent(ConfigPage.class)) {
- processCustomOption(field, page);
- continue;
- } else if (field.isAnnotationPresent(ConfigPage.class)) {
- ConfigPage option = field.getAnnotation(ConfigPage.class);
- if (!page.categories.containsKey(option.category()))
- page.categories.put(option.category(), new OptionCategory());
- OptionCategory category = page.categories.get(option.category());
- if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory()))
- category.subcategories.add(new OptionSubcategory(option.subcategory()));
- OptionSubcategory subcategory = category.subcategories.get(category.subcategories.size() - 1);
- OptionPage newPage = new OptionPage(option.name(), mod);
- try {
- field.setAccessible(true);
- Object object = field.get(clazz);
- generateOptionList(object, newPage, mod, migrate);
- ConfigPageButton configPageButton = new ConfigPageButton(field, instance, option.name(), option.description(), newPage);
- switch (option.location()) {
- case TOP:
- subcategory.topButtons.add(configPageButton);
- break;
- case BOTTOM:
- subcategory.bottomButtons.add(configPageButton);
- break;
- }
- optionNames.put(pagePrefix + field.getName(), configPageButton);
- } catch (IllegalAccessException ignored) {
- }
- continue;
- }
- Option option = field.getAnnotation(Option.class);
- if (!page.categories.containsKey(option.category()))
- page.categories.put(option.category(), new OptionCategory());
- OptionCategory category = page.categories.get(option.category());
- if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory()))
- category.subcategories.add(new OptionSubcategory(option.subcategory()));
- if (migrate) {
- try {
- Object value = mod.migrator.getValue(field, option.name(), option.category(), option.subcategory());
- if (value != null) {
- field.setAccessible(true);
- field.set(instance, value);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options;
- if (option.type() == OptionType.HUD) {
- try {
- field.setAccessible(true);
- BasicHud hud = (BasicHud) field.get(instance);
- HudCore.huds.add(hud);
- options.add(new ConfigHeader(field, hud, option.name(), 1));
- options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1));
- options.addAll(ConfigUtils.getClassOptions(hud));
- options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
- options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded);
- options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
- options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- } catch (IllegalAccessException | NoSuchFieldException e) {
- e.printStackTrace();
- }
- } else {
- options.add(ConfigUtils.getOption(option, field, instance));
- }
- if (!option.type().equals(OptionType.HUD))
- optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1));
+ for (Field field : instance.getClass().getDeclaredFields()) {
+ Option option = ConfigUtils.findAnnotation(field, Option.class);
+ if (option != null)
+ ConfigUtils.addOptionToPage(page, option, field, instance, migrate ? mod.migrator : null);
+ // TODO: Make dependencies work, pages, hud
}
}
@@ -227,6 +144,6 @@ public class Config {
*/
protected void addDependency(String option, Supplier<Boolean> condition) {
if (!optionNames.containsKey(option)) return;
- optionNames.get(option).setDependency(condition);
+ optionNames.get(option).addDependency(condition);
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java
new file mode 100644
index 0000000..300651f
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java
@@ -0,0 +1,24 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.BUTTON)
+public @interface Button {
+ String name();
+
+ String text();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java
new file mode 100644
index 0000000..eae35e4
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java
@@ -0,0 +1,22 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.CHECKBOX)
+public @interface Checkbox {
+ String name();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java
new file mode 100644
index 0000000..98cc5ec
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java
@@ -0,0 +1,22 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.COLOR)
+public @interface Color {
+ String name();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java
new file mode 100644
index 0000000..1fbf162
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java
@@ -0,0 +1,24 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.DROPDOWN)
+public @interface Dropdown {
+ String name();
+
+ String[] options();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java
new file mode 100644
index 0000000..f01d074
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java
@@ -0,0 +1,26 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.DUAL_OPTION)
+public @interface DualOption {
+ String name();
+
+ String left();
+
+ String right();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Header.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Header.java
new file mode 100644
index 0000000..3821a01
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Header.java
@@ -0,0 +1,22 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.HEADER)
+public @interface Header {
+ String text();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Info.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Info.java
new file mode 100644
index 0000000..3f058ed
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Info.java
@@ -0,0 +1,25 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.InfoType;
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.INFO)
+public @interface Info {
+ String text();
+
+ InfoType type();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java
new file mode 100644
index 0000000..7d6cfdc
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java
@@ -0,0 +1,22 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.KEYBIND)
+public @interface KeyBind {
+ String name();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java
deleted file mode 100644
index f30f01e..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package cc.polyfrost.oneconfig.config.annotations;
-
-import cc.polyfrost.oneconfig.config.data.InfoType;
-import cc.polyfrost.oneconfig.config.data.OptionType;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface Option {
- /**
- * The name of the option that will be displayed to the user
- */
- String name();
-
- /**
- * The type of the option
- */
- OptionType type();
-
- /**
- * The category of the component
- */
- String category() default "General";
-
- /**
- * The subcategory of the component (displayed as header)
- */
- String subcategory() default "";
-
- /**
- * The width of the option (1 = half width, 2 = full width)
- */
- int size() default 1;
-
- /**
- * A String array of all the possible values for the UniSelector, dropdownList, and ComboBox.
- * Also used in the DualOption slider, index 0 is the left, index 1 is the right; for example:
- * {"Option 1", "Option 2"}
- */
- String[] options() default {};
-
- /**
- * The placeholder in the text field
- */
- String placeholder() default "";
-
- /**
- * If the text field is secure or not
- */
- boolean secure() default false;
-
- /**
- * If the text field is multi line or not
- */
- boolean multiLine() default false;
-
- /**
- * Minimum value of slider
- */
- float min() default 0;
-
- /**
- * The maximum value of the slider
- */
- float max() default 0;
-
- /**
- * Steps of slider (0 for no steps)
- */
- int step() default 0;
-
- /**
- * Option for info option type
- */
- InfoType infoType() default InfoType.INFO;
-
- /**
- * Text displayed inside button
- */
- String buttonText() default "Activate";
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java
new file mode 100644
index 0000000..144d329
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java
@@ -0,0 +1,26 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.SLIDER)
+public @interface Slider {
+ String name();
+
+ float min();
+
+ float max();
+
+ int step() default 0;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java
new file mode 100644
index 0000000..d3b8e80
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java
@@ -0,0 +1,22 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.SWITCH)
+public @interface Switch {
+ String name();
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java
new file mode 100644
index 0000000..90e5779
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java
@@ -0,0 +1,28 @@
+package cc.polyfrost.oneconfig.config.annotations;
+
+import cc.polyfrost.oneconfig.config.data.OptionType;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Option(type = OptionType.TEXT)
+public @interface Text {
+ String name();
+
+ String placeholder() default "";
+
+ boolean secure() default false;
+
+ boolean multiline() default false;
+
+ int size() default 1;
+
+ String category() default "General";
+
+ String subcategory() default "";
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java
index 3b0fcd6..a34b792 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.config.compatibility.vigilance;
-import cc.polyfrost.oneconfig.internal.config.ConfigCore;
+import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.elements.OptionCategory;
@@ -55,7 +55,7 @@ public class VigilanceConfig extends Config {
}
private void generateOptionsList(OptionPage page) {
- for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) {
+ /*for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) {
PropertyAttributesExt attributes = option.getAttributesExt();
if (attributes.getHidden()) continue;
if (!page.categories.containsKey(getCategory(attributes)))
@@ -66,7 +66,7 @@ public class VigilanceConfig extends Config {
ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options;
switch (attributes.getType()) {
case SWITCH:
- options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2));
+ options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), "", "", 2));
break;
case CHECKBOX:
options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2));
@@ -97,7 +97,7 @@ public class VigilanceConfig extends Config {
if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) {
optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1));
}
- }
+ }*/
}
private Field getFieldOfProperty(PropertyData data) {
@@ -163,11 +163,11 @@ public class VigilanceConfig extends Config {
public void addDependency(PropertyData property, PropertyData dependency) {
BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt()));
if (option != null) {
- option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true));
+ option.addDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true));
}
}
- private static class CompatConfigColorElement extends ConfigColorElement {
+ /*private static class CompatConfigColorElement extends ConfigColorElement {
private final Field color;
private Color prevColor = null;
private OneColor cachedColor = null;
@@ -198,5 +198,5 @@ public class VigilanceConfig extends Config {
}
}
}
- }
+ }*/
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java
index e4b042a..8417ad8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.config.annotations;
+package cc.polyfrost.oneconfig.config.compatibility.vigilance;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
index d44488d..2002b01 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
@@ -1,9 +1,15 @@
package cc.polyfrost.oneconfig.config.core;
-import cc.polyfrost.oneconfig.config.annotations.Option;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
+import cc.polyfrost.oneconfig.config.elements.OptionCategory;
+import cc.polyfrost.oneconfig.config.elements.OptionPage;
+import cc.polyfrost.oneconfig.config.elements.OptionSubcategory;
+import cc.polyfrost.oneconfig.config.migration.Migrator;
import cc.polyfrost.oneconfig.gui.elements.config.*;
+import cc.polyfrost.oneconfig.internal.config.annotations.Option;
+import org.jetbrains.annotations.Nullable;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -11,38 +17,69 @@ public class ConfigUtils {
public static BasicOption getOption(Option option, Field field, Object instance) {
switch (option.type()) {
case SWITCH:
- return new ConfigSwitch(field, instance, option.name(), option.size());
+ return ConfigSwitch.create(field, instance);
case CHECKBOX:
- return new ConfigCheckbox(field, instance, option.name(), option.size());
- case TEXT:
- return new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine());
- case DUAL_OPTION:
- return new ConfigDualOption(field, instance, option.name(), option.size(), option.options());
- case DROPDOWN:
- return new ConfigDropdown(field, instance, option.name(), option.size(), option.options());
- case SLIDER:
- return new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step());
+ return ConfigCheckbox.create(field, instance);
case INFO:
- return new ConfigInfo(field, instance, option.name(), option.size(), option.infoType());
- case COLOR:
- return new ConfigColorElement(field, instance, option.name(), option.size());
+ return ConfigInfo.create(field, instance);
case HEADER:
- return new ConfigHeader(field, instance, option.name(), option.size());
+ return ConfigHeader.create(field, instance);
+ case COLOR:
+ return ConfigColorElement.create(field, instance);
+ case DROPDOWN:
+ return ConfigDropdown.create(field, instance);
+ case TEXT:
+ return ConfigTextBox.create(field, instance);
case BUTTON:
- return new ConfigButton(field, instance, option.name(), option.size(), option.buttonText());
+ return ConfigButton.create(field, instance);
+ case SLIDER:
+ return ConfigSlider.create(field, instance);
case KEYBIND:
- return new ConfigKeyBind(field, instance, option.name(), option.size());
+ return ConfigKeyBind.create(field, instance);
+ case DUAL_OPTION:
+ return ConfigDualOption.create(field, instance);
}
return null;
}
- public static ArrayList<BasicOption> getClassOptions(Object hud) {
+ public static ArrayList<BasicOption> getClassOptions(Object object) {
ArrayList<BasicOption> options = new ArrayList<>();
- for (Field field : hud.getClass().getDeclaredFields()) {
- if (!field.isAnnotationPresent(Option.class)) continue;
- Option option = field.getAnnotation(Option.class);
- options.add(getOption(option, field, hud));
+ for (Field field : object.getClass().getDeclaredFields()) {
+ Option option = findAnnotation(field, Option.class);
+ if (option == null) continue;
+ options.add(getOption(option, field, object));
}
return options;
}
+
+ public static void addOptionToPage(OptionPage page, Option option, Field field, Object instance, @Nullable Migrator migrator) {
+ BasicOption configOption = getOption(option, field, instance);
+ if (configOption == null) return;
+ if (migrator != null) {
+ Object value = migrator.getValue(field, configOption.name, configOption.category, configOption.subcategory);
+ if (value != null) {
+ try {
+ field.set(instance, value);
+ } catch (IllegalAccessException ignored) {
+ }
+ }
+ }
+ getOptions(page, configOption.category, configOption.subcategory).add(configOption);
+ }
+
+ public static ArrayList<BasicOption> getOptions(OptionPage page, String categoryName, String subcategoryName) {
+ if (!page.categories.containsKey(categoryName)) page.categories.put(categoryName, new OptionCategory());
+ OptionCategory category = page.categories.get(categoryName);
+ if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(subcategoryName))
+ category.subcategories.add(new OptionSubcategory(subcategoryName));
+ return category.subcategories.get(category.subcategories.size() - 1).options;
+ }
+
+ public static <T extends Annotation> T findAnnotation(Field field, Class<T> annotationType) {
+ for (Annotation ann : field.getDeclaredAnnotations()) {
+ if (ann.annotationType().isAnnotationPresent(annotationType))
+ return ann.annotationType().getAnnotation(annotationType);
+ }
+ return null;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
index 090d1f8..ca931b7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
@@ -2,7 +2,7 @@ package cc.polyfrost.oneconfig.config.data;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
-import cc.polyfrost.oneconfig.config.migration.vigilance.Migrator;
+import cc.polyfrost.oneconfig.config.migration.Migrator;
import org.jetbrains.annotations.Nullable;
public class Mod {
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index d4efeaa..947156a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -1,15 +1,18 @@
package cc.polyfrost.oneconfig.config.elements;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.function.Supplier;
@SuppressWarnings({"unused"})
public abstract class BasicOption {
public final int size;
protected final Field field;
- protected final String name;
protected final Object parent;
- private Supplier<Boolean> dependency;
+ public final String name;
+ public final String category;
+ public final String subcategory;
+ private final ArrayList<Supplier<Boolean>> dependencies = new ArrayList<>();
/**
* Initialize option
@@ -19,11 +22,13 @@ public abstract class BasicOption {
* @param name name of option
* @param size size of option, 0 for single column, 1 for double.
*/
- public BasicOption(Field field, Object parent, String name, int size) {
+ public BasicOption(Field field, Object parent, String name, String category, String subcategory, int size) {
this.field = field;
this.parent = parent;
this.name = name;
this.size = size;
+ this.category = category;
+ this.subcategory = subcategory;
if (field != null) field.setAccessible(true);
}
@@ -78,21 +83,21 @@ public abstract class BasicOption {
}
/**
- * @return If the component has an option to render at half size
+ * Add a condition to this option
+ *
+ * @param supplier The dependency
*/
- public boolean hasHalfSize() {
- return true;
- }
-
- public String getName() {
- return name;
- }
-
- public void setDependency(Supplier<Boolean> supplier) {
- this.dependency = supplier;
+ public void addDependency(Supplier<Boolean> supplier) {
+ this.dependencies.add(supplier);
}
+ /**
+ * @return If the option is enabled, based on the dependencies
+ */
protected boolean isEnabled() {
- return dependency == null || dependency.get();
+ for (Supplier<Boolean> dependency : dependencies) {
+ if (!dependency.get()) return false;
+ }
+ return true;
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
index ff1d770..66714a4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
@@ -1,7 +1,6 @@
package cc.polyfrost.oneconfig.config.elements;
-import cc.polyfrost.oneconfig.gui.Colors;
-import cc.polyfrost.oneconfig.config.elements.BasicOption;
+import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
import cc.polyfrost.oneconfig.renderer.RenderManager;
@@ -31,14 +30,14 @@ public class OptionSubcategory {
filteredTop.clear();
filteredBottom.clear();
for (BasicOption option : options) {
- if (option.getName().toLowerCase().contains(filter)) filteredOptions.add(option);
+ if (option.name.toLowerCase().contains(filter)) filteredOptions.add(option);
}
for (ConfigPageButton page : topButtons) {
- if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
+ if (page.name.toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
filteredTop.add(page);
}
for (ConfigPageButton page : bottomButtons) {
- if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
+ if (page.name.toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
filteredBottom.add(page);
}
}
@@ -60,7 +59,7 @@ public class OptionSubcategory {
BasicOption option = filteredOptions.get(i);
if (i + 1 < filteredOptions.size()) {
BasicOption nextOption = filteredOptions.get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
+ if (option.size == 1 && nextOption.size == 1) {
backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
i++;
continue;
@@ -79,7 +78,7 @@ public class OptionSubcategory {
option.draw(vg, x, optionY);
if (i + 1 < filteredOptions.size()) {
BasicOption nextOption = filteredOptions.get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
+ if (option.size == 1 && nextOption.size == 1) {
nextOption.draw(vg, x + 512, optionY);
optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
i++;
@@ -105,7 +104,7 @@ public class OptionSubcategory {
option.drawLast(vg, x, drawLastY);
if (i + 1 < filteredOptions.size()) {
BasicOption nextOption = filteredOptions.get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
+ if (option.size == 1 && nextOption.size == 1) {
nextOption.drawLast(vg, x + 512, drawLastY);
drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
i++;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java
index f3f60b7..abfb2a0 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.config.migration.vigilance;
+package cc.polyfrost.oneconfig.config.migration;
import java.lang.reflect.Field;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java
index 2870e03..4a9cd3b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java
@@ -1,6 +1,6 @@
-package cc.polyfrost.oneconfig.config.migration.vigilance;
+package cc.polyfrost.oneconfig.config.migration;
-import cc.polyfrost.oneconfig.config.annotations.VigilanceName;
+import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceName;
import java.io.BufferedReader;
import java.io.FileReader;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
index 2b0a97e..07ce53e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.config.profiles;
import cc.polyfrost.oneconfig.internal.OneConfig;
-import cc.polyfrost.oneconfig.internal.config.ConfigCore;
+import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import org.apache.commons.io.FileUtils;