diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-10 17:20:24 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-10 17:20:24 +0200 |
commit | f0aac9cac78fc14e2991741061c67b622c039f37 (patch) | |
tree | b957cfafb51656efdaa1cd92ce99281ef27328e9 /src/main/java/cc/polyfrost/oneconfig/config/data | |
parent | 20cf8146e88f3ca06399fdf163badef759f01d2c (diff) | |
download | OneConfig-f0aac9cac78fc14e2991741061c67b622c039f37.tar.gz OneConfig-f0aac9cac78fc14e2991741061c67b622c039f37.tar.bz2 OneConfig-f0aac9cac78fc14e2991741061c67b622c039f37.zip |
new category system
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/data')
3 files changed, 122 insertions, 6 deletions
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<String, ArrayList<BasicOption>> subcategories = new LinkedHashMap<>(); - public final ArrayList<ConfigPageButton> topPages = new ArrayList<>(); - public final ArrayList<ConfigPageButton> bottomPages = new ArrayList<>(); + public final ArrayList<OptionSubcategory> 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<BasicOption> options = new ArrayList<>(); + public ArrayList<ConfigPageButton> topButtons = new ArrayList<>(); + public ArrayList<ConfigPageButton> 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<BasicOption> filteredOptions = new ArrayList<>(options); + ArrayList<ConfigPageButton> filteredTop = new ArrayList<>(topButtons); + ArrayList<ConfigPageButton> 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, } |