aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java26
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java11
5 files changed, 35 insertions, 18 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index 70b82a8..8a90857 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -140,9 +140,14 @@ public class Config {
OptionSubcategory subcategory = ConfigUtils.getSubCategory(page, optionPage.category(), optionPage.subcategory());
Object pageInstance = ConfigUtils.getField(field, instance);
if (pageInstance == null) continue;
- OptionPage newPage = new OptionPage(optionPage.name(), mod);
- generateOptionList(pageInstance, newPage, mod, migrate);
- ConfigPageButton button = new ConfigPageButton(field, instance, optionPage.name(), optionPage.description(), optionPage.category(), optionPage.subcategory(), newPage);
+ ConfigPageButton button;
+ if(pageInstance instanceof cc.polyfrost.oneconfig.gui.pages.Page) {
+ button = new ConfigPageButton(field, instance, optionPage.name(), optionPage.description(), optionPage.category(), optionPage.subcategory(), (cc.polyfrost.oneconfig.gui.pages.Page) pageInstance);
+ } else {
+ OptionPage newPage = new OptionPage(optionPage.name(), mod);
+ generateOptionList(pageInstance, newPage, mod, migrate);
+ button = new ConfigPageButton(field, instance, optionPage.name(), optionPage.description(), optionPage.category(), optionPage.subcategory(), newPage);
+ }
if (optionPage.location() == PageLocation.TOP) subcategory.topButtons.add(button);
else subcategory.bottomButtons.add(button);
} else if (field.isAnnotationPresent(HUD.class)) {
@@ -170,6 +175,7 @@ public class Config {
* @param migrate If the data should be migrated
*/
protected BasicOption getCustomOption(Field field, CustomOption annotation, OptionPage page, Mod mod, boolean migrate) {
+ ConfigUtils.check("CustomOption", field, BasicOption.class);
return null;
}
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 c4c6d33..75807a1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
@@ -22,47 +22,47 @@ public class ConfigUtils {
public static BasicOption getOption(Option option, Field field, Object instance) {
switch (option.type()) {
case SWITCH:
- check(OptionType.SWITCH, field, boolean.class, Boolean.class);
+ check(OptionType.SWITCH.toString(), field, boolean.class, Boolean.class);
return ConfigSwitch.create(field, instance);
case CHECKBOX:
- check(OptionType.CHECKBOX, field, boolean.class, Boolean.class);
+ check(OptionType.CHECKBOX.toString(), field, boolean.class, Boolean.class);
return ConfigCheckbox.create(field, instance);
case INFO:
return ConfigInfo.create(field, instance);
case HEADER:
return ConfigHeader.create(field, instance);
case COLOR:
- check(OptionType.COLOR, field, OneColor.class);
+ check(OptionType.COLOR.toString(), field, OneColor.class);
return ConfigColorElement.create(field, instance);
case DROPDOWN:
- check(OptionType.DROPDOWN, field, int.class, Integer.class);
+ check(OptionType.DROPDOWN.toString(), field, int.class, Integer.class);
return ConfigDropdown.create(field, instance);
case TEXT:
- check(OptionType.TEXT, field, String.class);
+ check(OptionType.TEXT.toString(), field, String.class);
return ConfigTextBox.create(field, instance);
case BUTTON:
- check(OptionType.BUTTON, field, Runnable.class);
+ check(OptionType.BUTTON.toString(), field, Runnable.class);
return ConfigButton.create(field, instance);
case SLIDER:
- check(OptionType.SLIDER, field, int.class, float.class, Integer.class, Float.class);
+ check(OptionType.SLIDER.toString(), field, int.class, float.class, Integer.class, Float.class);
return ConfigSlider.create(field, instance);
case KEYBIND:
- check(OptionType.KEYBIND, field, OneKeyBind.class);
+ check(OptionType.KEYBIND.toString(), field, OneKeyBind.class);
return ConfigKeyBind.create(field, instance);
case DUAL_OPTION:
- check(OptionType.DUAL_OPTION, field, boolean.class, Boolean.class);
+ check(OptionType.DUAL_OPTION.toString(), field, boolean.class, Boolean.class);
return ConfigDualOption.create(field, instance);
}
return null;
}
- private static void check(OptionType type, Field field, Class<?>... expectedType) {
+ public static void check(String type, Field field, Class<?>... expectedType) {
// I have tried to check for supertype classes like Boolean other ways.
- // but they actually don't extend their primitive types (because that is impossible) so isAssignableFrom doesn't work.
+ // because they actually don't extend their primitive types (because that is impossible) so isAssignableFrom doesn't work.
for (Class<?> clazz : expectedType) {
- if (field.getType().equals(clazz)) return;
+ if (clazz.isAssignableFrom(field.getType())) return;
}
- throw new InvalidTypeException("Field " + field.getName() + " in config " + field.getDeclaringClass().getName() + " is annotated as a " + type.toString() + ", but is not of valid type, expected " + Arrays.toString(expectedType) + " (found " + field.getType() + ")");
+ throw new InvalidTypeException("Field " + field.getName() + " in config " + field.getDeclaringClass().getName() + " is annotated as a " + type + ", but is not of valid type, expected " + Arrays.toString(expectedType) + " (found " + field.getType() + ")");
}
public static ArrayList<BasicOption> getClassOptions(Object object) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
index b737d70..60c3cae 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
@@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.config.gson;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.Exclude;
import cc.polyfrost.oneconfig.config.annotations.NonProfileSpecific;
+import cc.polyfrost.oneconfig.gui.pages.Page;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
@@ -14,6 +15,7 @@ public class NonProfileSpecificExclusionStrategy extends ExclusionUtils implemen
@Override
public boolean shouldSkipField(FieldAttributes f) {
if (isSuperClassOf(f.getDeclaredClass(), Config.class)) return true;
+ if (isSuperClassOf(f.getDeclaredClass(), Page.class)) return true;
if (f.getDeclaredClass().isAssignableFrom(Runnable.class)) return true;
if (f.getAnnotation(NonProfileSpecific.class) == null) return true;
Exclude exclude = f.getAnnotation(Exclude.class);
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
index 0df63b0..591b0ac 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
@@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.config.gson;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.Exclude;
import cc.polyfrost.oneconfig.config.annotations.NonProfileSpecific;
+import cc.polyfrost.oneconfig.gui.pages.Page;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
@@ -14,6 +15,7 @@ public class ProfileExclusionStrategy extends ExclusionUtils implements Exclusio
@Override
public boolean shouldSkipField(FieldAttributes f) {
if (isSuperClassOf(f.getDeclaredClass(), Config.class)) return true;
+ if (isSuperClassOf(f.getDeclaredClass(), Page.class)) return true;
if (f.getDeclaredClass().isAssignableFrom(Runnable.class)) return true;
if (f.getAnnotation(NonProfileSpecific.class) != null) return true;
Exclude exclude = f.getAnnotation(Exclude.class);
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
index ece2888..60fc8fd 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.gui.elements.config;
+import cc.polyfrost.oneconfig.gui.pages.Page;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
@@ -16,13 +17,19 @@ import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import java.lang.reflect.Field;
public class ConfigPageButton extends BasicOption {
- public final OptionPage page;
+ public final Page page;
public final String description;
private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY);
public ConfigPageButton(Field field, Object parent, String name, String description, String category, String subcategory, OptionPage page) {
super(field, parent, name, category, subcategory, 2);
this.description = description;
+ this.page = new ModConfigPage(page);
+ }
+
+ public ConfigPageButton(Field field, Object parent, String name, String description, String category, String subcategory, Page page) {
+ super(field, parent, name, category, subcategory, 2);
+ this.description = description;
this.page = page;
}
@@ -40,7 +47,7 @@ public class ConfigPageButton extends BasicOption {
RenderManager.drawText(vg, name, x + 10, y + 70, Colors.WHITE_90, 14, Fonts.MEDIUM);
RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22);
- if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page));
+ if (clicked) OneConfigGui.INSTANCE.openPage(page);
RenderManager.setAlpha(vg, 1f);
}