From f0aac9cac78fc14e2991741061c67b622c039f37 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Tue, 10 May 2022 17:20:24 +0200 Subject: new category system --- .../oneconfig/config/annotations/ConfigPage.java | 5 + .../oneconfig/config/annotations/Option.java | 2 +- .../oneconfig/config/data/OptionCategory.java | 4 +- .../oneconfig/config/data/OptionSubcategory.java | 118 +++++++++++++++++++++ .../oneconfig/config/data/OptionType.java | 6 +- .../oneconfig/config/interfaces/Config.java | 19 +++- .../gui/elements/config/ConfigHeader.java | 32 ++++++ .../oneconfig/gui/pages/ModConfigPage.java | 16 ++- .../cc/polyfrost/oneconfig/test/TestConfig.java | 73 ++++++++++++- 9 files changed, 258 insertions(+), 17 deletions(-) create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java (limited to 'src/main') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java index f9d7c19..432d65c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java @@ -29,4 +29,9 @@ public @interface ConfigPage { * The category of the page */ String category() default "General"; + + /** + * The subcategory of the page + */ + String subcategory() default ""; } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java index d5e9fc7..633e7b9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java @@ -29,7 +29,7 @@ public @interface Option { /** * The subcategory of the component (displayed as header) */ - String subcategory(); + String subcategory() default ""; /** * The width of the option (1 = half width, 2 = full width) diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java index 14111f4..363cfda 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java @@ -7,7 +7,5 @@ import java.util.ArrayList; import java.util.LinkedHashMap; public class OptionCategory { - public final LinkedHashMap> subcategories = new LinkedHashMap<>(); - public final ArrayList topPages = new ArrayList<>(); - public final ArrayList bottomPages = new ArrayList<>(); + public final ArrayList subcategories = new ArrayList<>(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java new file mode 100644 index 0000000..cdd9c51 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java @@ -0,0 +1,118 @@ +package cc.polyfrost.oneconfig.config.data; + +import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; + +import java.util.ArrayList; + +public class OptionSubcategory { + private final String name; + public ArrayList options = new ArrayList<>(); + public ArrayList topButtons = new ArrayList<>(); + public ArrayList bottomButtons = new ArrayList<>(); + + public OptionSubcategory(String name) { + this.name = name; + } + + public int draw(long vg, int x, int y) { + String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); + ArrayList filteredOptions = new ArrayList<>(options); + ArrayList filteredTop = new ArrayList<>(topButtons); + ArrayList filteredBottom = new ArrayList<>(bottomButtons); + if (!filter.equals("") && !name.toLowerCase().contains(filter)) { + filteredOptions.clear(); + filteredTop.clear(); + filteredBottom.clear(); + for (BasicOption option : options) { + if (option.getName().toLowerCase().contains(filter)) filteredOptions.add(option); + } + for (ConfigPageButton page : topButtons) { + if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) + filteredTop.add(page); + } + for (ConfigPageButton page : bottomButtons) { + if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) + filteredBottom.add(page); + } + } + if (filteredOptions.size() == 0 && filteredTop.size() == 0 && filteredBottom.size() == 0) return 0; + int optionY = y; + if (!name.equals("")) { + RenderManager.drawString(vg, name, x, y + 12, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); + optionY += 36; + } + + for (ConfigPageButton page : filteredTop) { + page.draw(vg, x, optionY); + optionY += page.getHeight() + 16; + } + + if (filteredOptions.size() > 0) { + int backgroundSize = 16; + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.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; + } + RenderManager.drawRoundedRect(vg, x - 16, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); + optionY += 16; + } + + int drawLastY = optionY; + if (filteredOptions.size() > 0) { + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + option.draw(vg, x, optionY); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.draw(vg, x + 512, optionY); + optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + optionY += option.getHeight() + 16; + } + optionY += 16; + } + + for (ConfigPageButton page : filteredBottom) { + page.draw(vg, x, optionY); + optionY += page.getHeight() + 16; + } + + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + option.drawLast(vg, x, drawLastY); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.drawLast(vg, x + 512, drawLastY); + drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + drawLastY += option.getHeight() + 16; + } + + return optionY - y; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index a9b9a6a..c89ef2b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -36,11 +36,11 @@ public enum OptionType { DROPDOWN, //MULTI_DROPDOWN, /** - * Type: String + * Type: doesn't matter */ INFO, /** - * Type: class that extends BasicHud + * Type: doesn't matter */ - HUD + HEADER, } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index e8ffe42..35115b1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.config.core.ConfigCore; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.OptionCategory; import cc.polyfrost.oneconfig.config.data.OptionPage; +import cc.polyfrost.oneconfig.config.data.OptionSubcategory; import cc.polyfrost.oneconfig.config.profiles.Profiles; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.*; @@ -84,6 +85,10 @@ public class Config { ConfigPage option = field.getAnnotation(ConfigPage.class); if (!page.categories.containsKey(option.category())) page.categories.put(option.category(), new OptionCategory()); + OptionCategory category = page.categories.get(option.category()); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) + category.subcategories.add(new OptionSubcategory(option.subcategory())); + OptionSubcategory subcategory = category.subcategories.get(category.subcategories.size() - 1); OptionPage newPage = new OptionPage(option.name(), mod); try { field.setAccessible(true); @@ -91,10 +96,10 @@ public class Config { 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)); + subcategory.topButtons.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)); + subcategory.bottomButtons.add(new ConfigPageButton(field, option.name(), option.description(), newPage)); break; } } catch (IllegalAccessException e) { @@ -105,9 +110,10 @@ public class Config { Option option = field.getAnnotation(Option.class); if (!page.categories.containsKey(option.category())) 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()); + OptionCategory category = page.categories.get(option.category()); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) + category.subcategories.add(new OptionSubcategory(option.subcategory())); + ArrayList options = category.subcategories.get(category.subcategories.size() - 1).options; switch (option.type()) { case SWITCH: options.add(new ConfigSwitch(field, option.name(), option.size())); @@ -136,6 +142,9 @@ public class Config { case COLOR: options.add(new ConfigColorElement(field, option.name(), option.size())); break; + case HEADER: + options.add(new ConfigHeader(field, option.name(), option.size())); + break; } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java new file mode 100644 index 0000000..9daa965 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -0,0 +1,32 @@ +package cc.polyfrost.oneconfig.gui.elements.config; + +import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; +import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import net.minecraftforge.fml.client.FMLClientHandler; +import net.minecraftforge.fml.relauncher.FMLLaunchHandler; + +import java.lang.reflect.Field; + +public class ConfigHeader extends BasicOption { + + public ConfigHeader(Field field, String name, int size) { + super(field, name, size); + } + + @Override + public void draw(long vg, int x, int y) { + Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32); + RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); + ScissorManager.resetScissor(vg, scissor); + } + + + @Override + public int getHeight() { + return 32; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index 790d0e4..bdc7242 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -2,6 +2,7 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.data.OptionPage; +import cc.polyfrost.oneconfig.config.data.OptionSubcategory; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; @@ -38,7 +39,7 @@ public class ModConfigPage extends Page { @Override public void draw(long vg, int x, int y) { - if (page.categories.size() == 0) return; + /* String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); LinkedHashMap> filteredSubcategories = new LinkedHashMap<>(page.categories.get(selectedCategory).subcategories); if (!filter.equals("")) { @@ -141,7 +142,14 @@ public class ModConfigPage extends Page { optionLastY += option.getHeight() + 16; } } + }*/ + + if (page.categories.size() == 0) return; + int optionY = y + (page.categories.size() == 1 ? 16 : 64); + for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { + optionY += subCategory.draw(vg, x + 30, optionY); } + totalSize = optionY - y; } @Override @@ -166,9 +174,9 @@ public class ModConfigPage extends Page { @Override public void keyTyped(char key, int keyCode) { if (page.categories.size() == 0) return; - 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); + for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { + for (BasicOption option : subCategory.options) { + option.keyTyped(key, keyCode); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index a741865..141f975 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -195,6 +195,7 @@ public class TestConfig extends Config { max = 25 ) public static int slider1; + @Option( name = "Stepped Slider", subcategory = "Sliders", @@ -207,8 +208,78 @@ public class TestConfig extends Config { ) public static float slider2; + @Option( + name = "Slider", + type = OptionType.SLIDER, + category = "subcategory test", + min = 5, + max = 3287 + ) + public static float slider = 26; + + @Option( + name = "Slider", + type = OptionType.SLIDER, + category = "subcategory test", + min = 5, + max = 3287 + ) + public static float slider10 = 26; + + @Option( + name = "Slider", + type = OptionType.SLIDER, + category = "subcategory test", + min = 5, + max = 3287, + subcategory = "Second subcategory" + ) + public static float slider11 = 26; - TestHud testHud = new TestHud(); + @Option( + name = "Header Test", + type = OptionType.HEADER, + category = "subcategory test", + subcategory = "Second subcategory", + size = 2 + ) + public static boolean somethingHere; + + + @Option( + name = "Slider", + type = OptionType.SLIDER, + category = "subcategory test", + min = 5, + max = 3287, + subcategory = "Second subcategory" + ) + public static float slider12 = 26; + + @ConfigPage( + name = "Test page", + location = PageLocation.TOP, + category = "subcategory test", + subcategory = "Second subcategory" + ) + public static TestPage testPage23 = new TestPage(); + + @ConfigPage( + name = "Test page", + location = PageLocation.BOTTOM, + category = "subcategory test", + subcategory = "Second subcategory" + ) + public static TestPage testPage24 = new TestPage(); + + @Option( + name = "Slider", + type = OptionType.SLIDER, + category = "subcategory test", + min = 5, + max = 3287 + ) + public static float slider13 = 26; public TestConfig() { -- cgit From e299255d82e69e461893ce8ff0ec945c253d945f Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Tue, 10 May 2022 17:48:05 +0200 Subject: button --- .../oneconfig/config/annotations/Option.java | 5 + .../oneconfig/config/data/OptionType.java | 4 + .../oneconfig/config/interfaces/Config.java | 3 + .../gui/elements/config/ConfigButton.java | 36 +++++++ .../gui/elements/config/ConfigHeader.java | 2 - .../oneconfig/gui/pages/ModConfigPage.java | 105 --------------------- .../cc/polyfrost/oneconfig/test/TestConfig.java | 18 ++++ 7 files changed, 66 insertions(+), 107 deletions(-) create mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java (limited to 'src/main') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java index 633e7b9..efcadc8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java @@ -82,4 +82,9 @@ public @interface Option { * Option for info option type */ InfoType infoType() default InfoType.INFO; + + /** + * Text displayed inside button + */ + String buttonText() default "Activate"; } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index c89ef2b..6fe5733 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -43,4 +43,8 @@ public enum OptionType { * Type: doesn't matter */ HEADER, + /** + * Type: runnable + */ + BUTTON } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index 35115b1..c00c62e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -145,6 +145,9 @@ public class Config { case HEADER: options.add(new ConfigHeader(field, option.name(), option.size())); break; + case BUTTON: + options.add(new ConfigButton(field, option.name(), option.size(), option.buttonText())); + break; } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java new file mode 100644 index 0000000..fdb0157 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -0,0 +1,36 @@ +package cc.polyfrost.oneconfig.gui.elements.config; + +import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.elements.BasicButton; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; + +import java.lang.reflect.Field; + +public class ConfigButton extends BasicOption { + private final BasicButton button; + + public ConfigButton(Field field, String name, int size, String text) { + super(field, name, size); + Runnable runnable = () -> { + }; + try { + runnable = (Runnable) get(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, null, null, 1, BasicButton.ALIGNMENT_CENTER, runnable); + } + + @Override + public void draw(long vg, int x, int y) { + RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); + button.draw(vg, x + (size == 1 ? 352 : 736), y); + } + + @Override + public int getHeight() { + return 32; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java index 9daa965..3ef3d06 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -6,8 +6,6 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; -import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.relauncher.FMLLaunchHandler; import java.lang.reflect.Field; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index bdc7242..797f573 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -39,111 +39,6 @@ public class ModConfigPage extends Page { @Override public void draw(long vg, int x, int y) { - /* - String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); - LinkedHashMap> filteredSubcategories = new LinkedHashMap<>(page.categories.get(selectedCategory).subcategories); - if (!filter.equals("")) { - filteredSubcategories.clear(); - for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { - if (subCategory.toLowerCase().contains(filter)) { - filteredSubcategories.put(subCategory, page.categories.get(selectedCategory).subcategories.get(subCategory)); - continue; - } - for (BasicOption option : page.categories.get(selectedCategory).subcategories.get(subCategory)) { - if (!option.getName().toLowerCase().contains(filter)) continue; - if (!filteredSubcategories.containsKey(subCategory)) - filteredSubcategories.put(subCategory, new ArrayList<>()); - filteredSubcategories.get(subCategory).add(option); - } - } - } - int optionX = x + 30; - int optionY = y + (page.categories.size() == 1 ? 16 : 64); - - // Top page buttons - for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) { - if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter)) - continue; - page.draw(vg, optionX, optionY); - optionY += page.getHeight() + 16; - } - - // Background - if (filteredSubcategories.keySet().size() > 0) { - int backgroundSize = 16; - for (String subCategory : filteredSubcategories.keySet()) { - backgroundSize += 48; - for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) { - BasicOption option = filteredSubcategories.get(subCategory).get(i); - if (i + 1 < filteredSubcategories.get(subCategory).size()) { - BasicOption nextOption = filteredSubcategories.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; - } - } - RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); - } - - // draw options - int optionLastY = optionY + 16; - if (filteredSubcategories.keySet().size() > 0) { - optionY += 16; - for (String subCategory : filteredSubcategories.keySet()) { - RenderManager.drawString(vg, subCategory, optionX, optionY + 16, OneConfigConfig.WHITE_90, 24f, Fonts.MEDIUM); - optionY += 48; - for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) { - BasicOption option = filteredSubcategories.get(subCategory).get(i); - option.draw(vg, optionX, optionY); - if (i + 1 < filteredSubcategories.get(subCategory).size()) { - BasicOption nextOption = filteredSubcategories.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 += 16; - } - - // Bottom page buttons - for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) { - if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter)) - continue; - page.draw(vg, optionX, optionY); - optionY += page.getHeight() + 16; - } - totalSize = optionY - y; - - // Draw last options - if (filteredSubcategories.keySet().size() > 0) { - for (String subCategory : filteredSubcategories.keySet()) { - optionLastY += 48; - for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) { - BasicOption option = filteredSubcategories.get(subCategory).get(i); - option.drawLast(vg, optionX, optionLastY); - if (i + 1 < filteredSubcategories.get(subCategory).size()) { - BasicOption nextOption = filteredSubcategories.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; - } - } - }*/ - if (page.categories.size() == 0) return; int optionY = y + (page.categories.size() == 1 ? 16 : 64); for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index 141f975..d314354 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -5,6 +5,7 @@ import cc.polyfrost.oneconfig.config.annotations.Option; import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.interfaces.Config; import cc.polyfrost.oneconfig.lwjgl.OneColor; +import net.minecraftforge.fml.common.FMLCommonHandler; public class TestConfig extends Config { @@ -17,6 +18,23 @@ public class TestConfig extends Config { ) public static boolean ignored; + @Option( + name = "Crash game", + subcategory = "Test", + type = OptionType.BUTTON, + buttonText = "Crash!" + ) + public static Runnable runnable = () -> FMLCommonHandler.instance().exitJava(69, false); + + @Option( + name = "Crash game", + subcategory = "Test", + type = OptionType.BUTTON, + size = 2, + buttonText = "Crash!" + ) + public static Runnable runnable2 = () -> FMLCommonHandler.instance().exitJava(69, false); + @Option( name = "Test color selector", subcategory = "Test", -- cgit From c920e2c93970e0df1dc863afc70741ade6b3cec4 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Tue, 10 May 2022 18:22:56 +0200 Subject: new sidebar --- .../oneconfig/config/interfaces/Config.java | 2 +- .../java/cc/polyfrost/oneconfig/gui/SideBar.java | 29 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src/main') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index c00c62e..906153e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -184,7 +184,7 @@ public class Config { Object object = adapter.fromJsonTree(value); field.setAccessible(true); field.set(this, object); - } catch (NoSuchFieldException | IllegalAccessException ignored) { + } catch (Exception ignored) { } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 978f420..25b0132 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -21,14 +21,16 @@ public class SideBar { public SideBar() { btnList.add(new BasicButton(192, 36, "Dashboard", Images.DASHBOARD, null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage())); btnList.add(new BasicButton(192, 36, "Global Search", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "Mods", Images.MODS, null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage())); btnList.add(new BasicButton(192, 36, "Performance", Images.PERFORMANCE, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "Profiles", Images.PROFILES, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "Updates", Images.UPDATES, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Theme", Images.THEMES, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "HUD Settings", Images.HUD_SETTINGS, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Themes Library", Images.THEMES, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Themes Browser", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Packs Library", Images.MOD_BOX, null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Packs Browser", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "Close", Images.CLOSE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(null))); btnList.add(new BasicButton(192, 36, "Minimize", Images.MINIMIZE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> { OneConfigGui.instanceToRestore = OneConfigGui.INSTANCE; @@ -38,8 +40,6 @@ public class SideBar { } public void draw(long vg, int x, int y) { - //percentMove = 36f; - currentY = MathUtils.easeInOutCirc(50, currentY, targetY - currentY, 120); RenderManager.drawRoundedRect(vg, x + 16, currentY, 192, 36, OneConfigConfig.BLUE_600, OneConfigConfig.CORNER_RADIUS); int i = 0; @@ -49,16 +49,17 @@ public class SideBar { } for (BasicButton btn : btnList) { btn.draw(vg, x + 16, y + 96 + i); - i += 44; - if (i == 88) { // +88 - RenderManager.drawString(vg, "MOD CONFIG", x + 16, y + 200, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD); - i = 122; + if (i >= 562) i += 44; + else i += 36; + if (i == 144) { + RenderManager.drawString(vg, "MOD CONFIG", x + 16, y + 266, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD); + i = 180; } - if (i == 298) { - RenderManager.drawString(vg, "PERSONALIZATION", x + 16, y + 420, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD); - i = 342; + if (i == 324) { + RenderManager.drawString(vg, "PERSONALIZATION", x + 16, y + 446, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD); + i = 360; } - if (i == 518) { + if (i == 504) { i = 562; } -- cgit From 6fdef44be55116bff1eadfd2c7896808ac782dc1 Mon Sep 17 00:00:00 2001 From: MoonTidez <79183852+MoonTidez@users.noreply.github.com> Date: Tue, 10 May 2022 21:26:03 +0400 Subject: Added a few notes to an extent on naming etc --- .../cc/polyfrost/oneconfig/lwjgl/RenderManager.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 979acde..663092e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -74,7 +74,7 @@ public final class RenderManager { } } - +// Can be removed or atleast marked out since it is no longer used - MoonTidez public static void drawGradientRoundedRect(long vg, float x, float y, float width, float height, int color, int color2, float radius) { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); @@ -94,27 +94,28 @@ public final class RenderManager { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); nvgRoundedRect(vg, x, y, width, height, 8f); - NVGColor nvgColor = color(vg, OneConfigConfig.WHITE); - NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT_25); + NVGColor nvgColor = color(vg, OneConfigConfig.WHITE); // Do not use OneConfigConfig colors for this, use rgba code - MoonTidez + NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT_25); // Why is this Transparent_25?? - MoonTidez nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); nvgFill(vg); - nvgColor.free(); + nvgColor.free(); // Can you please give these proper color names :wahh: so unprofeshunal smh - MoonTidez nvgColor2.free(); NVGPaint bg2 = NVGPaint.create(); nvgBeginPath(vg); nvgRoundedRect(vg, x, y, width, height, 8f); - NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT_25); - NVGColor nvgColor4 = color(vg, OneConfigConfig.BLACK); + NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT_25); // Why is this Transparent_25?? [v2] - MoonTidez + NVGColor nvgColor4 = color(vg, OneConfigConfig.BLACK); // Do not use OneConfigConfig colors for this, use rgba code - MoonTidez nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + height, nvgColor3, nvgColor4, bg2)); nvgFill(vg); - nvgColor3.free(); - nvgColor4.free(); + nvgColor3.free(); // Can you please give these proper color names :wahh: so unprofeshunal smh [v2] - MoonTidez + nvgColor4.free(); //drawHollowRoundRect(vg, x - 0.5f, y - 0.5f, width, height, new Color(77,77,77,255).getRGB(), 8f, 1f); } +// Can be removed or atleast marked out since it is no longer used - MoonTidez public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); @@ -128,6 +129,7 @@ public final class RenderManager { nvgColor2.free(); } +// I stopped reviewing code here, I'll review the rest later - MoonTidez public static void drawRect(long vg, float x, float y, float width, float height, int color) { nvgBeginPath(vg); nvgRect(vg, x, y, width, height); -- cgit From 3872c0ae8746e69671ac9b44ff94dc3c7b194817 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Tue, 10 May 2022 19:34:08 +0200 Subject: remove useless moon comments --- .../cc/polyfrost/oneconfig/lwjgl/RenderManager.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 663092e..04b94f3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -74,7 +74,7 @@ public final class RenderManager { } } -// Can be removed or atleast marked out since it is no longer used - MoonTidez + // Can be removed or atleast marked out since it is no longer used - MoonTidez public static void drawGradientRoundedRect(long vg, float x, float y, float width, float height, int color, int color2, float radius) { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); @@ -88,34 +88,30 @@ public final class RenderManager { } public static void drawHSBBox(long vg, float x, float y, float width, float height, int colorTarget) { - drawRoundedRect(vg, x, y, width, height, colorTarget, 8f); NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); nvgRoundedRect(vg, x, y, width, height, 8f); NVGColor nvgColor = color(vg, OneConfigConfig.WHITE); // Do not use OneConfigConfig colors for this, use rgba code - MoonTidez - NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT_25); // Why is this Transparent_25?? - MoonTidez + NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT_25); nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); nvgFill(vg); - nvgColor.free(); // Can you please give these proper color names :wahh: so unprofeshunal smh - MoonTidez + nvgColor.free(); nvgColor2.free(); NVGPaint bg2 = NVGPaint.create(); nvgBeginPath(vg); nvgRoundedRect(vg, x, y, width, height, 8f); - NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT_25); // Why is this Transparent_25?? [v2] - MoonTidez + NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT_25); NVGColor nvgColor4 = color(vg, OneConfigConfig.BLACK); // Do not use OneConfigConfig colors for this, use rgba code - MoonTidez nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + height, nvgColor3, nvgColor4, bg2)); nvgFill(vg); - nvgColor3.free(); // Can you please give these proper color names :wahh: so unprofeshunal smh [v2] - MoonTidez - nvgColor4.free(); - - //drawHollowRoundRect(vg, x - 0.5f, y - 0.5f, width, height, new Color(77,77,77,255).getRGB(), 8f, 1f); - + nvgColor3.free(); + nvgColor4.free(); } -// Can be removed or atleast marked out since it is no longer used - MoonTidez + /* public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); @@ -128,8 +124,8 @@ public final class RenderManager { nvgColor.free(); nvgColor2.free(); } + */ -// I stopped reviewing code here, I'll review the rest later - MoonTidez public static void drawRect(long vg, float x, float y, float width, float height, int color) { nvgBeginPath(vg); nvgRect(vg, x, y, width, height); -- cgit