aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java17
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java18
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java18
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java42
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java22
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/data/Mod.java (renamed from src/main/java/io/polyfrost/oneconfig/config/data/ModData.java)5
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java6
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java (renamed from src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java)4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java101
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java10
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java26
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java (renamed from src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java)15
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigButton.java36
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigCategory.java24
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigColor.java24
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSelector.java26
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSlider.java28
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSwitch.java22
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigText.java26
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java32
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/PerformanceModsPage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestConfig.java36
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestPage.java14
32 files changed, 215 insertions, 471 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index f3668d8..658536a 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -3,7 +3,7 @@ package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.config.core.ConfigCore;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.test.TestConfig;
@@ -11,7 +11,6 @@ import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
-import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -23,7 +22,7 @@ import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
-@Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
+@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
private static final Minecraft mc = Minecraft.getMinecraft();
public static File jarFile;
@@ -31,10 +30,10 @@ public class OneConfig {
public static File themesDir = new File(oneConfigDir, "themes/");
public static OneConfigConfig config;
public static TestConfig testConfig;
- public static List<ModData> loadedMods = new ArrayList<>();
+ public static List<Mod> loadedMods = new ArrayList<>();
public static List<ModMetadata> loadedOtherMods = new ArrayList<>();
- @Mod.EventHandler
+ @net.minecraftforge.fml.common.Mod.EventHandler
public void onPreFMLInit(FMLPreInitializationEvent event) {
jarFile = event.getSourceFile();
oneConfigDir.mkdirs();
@@ -42,7 +41,7 @@ public class OneConfig {
config = new OneConfigConfig();
}
- @Mod.EventHandler
+ @net.minecraftforge.fml.common.Mod.EventHandler
public void onFMLInitialization(FMLInitializationEvent event) {
testConfig = new TestConfig();
ClientCommandHandler.instance.registerCommand(new OneConfigCommand());
@@ -50,19 +49,19 @@ public class OneConfig {
MinecraftForge.EVENT_BUS.register(new HudCore());
}
- @Mod.EventHandler
+ @net.minecraftforge.fml.common.Mod.EventHandler
public void onPostFMLInit(FMLPostInitializationEvent event) {
reloadModsList();
}
public static void reloadModsList() {
loadedMods.addAll(ConfigCore.settings.keySet());
- LinkedHashSet<ModData> modData = new LinkedHashSet<>(ConfigCore.settings.keySet());
+ LinkedHashSet<Mod> modData = new LinkedHashSet<>(ConfigCore.settings.keySet());
for (ModContainer mod : Loader.instance().getActiveModList()) {
ModMetadata metadata = mod.getMetadata();
loadedOtherMods.add(metadata);
String author = metadata.authorList.size() > 0 ? metadata.authorList.get(0) : "";
- ModData newMod = new ModData(metadata.name, ModType.OTHER, author, metadata.version);
+ Mod newMod = new Mod(metadata.name, ModType.OTHER, author, metadata.version);
if (newMod.name.equals("Minecraft Coder Pack") || newMod.name.equals("Forge Mod Loader") || newMod.name.equals("Minecraft Forge")) { // TODO add oneconfig
continue;
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
index bfb123a..f10111c 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
@@ -1,7 +1,7 @@
package io.polyfrost.oneconfig.config;
import com.google.gson.JsonParser;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.interfaces.Config;
import java.awt.*;
@@ -48,7 +48,7 @@ public class OneConfigConfig extends Config {
}
@Override
- public void init(ModData modData) {
+ public void init(Mod mod) {
if (new File("OneConfig/" + configFile).exists()) load();
else save();
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java
deleted file mode 100644
index 3ba1078..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 Button {
- String name();
-
- String description() default "";
-
- String text() default "Button";
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java
deleted file mode 100644
index 83b7af4..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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.TYPE)
-public @interface Category {
- String name();
-
- String description() default "";
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java
deleted file mode 100644
index 6854bc2..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 ColorPicker {
- String name();
-
- String description() default "";
-
- boolean allowAlpha() default true;
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java
deleted file mode 100644
index 00a2e74..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 HudComponent {
- String name();
-
- String description() default "";
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
new file mode 100644
index 0000000..8abb303
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
@@ -0,0 +1,42 @@
+package io.polyfrost.oneconfig.config.annotations;
+
+import io.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 page that will be displayed to the user
+ */
+ String name();
+
+ /**
+ * The description of the page that will be displayed to the user
+ */
+ String description() default "";
+
+ /**
+ * 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();
+
+ /**
+ * The width of the option (1 = half width, 2 = full width)
+ */
+ int size() default 1;
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java
deleted file mode 100644
index 00d88d8..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 Selector {
- String name();
-
- String description() default "";
-
- String[] options();
-
- int defaultSelection() default 0;
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java
deleted file mode 100644
index ea19da5..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 Slider {
- String name();
-
- String description() default "";
-
- float min();
-
- float max();
-
- float precision();
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java
deleted file mode 100644
index 8ff2f11..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 Switch {
- String name();
-
- String description() default "";
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java
deleted file mode 100644
index 0df1426..0000000
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package io.polyfrost.oneconfig.config.annotations;
-
-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 TextField {
- String name();
-
- String description() default "";
-
- String placeholder() default "";
-
- boolean hideText() default false;
-
- int size() default 1;
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
index 9bb2e85..9be25e9 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
@@ -1,26 +1,24 @@
package io.polyfrost.oneconfig.config.core;
-import io.polyfrost.oneconfig.config.data.ModData;
-import io.polyfrost.oneconfig.config.interfaces.Option;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.hud.HudCore;
import java.util.ArrayList;
-import java.util.HashMap;
public class ConfigCore {
- public static HashMap<ModData, ArrayList<Option>> settings = new HashMap<>();
+ public static ArrayList<Mod> OneConfigMods = new ArrayList<>();
public static void saveAll() {
- for (ModData modData : settings.keySet()) {
+ for (Mod modData : OneConfigMods) {
modData.config.save();
}
}
public static void reInitAll() {
- ArrayList<ModData> data = new ArrayList<>(settings.keySet());
- settings.clear();
+ ArrayList<Mod> data = new ArrayList<>(OneConfigMods);
+ OneConfigMods.clear();
HudCore.huds.clear();
- for (ModData modData : data) {
+ for (Mod modData : data) {
modData.config.init(modData);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/ModData.java b/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java
index c5e6633..435fb32 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/data/ModData.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java
@@ -2,12 +2,13 @@ package io.polyfrost.oneconfig.config.data;
import io.polyfrost.oneconfig.config.interfaces.Config;
-public class ModData {
+public class Mod {
public final String name;
public final ModType modType;
public final String creator;
public final String version;
public Config config;
+ public OptionPage defaultPage = new OptionPage("");
/**
* @param name Friendly name of the mod
@@ -15,7 +16,7 @@ public class ModData {
* @param creator Creator of the mod
* @param version Version of the mod
*/
- public ModData(String name, ModType modType, String creator, String version) {
+ public Mod(String name, ModType modType, String creator, String version) {
this.name = name;
this.modType = modType;
this.creator = creator;
diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java
new file mode 100644
index 0000000..021786d
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java
@@ -0,0 +1,20 @@
+package io.polyfrost.oneconfig.config.data;
+
+import io.polyfrost.oneconfig.config.interfaces.BasicOption;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class OptionPage {
+ public final String name;
+ /**
+ * Depth 1 = categories
+ * Depth 2 = subcategories
+ * Depth 3 = list of options
+ */
+ public final HashMap<String, HashMap<String, ArrayList<BasicOption>>> categories = new HashMap<>();
+
+ public OptionPage(String name) {
+ this.name = name;
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java
new file mode 100644
index 0000000..22c92c0
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java
@@ -0,0 +1,6 @@
+package io.polyfrost.oneconfig.config.data;
+
+public enum OptionType {
+ PAGE,
+ SWITCH
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
index bd9c034..42c826e 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
@@ -3,7 +3,7 @@ package io.polyfrost.oneconfig.config.interfaces;
import java.lang.reflect.Field;
@SuppressWarnings({"unused"})
-public abstract class Option {
+public abstract class BasicOption {
protected final Field field;
protected final String name;
protected final String description;
@@ -17,7 +17,7 @@ public abstract class Option {
* @param description description of option
* @param size size of option, 0 for single column, 1 for double.
*/
- public Option(Field field, String name, String description, int size) {
+ public BasicOption(Field field, String name, String description, int size) {
this.field = field;
this.name = name;
this.description = description;
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index f0efcb0..c68162e 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -1,23 +1,20 @@
package io.polyfrost.oneconfig.config.interfaces;
import com.google.gson.*;
-import io.polyfrost.oneconfig.config.annotations.*;
-import io.polyfrost.oneconfig.config.core.ConfigCore;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.annotations.Option;
+import io.polyfrost.oneconfig.config.data.Mod;
+import io.polyfrost.oneconfig.config.data.OptionPage;
import io.polyfrost.oneconfig.config.profiles.Profiles;
-import io.polyfrost.oneconfig.gui.elements.config.*;
-import io.polyfrost.oneconfig.hud.HudCore;
-import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
+import io.polyfrost.oneconfig.gui.elements.config.ConfigPage;
+import io.polyfrost.oneconfig.gui.elements.config.ConfigSwitch;
+import io.polyfrost.oneconfig.test.TestConfig;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
public class Config {
protected final String configFile;
@@ -27,16 +24,16 @@ public class Config {
* @param modData information about the mod
* @param configFile file where config is stored
*/
- public Config(ModData modData, String configFile) {
+ public Config(Mod modData, String configFile) {
this.configFile = configFile;
init(modData);
}
- public void init(ModData modData) {
+ public void init(Mod mod) {
if (Profiles.getProfileFile(configFile).exists()) load();
else save();
- modData.config = this;
- ConfigCore.settings.put(modData, generateOptionList(this.getClass()));
+ mod.config = this;
+ generateOptionList(this.getClass(), mod.defaultPage);
}
/**
@@ -62,63 +59,51 @@ public class Config {
}
/**
- * Generate the option list for internal use only
+ * Generate the option list, for internal use only
*
* @param clazz target class
- * @return list of options
+ * @param page page to add options too
*/
- protected ArrayList<Option> generateOptionList(Class<?> clazz) {
- ArrayList<Option> options = new ArrayList<>();
- for (Class<?> innerClass : clazz.getClasses()) {
- if (innerClass.isAnnotationPresent(Category.class)) {
- Category category = innerClass.getAnnotation(Category.class);
- options.add(new OConfigCategory(category.name(), category.description(), generateOptionList(innerClass), category.size()));
+ protected void generateOptionList(Class<?> clazz, OptionPage page) {
+ for (Field field : clazz.getDeclaredFields()) {
+ System.out.println(field);
+ if (!field.isAnnotationPresent(Option.class)) {
+ processCustomOption(field, page);
+ continue;
}
- }
- for (Field field : clazz.getFields()) {
- if (field.isAnnotationPresent(Button.class)) {
- Button button = field.getAnnotation(Button.class);
- options.add(new OConfigButton(field, button.name(), button.description(), button.text(), button.size()));
- } else if (field.isAnnotationPresent(ColorPicker.class)) {
- ColorPicker colorPicker = field.getAnnotation(ColorPicker.class);
- options.add(new OConfigColor(field, colorPicker.name(), colorPicker.description(), colorPicker.allowAlpha(), colorPicker.size()));
- } else if (field.isAnnotationPresent(Selector.class)) {
- Selector selector = field.getAnnotation(Selector.class);
- options.add(new OConfigSelector(field, selector.name(), selector.description(), selector.options(), selector.defaultSelection(), selector.size()));
- } else if (field.isAnnotationPresent(Slider.class)) {
- Slider slider = field.getAnnotation(Slider.class);
- options.add(new OConfigSlider(field, slider.name(), slider.description(), slider.min(), slider.max(), slider.precision(), slider.size()));
- } else if (field.isAnnotationPresent(Switch.class)) {
- Switch aSwitch = field.getAnnotation(Switch.class);
- options.add(new OConfigSwitch(field, aSwitch.name(), aSwitch.description(), aSwitch.size()));
- } else if (field.isAnnotationPresent(TextField.class)) {
- TextField textField = field.getAnnotation(TextField.class);
- options.add(new OConfigText(field, textField.name(), textField.description(), textField.placeholder(), textField.hideText(), textField.size()));
- } else if (field.isAnnotationPresent(HudComponent.class)) {
- HudComponent hudComponent = field.getAnnotation(HudComponent.class);
- options.add(new OConfigHud(field, hudComponent.name(), hudComponent.description(), hudComponent.size()));
- try {
- Object hud = field.get(BasicHud.class);
- HudCore.huds.add((BasicHud) hud);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- } else {
- Option customOption = processCustomOption(field);
- if (customOption != null) options.add(customOption);
+ Option option = field.getAnnotation(Option.class);
+ if (!page.categories.containsKey(option.category()))
+ page.categories.put(option.category(), new HashMap<>());
+ if (!page.categories.get(option.category()).containsKey(option.subcategory()))
+ page.categories.get(option.category()).put(option.subcategory(), new ArrayList<>());
+ ArrayList<BasicOption> options = page.categories.get(option.category()).get(option.subcategory());
+ switch (option.type()) {
+ case PAGE:
+ OptionPage newPage = new OptionPage(option.name());
+ try {
+ field.setAccessible(true);
+ Object object = field.get(clazz);
+ generateOptionList(object.getClass(), newPage);
+ System.out.println(newPage.categories);
+ options.add(new ConfigPage(field, option.name(), option.description(), option.size(), newPage));
+ } catch (IllegalAccessException e) {
+ continue;
+ }
+ break;
+ case SWITCH:
+ options.add(new ConfigSwitch(field, option.name(), option.description(), option.size()));
+ break;
}
}
- return options;
}
/**
* Overwrite this method to add your own custom option types
*
* @param field target field
- * @return custom option
+ * @param page page to add options too
*/
- protected Option processCustomOption(Field field) {
- return null;
+ protected void processCustomOption(Field field, OptionPage page) {
}
/**
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
index 071a311..09c6aa0 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -2,7 +2,7 @@ package io.polyfrost.oneconfig.gui.elements;
import io.polyfrost.oneconfig.OneConfig;
import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.gui.OneConfigGui;
import io.polyfrost.oneconfig.gui.pages.ModConfigPage;
@@ -19,14 +19,14 @@ import org.lwjgl.nanovg.NanoVG;
public class ModCard extends BasicElement {
private final String iconPath;
- private final ModData modData;
+ private final Mod modData;
private final BasicElement favoriteHitbox = new BasicElement(32, 32, -2, true);
private boolean active, disabled, favorite;
private int colorGray = OneConfigConfig.GRAY_600;
private int colorPrimary = OneConfigConfig.BLUE_600;
private boolean isHoveredMain = false;
- public ModCard(@NotNull ModData mod, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) {
+ public ModCard(@NotNull Mod mod, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) {
super(244, 119, false);
this.modData = mod;
this.iconPath = iconPath;
@@ -83,7 +83,7 @@ public class ModCard extends BasicElement {
public void onClick() {
if (isHoveredMain) {
- for (ModData data : OneConfig.loadedMods) {
+ for (Mod data : OneConfig.loadedMods) {
if (data.modType != ModType.OTHER) {
if (data.name.equalsIgnoreCase(modData.name)) {
OneConfigGui.INSTANCE.openPage(new ModConfigPage(data));
@@ -113,7 +113,7 @@ public class ModCard extends BasicElement {
}
}
- public ModData getModData() {
+ public Mod getModData() {
return modData;
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java
new file mode 100644
index 0000000..c761cd7
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java
@@ -0,0 +1,26 @@
+package io.polyfrost.oneconfig.gui.elements.config;
+
+import io.polyfrost.oneconfig.config.data.OptionPage;
+import io.polyfrost.oneconfig.config.interfaces.BasicOption;
+
+import java.lang.reflect.Field;
+
+public class ConfigPage extends BasicOption {
+ public final OptionPage page;
+
+ public ConfigPage(Field field, String name, String description, int size, OptionPage page) {
+ super(field, name, description, size);
+ this.page = page;
+ }
+
+
+ @Override
+ public void draw(long vg, int x, int y, int mouseX, int mouseY) {
+
+ }
+
+ @Override
+ public int getHeight() {
+ return 0;
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
index 8e36fe9..3da2480 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
@@ -1,22 +1,23 @@
package io.polyfrost.oneconfig.gui.elements.config;
-import io.polyfrost.oneconfig.config.interfaces.Option;
+import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import java.lang.reflect.Field;
-public class OConfigHud extends Option {
+public class ConfigSwitch extends BasicOption {
- public OConfigHud(Field field, String name, String description, int size) {
+ public ConfigSwitch(Field field, String name, String description, int size) {
super(field, name, description, size);
}
- @Override
- public int getHeight() {
- return 0;
- }
@Override
public void draw(long vg, int x, int y, int mouseX, int mouseY) {
}
+
+ @Override
+ public int getHeight() {
+ return 0;
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigButton.java
deleted file mode 100644
index a19cb55..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigButton.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.config.interfaces.Option;
-import io.polyfrost.oneconfig.gui.elements.BasicElement;
-import io.polyfrost.oneconfig.lwjgl.RenderManager;
-import io.polyfrost.oneconfig.lwjgl.font.Fonts;
-
-import java.lang.reflect.Field;
-
-public class OConfigButton extends Option {
- private final String text;
- private final BasicElement element;
-
- public OConfigButton(Field field, String name, String description, String text, int size) {
- super(field, name, description, size);
- this.text = text;
- element = new BasicElement(128, 32, 1, true);
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
- if (size == 0) {
- RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM);
- element.setWidth((int) RenderManager.getTextWidth(vg, text, 12f) + 80);
- element.draw(vg, x + 480 - element.getWidth(), y);
- RenderManager.drawString(vg, text, x + element.getWidth() / 2f, y + 16, OneConfigConfig.WHITE, 12f, Fonts.INTER_MEDIUM);
- // ???
- }
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigCategory.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigCategory.java
deleted file mode 100644
index aa763ef..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigCategory.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.util.List;
-
-public class OConfigCategory extends Option {
- public final List<Option> options;
-
- public OConfigCategory(String name, String description, List<Option> options, int size) {
- super(null, name, description, size);
- this.options = options;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigColor.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigColor.java
deleted file mode 100644
index ed98bd4..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigColor.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.lang.reflect.Field;
-
-public class OConfigColor extends Option {
- private final boolean allowAlpha;
-
- public OConfigColor(Field field, String name, String description, boolean allowAlpha, int size) {
- super(field, name, description, size);
- this.allowAlpha = allowAlpha;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSelector.java
deleted file mode 100644
index 30bb709..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSelector.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.lang.reflect.Field;
-
-public class OConfigSelector extends Option {
- private final String[] options;
- private final int defaultSelection;
-
- public OConfigSelector(Field field, String name, String description, String[] options, int defaultSelection, int size) {
- super(field, name, description, size);
- this.options = options;
- this.defaultSelection = defaultSelection;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSlider.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSlider.java
deleted file mode 100644
index bb3a485..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSlider.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.lang.reflect.Field;
-
-public class OConfigSlider extends Option {
- private final float min;
- private final float max;
- private final float precision;
-
- public OConfigSlider(Field field, String name, String description, float min, float max, float precision, int size) {
- super(field, name, description, size);
- this.min = min;
- this.max = max;
- this.precision = precision;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSwitch.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSwitch.java
deleted file mode 100644
index 753d8f6..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigSwitch.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.lang.reflect.Field;
-
-public class OConfigSwitch extends Option {
-
- public OConfigSwitch(Field field, String name, String description, int size) {
- super(field, name, description, size);
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigText.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigText.java
deleted file mode 100644
index 606d493..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigText.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements.config;
-
-import io.polyfrost.oneconfig.config.interfaces.Option;
-
-import java.lang.reflect.Field;
-
-public class OConfigText extends Option {
- private final String placeholder;
- private final boolean hideText;
-
- public OConfigText(Field field, String name, String description, String placeholder, boolean hideText, int size) {
- super(field, name, description, size);
- this.placeholder = placeholder;
- this.hideText = hideText;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-
- @Override
- public void draw(long vg, int x, int y, int mouseX, int mouseY) {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index 357d684..6d24f4a 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -1,18 +1,16 @@
package io.polyfrost.oneconfig.gui.pages;
import io.polyfrost.oneconfig.config.core.ConfigCore;
-import io.polyfrost.oneconfig.config.data.ModData;
-import io.polyfrost.oneconfig.config.interfaces.Option;
-import io.polyfrost.oneconfig.gui.elements.config.OConfigCategory;
-import org.lwjgl.input.Mouse;
+import io.polyfrost.oneconfig.config.data.Mod;
+import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import java.util.ArrayList;
public class ModConfigPage extends Page {
- private final ModData modData;
- private final ArrayList<Option> options;
+ private final Mod modData;
+ private final ArrayList<BasicOption> options;
- public ModConfigPage(ModData mod) {
+ public ModConfigPage(Mod mod) {
super("Mod: " + mod.name);
this.modData = mod;
options = ConfigCore.settings.get(mod);
@@ -20,21 +18,7 @@ public class ModConfigPage extends Page {
@Override
public void draw(long vg, int x, int y) {
- for (Option option : options) {
- if (option instanceof OConfigCategory) {
- OConfigCategory category = (OConfigCategory) option;
- for (Option subOption : category.options) {
- if (subOption.size == 0) {
- subOption.draw(vg, x, y, Mouse.getX(), Mouse.getY());
- }
- }
- for (Option subOption : category.options) {
- if (subOption.size == 1) {
- subOption.draw(vg, x, y, Mouse.getX(), Mouse.getY());
- }
- }
- }
- }
+
}
@Override
@@ -42,11 +26,11 @@ public class ModConfigPage extends Page {
modData.config.save(); // TODO
}
- public ModData getModData() {
+ public Mod getModData() {
return modData;
}
- protected ArrayList<Option> getOptions() {
+ protected ArrayList<BasicOption> getOptions() {
return options;
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
index 9fc14f7..b45facb 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
@@ -2,7 +2,7 @@ package io.polyfrost.oneconfig.gui.pages;
import io.polyfrost.oneconfig.OneConfig;
import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.gui.elements.BasicButton;
import io.polyfrost.oneconfig.gui.elements.ModCard;
@@ -19,7 +19,7 @@ public class ModsPage extends Page {
public ModsPage() {
super("Mods");
- for (ModData modData : OneConfig.loadedMods) {
+ for (Mod modData : OneConfig.loadedMods) {
modCards.add(new ModCard(modData, null, true, false, false));
}
for (ModCard card : modCards) {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/PerformanceModsPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/PerformanceModsPage.java
index 8dbdea9..43cc423 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/PerformanceModsPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/PerformanceModsPage.java
@@ -2,7 +2,7 @@ package io.polyfrost.oneconfig.gui.pages;
import io.polyfrost.oneconfig.OneConfig;
import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.gui.elements.ModCard;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
@@ -16,7 +16,7 @@ public class PerformanceModsPage extends Page {
public PerformanceModsPage() {
super("Performance Mods");
- for (ModData mod : OneConfig.loadedMods) {
+ for (Mod mod : OneConfig.loadedMods) {
if (mod.modType == ModType.PERFORMANCE) {
modCards.add(new ModCard(mod, null, true, false, false));
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
index 940d9c0..d045df0 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
@@ -1,30 +1,30 @@
package io.polyfrost.oneconfig.test;
-import io.polyfrost.oneconfig.config.annotations.Category;
-import io.polyfrost.oneconfig.config.annotations.HudComponent;
-import io.polyfrost.oneconfig.config.annotations.Switch;
-import io.polyfrost.oneconfig.config.annotations.TextField;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.annotations.Option;
+import io.polyfrost.oneconfig.config.data.Mod;
import io.polyfrost.oneconfig.config.data.ModType;
+import io.polyfrost.oneconfig.config.data.OptionType;
import io.polyfrost.oneconfig.config.interfaces.Config;
public class TestConfig extends Config {
- @Switch(name = "Cool Switch")
- public static boolean toggle = false;
+ @Option(
+ name = "Test switch",
+ description = "Best description",
+ subcategory = "Test",
+ type = OptionType.SWITCH
+ )
+ public static boolean switchTest;
- @Category(name = "Cool Category")
- public static class category {
- @TextField(name = "Cool text field")
- public static String text = "Very cool text";
- }
-
- @HudComponent(name = "text hud")
- public static TestHud testTextHud = new TestHud();
- @HudComponent(name = "text hud v2")
- public static TestHud testTextHud2 = new TestHud();
+ @Option(
+ name = "Test Page",
+ type = OptionType.PAGE,
+ subcategory = "Test"
+ )
+ public static TestPage testPage = new TestPage();
public TestConfig() {
- super(new ModData("hacks", ModType.UTIL_QOL, "ShadyDev", "1.0"), "hacksConfig.json");
+ super(new Mod("hacks", ModType.UTIL_QOL, "ShadyDev", "1.0"), "hacksConfig.json");
}
}
+
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestPage.java b/src/main/java/io/polyfrost/oneconfig/test/TestPage.java
new file mode 100644
index 0000000..93fe201
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestPage.java
@@ -0,0 +1,14 @@
+package io.polyfrost.oneconfig.test;
+
+import io.polyfrost.oneconfig.config.annotations.Option;
+import io.polyfrost.oneconfig.config.data.OptionType;
+
+public class TestPage {
+ @Option(
+ name = "Other test switch",
+ description = "Best description",
+ subcategory = "Test",
+ type = OptionType.SWITCH
+ )
+ public static boolean switchTest;
+}