From f33aaadbb09e0691479192ad0b5342e8c47f2a1e Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Tue, 28 Jun 2022 14:14:14 +0200 Subject: hide condition things --- .../oneconfig/config/elements/BasicOption.java | 20 +++++++++++++++++++- .../oneconfig/config/elements/OptionSubcategory.java | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/config/elements') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java index eba2f9f..86b339b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java @@ -14,6 +14,7 @@ public abstract class BasicOption { public final String subcategory; private final ArrayList> dependencies = new ArrayList<>(); private final ArrayList listeners = new ArrayList<>(); + private final ArrayList> hideConditions = new ArrayList<>(); /** * Initialize option @@ -39,6 +40,7 @@ public abstract class BasicOption { protected void set(Object object) throws IllegalAccessException { if (field == null) return; field.set(parent, object); + for (Runnable listener : listeners) listener.run(); } /** @@ -86,13 +88,20 @@ public abstract class BasicOption { /** * @return If the option is enabled, based on the dependencies */ - protected boolean isEnabled() { + public boolean isEnabled() { for (Supplier dependency : dependencies) { if (!dependency.get()) return false; } return true; } + public boolean isHidden() { + for (Supplier condition : hideConditions) { + if (condition.get()) return true; + } + return false; + } + /** * Add a condition to this option * @@ -110,4 +119,13 @@ public abstract class BasicOption { public void addListener(Runnable runnable) { this.listeners.add(runnable); } + + /** + * Hide an option if a condition is met + * + * @param supplier The condition + */ + public void addHideCondition(Supplier supplier) { + this.hideConditions.add(supplier); + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java index 66714a4..0066dd8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java @@ -49,6 +49,7 @@ public class OptionSubcategory { } for (ConfigPageButton page : filteredTop) { + if (page.isHidden()) continue; page.draw(vg, x, optionY); optionY += page.getHeight() + 16; } @@ -57,6 +58,7 @@ public class OptionSubcategory { int backgroundSize = 16; for (int i = 0; i < filteredOptions.size(); i++) { BasicOption option = filteredOptions.get(i); + if (option.isHidden()) continue; if (i + 1 < filteredOptions.size()) { BasicOption nextOption = filteredOptions.get(i + 1); if (option.size == 1 && nextOption.size == 1) { @@ -75,6 +77,7 @@ public class OptionSubcategory { if (filteredOptions.size() > 0) { for (int i = 0; i < filteredOptions.size(); i++) { BasicOption option = filteredOptions.get(i); + if (option.isHidden()) continue; option.draw(vg, x, optionY); if (i + 1 < filteredOptions.size()) { BasicOption nextOption = filteredOptions.get(i + 1); @@ -91,6 +94,7 @@ public class OptionSubcategory { } for (ConfigPageButton page : filteredBottom) { + if (page.isHidden()) continue; page.draw(vg, x, optionY); optionY += page.getHeight() + 16; } @@ -101,6 +105,7 @@ public class OptionSubcategory { public void drawLast(long vg, int x) { for (int i = 0; i < filteredOptions.size(); i++) { BasicOption option = filteredOptions.get(i); + if (option.isHidden()) continue; option.drawLast(vg, x, drawLastY); if (i + 1 < filteredOptions.size()) { BasicOption nextOption = filteredOptions.get(i + 1); -- cgit