|
@@ -23,9 +23,9 @@ import net.minecraft.client.render.VertexFormats;
|
|
|
import net.minecraft.client.resource.language.I18n;
|
|
|
import net.minecraft.client.util.Window;
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
-import javax.annotation.Nonnull;
|
|
|
-import javax.annotation.Nullable;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
@@ -33,20 +33,22 @@ import java.util.function.Supplier;
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
-
|
|
|
+
|
|
|
protected ButtonWidget resetButton;
|
|
|
protected SelectionElement<T> selectionElement;
|
|
|
- @Nonnull private Supplier<T> defaultValue;
|
|
|
- @Nullable private Consumer<T> saveConsumer;
|
|
|
-
|
|
|
+ @NotNull
|
|
|
+ private Supplier<T> defaultValue;
|
|
|
+ @Nullable
|
|
|
+ private Consumer<T> saveConsumer;
|
|
|
+
|
|
|
@Deprecated
|
|
|
public DropdownBoxEntry(String fieldName,
|
|
|
- @Nonnull String resetButtonKey,
|
|
|
- @Nullable Supplier<Optional<String[]>> tooltipSupplier, boolean requiresRestart,
|
|
|
- @Nullable Supplier<T> defaultValue,
|
|
|
- @Nullable Consumer<T> saveConsumer,
|
|
|
- @Nullable Iterable<T> selections,
|
|
|
- @Nonnull SelectionTopCellElement<T> topRenderer, @Nonnull SelectionCellCreator<T> cellCreator) {
|
|
|
+ @NotNull String resetButtonKey,
|
|
|
+ @Nullable Supplier<Optional<String[]>> tooltipSupplier, boolean requiresRestart,
|
|
|
+ @Nullable Supplier<T> defaultValue,
|
|
|
+ @Nullable Consumer<T> saveConsumer,
|
|
|
+ @Nullable Iterable<T> selections,
|
|
|
+ @NotNull SelectionTopCellElement<T> topRenderer, @NotNull SelectionCellCreator<T> cellCreator) {
|
|
|
super(I18n.translate(fieldName), tooltipSupplier, requiresRestart);
|
|
|
this.defaultValue = defaultValue;
|
|
|
this.saveConsumer = saveConsumer;
|
|
@@ -56,7 +58,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
});
|
|
|
this.selectionElement = new SelectionElement(this, new Rectangle(0, 0, 150, 20), new DefaultDropdownMenuElement(selections == null ? ImmutableList.of() : ImmutableList.copyOf(selections)), topRenderer, cellCreator);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
|
super.render(index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
|
|
@@ -78,58 +80,58 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
resetButton.render(mouseX, mouseY, delta);
|
|
|
selectionElement.render(mouseX, mouseY, delta);
|
|
|
}
|
|
|
-
|
|
|
- @Nonnull
|
|
|
+
|
|
|
+ @NotNull
|
|
|
public ImmutableList<T> getSelections() {
|
|
|
return selectionElement.menu.getSelections();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public T getValue() {
|
|
|
return selectionElement.getValue();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Deprecated
|
|
|
public SelectionElement<T> getSelectionElement() {
|
|
|
return selectionElement;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Optional<T> getDefaultValue() {
|
|
|
return defaultValue == null ? Optional.empty() : Optional.ofNullable(defaultValue.get());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void save() {
|
|
|
if (saveConsumer != null)
|
|
|
saveConsumer.accept(getValue());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public List<? extends Element> children() {
|
|
|
return Lists.newArrayList(selectionElement, resetButton);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Optional<String> getError() {
|
|
|
return selectionElement.topRenderer.getError();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void lateRender(int mouseX, int mouseY, float delta) {
|
|
|
selectionElement.lateRender(mouseX, mouseY, delta);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public int getMorePossibleHeight() {
|
|
|
return selectionElement.getMorePossibleHeight();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseScrolled(double double_1, double double_2, double double_3) {
|
|
|
return selectionElement.mouseScrolled(double_1, double_2, double_3);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static class SelectionElement<R> extends AbstractParentElement implements Drawable {
|
|
|
protected Rectangle bounds;
|
|
|
protected boolean active;
|
|
@@ -137,7 +139,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
protected DropdownBoxEntry<R> entry;
|
|
|
protected DropdownMenuElement<R> menu;
|
|
|
protected boolean dontReFocus = false;
|
|
|
-
|
|
|
+
|
|
|
public SelectionElement(DropdownBoxEntry<R> entry, Rectangle bounds, DropdownMenuElement<R> menu, SelectionTopCellElement<R> topRenderer, SelectionCellCreator<R> cellCreator) {
|
|
|
this.bounds = bounds;
|
|
|
this.entry = entry;
|
|
@@ -148,48 +150,48 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
this.topRenderer = Objects.requireNonNull(topRenderer);
|
|
|
this.topRenderer.entry = entry;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void render(int mouseX, int mouseY, float delta) {
|
|
|
fill(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, -6250336);
|
|
|
fill(bounds.x + 1, bounds.y + 1, bounds.x + bounds.width - 1, bounds.y + bounds.height - 1, -16777216);
|
|
|
topRenderer.render(mouseX, mouseY, bounds.x, bounds.y, bounds.width, bounds.height, delta);
|
|
|
- if (menu.isExpended())
|
|
|
+ if (menu.isExpanded())
|
|
|
menu.render(mouseX, mouseY, bounds, delta);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Deprecated
|
|
|
public SelectionTopCellElement<R> getTopRenderer() {
|
|
|
return topRenderer;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseScrolled(double double_1, double double_2, double double_3) {
|
|
|
- if (menu.isExpended())
|
|
|
+ if (menu.isExpanded())
|
|
|
return menu.mouseScrolled(double_1, double_2, double_3);
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void lateRender(int mouseX, int mouseY, float delta) {
|
|
|
- if (menu.isExpended())
|
|
|
+ if (menu.isExpanded())
|
|
|
menu.lateRender(mouseX, mouseY, delta);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getMorePossibleHeight() {
|
|
|
- if (menu.isExpended())
|
|
|
+ if (menu.isExpanded())
|
|
|
return menu.getHeight();
|
|
|
return -1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public R getValue() {
|
|
|
return topRenderer.getValue();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public List<? extends Element> children() {
|
|
|
return Lists.newArrayList(topRenderer, menu);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseClicked(double double_1, double double_2, int int_1) {
|
|
|
dontReFocus = false;
|
|
@@ -201,90 +203,97 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
return b;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static abstract class DropdownMenuElement<R> extends AbstractParentElement {
|
|
|
- @Deprecated @Nonnull private SelectionCellCreator<R> cellCreator;
|
|
|
- @Deprecated @Nonnull private DropdownBoxEntry<R> entry;
|
|
|
-
|
|
|
- @Nonnull
|
|
|
+ @Deprecated
|
|
|
+ @NotNull
|
|
|
+ private SelectionCellCreator<R> cellCreator;
|
|
|
+ @Deprecated
|
|
|
+ @NotNull
|
|
|
+ private DropdownBoxEntry<R> entry;
|
|
|
+
|
|
|
+ @NotNull
|
|
|
public SelectionCellCreator<R> getCellCreator() {
|
|
|
return cellCreator;
|
|
|
}
|
|
|
-
|
|
|
- @Nonnull
|
|
|
+
|
|
|
+ @NotNull
|
|
|
public final DropdownBoxEntry<R> getEntry() {
|
|
|
return entry;
|
|
|
}
|
|
|
-
|
|
|
- @Nonnull
|
|
|
+
|
|
|
+ @NotNull
|
|
|
public abstract ImmutableList<R> getSelections();
|
|
|
-
|
|
|
+
|
|
|
public abstract void initCells();
|
|
|
-
|
|
|
+
|
|
|
public abstract void render(int mouseX, int mouseY, Rectangle rectangle, float delta);
|
|
|
-
|
|
|
+
|
|
|
public abstract void lateRender(int mouseX, int mouseY, float delta);
|
|
|
-
|
|
|
+
|
|
|
public abstract int getHeight();
|
|
|
-
|
|
|
- public final boolean isExpended() {
|
|
|
+
|
|
|
+ public final boolean isExpanded() {
|
|
|
return (getEntry().selectionElement.getFocused() == getEntry().selectionElement.topRenderer || getEntry().selectionElement.getFocused() == getEntry().selectionElement.menu) && getEntry().getFocused() == getEntry().selectionElement && getEntry().getParent().getFocused() == getEntry();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public abstract List<SelectionCellElement<R>> children();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static class DefaultDropdownMenuElement<R> extends DropdownMenuElement<R> {
|
|
|
- @Nonnull protected ImmutableList<R> selections;
|
|
|
- @Nonnull protected List<SelectionCellElement<R>> cells;
|
|
|
- @Nonnull protected List<SelectionCellElement<R>> currentElements;
|
|
|
+ @NotNull
|
|
|
+ protected ImmutableList<R> selections;
|
|
|
+ @NotNull
|
|
|
+ protected List<SelectionCellElement<R>> cells;
|
|
|
+ @NotNull
|
|
|
+ protected List<SelectionCellElement<R>> currentElements;
|
|
|
protected String lastSearchKeyword = "";
|
|
|
protected Rectangle lastRectangle;
|
|
|
protected boolean scrolling;
|
|
|
protected double scroll, target;
|
|
|
protected long start;
|
|
|
protected long duration;
|
|
|
-
|
|
|
- public DefaultDropdownMenuElement(@Nonnull ImmutableList<R> selections) {
|
|
|
+
|
|
|
+ public DefaultDropdownMenuElement(@NotNull ImmutableList<R> selections) {
|
|
|
this.selections = selections;
|
|
|
this.cells = Lists.newArrayList();
|
|
|
this.currentElements = Lists.newArrayList();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public final double clamp(double v) {
|
|
|
return MathHelper.clamp(v, -SmoothScrollingSettings.CLAMP_EXTENSION, getMaxScrollPosition() + SmoothScrollingSettings.CLAMP_EXTENSION);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public double getMaxScroll() {
|
|
|
return getCellCreator().getCellHeight() * currentElements.size();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected double getMaxScrollPosition() {
|
|
|
return Math.max(0, this.getMaxScroll() - (getHeight()));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- @Nonnull
|
|
|
+ @NotNull
|
|
|
public ImmutableList<R> getSelections() {
|
|
|
return selections;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void initCells() {
|
|
|
- for(R selection : getSelections()) {
|
|
|
+ for (R selection : getSelections()) {
|
|
|
cells.add(getCellCreator().create(selection));
|
|
|
}
|
|
|
- for(SelectionCellElement<R> cell : cells) {
|
|
|
+ for (SelectionCellElement<R> cell : cells) {
|
|
|
cell.entry = getEntry();
|
|
|
}
|
|
|
search();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void search() {
|
|
|
currentElements.clear();
|
|
|
String keyword = this.lastSearchKeyword.toLowerCase();
|
|
|
- for(SelectionCellElement<R> cell : cells) {
|
|
|
+ for (SelectionCellElement<R> cell : cells) {
|
|
|
String key = cell.getSearchKey();
|
|
|
if (key == null || key.toLowerCase().contains(keyword))
|
|
|
currentElements.add(cell);
|
|
@@ -295,15 +304,15 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
scrollTo(0, false);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected int editDistance(String s1, String s2) {
|
|
|
s1 = s1.toLowerCase();
|
|
|
s2 = s2.toLowerCase();
|
|
|
-
|
|
|
+
|
|
|
int[] costs = new int[s2.length() + 1];
|
|
|
- for(int i = 0; i <= s1.length(); i++) {
|
|
|
+ for (int i = 0; i <= s1.length(); i++) {
|
|
|
int lastValue = i;
|
|
|
- for(int j = 0; j <= s2.length(); j++) {
|
|
|
+ for (int j = 0; j <= s2.length(); j++) {
|
|
|
if (i == 0)
|
|
|
costs[j] = j;
|
|
|
else {
|
|
@@ -321,7 +330,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
return costs[s2.length()];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected double similarity(String s1, String s2) {
|
|
|
String longer = s1, shorter = s2;
|
|
|
if (s1.length() < s2.length()) { // longer should always have greater length
|
|
@@ -334,7 +343,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
return (longerLength - editDistance(longer, shorter)) / (double) longerLength;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void render(int mouseX, int mouseY, Rectangle rectangle, float delta) {
|
|
|
if (!getEntry().selectionElement.topRenderer.getSearchTerm().equals(lastSearchKeyword)) {
|
|
@@ -345,7 +354,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
lastRectangle = rectangle.clone();
|
|
|
lastRectangle.translate(0, -1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void updatePosition(float delta) {
|
|
|
target = clamp(target);
|
|
|
if (target < 0) {
|
|
@@ -358,7 +367,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
else
|
|
|
scroll = target;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void lateRender(int mouseX, int mouseY, float delta) {
|
|
|
int last10Height = getHeight();
|
|
@@ -367,10 +376,10 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, -16777216);
|
|
|
RenderSystem.pushMatrix();
|
|
|
RenderSystem.translatef(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;
|
|
|
- for(SelectionCellElement<R> cell : currentElements) {
|
|
|
+ for (SelectionCellElement<R> cell : currentElements) {
|
|
|
if (yy + getCellCreator().getCellHeight() >= lastRectangle.y + lastRectangle.height && yy <= lastRectangle.y + lastRectangle.height + last10Height + 1)
|
|
|
cell.render(mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight(), delta);
|
|
|
else
|
|
@@ -378,13 +387,13 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
yy += getCellCreator().getCellHeight();
|
|
|
}
|
|
|
ScissorsHandler.INSTANCE.removeLastScissor();
|
|
|
-
|
|
|
+
|
|
|
if (currentElements.isEmpty()) {
|
|
|
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
|
|
String s = I18n.translate("text.cloth-config.dropdown.value.unknown");
|
|
|
textRenderer.drawWithShadow(s, lastRectangle.x + getCellCreator().getCellWidth() / 2 - textRenderer.getStringWidth(s) / 2, lastRectangle.y + lastRectangle.height + 3, -1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (getMaxScrollPosition() > 6) {
|
|
|
RenderSystem.disableTexture();
|
|
|
int scrollbarPositionMinX = lastRectangle.x + getCellCreator().getCellWidth() - 6;
|
|
@@ -394,13 +403,13 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
height -= Math.min((scroll < 0 ? (int) -scroll : scroll > getMaxScrollPosition() ? (int) scroll - getMaxScrollPosition() : 0), height * .95);
|
|
|
height = Math.max(10, height);
|
|
|
int minY = (int) Math.min(Math.max((int) scroll * (last10Height - height) / getMaxScrollPosition() + (lastRectangle.y + lastRectangle.height + 1), (lastRectangle.y + lastRectangle.height + 1)), (lastRectangle.y + lastRectangle.height + 1 + last10Height) - height);
|
|
|
-
|
|
|
+
|
|
|
int bottomc = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.fromMouse()) ? 168 : 128;
|
|
|
int topc = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.fromMouse()) ? 222 : 172;
|
|
|
-
|
|
|
+
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
|
|
BufferBuilder buffer = tessellator.getBuffer();
|
|
|
-
|
|
|
+
|
|
|
// Bottom
|
|
|
buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
|
|
|
buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).texture(0, 1).color(bottomc, bottomc, bottomc, 255).next();
|
|
@@ -408,7 +417,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).texture(1, 0).color(bottomc, bottomc, bottomc, 255).next();
|
|
|
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(bottomc, bottomc, bottomc, 255).next();
|
|
|
tessellator.draw();
|
|
|
-
|
|
|
+
|
|
|
// Top
|
|
|
buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
|
|
|
buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).texture(0, 1).color(topc, topc, topc, 255).next();
|
|
@@ -421,20 +430,20 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
RenderSystem.translatef(0, 0, -300f);
|
|
|
RenderSystem.popMatrix();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public int getHeight() {
|
|
|
return Math.max(Math.min(getCellCreator().getDropBoxMaxHeight(), (int) getMaxScroll()), 14);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean isMouseOver(double mouseX, double mouseY) {
|
|
|
- return isExpended() && 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 + getCellCreator().getCellWidth() && mouseY >= lastRectangle.y + lastRectangle.height && mouseY <= lastRectangle.y + lastRectangle.height + getHeight() + 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
|
|
|
- if (!isExpended())
|
|
|
+ if (!isExpanded())
|
|
|
return false;
|
|
|
if (int_1 == 0 && this.scrolling) {
|
|
|
if (double_2 < (double) lastRectangle.y + lastRectangle.height) {
|
|
@@ -453,7 +462,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseScrolled(double mouseX, double mouseY, double double_3) {
|
|
|
if (isMouseOver(mouseX, mouseY)) {
|
|
@@ -462,101 +471,103 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected void updateScrollingState(double double_1, double double_2, int int_1) {
|
|
|
- this.scrolling = isExpended() && 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 + getCellCreator().getCellWidth() - 6 && double_1 < (double) (lastRectangle.x + getCellCreator().getCellWidth());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseClicked(double double_1, double double_2, int int_1) {
|
|
|
- if (!isExpended())
|
|
|
+ if (!isExpanded())
|
|
|
return false;
|
|
|
updateScrollingState(double_1, double_2, int_1);
|
|
|
return super.mouseClicked(double_1, double_2, int_1) || scrolling;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void offset(double value, boolean animated) {
|
|
|
scrollTo(target + value, animated);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void scrollTo(double value, boolean animated) {
|
|
|
scrollTo(value, animated, ClothConfigInitializer.getScrollDuration());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void scrollTo(double value, boolean animated, long duration) {
|
|
|
target = clamp(value);
|
|
|
-
|
|
|
+
|
|
|
if (animated) {
|
|
|
start = System.currentTimeMillis();
|
|
|
this.duration = duration;
|
|
|
} else
|
|
|
scroll = target;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public List<SelectionCellElement<R>> children() {
|
|
|
return currentElements;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static abstract class SelectionCellCreator<R> {
|
|
|
public abstract SelectionCellElement<R> create(R selection);
|
|
|
-
|
|
|
+
|
|
|
public abstract int getCellHeight();
|
|
|
-
|
|
|
+
|
|
|
public abstract int getDropBoxMaxHeight();
|
|
|
-
|
|
|
+
|
|
|
public int getCellWidth() {
|
|
|
return 132;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static class DefaultSelectionCellCreator<R> extends SelectionCellCreator<R> {
|
|
|
protected Function<R, String> toStringFunction;
|
|
|
-
|
|
|
+
|
|
|
public DefaultSelectionCellCreator(Function<R, String> toStringFunction) {
|
|
|
this.toStringFunction = toStringFunction;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DefaultSelectionCellCreator() {
|
|
|
this(Object::toString);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public SelectionCellElement<R> create(R selection) {
|
|
|
return new DefaultSelectionCellElement<>(selection, toStringFunction);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public int getCellHeight() {
|
|
|
return 14;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public int getDropBoxMaxHeight() {
|
|
|
return getCellHeight() * 7;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static abstract class SelectionCellElement<R> extends AbstractParentElement {
|
|
|
- @Deprecated @Nonnull private DropdownBoxEntry<R> entry;
|
|
|
-
|
|
|
- @Nonnull
|
|
|
+ @Deprecated
|
|
|
+ @NotNull
|
|
|
+ private DropdownBoxEntry<R> entry;
|
|
|
+
|
|
|
+ @NotNull
|
|
|
public final DropdownBoxEntry<R> getEntry() {
|
|
|
return entry;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public abstract void render(int mouseX, int mouseY, int x, int y, int width, int height, float delta);
|
|
|
-
|
|
|
+
|
|
|
public abstract void dontRender(float delta);
|
|
|
-
|
|
|
+
|
|
|
@Nullable
|
|
|
public abstract String getSearchKey();
|
|
|
-
|
|
|
+
|
|
|
@Nullable
|
|
|
public abstract R getSelection();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static class DefaultSelectionCellElement<R> extends SelectionCellElement<R> {
|
|
|
protected R r;
|
|
|
protected int x;
|
|
@@ -565,12 +576,12 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
protected int height;
|
|
|
protected boolean rendering;
|
|
|
protected Function<R, String> toStringFunction;
|
|
|
-
|
|
|
+
|
|
|
public DefaultSelectionCellElement(R r, Function<R, String> toStringFunction) {
|
|
|
this.r = r;
|
|
|
this.toStringFunction = toStringFunction;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void render(int mouseX, int mouseY, int x, int y, int width, int height, float delta) {
|
|
|
rendering = true;
|
|
@@ -583,29 +594,29 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
fill(x + 1, y + 1, x + width - 1, y + height - 1, -15132391);
|
|
|
MinecraftClient.getInstance().textRenderer.drawWithShadow(toStringFunction.apply(r), x + 6, y + 3, b ? 16777215 : 8947848);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void dontRender(float delta) {
|
|
|
rendering = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Nullable
|
|
|
@Override
|
|
|
public String getSearchKey() {
|
|
|
return toStringFunction.apply(r);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Nullable
|
|
|
@Override
|
|
|
public R getSelection() {
|
|
|
return r;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public List<? extends Element> children() {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean mouseClicked(double mouseX, double mouseY, int int_1) {
|
|
|
boolean b = rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
|
|
@@ -618,37 +629,38 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static abstract class SelectionTopCellElement<R> extends AbstractParentElement {
|
|
|
- @Deprecated private DropdownBoxEntry<R> entry;
|
|
|
-
|
|
|
+ @Deprecated
|
|
|
+ private DropdownBoxEntry<R> entry;
|
|
|
+
|
|
|
public abstract R getValue();
|
|
|
-
|
|
|
+
|
|
|
public abstract void setValue(R value);
|
|
|
-
|
|
|
+
|
|
|
public abstract String getSearchTerm();
|
|
|
-
|
|
|
+
|
|
|
public abstract Optional<String> getError();
|
|
|
-
|
|
|
+
|
|
|
public final Optional<String> getConfigError() {
|
|
|
return entry.getConfigError();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DropdownBoxEntry<R> getParent() {
|
|
|
return entry;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public final boolean hasConfigError() {
|
|
|
return getConfigError().isPresent();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public final int getPreferredTextColor() {
|
|
|
return getConfigError().isPresent() ? 16733525 : 16777215;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void selectFirstRecommendation() {
|
|
|
List<SelectionCellElement<R>> children = getParent().selectionElement.menu.children();
|
|
|
- for(SelectionCellElement<R> child : children) {
|
|
|
+ for (SelectionCellElement<R> child : children) {
|
|
|
if (child.getSelection() != null) {
|
|
|
setValue(child.getSelection());
|
|
|
getParent().selectionElement.setFocused(null);
|
|
@@ -656,16 +668,16 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public abstract void render(int mouseX, int mouseY, int x, int y, int width, int height, float delta);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static class DefaultSelectionTopCellElement<R> extends SelectionTopCellElement<R> {
|
|
|
protected TextFieldWidget textFieldWidget;
|
|
|
protected Function<String, R> toObjectFunction;
|
|
|
protected Function<R, String> toStringFunction;
|
|
|
protected R value;
|
|
|
-
|
|
|
+
|
|
|
public DefaultSelectionTopCellElement(R value, Function<String, R> toObjectFunction, Function<R, String> toStringFunction) {
|
|
|
this.value = Objects.requireNonNull(value);
|
|
|
this.toObjectFunction = Objects.requireNonNull(toObjectFunction);
|
|
@@ -678,7 +690,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
super.render(int_1, int_2, float_1);
|
|
|
setFocused(f);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean keyPressed(int int_1, int int_2, int int_3) {
|
|
|
if (int_1 == 257 || int_1 == 335) {
|
|
@@ -696,7 +708,7 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
getParent().getScreen().setEdited(true, getParent().isRequiresRestart());
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void render(int mouseX, int mouseY, int x, int y, int width, int height, float delta) {
|
|
|
textFieldWidget.x = x + 4;
|
|
@@ -706,32 +718,32 @@ public class DropdownBoxEntry<T> extends TooltipListEntry<T> {
|
|
|
textFieldWidget.setEditableColor(getPreferredTextColor());
|
|
|
textFieldWidget.render(mouseX, mouseY, delta);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public R getValue() {
|
|
|
if (hasConfigError())
|
|
|
return value;
|
|
|
return toObjectFunction.apply(textFieldWidget.getText());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setValue(R value) {
|
|
|
textFieldWidget.setText(toStringFunction.apply(value));
|
|
|
textFieldWidget.setCursor(0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public String getSearchTerm() {
|
|
|
return textFieldWidget.getText();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Optional<String> getError() {
|
|
|
if (toObjectFunction.apply(textFieldWidget.getText()) != null)
|
|
|
return Optional.empty();
|
|
|
return Optional.of("Invalid Value!");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public List<? extends Element> children() {
|
|
|
return Collections.singletonList(textFieldWidget);
|