From 3857800292a7cc078ee05c5487b11a256682bef1 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <12willettsh@gmail.com> Date: Sun, 13 Feb 2022 10:46:44 +0000 Subject: remake theme stuff + move packages around --- .../io/polyfrost/oneconfig/annotations/Button.java | 14 --- .../polyfrost/oneconfig/annotations/Category.java | 13 -- .../oneconfig/annotations/ColorPicker.java | 14 --- .../polyfrost/oneconfig/annotations/Selector.java | 15 --- .../io/polyfrost/oneconfig/annotations/Slider.java | 16 --- .../io/polyfrost/oneconfig/annotations/Switch.java | 13 -- .../polyfrost/oneconfig/annotations/TextField.java | 15 --- .../oneconfig/config/annotations/Button.java | 14 +++ .../oneconfig/config/annotations/Category.java | 13 ++ .../oneconfig/config/annotations/ColorPicker.java | 14 +++ .../oneconfig/config/annotations/Selector.java | 15 +++ .../oneconfig/config/annotations/Slider.java | 16 +++ .../oneconfig/config/annotations/Switch.java | 13 ++ .../oneconfig/config/annotations/TextField.java | 15 +++ .../oneconfig/config/core/ConfigCore.java | 11 ++ .../polyfrost/oneconfig/config/data/ModData.java | 24 ++++ .../polyfrost/oneconfig/config/data/ModType.java | 10 ++ .../oneconfig/config/interfaces/Config.java | 126 +++++++++++++++++++ .../config/interfaces/OneConfigTypeAdapter.java | 51 ++++++++ .../interfaces/OneConfigTypeAdapterFactory.java | 30 +++++ .../oneconfig/config/interfaces/Option.java | 76 ++++++++++++ .../io/polyfrost/oneconfig/core/ConfigCore.java | 11 -- .../java/io/polyfrost/oneconfig/data/ModData.java | 24 ---- .../java/io/polyfrost/oneconfig/data/ModType.java | 10 -- .../java/io/polyfrost/oneconfig/gui/Window.java | 5 +- .../gui/elements/config/OConfigButton.java | 2 +- .../gui/elements/config/OConfigCategory.java | 2 +- .../gui/elements/config/OConfigColor.java | 2 +- .../gui/elements/config/OConfigSelector.java | 2 +- .../gui/elements/config/OConfigSlider.java | 2 +- .../gui/elements/config/OConfigSwitch.java | 2 +- .../oneconfig/gui/elements/config/OConfigText.java | 2 +- .../io/polyfrost/oneconfig/interfaces/Config.java | 126 ------------------- .../oneconfig/interfaces/OneConfigTypeAdapter.java | 51 -------- .../interfaces/OneConfigTypeAdapterFactory.java | 30 ----- .../io/polyfrost/oneconfig/interfaces/Option.java | 76 ------------ .../io/polyfrost/oneconfig/renderer/Renderer.java | 3 + .../oneconfig/renderer/shaders/ShaderHelper.java | 4 + .../io/polyfrost/oneconfig/test/TestConfig.java | 12 +- .../polyfrost/oneconfig/themes/TextureManager.java | 82 +++++++++++++ .../java/io/polyfrost/oneconfig/themes/Theme.java | 136 ++------------------- .../polyfrost/oneconfig/themes/ThemeElement.java | 42 +++++++ .../java/io/polyfrost/oneconfig/themes/Themes.java | 1 + 43 files changed, 584 insertions(+), 571 deletions(-) delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/Button.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/Category.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/ColorPicker.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/Selector.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/Slider.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/Switch.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/annotations/TextField.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/data/ModData.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/data/ModType.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/OneConfigTypeAdapter.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/OneConfigTypeAdapterFactory.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/core/ConfigCore.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/data/ModData.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/data/ModType.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/interfaces/Config.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/interfaces/OneConfigTypeAdapter.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/interfaces/OneConfigTypeAdapterFactory.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/interfaces/Option.java create mode 100644 src/main/java/io/polyfrost/oneconfig/renderer/shaders/ShaderHelper.java create mode 100644 src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java create mode 100644 src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java (limited to 'src') diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/Button.java b/src/main/java/io/polyfrost/oneconfig/annotations/Button.java deleted file mode 100644 index 98b735f..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/Button.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.polyfrost.oneconfig.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"; -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/Category.java b/src/main/java/io/polyfrost/oneconfig/annotations/Category.java deleted file mode 100644 index 21c5533..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/Category.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.polyfrost.oneconfig.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 ""; -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/ColorPicker.java b/src/main/java/io/polyfrost/oneconfig/annotations/ColorPicker.java deleted file mode 100644 index bf997a6..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/ColorPicker.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.polyfrost.oneconfig.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; -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/Selector.java b/src/main/java/io/polyfrost/oneconfig/annotations/Selector.java deleted file mode 100644 index 39d238c..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/Selector.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.polyfrost.oneconfig.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; -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/Slider.java b/src/main/java/io/polyfrost/oneconfig/annotations/Slider.java deleted file mode 100644 index fa855bf..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/Slider.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.polyfrost.oneconfig.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(); -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/Switch.java b/src/main/java/io/polyfrost/oneconfig/annotations/Switch.java deleted file mode 100644 index fffb490..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/Switch.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.polyfrost.oneconfig.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 ""; -} diff --git a/src/main/java/io/polyfrost/oneconfig/annotations/TextField.java b/src/main/java/io/polyfrost/oneconfig/annotations/TextField.java deleted file mode 100644 index 5761dd6..0000000 --- a/src/main/java/io/polyfrost/oneconfig/annotations/TextField.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.polyfrost.oneconfig.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; -} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java new file mode 100644 index 0000000..449d297 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Button.java @@ -0,0 +1,14 @@ +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"; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java new file mode 100644 index 0000000..05b5277 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Category.java @@ -0,0 +1,13 @@ +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 ""; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java new file mode 100644 index 0000000..feee4b4 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/ColorPicker.java @@ -0,0 +1,14 @@ +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; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java new file mode 100644 index 0000000..8b476ab --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Selector.java @@ -0,0 +1,15 @@ +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; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java new file mode 100644 index 0000000..cf8bfcd --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Slider.java @@ -0,0 +1,16 @@ +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(); +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java new file mode 100644 index 0000000..19ec1db --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Switch.java @@ -0,0 +1,13 @@ +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 ""; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java new file mode 100644 index 0000000..7b5837c --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/TextField.java @@ -0,0 +1,15 @@ +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; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java new file mode 100644 index 0000000..ff7ed28 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java @@ -0,0 +1,11 @@ +package io.polyfrost.oneconfig.config.core; + +import io.polyfrost.oneconfig.config.data.ModData; +import io.polyfrost.oneconfig.config.interfaces.Option; + +import java.util.ArrayList; +import java.util.HashMap; + +public class ConfigCore { + public static HashMap> settings = new HashMap<>(); +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/ModData.java b/src/main/java/io/polyfrost/oneconfig/config/data/ModData.java new file mode 100644 index 0000000..c5e6633 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/data/ModData.java @@ -0,0 +1,24 @@ +package io.polyfrost.oneconfig.config.data; + +import io.polyfrost.oneconfig.config.interfaces.Config; + +public class ModData { + public final String name; + public final ModType modType; + public final String creator; + public final String version; + public Config config; + + /** + * @param name Friendly name of the mod + * @param modType Type of the mod (for example ModType.QOL) + * @param creator Creator of the mod + * @param version Version of the mod + */ + public ModData(String name, ModType modType, String creator, String version) { + this.name = name; + this.modType = modType; + this.creator = creator; + this.version = version; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/ModType.java b/src/main/java/io/polyfrost/oneconfig/config/data/ModType.java new file mode 100644 index 0000000..8b6e7de --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/data/ModType.java @@ -0,0 +1,10 @@ +package io.polyfrost.oneconfig.config.data; + +public enum ModType { + PVP, + PERFORMANCE, + HUD, + QOL, + HYPIXEL, + OTHER +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java new file mode 100644 index 0000000..ce73f0c --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -0,0 +1,126 @@ +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.gui.elements.config.*; + +import java.io.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Map; + +public class Config { + private final File configFile; + + Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting() + .registerTypeAdapterFactory(OneConfigTypeAdapterFactory.getStaticTypeAdapterFactory()).create(); + + /** + * @param modData information about the mod + * @param configFile file where config is stored + */ + public Config(ModData modData, File configFile) { + this.configFile = configFile; + if (configFile.exists()) + load(); + else + save(); + modData.config = this; + ConfigCore.settings.put(modData, generateOptionList(this.getClass())); + } + + /** + * Save current config to file + */ + public void save() { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { + writer.write(gson.toJson(this.getClass())); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Load file and overwrite current values + */ + public void load() { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { + deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this.getClass()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Generate the option list for internal use only + * + * @param clazz target class + * @return list of options + */ + private ArrayList