aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/elements
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/elements')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java20
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java5
2 files changed, 24 insertions, 1 deletions
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<Supplier<Boolean>> dependencies = new ArrayList<>();
private final ArrayList<Runnable> listeners = new ArrayList<>();
+ private final ArrayList<Supplier<Boolean>> 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<Boolean> dependency : dependencies) {
if (!dependency.get()) return false;
}
return true;
}
+ public boolean isHidden() {
+ for (Supplier<Boolean> 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<Boolean> 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);