diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java index f572a791..0989e87f 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java @@ -31,8 +31,12 @@ import net.fabricmc.api.Environment; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import java.util.List; import java.util.function.Function; @@ -155,4 +159,30 @@ default DropdownMenuBuilder startStringDropdownMenu(Component fieldNameK default DropdownMenuBuilder startStringDropdownMenu(Component fieldNameKey, String value, Function toTextFunction) { return startDropdownMenu(fieldNameKey, TopCellElementBuilder.of(value, s -> s, toTextFunction), new DefaultSelectionCellCreator<>()); } + + DropdownListBuilder startDropdownList(Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator); + + default DropdownListBuilder startItemIdentifierList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemIdentifier(BuiltInRegistries.ITEM.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofItemIdentifier()); + entry.setSelections(BuiltInRegistries.ITEM.keySet()); + return entry; + } + + default DropdownListBuilder startBlockIdentifierList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockIdentifier(BuiltInRegistries.BLOCK.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofBlockIdentifier()); + entry.setSelections(BuiltInRegistries.BLOCK.keySet()); + return entry; + } + + default DropdownListBuilder startItemObjectList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()); + entry.setSelections(BuiltInRegistries.ITEM); + return entry; + } + + default DropdownListBuilder startBlockObjectList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofBlockObject()); + entry.setSelections(BuiltInRegistries.BLOCK); + return entry; + } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java index da1ff9e7..f5b7295f 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java @@ -53,6 +53,12 @@ public void setErrorSupplier(Supplier> errorSupplier) { public abstract void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta); + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) {} + + public int getMorePossibleHeight() { + return 0; + } + public void updateSelected(boolean isSelected) {} public boolean isRequiresRestart() { diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java index 8d98d830..81b2d06e 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java @@ -310,6 +310,21 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth } } + @Override + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + super.lateRender(graphics, mouseX, mouseY, delta); + BaseListCell focused = !isExpanded() || getFocused() == null || !(getFocused() instanceof BaseListCell) ? null : (BaseListCell) getFocused(); + if(focused != null) { + focused.lateRender(graphics, mouseX, mouseY, delta); + } + } + + @Override + public int getMorePossibleHeight() { + BaseListCell focused = !isExpanded() || getFocused() == null || !(getFocused() instanceof BaseListCell) ? null : (BaseListCell) getFocused(); + return focused != null ? focused.getMorePossibleHeight() : 0; + } + @Override public void updateSelected(boolean isSelected) { for (C cell : cells) { diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java index 1ddfc731..8c1ccd35 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java @@ -66,6 +66,7 @@ public class DropdownBoxEntry extends TooltipListEntry { protected SelectionElement selectionElement; @NotNull private final Supplier defaultValue; private boolean suggestionMode = true; + protected boolean dontReFocus = false; @ApiStatus.Internal @Deprecated @@ -76,7 +77,7 @@ public DropdownBoxEntry(Component fieldName, @NotNull Component resetButtonKey, this.resetButton = Button.builder(resetButtonKey, widget -> { selectionElement.topRenderer.setValue(defaultValue.get()); }).bounds(0, 0, Minecraft.getInstance().font.width(resetButtonKey) + 6, 20).build(); - this.selectionElement = new SelectionElement<>(this, new Rectangle(0, 0, 150, 20), new DefaultDropdownMenuElement<>(selections == null ? ImmutableList.of() : ImmutableList.copyOf(selections)), topRenderer, cellCreator); + this.selectionElement = new SelectionElement<>(this, new Rectangle(0, 0, fieldName.getString().isBlank() ? 300 : 150, 20), new DefaultDropdownMenuElement<>(selections == null ? ImmutableList.of() : ImmutableList.copyOf(selections)), topRenderer, cellCreator); } @Override @@ -88,6 +89,7 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth this.selectionElement.active = isEditable(); this.selectionElement.bounds.y = y; Component displayedFieldName = getDisplayedFieldName(); + boolean hasName = !displayedFieldName.getString().isBlank(); if (Minecraft.getInstance().font.isBidirectional()) { graphics.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), window.getGuiScaledWidth() - x - Minecraft.getInstance().font.width(displayedFieldName), y + 6, getPreferredTextColor()); this.resetButton.setX(x); @@ -95,9 +97,9 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth } else { graphics.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), x, y + 6, getPreferredTextColor()); this.resetButton.setX(x + entryWidth - resetButton.getWidth()); - this.selectionElement.bounds.x = x + entryWidth - 150 + 1; + this.selectionElement.bounds.x = x + (hasName ? entryWidth - 150 : 0) + 1; } - this.selectionElement.bounds.width = 150 - resetButton.getWidth() - 4; + this.selectionElement.bounds.width = (hasName ? 150 : entryWidth) - resetButton.getWidth() - 4; resetButton.render(graphics, mouseX, mouseY, delta); selectionElement.render(graphics, mouseX, mouseY, delta); } @@ -171,13 +173,22 @@ public boolean mouseScrolled(double double_1, double double_2, double amountX, d return selectionElement.mouseScrolled(double_1, double_2, amountX, amountY); } + @Override + public boolean mouseClicked(double double_1, double double_2, int int_1) { + boolean b = super.mouseClicked(double_1, double_2, int_1); + if (dontReFocus) { + setFocused(null); + dontReFocus = false; + } + return b; + } + public static class SelectionElement extends AbstractContainerEventHandler implements Renderable { protected Rectangle bounds; protected boolean active; protected SelectionTopCellElement topRenderer; protected DropdownBoxEntry entry; protected DropdownMenuElement menu; - protected boolean dontReFocus = false; public SelectionElement(DropdownBoxEntry entry, Rectangle bounds, DropdownMenuElement menu, SelectionTopCellElement topRenderer, SelectionCellCreator cellCreator) { this.bounds = bounds; @@ -230,17 +241,6 @@ public R getValue() { public List children() { return Lists.newArrayList(topRenderer, menu); } - - @Override - public boolean mouseClicked(double double_1, double double_2, int int_1) { - dontReFocus = false; - boolean b = super.mouseClicked(double_1, double_2, int_1); - if (dontReFocus) { - setFocused(null); - dontReFocus = false; - } - return b; - } } public static abstract class DropdownMenuElement extends AbstractContainerEventHandler { @@ -253,6 +253,10 @@ public SelectionCellCreator getCellCreator() { return cellCreator; } + public int getCellWidth() { + return getCellCreator().getCellWidth() > 0 ? getCellCreator().getCellWidth() : getEntry().selectionElement.bounds.width; + } + @NotNull public final DropdownBoxEntry getEntry() { return entry; @@ -408,18 +412,19 @@ private void updatePosition(float delta) { @Override public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { int last10Height = getHeight(); - int cWidth = getCellCreator().getCellWidth(); - graphics.fill(lastRectangle.x, lastRectangle.y + lastRectangle.height, lastRectangle.x + cWidth, lastRectangle.y + lastRectangle.height + last10Height + 1, isExpanded() ? -1 : -6250336); - graphics.fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, -16777216); + int cWidth = getCellWidth(); graphics.pose().pushPose(); graphics.pose().translate(0, 0, 300f); + graphics.fill(lastRectangle.x, lastRectangle.y + lastRectangle.height, lastRectangle.x + cWidth, lastRectangle.y + lastRectangle.height + last10Height + 1, isExpanded() ? 0xFFFFFFFF : -6250336); + graphics.fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, 0xFF000000); + graphics.pose().translate(0, 0, 300f); ScissorsHandler.INSTANCE.scissor(new Rectangle(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, cWidth - 6, last10Height - 1)); - double yy = lastRectangle.y + lastRectangle.height - scroll; + double yy = lastRectangle.y + lastRectangle.height - scroll + 1; for (SelectionCellElement cell : currentElements) { if (yy + getCellCreator().getCellHeight() >= lastRectangle.y + lastRectangle.height && yy <= lastRectangle.y + lastRectangle.height + last10Height + 1) { - graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + getCellCreator().getCellWidth(), (int) yy + getCellCreator().getCellHeight(), 0xFF000000); - cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight(), delta); + graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + cWidth, (int) yy + getCellCreator().getCellHeight(), 0xFF000000); + cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? cWidth - 6 : cWidth, getCellCreator().getCellHeight(), delta); } else cell.dontRender(graphics, delta); yy += getCellCreator().getCellHeight(); @@ -429,12 +434,12 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta if (currentElements.isEmpty()) { Font textRenderer = Minecraft.getInstance().font; Component text = Component.translatable("text.cloth-config.dropdown.value.unknown"); - graphics.drawString(textRenderer, text.getVisualOrderText(), (int) (lastRectangle.x + getCellCreator().getCellWidth() / 2f - textRenderer.width(text) / 2f), lastRectangle.y + lastRectangle.height + 3, -1); + graphics.drawString(textRenderer, text.getVisualOrderText(), (int) (lastRectangle.x + cWidth / 2f - textRenderer.width(text) / 2f), lastRectangle.y + lastRectangle.height + 3, -1); } if (getMaxScrollPosition() > 6) { RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - int scrollbarPositionMinX = lastRectangle.x + getCellCreator().getCellWidth() - 6; + int scrollbarPositionMinX = lastRectangle.x + cWidth - 6; int scrollbarPositionMaxX = scrollbarPositionMinX + 6; int height = (int) (((last10Height) * (last10Height)) / this.getMaxScrollPosition()); height = Mth.clamp(height, 32, last10Height - 8); @@ -470,7 +475,7 @@ public int getHeight() { @Override public boolean isMouseOver(double mouseX, double mouseY) { - return isExpanded() && mouseX >= lastRectangle.x && mouseX <= lastRectangle.x + getCellCreator().getCellWidth() && mouseY >= lastRectangle.y + lastRectangle.height && mouseY <= lastRectangle.y + lastRectangle.height + getHeight() + 1; + return isExpanded() && mouseX >= lastRectangle.x && mouseX <= lastRectangle.x + getCellWidth() && mouseY >= lastRectangle.y + lastRectangle.height && mouseY <= lastRectangle.y + lastRectangle.height + getHeight() + 1; } @Override @@ -505,7 +510,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amountX, doubl } protected void updateScrollingState(double double_1, double double_2, int int_1) { - this.scrolling = isExpanded() && lastRectangle != null && int_1 == 0 && double_1 >= (double) lastRectangle.x + getCellCreator().getCellWidth() - 6 && double_1 < (double) (lastRectangle.x + getCellCreator().getCellWidth()); + this.scrolling = isExpanded() && lastRectangle != null && int_1 == 0 && double_1 >= (double) lastRectangle.x + getCellWidth() - 6 && double_1 < (double) (lastRectangle.x + getCellWidth()); } @Override @@ -513,7 +518,19 @@ public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!isExpanded()) return false; updateScrollingState(double_1, double_2, int_1); - return super.mouseClicked(double_1, double_2, int_1) || scrolling; + + if(!isMouseOver(double_1, double_2)) { + getEntry().dontReFocus = true; + getEntry().setFocused(null); + return true; + } else { + boolean elementClicked = super.mouseClicked(double_1, double_2, int_1); + if(elementClicked) { + getEntry().dontReFocus = true; + getEntry().setFocused(null); + } + return elementClicked || scrolling; + } } public void offset(double value, boolean animated) { @@ -548,7 +565,7 @@ public static abstract class SelectionCellCreator { public abstract int getDropBoxMaxHeight(); public int getCellWidth() { - return 132; + return -1; } } @@ -652,8 +669,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int int_1) { boolean b = rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; if (b) { getEntry().selectionElement.topRenderer.setValue(r); - getEntry().selectionElement.setFocused(null); - getEntry().selectionElement.dontReFocus = true; + getEntry().setFocused(null); + getEntry().dontReFocus = true; return true; } return false; diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java index f7fc1571..efe2944e 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java @@ -58,7 +58,7 @@ public MultiElementListEntry(Component categoryName, T object, List.CategoryLabelWidget(); + this.widget = new MultiElementListEntry.CategoryLabelWidget(); this.children = Lists.newArrayList(widget); this.children.addAll(entries); this.setReferenceProviderEntries((List) entries); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java index b513c7f5..0352d45c 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java @@ -112,6 +112,18 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth nestedEntry.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); } + @Override + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + nestedEntry.setParent((DynamicEntryListWidget) listListEntry.getParent()); + nestedEntry.setScreen(listListEntry.getConfigScreen()); + nestedEntry.lateRender(graphics, mouseX, mouseY, delta); + } + + @Override + public int getMorePossibleHeight() { + return nestedEntry.getMorePossibleHeight(); + } + @Override public List children() { return Collections.singletonList(nestedEntry); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java index 85ece43f..1709b2a3 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.UUID; +import java.util.function.Function; @Environment(EnvType.CLIENT) public class ConfigEntryBuilderImpl implements ConfigEntryBuilder { @@ -176,4 +177,8 @@ public DropdownMenuBuilder startDropdownMenu(Component fieldNameKey, Sele return new DropdownMenuBuilder<>(resetButtonKey, fieldNameKey, topCellElement, cellCreator); } + @Override + public DropdownListBuilder startDropdownList(Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator) { + return new DropdownListBuilder<>(resetButtonKey, fieldNameKey, value, topCellCreator, cellCreator); + } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java new file mode 100644 index 00000000..b789d54d --- /dev/null +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java @@ -0,0 +1,149 @@ +/* + * This file is part of Cloth Config. + * Copyright (C) 2020 - 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.clothconfig2.impl.builders; + +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry; +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry.SelectionCellCreator; +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry.SelectionTopCellElement; +import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class DropdownListBuilder extends FieldBuilder, NestedListListEntry>, DropdownListBuilder> { + protected List value; + protected Supplier defaultEntryValue = null; + protected Function> topCellCreator; + protected SelectionCellCreator cellCreator; + protected Supplier> tooltipSupplier = () -> Optional.empty(); + protected Consumer> saveConsumer = null; + protected Iterable selections = Collections.emptyList(); + protected boolean suggestionMode = true; + + public DropdownListBuilder(Component resetButtonKey, Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator) { + super(resetButtonKey, fieldNameKey); + this.value = value; + this.topCellCreator = Objects.requireNonNull(topCellCreator); + this.cellCreator = Objects.requireNonNull(cellCreator); + } + + public DropdownListBuilder setSelections(Iterable selections) { + this.selections = selections; + return this; + } + + public DropdownListBuilder setDefaultValue(Supplier> defaultValue) { + this.defaultValue = defaultValue; + return this; + } + + public DropdownListBuilder setDefaultValue(List defaultValue) { + this.defaultValue = () -> Objects.requireNonNull(defaultValue); + return this; + } + + public DropdownListBuilder setDefaultEntryValue(Supplier defaultEntryValue) { + this.defaultEntryValue = defaultEntryValue; + return this; + } + + public DropdownListBuilder setDefaultEntryValue(T defaultEntryValue) { + this.defaultEntryValue = () -> Objects.requireNonNull(defaultEntryValue); + return this; + } + + public DropdownListBuilder setSaveConsumer(Consumer> saveConsumer) { + this.saveConsumer = saveConsumer; + return this; + } + + public DropdownListBuilder setTooltipSupplier(Supplier> tooltipSupplier) { + this.tooltipSupplier = tooltipSupplier; + return this; + } + + public DropdownListBuilder setTooltip(Optional tooltip) { + this.tooltipSupplier = () -> tooltip; + return this; + } + + public DropdownListBuilder setTooltip(Component... tooltip) { + this.tooltipSupplier = () -> Optional.ofNullable(tooltip); + return this; + } + + public DropdownListBuilder requireRestart() { + requireRestart(true); + return this; + } + + public DropdownListBuilder setErrorSupplier(Function, Optional> errorSupplier) { + this.errorSupplier = errorSupplier; + return this; + } + + public DropdownListBuilder setSuggestionMode(boolean suggestionMode) { + this.suggestionMode = suggestionMode; + return this; + } + + public boolean isSuggestionMode() { + return suggestionMode; + } + + @NotNull + @Override + public NestedListListEntry> build() { + NestedListListEntry> listEntry = new NestedListListEntry>( + getFieldNameKey(), + value, + false, + tooltipSupplier, + saveConsumer, + defaultValue, + getResetButtonKey(), + true, + false, + (entryValue, list) -> { + Supplier defaultValue = () -> entryValue; + if(entryValue == null) defaultValue = defaultEntryValue; + DropdownBoxEntry entry = new DropdownBoxEntry(CommonComponents.EMPTY, getResetButtonKey(), null, isRequireRestart(), defaultValue, null, selections, topCellCreator.apply(entryValue), cellCreator); + entry.setSuggestionMode(suggestionMode); + return entry; + }); + if (errorSupplier != null) + listEntry.setErrorSupplier(() -> errorSupplier.apply(listEntry.getValue())); + + + return finishBuilding(listEntry); + } +} diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java index 79ac96c5..aef894a4 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java @@ -361,11 +361,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofItemIdentifier() { - return ofItemIdentifier(20, 146, 7); + return ofItemIdentifier(20, -1, 7); } public static SelectionCellCreator ofItemIdentifier(int maxItems) { - return ofItemIdentifier(20, 146, maxItems); + return ofItemIdentifier(20, -1, maxItems); } public static SelectionCellCreator ofItemIdentifier(int cellHeight, int cellWidth, int maxItems) { @@ -410,11 +410,11 @@ public int getDropBoxMaxHeight() { public static SelectionCellCreator ofBlockIdentifier() { - return ofBlockIdentifier(20, 146, 7); + return ofBlockIdentifier(20, -1, 7); } public static SelectionCellCreator ofBlockIdentifier(int maxItems) { - return ofBlockIdentifier(20, 146, maxItems); + return ofBlockIdentifier(20, -1, maxItems); } public static SelectionCellCreator ofBlockIdentifier(int cellHeight, int cellWidth, int maxItems) { @@ -458,11 +458,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofItemObject() { - return ofItemObject(20, 146, 7); + return ofItemObject(20, -1, 7); } public static SelectionCellCreator ofItemObject(int maxItems) { - return ofItemObject(20, 146, maxItems); + return ofItemObject(20, -1, maxItems); } public static SelectionCellCreator ofItemObject(int cellHeight, int cellWidth, int maxItems) { @@ -506,11 +506,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofBlockObject() { - return ofBlockObject(20, 146, 7); + return ofBlockObject(20, -1, 7); } public static SelectionCellCreator ofBlockObject(int maxItems) { - return ofBlockObject(20, 146, maxItems); + return ofBlockObject(20, -1, maxItems); } public static SelectionCellCreator ofBlockObject(int cellHeight, int cellWidth, int maxItems) {