From 16e781c4bee6c68c0c3e2d485b57daa0f589101e Mon Sep 17 00:00:00 2001 From: isXander Date: Tue, 20 Dec 2022 16:29:17 +0000 Subject: minor fixes/improvements new LabelOption to create labels easier add 'List is empty' entry to lists that are empty fix option list widget background not being wide enough --- .../dev/isxander/yacl/gui/OptionListWidget.java | 82 ++++++++++++++++++---- .../dev/isxander/yacl/gui/SearchFieldWidget.java | 4 ++ 2 files changed, 71 insertions(+), 15 deletions(-) (limited to 'src/client/java/dev/isxander/yacl/gui') diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java index c18597f..674fc56 100644 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -3,8 +3,6 @@ package dev.isxander.yacl.gui; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; -import dev.isxander.yacl.gui.controllers.ListEntryWidget; -import dev.isxander.yacl.impl.ListOptionEntryImpl; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.MultilineText; @@ -16,6 +14,7 @@ import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -27,7 +26,7 @@ public class OptionListWidget extends ElementListWidgetExt viewableChildren; public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) { - super(client, width / 3, 0, width / 3 * 2, height, true); + super(client, width / 3, 0, width / 3 * 2 + 1, height, true); this.yaclScreen = screen; refreshOptions(); @@ -65,7 +64,17 @@ public class OptionListWidget extends ElementListWidgetExt optionEntries = new ArrayList<>(); + List optionEntries = new ArrayList<>(); + + // add empty entry to make sure users know it's empty not just bugging out + if (groupSeparatorEntry instanceof ListGroupSeparatorEntry listGroupSeparatorEntry) { + if (listGroupSeparatorEntry.listOption.options().isEmpty()) { + EmptyListLabel emptyListLabel = new EmptyListLabel(listGroupSeparatorEntry, category); + addEntry(emptyListLabel); + optionEntries.add(emptyListLabel); + } + } + for (Option option : group.options()) { OptionEntry entry = new OptionEntry(option, category, group, groupSeparatorEntry, option.controller().provideWidget(yaclScreen, getDefaultEntryDimension())); addEntry(entry); @@ -73,7 +82,7 @@ public class OptionListWidget extends ElementListWidgetExt listOption, ConfigCategory category) { // find group separator for group - GroupSeparatorEntry groupSeparator = super.children().stream().filter(e -> e instanceof GroupSeparatorEntry gs && gs.group == listOption).map(GroupSeparatorEntry.class::cast).findAny().orElse(null); + ListGroupSeparatorEntry groupSeparator = super.children().stream().filter(e -> e instanceof ListGroupSeparatorEntry gs && gs.group == listOption).map(ListGroupSeparatorEntry.class::cast).findAny().orElse(null); if (groupSeparator == null) { YACLConstants.LOGGER.warn("Can't find group seperator to refresh list option entries for list option " + listOption.name()); return; } - for (OptionEntry entry : groupSeparator.optionEntries) + for (Entry entry : groupSeparator.childEntries) super.removeEntry(entry); - groupSeparator.optionEntries.clear(); + groupSeparator.childEntries.clear(); // if no entries, below loop won't run where addEntryBelow() recaches viewable children if (listOption.options().isEmpty()) { - recacheViewableChildren(); + EmptyListLabel emptyListLabel; + addEntryBelow(groupSeparator, emptyListLabel = new EmptyListLabel(groupSeparator, category)); + groupSeparator.childEntries.add(emptyListLabel); return; } @@ -106,7 +117,7 @@ public class OptionListWidget extends ElementListWidgetExt listOptionEntry : listOption.options()) { OptionEntry optionEntry = new OptionEntry(listOptionEntry, category, listOption, groupSeparator, listOptionEntry.controller().provideWidget(yaclScreen, getDefaultEntryDimension())); addEntryBelow(lastEntry, optionEntry); - groupSeparator.optionEntries.add(optionEntry); + groupSeparator.childEntries.add(optionEntry); lastEntry = optionEntry; } } @@ -304,7 +315,7 @@ public class OptionListWidget extends ElementListWidgetExt optionEntries; + protected List childEntries = new ArrayList<>(); private int y; @@ -401,13 +412,14 @@ public class OptionListWidget extends ElementListWidgetExt optionEntries) { - this.optionEntries = optionEntries; + public void setChildEntries(List childEntries) { + this.childEntries.clear(); + this.childEntries.addAll(childEntries); } @Override public boolean isViewable() { - return yaclScreen.searchFieldWidget.isEmpty() || optionEntries.stream().anyMatch(OptionEntry::isViewable); + return yaclScreen.searchFieldWidget.isEmpty() || childEntries.stream().anyMatch(Entry::isViewable); } @Override @@ -506,4 +518,44 @@ public class OptionListWidget extends ElementListWidgetExt children() { + return ImmutableList.of(); + } + + @Override + public List selectableChildren() { + return ImmutableList.of(); + } + } } diff --git a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java index 5b7c9dc..3cfe75e 100644 --- a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java @@ -48,6 +48,10 @@ public class SearchFieldWidget extends TextFieldWidget { yaclScreen.categoryList.setScrollAmount(0); } + public String getQuery() { + return getText().toLowerCase(); + } + public boolean isEmpty() { return isEmpty; } -- cgit