aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/dev/isxander/yacl/gui/OptionListWidget.java15
-rw-r--r--src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java21
2 files changed, 32 insertions, 4 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
index 0c9baf5..a947f61 100644
--- a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
+++ b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
@@ -29,6 +29,7 @@ import java.util.function.Supplier;
public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> {
private final YACLScreen yaclScreen;
+ private boolean singleCategory = false;
public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) {
super(client, width / 3 * 2, height, 0, height, 22);
@@ -48,6 +49,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
} else {
categories.add(yaclScreen.config.categories().get(yaclScreen.currentCategoryIdx));
}
+ singleCategory = categories.size() == 1;
for (ConfigCategory category : categories) {
for (OptionGroup group : category.groups()) {
@@ -63,7 +65,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
List<OptionEntry> optionEntries = new ArrayList<>();
for (Option<?> option : group.options()) {
- OptionEntry entry = new OptionEntry(option.controller().provideWidget(yaclScreen, Dimension.ofInt(getRowLeft(), 0, getRowWidth(), 20)), viewableSupplier);
+ OptionEntry entry = new OptionEntry(category, group, option.controller().provideWidget(yaclScreen, Dimension.ofInt(getRowLeft(), 0, getRowWidth(), 20)), viewableSupplier);
addEntry(entry);
optionEntries.add(entry);
}
@@ -229,11 +231,16 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
}
}
- private class OptionEntry extends Entry {
+ public class OptionEntry extends Entry {
+ public final ConfigCategory category;
+ public final OptionGroup group;
+
public final AbstractWidget widget;
private final Supplier<Boolean> viewableSupplier;
- public OptionEntry(AbstractWidget widget, Supplier<Boolean> viewableSupplier) {
+ private OptionEntry(ConfigCategory category, OptionGroup group, AbstractWidget widget, Supplier<Boolean> viewableSupplier) {
+ this.category = category;
+ this.group = group;
this.widget = widget;
this.viewableSupplier = viewableSupplier;
}
@@ -267,7 +274,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
@Override
public boolean isViewable() {
- return viewableSupplier.get() && widget.matchesSearch(yaclScreen.searchFieldWidget.getText().trim());
+ return viewableSupplier.get() && yaclScreen.searchFieldWidget.matches(this, singleCategory);
}
@Override
diff --git a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
index 2af677d..2405dbd 100644
--- a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
+++ b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
@@ -1,5 +1,7 @@
package dev.isxander.yacl.gui;
+import dev.isxander.yacl.api.ConfigCategory;
+import dev.isxander.yacl.api.OptionGroup;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
@@ -45,6 +47,25 @@ public class SearchFieldWidget extends TextFieldWidget {
super.eraseCharacters(characterOffset);
}
+ public boolean matches(OptionListWidget.OptionEntry optionEntry, boolean ignoreCategory) {
+ return (matchesCategory(optionEntry.category) && !ignoreCategory) || matchesGroup(optionEntry.group) || matchesWidget(optionEntry.widget);
+ }
+
+ public boolean matchesCategory(ConfigCategory category) {
+ return category.name().getString().toLowerCase().contains(getText().trim());
+ }
+
+ public boolean matchesGroup(OptionGroup group) {
+ if (group.isRoot())
+ return false;
+
+ return group.name().getString().toLowerCase().contains(getText().trim());
+ }
+
+ public boolean matchesWidget(AbstractWidget widget) {
+ return widget.matchesSearch(getText().trim());
+ }
+
public Text getEmptyText() {
return emptyText;
}