From 0283a6618360ed473da42c1144da5b44146155bb Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sat, 30 Apr 2022 17:05:10 +0200 Subject: more config system stuff --- .../oneconfig/config/annotations/ConfigPage.java | 32 ++++++++++++ .../oneconfig/config/annotations/Option.java | 10 ++-- .../oneconfig/config/data/OptionCategory.java | 12 ++--- .../oneconfig/config/data/OptionPage.java | 5 +- .../oneconfig/config/data/OptionType.java | 4 -- .../oneconfig/config/data/PageLocation.java | 6 +++ .../oneconfig/config/interfaces/Config.java | 46 ++++++++++------- .../gui/elements/config/ConfigCheckbox.java | 12 ++++- .../oneconfig/gui/elements/config/ConfigPage.java | 55 --------------------- .../gui/elements/config/ConfigPageButton.java | 55 +++++++++++++++++++++ .../gui/elements/config/ConfigTextBox.java | 23 ++++----- .../gui/elements/config/ConfigUniSelector.java | 31 ++++++++++-- .../oneconfig/gui/pages/ModConfigPage.java | 39 ++++++++++----- .../io/polyfrost/oneconfig/lwjgl/font/Fonts.java | 5 +- .../io/polyfrost/oneconfig/test/TestConfig.java | 21 ++++---- .../resources/assets/oneconfig/font/Inter-Bold.ttf | Bin 316100 -> 0 bytes 16 files changed, 221 insertions(+), 135 deletions(-) create mode 100644 src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java create mode 100644 src/main/java/io/polyfrost/oneconfig/config/data/PageLocation.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java delete mode 100644 src/main/resources/assets/oneconfig/font/Inter-Bold.ttf diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java new file mode 100644 index 0000000..fecd438 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java @@ -0,0 +1,32 @@ +package io.polyfrost.oneconfig.config.annotations; + +import io.polyfrost.oneconfig.config.data.PageLocation; + +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 ConfigPage { + /** + * The name of the page that will be displayed to the user + */ + String name(); + + /** + * If the page button is at the top or bottem of the page + */ + PageLocation location(); + + /** + * The description of the page that will be displayed to the user + */ + String description() default ""; + + /** + * The category of the page + */ + String category() default "general"; +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java index b7bcf4f..fe61a02 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java @@ -16,11 +16,6 @@ public @interface Option { */ String name(); - /** - * The description of the page that will be displayed to the user - */ - String description() default ""; - /** * The type of the option */ @@ -50,6 +45,11 @@ public @interface Option { */ int size() default 1; + /** + * The placeholder in the text field + */ + String placeholder() default ""; + /** * If the text field is secure or not */ diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java b/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java index 4286264..15c073c 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java @@ -1,17 +1,13 @@ package io.polyfrost.oneconfig.config.data; import io.polyfrost.oneconfig.config.interfaces.BasicOption; -import io.polyfrost.oneconfig.gui.elements.config.ConfigPage; +import io.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import java.util.ArrayList; import java.util.HashMap; public class OptionCategory { - public final HashMap> options; - public final ArrayList pages; - - public OptionCategory(HashMap> options, ArrayList pages) { - this.options = options; - this.pages = pages; - } + public final HashMap> subcategories = new HashMap<>(); + public final ArrayList topPages = new ArrayList<>(); + public final ArrayList bottomPages = new ArrayList<>(); } diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java index 8dcd9a1..12aef6a 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java @@ -1,9 +1,6 @@ package io.polyfrost.oneconfig.config.data; -import io.polyfrost.oneconfig.config.interfaces.BasicOption; - -import java.util.ArrayList; import java.util.HashMap; public class OptionPage { @@ -14,7 +11,7 @@ public class OptionPage { * Depth 2 = subcategories * Depth 3 = list of options */ - public final HashMap>> categories = new HashMap<>(); + public final HashMap categories = new HashMap<>(); public OptionPage(String name, Mod mod) { 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 index 4378d34..7e106f4 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java @@ -1,10 +1,6 @@ package io.polyfrost.oneconfig.config.data; public enum OptionType { - /** - * Type: class - */ - PAGE, /** * Type: boolean */ diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/PageLocation.java b/src/main/java/io/polyfrost/oneconfig/config/data/PageLocation.java new file mode 100644 index 0000000..9fe0c91 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/data/PageLocation.java @@ -0,0 +1,6 @@ +package io.polyfrost.oneconfig.config.data; + +public enum PageLocation { + TOP, + BOTTOM +} 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 ee72fee..af3d037 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -1,9 +1,11 @@ package io.polyfrost.oneconfig.config.interfaces; import com.google.gson.*; +import io.polyfrost.oneconfig.config.annotations.ConfigPage; import io.polyfrost.oneconfig.config.annotations.Option; import io.polyfrost.oneconfig.config.core.ConfigCore; import io.polyfrost.oneconfig.config.data.Mod; +import io.polyfrost.oneconfig.config.data.OptionCategory; import io.polyfrost.oneconfig.config.data.OptionPage; import io.polyfrost.oneconfig.config.profiles.Profiles; import io.polyfrost.oneconfig.gui.elements.config.*; @@ -66,28 +68,38 @@ public class Config { */ protected void generateOptionList(Class clazz, OptionPage page, Mod mod) { for (Field field : clazz.getDeclaredFields()) { - if (!field.isAnnotationPresent(Option.class)) { + 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()); + OptionPage newPage = new OptionPage(option.name(), mod); + try { + field.setAccessible(true); + Object object = field.get(clazz); + generateOptionList(object.getClass(), newPage, mod); + switch (option.location()) { + case TOP: + page.categories.get(option.category()).topPages.add(new ConfigPageButton(field, option.name(), option.description(), newPage)); + break; + case BOTTOM: + page.categories.get(option.category()).bottomPages.add(new ConfigPageButton(field, option.name(), option.description(), newPage)); + break; + } + } catch (IllegalAccessException e) { + continue; + } + continue; } 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 options = page.categories.get(option.category()).get(option.subcategory()); + page.categories.put(option.category(), new OptionCategory()); + if (!page.categories.get(option.category()).subcategories.containsKey(option.subcategory())) + page.categories.get(option.category()).subcategories.put(option.subcategory(), new ArrayList<>()); + ArrayList options = page.categories.get(option.category()).subcategories.get(option.subcategory()); switch (option.type()) { - case PAGE: - OptionPage newPage = new OptionPage(option.name(), mod); - try { - field.setAccessible(true); - Object object = field.get(clazz); - generateOptionList(object.getClass(), newPage, mod); - 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.size())); break; @@ -95,7 +107,7 @@ public class Config { options.add(new ConfigCheckbox(field, option.name(), option.size())); break; case TEXT: - options.add(new ConfigTextBox(field, option.name(), option.size(), option.secure(), option.multiLine())); + options.add(new ConfigTextBox(field, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); break; case DUAL_OPTION: options.add(new ConfigDualOption(field, option.name(), option.size(), option.optionLeft(), option.optionRight())); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index e9ed4bf..6832236 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -14,7 +14,6 @@ import java.lang.reflect.Field; public class ConfigCheckbox extends BasicOption { private int color; private float percentOn = 0f; - private boolean toggled = false; public ConfigCheckbox(Field field, String name, int size) { super(field, name, size); @@ -22,11 +21,22 @@ public class ConfigCheckbox extends BasicOption { @Override public void draw(long vg, int x, int y) { + boolean toggled = false; + try { + toggled = (boolean) get(); + } catch (IllegalAccessException ignored) { + } boolean hover = InputUtils.isAreaHovered(x, y, 24, 24); boolean clicked = InputUtils.isClicked() && hover; if(clicked) { toggled = !toggled; + try { + set(toggled); + } catch (IllegalAccessException e) { + System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled); + e.printStackTrace(); + } } if(percentOn != 1f) { // performance RenderManager.drawRoundedRect(vg, x, y, 24, 24, color, 6f); 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 deleted file mode 100644 index 569d799..0000000 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.polyfrost.oneconfig.gui.elements.config; - -import io.polyfrost.oneconfig.config.OneConfigConfig; -import io.polyfrost.oneconfig.config.data.OptionPage; -import io.polyfrost.oneconfig.config.interfaces.BasicOption; -import io.polyfrost.oneconfig.gui.OneConfigGui; -import io.polyfrost.oneconfig.gui.pages.ModConfigPage; -import io.polyfrost.oneconfig.lwjgl.RenderManager; -import io.polyfrost.oneconfig.lwjgl.font.Fonts; -import io.polyfrost.oneconfig.utils.ColorUtils; -import io.polyfrost.oneconfig.utils.InputUtils; -import org.lwjgl.nanovg.NanoVG; - -import java.lang.reflect.Field; - -public class ConfigPage extends BasicOption { - public final OptionPage page; - public final String description; - private int backgroundColor = OneConfigConfig.GRAY_500; - - public ConfigPage(Field field, String name, String description, int size, OptionPage page) { - super(field, name, size); - this.description = description; - this.page = page; - } - - @Override - public void draw(long vg, int x, int y) { - int height = description.equals("") ? 64 : 96; - boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height); - boolean clicked = InputUtils.isAreaClicked(x - 2, y, 1024, height); - backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); - - if (clicked) NanoVG.nvgGlobalAlpha(vg, 0.8f); - - RenderManager.drawRoundedRect(vg, x - 16, y, 1024, height, backgroundColor, 20); - RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE, 24, Fonts.INTER_MEDIUM); - if (!description.equals("")) - RenderManager.drawString(vg, name, x + 10, y + 70, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM); - RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22); - - if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); - NanoVG.nvgGlobalAlpha(vg, 1f); - } - - @Override - public int getHeight() { - return description.equals("") ? 64 : 96; - } - - @Override - public boolean hasHalfSize() { - return false; - } -} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java new file mode 100644 index 0000000..607c877 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java @@ -0,0 +1,55 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.config.data.OptionPage; +import io.polyfrost.oneconfig.config.interfaces.BasicOption; +import io.polyfrost.oneconfig.gui.OneConfigGui; +import io.polyfrost.oneconfig.gui.pages.ModConfigPage; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import io.polyfrost.oneconfig.utils.ColorUtils; +import io.polyfrost.oneconfig.utils.InputUtils; +import org.lwjgl.nanovg.NanoVG; + +import java.lang.reflect.Field; + +public class ConfigPageButton extends BasicOption { + public final OptionPage page; + public final String description; + private int backgroundColor = OneConfigConfig.GRAY_500; + + public ConfigPageButton(Field field, String name, String description, OptionPage page) { + super(field, name, 2); + this.description = description; + this.page = page; + } + + @Override + public void draw(long vg, int x, int y) { + int height = description.equals("") ? 64 : 96; + boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height); + boolean clicked = InputUtils.isAreaClicked(x - 2, y, 1024, height); + backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); + + if (clicked) NanoVG.nvgGlobalAlpha(vg, 0.8f); + + RenderManager.drawRoundedRect(vg, x - 16, y, 1024, height, backgroundColor, 20); + RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE_90, 24, Fonts.INTER_MEDIUM); + if (!description.equals("")) + RenderManager.drawString(vg, name, x + 10, y + 70, OneConfigConfig.WHITE_90, 14, Fonts.INTER_MEDIUM); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22); + + if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); + NanoVG.nvgGlobalAlpha(vg, 1f); + } + + @Override + public int getHeight() { + return description.equals("") ? 64 : 96; + } + + @Override + public boolean hasHalfSize() { + return false; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java index 8d6179c..b3f689c 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -6,8 +6,8 @@ import io.polyfrost.oneconfig.gui.elements.TextInputField; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.InputUtils; -import org.lwjgl.nanovg.NanoVG; +import java.awt.*; import java.lang.reflect.Field; public class ConfigTextBox extends BasicOption { @@ -15,26 +15,27 @@ public class ConfigTextBox extends BasicOption { private final boolean multiLine; private final TextInputField textField; - public ConfigTextBox(Field field, String name, int size, boolean secure, boolean multiLine) { + public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) { super(field, name, size); this.secure = secure; this.multiLine = multiLine; - String value = null; - try { - value = (String) get(); - } catch (IllegalAccessException ignored) { - } - if (value == null) value = ""; - this.textField = new TextInputField(size == 1 && hasHalfSize() ? 216 : 640, multiLine ? 64 : 32, value, multiLine, secure); + this.textField = new TextInputField(size == 1 && hasHalfSize() ? 256 : 640, multiLine ? 64 : 32, placeholder, multiLine, secure); } @Override public void draw(long vg, int x, int y) { - RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14, Fonts.INTER_MEDIUM); + + try { + String value = (String) get(); + textField.setInput(value == null ? "" : value); + } catch (IllegalAccessException ignored) { + } + textField.draw(vg, x + (size == 1 && hasHalfSize() ? 224 : 352), y); - if (secure) RenderManager.drawImage(vg, "/assets/oneconfig/textures/eye.png", x + 967, y + 7, 18, 18); + if (secure) RenderManager.drawImage(vg, "/assets/oneconfig/textures/eye.png", x + 967, y + 7, 18, 18, new Color(196,196,196).getRGB()); if (secure && InputUtils.isAreaClicked(x + 967, y + 7, 18, 18)) textField.setPassword(!textField.getPassword()); } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java index 39f8cf9..b20e8bc 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -4,6 +4,8 @@ import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.config.interfaces.BasicOption; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import io.polyfrost.oneconfig.utils.InputUtils; +import org.lwjgl.nanovg.NanoVG; import java.lang.reflect.Field; @@ -17,7 +19,7 @@ public class ConfigUniSelector extends BasicOption { @Override public int getHeight() { - return 0; + return 32; } @Override @@ -27,8 +29,31 @@ public class ConfigUniSelector extends BasicOption { selected = (int) get(); } catch (IllegalAccessException ignored) { } + String option = options[selected] + " " + (selected + 1) + "/" + options.length; RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); - RenderManager.drawString(vg, options[selected], x + 16, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); - RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 230, y + 7, 13, 22, OneConfigConfig.BLUE_400); // TODO + RenderManager.drawString(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 14f, Fonts.INTER_MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + + // actual coordinates: 240, 7 + NanoVG.nvgTranslate(vg, x + 248, y + 21); + NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", 0, 0, 8, 14, OneConfigConfig.BLUE_400); + NanoVG.nvgResetTransform(vg); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 456, y + 7, 8, 14, OneConfigConfig.BLUE_400); + + if (InputUtils.isAreaClicked(x + 240, y + 7, 8, 14)) { + if (selected > 0) selected -= 1; + else selected = options.length - 1; + try { + set(selected); + } catch (IllegalAccessException ignored) { + } + } else if (InputUtils.isAreaClicked(x + 456, y + 7, 8, 14)) { + if (selected < options.length - 1) selected += 1; + else selected = 0; + try { + set(selected); + } catch (IllegalAccessException ignored) { + } + } } } 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 2b31421..4827ebe 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -3,6 +3,7 @@ package io.polyfrost.oneconfig.gui.pages; import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.config.data.OptionPage; import io.polyfrost.oneconfig.config.interfaces.BasicOption; +import io.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; @@ -20,13 +21,19 @@ public class ModConfigPage extends Page { String selectedCategory = page.categories.keySet().stream().findFirst().get(); int optionX = x + 30; int optionY = y + (page.categories.size() == 1 ? 16 : 64); + + for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) { + page.draw(vg, optionX, optionY); + optionY += page.getHeight() + 16; + } + int backgroundSize = 48; - for (String subCategory : page.categories.get(selectedCategory).keySet()) { + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { backgroundSize += 32; - for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) { - BasicOption option = page.categories.get(selectedCategory).get(subCategory).get(i); - if (i + 1 < page.categories.get(selectedCategory).get(subCategory).size()) { - BasicOption nextOption = page.categories.get(selectedCategory).get(subCategory).get(i + 1); + for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) { + BasicOption option = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i); + if (i + 1 < page.categories.get(selectedCategory).subcategories.get(subCategory).size()) { + BasicOption nextOption = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i + 1); if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16; i++; @@ -39,14 +46,14 @@ public class ModConfigPage extends Page { RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); optionY += 16; - for (String subCategory : page.categories.get(selectedCategory).keySet()) { + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { RenderManager.drawString(vg, subCategory, optionX, optionY + 16, OneConfigConfig.WHITE_90, 24f, Fonts.INTER_MEDIUM); optionY += 48; - for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) { - BasicOption option = page.categories.get(selectedCategory).get(subCategory).get(i); + for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) { + BasicOption option = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i); option.draw(vg, optionX, optionY); - if (i + 1 < page.categories.get(selectedCategory).get(subCategory).size()) { - BasicOption nextOption = page.categories.get(selectedCategory).get(subCategory).get(i + 1); + if (i + 1 < page.categories.get(selectedCategory).subcategories.get(subCategory).size()) { + BasicOption nextOption = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i + 1); if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { nextOption.draw(vg, optionX + 512, optionY); optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; @@ -57,6 +64,12 @@ public class ModConfigPage extends Page { optionY += option.getHeight() + 16; } } + optionY += 16; + + for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) { + page.draw(vg, optionX, optionY); + optionY += page.getHeight() + 16; + } } @Override @@ -68,9 +81,9 @@ public class ModConfigPage extends Page { public void keyTyped(char key, int keyCode) { if (page.categories.size() == 0) return; String selectedCategory = page.categories.keySet().stream().findFirst().get(); - for (String subCategory : page.categories.get(selectedCategory).keySet()) { - for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) { - page.categories.get(selectedCategory).get(subCategory).get(i).keyTyped(key, keyCode); + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { + for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) { + page.categories.get(selectedCategory).subcategories.get(subCategory).get(i).keyTyped(key, keyCode); } } } diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java index 5d36271..c60742a 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java @@ -1,8 +1,7 @@ package io.polyfrost.oneconfig.lwjgl.font; public enum Fonts { - - INTER_BOLD(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.ttf")), + INTER_BOLD(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.otf")), INTER_REGULAR(new Font("inter-regular", "/assets/oneconfig/font/Inter-Regular.otf")), INTER_SEMIBOLD(new Font("inter-semibold", "/assets/oneconfig/font/Inter-SemiBold.otf")), INTER_MEDIUM(new Font("inter-medium", "/assets/oneconfig/font/Inter-Medium.otf")), @@ -13,6 +12,4 @@ public enum Fonts { Fonts(Font font) { this.font = font; } - - } diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java index a250318..7b99cc1 100644 --- a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java @@ -1,16 +1,17 @@ package io.polyfrost.oneconfig.test; +import io.polyfrost.oneconfig.config.annotations.ConfigPage; 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.data.PageLocation; import io.polyfrost.oneconfig.config.interfaces.Config; public class TestConfig extends Config { @Option( name = "Test dual thing", - description = "Best description", subcategory = "Test", optionLeft = "FUNNY", optionRight = "not funny", type = OptionType.DUAL_OPTION @@ -19,7 +20,6 @@ public class TestConfig extends Config { @Option( name = "Test string", - description = "Best description", subcategory = "Test", optionLeft = "HI", optionRight = "BYE", type = OptionType.DUAL_OPTION @@ -28,7 +28,6 @@ public class TestConfig extends Config { @Option( name = "Test dual option", - description = "Best description", subcategory = "Test", optionRight = "cool", optionLeft = "not cool", type = OptionType.DUAL_OPTION, @@ -38,23 +37,27 @@ public class TestConfig extends Config { @Option( name = "Test option", - description = "Best description", subcategory = "Test", options = {"Hello", "World", "Fish", "Cat"}, type = OptionType.UNI_SELECTOR ) public static int switchTest3; - @Option( + @ConfigPage( name = "Test Page", - type = OptionType.PAGE, - subcategory = "Test" + location = PageLocation.TOP ) public static TestPage testPage = new TestPage(); + @ConfigPage( + name = "Test Page width description", + description = "Wow, an epic description", + location = PageLocation.BOTTOM + ) + public static TestPage testPage2 = new TestPage(); + @Option( name = "Test switch", - description = "Best description", subcategory = "Other subcategory", type = OptionType.SWITCH ) @@ -62,7 +65,6 @@ public class TestConfig extends Config { @Option( name = "Test switch", - description = "Best description", subcategory = "Other subcategory", type = OptionType.SWITCH ) @@ -70,7 +72,6 @@ public class TestConfig extends Config { @Option( name = "Test check", - description = "Best description", subcategory = "Other subcategory", type = OptionType.CHECKBOX ) diff --git a/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf b/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf deleted file mode 100644 index 76a215c..0000000 Binary files a/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf and /dev/null differ -- cgit