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/api/YetAnotherConfigLib.java5
-rw-r--r--src/main/java/dev/isxander/yacl/gui/CategoryWidget.java2
-rw-r--r--src/main/java/dev/isxander/yacl/gui/OptionListWidget.java13
-rw-r--r--src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java37
-rw-r--r--src/main/java/dev/isxander/yacl/gui/YACLScreen.java15
5 files changed, 37 insertions, 35 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
index 34ccc6a..a69ae4e 100644
--- a/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
+++ b/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
@@ -94,8 +94,8 @@ public interface YetAnotherConfigLib {
*
* @see YetAnotherConfigLib#categories()
*/
- public Builder categories(@NotNull Collection<ConfigCategory> categories) {
- Validate.notEmpty(categories, "`categories` cannot be empty");
+ public Builder categories(@NotNull Collection<? extends ConfigCategory> categories) {
+ Validate.notNull(categories, "`categories` cannot be null");
this.categories.addAll(categories);
return this;
@@ -128,6 +128,7 @@ public interface YetAnotherConfigLib {
public YetAnotherConfigLib build() {
Validate.notNull(title, "`title must not be null to build `YetAnotherConfigLib`");
Validate.notEmpty(categories, "`categories` must not be empty to build `YetAnotherConfigLib`");
+ Validate.isTrue(!categories.stream().allMatch(category -> category instanceof PlaceholderCategory), "At least one regular category is required to build `YetAnotherConfigLib`");
return new YetAnotherConfigLibImpl(title, ImmutableList.copyOf(categories), saveFunction, initConsumer);
}
diff --git a/src/main/java/dev/isxander/yacl/gui/CategoryWidget.java b/src/main/java/dev/isxander/yacl/gui/CategoryWidget.java
index 634056a..3c5d8d2 100644
--- a/src/main/java/dev/isxander/yacl/gui/CategoryWidget.java
+++ b/src/main/java/dev/isxander/yacl/gui/CategoryWidget.java
@@ -15,7 +15,7 @@ public class CategoryWidget extends TooltipButtonWidget {
}
private boolean isCurrentCategory() {
- return ((YACLScreen) screen).currentCategoryIdx == categoryIndex;
+ return ((YACLScreen) screen).getCurrentCategoryIdx() == categoryIndex;
}
@Override
diff --git a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
index 4adb30b..bfa203a 100644
--- a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
+++ b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java
@@ -41,10 +41,10 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
clearEntries();
List<ConfigCategory> categories = new ArrayList<>();
- if (yaclScreen.currentCategoryIdx == -1) {
+ if (yaclScreen.getCurrentCategoryIdx() == -1) {
categories.addAll(yaclScreen.config.categories());
} else {
- categories.add(yaclScreen.config.categories().get(yaclScreen.currentCategoryIdx));
+ categories.add(yaclScreen.config.categories().get(yaclScreen.getCurrentCategoryIdx()));
}
singleCategory = categories.size() == 1;
@@ -77,6 +77,14 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
setScrollAmount(0);
}
+ public void expandAllGroups() {
+ for (Entry entry : super.children()) {
+ if (entry instanceof GroupSeparatorEntry groupSeparatorEntry) {
+ groupSeparatorEntry.setExpanded(true);
+ }
+ }
+ }
+
/*
below code is licensed from cloth-config under LGPL3
modified to inherit vanilla's EntryListWidget and use yarn mappings
@@ -282,6 +290,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
@Override
public boolean isViewable() {
String query = yaclScreen.searchFieldWidget.getText();
+ System.out.println(viewableSupplier.get());
return viewableSupplier.get()
&& (yaclScreen.searchFieldWidget.isEmpty()
|| (!singleCategory && categoryName.contains(query))
diff --git a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
index b4834db..6184405 100644
--- a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
+++ b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java
@@ -14,6 +14,7 @@ public class SearchFieldWidget extends TextFieldWidget {
public SearchFieldWidget(YACLScreen yaclScreen, TextRenderer textRenderer, int x, int y, int width, int height, Text text, Text emptyText) {
super(textRenderer, x, y, width, height, text);
+ setChangedListener(string -> update());
setTextPredicate(string -> !string.endsWith(" ") && !string.startsWith(" "));
this.yaclScreen = yaclScreen;
this.textRenderer = textRenderer;
@@ -28,33 +29,23 @@ public class SearchFieldWidget extends TextFieldWidget {
}
}
- @Override
- public void write(String text) {
- update();
- super.write(text);
- postUpdate();
- }
+ private void update() {
+ boolean wasEmpty = isEmpty;
+ isEmpty = getText().isEmpty();
- @Override
- public void eraseCharacters(int characterOffset) {
- update();
- super.eraseCharacters(characterOffset);
- postUpdate();
- }
+ if (isEmpty && wasEmpty)
+ return;
- private void update() {
- yaclScreen.optionList.setScrollAmount(0);
- yaclScreen.categoryList.setScrollAmount(0);
- for (OptionListWidget.Entry entry : yaclScreen.optionList.children()) {
- if (entry instanceof OptionListWidget.GroupSeparatorEntry groupSeparatorEntry) {
- groupSeparatorEntry.setExpanded(true);
- }
- }
- }
+ if (!isEmpty && yaclScreen.getCurrentCategoryIdx() != -1)
+ yaclScreen.changeCategory(-1);
+ if (isEmpty && yaclScreen.getCurrentCategoryIdx() == -1)
+ yaclScreen.changeCategory(0);
- private void postUpdate() {
- isEmpty = getText().isEmpty();
+ yaclScreen.optionList.expandAllGroups();
yaclScreen.optionList.recacheViewableChildren();
+
+ yaclScreen.optionList.setScrollAmount(0);
+ yaclScreen.categoryList.setScrollAmount(0);
}
public boolean isEmpty() {
diff --git a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java
index 63cb2f6..70c61c1 100644
--- a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java
+++ b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java
@@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class YACLScreen extends Screen {
public final YetAnotherConfigLib config;
- public int currentCategoryIdx;
+ private int currentCategoryIdx;
private final Screen parent;
@@ -139,6 +139,9 @@ public class YACLScreen extends Screen {
}
public void changeCategory(int idx) {
+ if (idx == currentCategoryIdx)
+ return;
+
if (idx != -1 && config.categories().get(idx) instanceof PlaceholderCategory placeholderCategory) {
client.setScreen(placeholderCategory.screen().apply(client, this));
} else {
@@ -147,6 +150,10 @@ public class YACLScreen extends Screen {
}
}
+ public int getCurrentCategoryIdx() {
+ return currentCategoryIdx;
+ }
+
private void updateActionAvailability() {
boolean pendingChanges = pendingChanges();
@@ -160,12 +167,6 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
searchFieldWidget.tick();
- if (!searchFieldWidget.getText().isEmpty() && currentCategoryIdx != -1) {
- changeCategory(-1);
- }
- if (searchFieldWidget.getText().isEmpty() && currentCategoryIdx == -1) {
- changeCategory(0);
- }
updateActionAvailability();