diff options
Diffstat (limited to 'src/main/java/io/polyfrost')
8 files changed, 84 insertions, 33 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java index 435fb32..bd6c3f3 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/Mod.java @@ -8,7 +8,7 @@ public class Mod { public final String creator; public final String version; public Config config; - public OptionPage defaultPage = new OptionPage(""); + public OptionPage defaultPage = new OptionPage("", this); /** * @param name Friendly name of the mod 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 021786d..8dcd9a1 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java @@ -1,5 +1,6 @@ package io.polyfrost.oneconfig.config.data; + import io.polyfrost.oneconfig.config.interfaces.BasicOption; import java.util.ArrayList; @@ -7,6 +8,7 @@ import java.util.HashMap; public class OptionPage { public final String name; + public final Mod mod; /** * Depth 1 = categories * Depth 2 = subcategories @@ -14,7 +16,8 @@ public class OptionPage { */ public final HashMap<String, HashMap<String, ArrayList<BasicOption>>> categories = new HashMap<>(); - public OptionPage(String name) { + public OptionPage(String name, Mod mod) { this.name = name; + this.mod = mod; } } diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java index 42c826e..5b6e2c0 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java @@ -1,12 +1,13 @@ package io.polyfrost.oneconfig.config.interfaces; +import io.polyfrost.oneconfig.gui.elements.BasicElement; + import java.lang.reflect.Field; @SuppressWarnings({"unused"}) public abstract class BasicOption { protected final Field field; protected final String name; - protected final String description; public final int size; /** @@ -14,13 +15,11 @@ public abstract class BasicOption { * * @param field variable attached to option (null for category) * @param name name of option - * @param description description of option * @param size size of option, 0 for single column, 1 for double. */ - public BasicOption(Field field, String name, String description, int size) { + public BasicOption(Field field, String name, int size) { this.field = field; this.name = name; - this.description = description; this.size = size; if (field != null) field.setAccessible(true); } @@ -52,10 +51,8 @@ public abstract class BasicOption { * @param vg NanoVG context * @param x x position * @param y y position - * @param mouseX x position of mouse - * @param mouseY y position of mouse */ - public abstract void draw(long vg, int x, int y, int mouseX, int mouseY); + public abstract void draw(long vg, int x, int y); /** * Function that gets called when mouse is clicked @@ -75,4 +72,11 @@ public abstract class BasicOption { */ protected void keyTyped(char typedChar, int keyCode) { } + + /** + * @return If the component has an option to render at half size + */ + public boolean hasHalfSize() { + return true; + } } 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 0539d5f..cbb7610 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -34,7 +34,7 @@ public class Config { if (Profiles.getProfileFile(configFile).exists()) load(); else save(); mod.config = this; - generateOptionList(this.getClass(), mod.defaultPage); + generateOptionList(this.getClass(), mod.defaultPage, mod); ConfigCore.oneConfigMods.add(mod); } @@ -66,7 +66,7 @@ public class Config { * @param clazz target class * @param page page to add options too */ - protected void generateOptionList(Class<?> clazz, OptionPage page) { + protected void generateOptionList(Class<?> clazz, OptionPage page, Mod mod) { for (Field field : clazz.getDeclaredFields()) { System.out.println(field); if (!field.isAnnotationPresent(Option.class)) { @@ -81,11 +81,11 @@ public class Config { ArrayList<BasicOption> options = page.categories.get(option.category()).get(option.subcategory()); switch (option.type()) { case PAGE: - OptionPage newPage = new OptionPage(option.name()); + OptionPage newPage = new OptionPage(option.name(), mod); try { field.setAccessible(true); Object object = field.get(clazz); - generateOptionList(object.getClass(), newPage); + generateOptionList(object.getClass(), newPage, mod); System.out.println(newPage.categories); options.add(new ConfigPage(field, option.name(), option.description(), option.size(), newPage)); } catch (IllegalAccessException e) { @@ -93,7 +93,7 @@ public class Config { } break; case SWITCH: - options.add(new ConfigSwitch(field, option.name(), option.description(), option.size())); + options.add(new ConfigSwitch(field, option.name(), option.size())); break; } } 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 bb8b830..444094e 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java @@ -88,7 +88,7 @@ public class ModCard extends BasicElement { for (Mod data : OneConfig.loadedMods) { if (data.modType != ModType.OTHER) { if (data.name.equalsIgnoreCase(modData.name)) { - OneConfigGui.INSTANCE.openPage(new ModConfigPage(data)); + OneConfigGui.INSTANCE.openPage(new ModConfigPage(data.defaultPage)); } } } 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 index c761cd7..1a2d001 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java @@ -7,20 +7,26 @@ import java.lang.reflect.Field; public class ConfigPage extends BasicOption { public final OptionPage page; + public final String description; public ConfigPage(Field field, String name, String description, int size, OptionPage page) { - super(field, name, description, size); + super(field, name, size); + this.description = description; this.page = page; } - @Override - public void draw(long vg, int x, int y, int mouseX, int mouseY) { + public void draw(long vg, int x, int y) { } @Override public int getHeight() { - return 0; + return description.equals("") ? 64 : 96; + } + + @Override + public boolean hasHalfSize() { + return false; } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 3da2480..a65e873 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -6,18 +6,17 @@ import java.lang.reflect.Field; public class ConfigSwitch extends BasicOption { - public ConfigSwitch(Field field, String name, String description, int size) { - super(field, name, description, size); + public ConfigSwitch(Field field, String name, int size) { + super(field, name, size); } - @Override - public void draw(long vg, int x, int y, int mouseX, int mouseY) { + public void draw(long vg, int x, int y) { } @Override public int getHeight() { - return 0; + return 32; } } 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 04b2ce7..9d93205 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -1,26 +1,65 @@ package io.polyfrost.oneconfig.gui.pages; +import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.config.data.Mod; +import io.polyfrost.oneconfig.config.data.OptionPage; +import io.polyfrost.oneconfig.config.interfaces.BasicOption; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; public class ModConfigPage extends Page { - private final Mod modData; + private final OptionPage page; - public ModConfigPage(Mod mod) { - super("Mod: " + mod.name); - this.modData = mod; + public ModConfigPage(OptionPage page) { + super("Mod: " + page.mod.name); + this.page = page; } @Override public void draw(long vg, int x, int y) { + if (page.categories.size() == 0) return; + String selectedCategory = page.categories.keySet().stream().findFirst().get(); + int optionX = x + 16; + int optionY = y + (page.categories.size() == 1 ? 32 : 72); + for (String subCategory : page.categories.get(selectedCategory).keySet()) { + RenderManager.drawString(vg, subCategory, x + 18, optionY, OneConfigConfig.WHITE, 24f, Fonts.INTER_MEDIUM); + optionY += 20; + int 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); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + backgroundSize += option.getHeight(); + } + RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); + + optionY += 16; + for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) { + BasicOption option = page.categories.get(selectedCategory).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 (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.draw(vg, optionX + 464, optionY); + optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + optionY += option.getHeight() + 16; + } + } } @Override public void finishUpAndClose() { - modData.config.save(); // TODO - } - - public Mod getModData() { - return modData; + page.mod.config.save(); // TODO } } |