From fe8261cf7c10af90c0154633a6a8f18b3e5bfb12 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 1 May 2022 11:23:06 +0200 Subject: icons sidebar, categories in config, fix some other issues --- .../io/polyfrost/oneconfig/config/annotations/Option.java | 2 +- .../java/io/polyfrost/oneconfig/config/data/OptionType.java | 6 ++++++ .../io/polyfrost/oneconfig/config/interfaces/Config.java | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main/java/io/polyfrost/oneconfig/config') 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 fe61a02..7a0b6c1 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java @@ -24,7 +24,7 @@ public @interface Option { /** * The category of the component */ - String category() default "general"; + String category() default "General"; /** * The subcategory of the component (displayed as header) 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 7e106f4..8376786 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java @@ -9,7 +9,13 @@ public enum OptionType { * Type: boolean */ CHECKBOX, + /** + * Type: boolean + */ DUAL_OPTION, + /** + * Type: int + */ UNI_SELECTOR, /** * Type: String 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 af3d037..211c2ce 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -8,7 +8,10 @@ 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.OneConfigGui; import io.polyfrost.oneconfig.gui.elements.config.*; +import io.polyfrost.oneconfig.gui.pages.ModConfigPage; +import net.minecraft.client.Minecraft; import java.io.*; import java.lang.reflect.Field; @@ -20,6 +23,7 @@ import java.util.*; public class Config { protected final String configFile; protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().registerTypeAdapterFactory(OneConfigTypeAdapterFactory.getStaticTypeAdapterFactory()).create(); + private static Mod mod; /** * @param modData information about the mod @@ -36,6 +40,7 @@ public class Config { mod.config = this; generateOptionList(this.getClass(), mod.defaultPage, mod); ConfigCore.oneConfigMods.add(mod); + this.mod = mod; } /** @@ -155,4 +160,12 @@ public class Config { } } } + + /** + * Function to open the gui of this mod + */ + public void openGui() { + if (mod == null) return; + Minecraft.getMinecraft().displayGuiScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); + } } -- cgit From d0d1de91a163d69976ce113cad0fe49556112e36 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 1 May 2022 11:32:02 +0200 Subject: fix ordering issues --- .../oneconfig/config/annotations/ConfigPage.java | 2 +- .../oneconfig/config/data/OptionCategory.java | 4 +- .../oneconfig/config/data/OptionPage.java | 5 +- .../oneconfig/gui/pages/ModConfigPage.java | 97 ++++++++++++---------- 4 files changed, 58 insertions(+), 50 deletions(-) (limited to 'src/main/java/io/polyfrost/oneconfig/config') diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java index fecd438..c0a4169 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/ConfigPage.java @@ -28,5 +28,5 @@ public @interface ConfigPage { /** * The category of the page */ - String category() default "general"; + String category() default "General"; } 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 15c073c..a3752bb 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionCategory.java @@ -4,10 +4,10 @@ import io.polyfrost.oneconfig.config.interfaces.BasicOption; import io.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; public class OptionCategory { - public final HashMap> subcategories = new HashMap<>(); + public final LinkedHashMap> subcategories = new LinkedHashMap<>(); 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 12aef6a..8103404 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionPage.java @@ -1,7 +1,6 @@ package io.polyfrost.oneconfig.config.data; - -import java.util.HashMap; +import java.util.LinkedHashMap; public class OptionPage { public final String name; @@ -11,7 +10,7 @@ public class OptionPage { * Depth 2 = subcategories * Depth 3 = list of options */ - public final HashMap categories = new HashMap<>(); + public final LinkedHashMap categories = new LinkedHashMap<>(); public OptionPage(String name, Mod mod) { this.name = name; 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 6bdf9d9..4839c61 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -19,7 +19,10 @@ public class ModConfigPage extends Page { super("Mod: " + page.mod.name); this.page = page; if (page.categories.size() == 0) return; - selectedCategory = page.categories.keySet().stream().findFirst().get(); + for (String category : page.categories.keySet()) { + selectedCategory = category; + break; + } if (page.categories.size() < 2) return; for (String category : page.categories.keySet()) { BasicButton button = new BasicButton(0, 32, category, null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> switchCategory(category)); @@ -50,46 +53,50 @@ public class ModConfigPage extends Page { } // Background - int backgroundSize = 16; - for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { - backgroundSize += 48; - 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++; - continue; + if (page.categories.get(selectedCategory).subcategories.keySet().size() > 0) { + int backgroundSize = 16; + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { + backgroundSize += 48; + 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++; + continue; + } } + backgroundSize += option.getHeight() + 16; } - backgroundSize += option.getHeight() + 16; } + RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); } - RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); // draw options - optionY += 16; - int optionLastY = optionY; - 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).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).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; - i++; - continue; + int optionLastY = optionY + 16; + if (page.categories.get(selectedCategory).subcategories.keySet().size() > 0) { + optionY += 16; + 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).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).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; + i++; + continue; + } } + optionY += option.getHeight() + 16; } - optionY += option.getHeight() + 16; } + optionY += 16; } - optionY += 16; // Bottom page buttons for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) { @@ -98,21 +105,23 @@ public class ModConfigPage extends Page { } // Draw last options - for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { - optionLastY += 48; - 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.drawLast(vg, optionX, optionLastY); - 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.drawLast(vg, optionX + 512, optionLastY); - optionLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; - i++; - continue; + if (page.categories.get(selectedCategory).subcategories.keySet().size() > 0) { + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { + optionLastY += 48; + 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.drawLast(vg, optionX, optionLastY); + 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.drawLast(vg, optionX + 512, optionLastY); + optionLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } } + optionLastY += option.getHeight() + 16; } - optionLastY += option.getHeight() + 16; } } } -- cgit