aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-07-25 13:01:16 +0100
committerGitHub <noreply@github.com>2022-07-25 13:01:16 +0100
commit8a01f36d1021159f2c49ae8083febc046a4a8502 (patch)
treeab79fa993952543131fb3b3f9fddc645c1456d1a
parent2159b8d6cc7e0de418062fecb8e57244184e8820 (diff)
downloadOneConfig-8a01f36d1021159f2c49ae8083febc046a4a8502.tar.gz
OneConfig-8a01f36d1021159f2c49ae8083febc046a4a8502.tar.bz2
OneConfig-8a01f36d1021159f2c49ae8083febc046a4a8502.zip
page button changes (#71)
-rw-r--r--api/OneConfig.api4
-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
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java11
7 files changed, 49 insertions, 19 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api
index c9c7ae3..5a5955e 100644
--- a/api/OneConfig.api
+++ b/api/OneConfig.api
@@ -143,6 +143,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat
public class cc/polyfrost/oneconfig/config/core/ConfigUtils {
public fun <init> ()V
public static fun addOptionToPage (Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/internal/config/annotations/Option;Ljava/lang/reflect/Field;Ljava/lang/Object;Lcc/polyfrost/oneconfig/config/migration/Migrator;)Lcc/polyfrost/oneconfig/config/elements/BasicOption;
+ public static fun check (Ljava/lang/String;Ljava/lang/reflect/Field;[Ljava/lang/Class;)V
public static fun findAnnotation (Lcom/google/gson/FieldAttributes;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
public static fun findAnnotation (Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
public static fun findAnnotation (Ljava/lang/reflect/Field;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
@@ -755,8 +756,9 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind : cc/polyf
public class cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton : cc/polyfrost/oneconfig/config/elements/BasicOption {
public final field description Ljava/lang/String;
- public final field page Lcc/polyfrost/oneconfig/config/elements/OptionPage;
+ public final field page Lcc/polyfrost/oneconfig/gui/pages/Page;
public fun <init> (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/config/elements/OptionPage;)V
+ public fun <init> (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/gui/pages/Page;)V
public fun draw (JII)V
public fun getHeight ()I
}
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);
}
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
index 3b7490c..94f3b3b 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
@@ -7,6 +7,7 @@ import cc.polyfrost.oneconfig.config.data.*;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator;
+import cc.polyfrost.oneconfig.gui.pages.HomePage;
import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
@@ -25,6 +26,16 @@ public class TestConfig_Test extends Config {
)
public static boolean testCheckBox = true;
+ @CustomOption
+
+
+ @Page(
+ name = "An actual page",
+ description = "yes very cool",
+ location = PageLocation.BOTTOM
+ )
+ private final cc.polyfrost.oneconfig.gui.pages.Page page = new HomePage();
+
@Button(
name = "hello",
text = "click"