aboutsummaryrefslogtreecommitdiff
path: root/src/client/java/dev
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2022-12-20 20:07:04 +0000
committerisXander <xandersmith2008@gmail.com>2022-12-20 20:07:04 +0000
commit751a409c0adaae2763d9986ccb14cc343684720f (patch)
treeee07f36b332d14263fe2d6ed7cae55506bc144e4 /src/client/java/dev
parent16e781c4bee6c68c0c3e2d485b57daa0f589101e (diff)
downloadYetAnotherConfigLib-751a409c0adaae2763d9986ccb14cc343684720f.tar.gz
YetAnotherConfigLib-751a409c0adaae2763d9986ccb14cc343684720f.tar.bz2
YetAnotherConfigLib-751a409c0adaae2763d9986ccb14cc343684720f.zip
fix category buttons sometimes not being registered as clicked
Diffstat (limited to 'src/client/java/dev')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java40
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java41
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java53
-rw-r--r--src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java35
4 files changed, 129 insertions, 40 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
index f2a19f2..708c6bf 100644
--- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
+++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
@@ -73,33 +73,33 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
}
}
- /*
- below code is licensed from cloth-config under LGPL3
- modified to inherit vanilla's EntryListWidget and use yarn mappings
-
- code is responsible for having dynamic item heights
- */
-
@Nullable
@Override
protected E getEntryAtPosition(double x, double y) {
- int listMiddleX = this.left + this.width / 2;
- int minX = listMiddleX - this.getRowWidth() / 2;
- int maxX = listMiddleX + this.getRowWidth() / 2;
- int currentY = MathHelper.floor(y - (double) this.top) - this.headerHeight + (int) this.getScrollAmount() - 4;
- int itemY = 0;
- int itemIndex = -1;
- for (int i = 0; i < children().size(); i++) {
- E item = children().get(i);
- itemY += item.getItemHeight();
- if (itemY > currentY) {
- itemIndex = i;
- break;
+ y += getScrollAmount();
+
+ if (x < this.left || x > this.right)
+ return null;
+
+ int currentY = this.top - headerHeight + 4;
+ for (E entry : children()) {
+ if (y >= currentY && y <= currentY + entry.getItemHeight()) {
+ return entry;
}
+
+ currentY += entry.getItemHeight();
}
- return x < (double) this.getScrollbarPositionX() && x >= minX && y <= maxX && itemIndex >= 0 && currentY >= 0 && itemIndex < this.getEntryCount() ? this.children().get(itemIndex) : null;
+
+ return null;
}
+ /*
+ below code is licensed from cloth-config under LGPL3
+ modified to inherit vanilla's EntryListWidget and use yarn mappings
+
+ code is responsible for having dynamic item heights
+ */
+
@Override
protected int getMaxPosition() {
return children().stream().map(E::getItemHeight).reduce(0, Integer::sum) + headerHeight;
diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
index b3da814..5f9bdd0 100644
--- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
@@ -17,9 +17,34 @@ import java.util.Collection;
import java.util.List;
@ApiStatus.Internal
-public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, Text tooltip) implements ConfigCategory {
+public class ConfigCategoryImpl implements ConfigCategory {
+ private final Text name;
+ private final ImmutableList<OptionGroup> groups;
+ private final Text tooltip;
+
+ public ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, Text tooltip) {
+ this.name = name;
+ this.groups = groups;
+ this.tooltip = tooltip;
+ }
+
+ @Override
+ public @NotNull Text name() {
+ return name;
+ }
+
+ @Override
+ public @NotNull ImmutableList<OptionGroup> groups() {
+ return groups;
+ }
+
+ @Override
+ public @NotNull Text tooltip() {
+ return tooltip;
+ }
+
@ApiStatus.Internal
- public static final class BuilderImpl implements ConfigCategory.Builder {
+ public static final class BuilderImpl implements Builder {
private Text name;
private final List<Option<?>> rootOptions = new ArrayList<>();
@@ -28,7 +53,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
private final List<Text> tooltipLines = new ArrayList<>();
@Override
- public ConfigCategory.Builder name(@NotNull Text name) {
+ public Builder name(@NotNull Text name) {
Validate.notNull(name, "`name` cannot be null");
this.name = name;
@@ -36,7 +61,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
}
@Override
- public ConfigCategory.Builder option(@NotNull Option<?> option) {
+ public Builder option(@NotNull Option<?> option) {
Validate.notNull(option, "`option` must not be null");
if (option instanceof ListOption<?> listOption) {
@@ -49,7 +74,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
}
@Override
- public ConfigCategory.Builder options(@NotNull Collection<Option<?>> options) {
+ public Builder options(@NotNull Collection<Option<?>> options) {
Validate.notNull(options, "`options` must not be null");
if (options.stream().anyMatch(ListOption.class::isInstance))
@@ -60,7 +85,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
}
@Override
- public ConfigCategory.Builder group(@NotNull OptionGroup group) {
+ public Builder group(@NotNull OptionGroup group) {
Validate.notNull(group, "`group` must not be null");
this.groups.add(group);
@@ -68,7 +93,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
}
@Override
- public ConfigCategory.Builder groups(@NotNull Collection<OptionGroup> groups) {
+ public Builder groups(@NotNull Collection<OptionGroup> groups) {
Validate.notEmpty(groups, "`groups` must not be empty");
this.groups.addAll(groups);
@@ -76,7 +101,7 @@ public record ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, T
}
@Override
- public ConfigCategory.Builder tooltip(@NotNull Text... tooltips) {
+ public Builder tooltip(@NotNull Text... tooltips) {
Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
tooltipLines.addAll(List.of(tooltips));
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
index 89a2adf..ba96941 100644
--- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
@@ -15,16 +15,55 @@ import java.util.Collection;
import java.util.List;
@ApiStatus.Internal
-public record OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) implements OptionGroup {
+public class OptionGroupImpl implements OptionGroup {
+ private final @NotNull Text name;
+ private final @NotNull Text tooltip;
+ private final ImmutableList<? extends Option<?>> options;
+ private final boolean collapsed;
+ private final boolean isRoot;
+
+ public OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) {
+ this.name = name;
+ this.tooltip = tooltip;
+ this.options = options;
+ this.collapsed = collapsed;
+ this.isRoot = isRoot;
+ }
+
+ @Override
+ public @NotNull Text name() {
+ return name;
+ }
+
+ @Override
+ public @NotNull Text tooltip() {
+ return tooltip;
+ }
+
+ @Override
+ public @NotNull ImmutableList<? extends Option<?>> options() {
+ return options;
+ }
+
+ @Override
+ public boolean collapsed() {
+ return collapsed;
+ }
+
+ @Override
+ public boolean isRoot() {
+ return isRoot;
+ }
+
@ApiStatus.Internal
- public static final class BuilderImpl implements OptionGroup.Builder {
+ public static final class BuilderImpl implements Builder {
private Text name = Text.empty();
private final List<Text> tooltipLines = new ArrayList<>();
private final List<Option<?>> options = new ArrayList<>();
private boolean collapsed = false;
@Override
- public OptionGroup.Builder name(@NotNull Text name) {
+ public Builder name(@NotNull Text name) {
Validate.notNull(name, "`name` must not be null");
this.name = name;
@@ -32,7 +71,7 @@ public record OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, Immutab
}
@Override
- public OptionGroup.Builder tooltip(@NotNull Text... tooltips) {
+ public Builder tooltip(@NotNull Text... tooltips) {
Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
tooltipLines.addAll(List.of(tooltips));
@@ -40,7 +79,7 @@ public record OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, Immutab
}
@Override
- public OptionGroup.Builder option(@NotNull Option<?> option) {
+ public Builder option(@NotNull Option<?> option) {
Validate.notNull(option, "`option` must not be null");
if (option instanceof ListOption<?>)
@@ -51,7 +90,7 @@ public record OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, Immutab
}
@Override
- public OptionGroup.Builder options(@NotNull Collection<? extends Option<?>> options) {
+ public Builder options(@NotNull Collection<? extends Option<?>> options) {
Validate.notEmpty(options, "`options` must not be empty");
if (options.stream().anyMatch(ListOption.class::isInstance))
@@ -62,7 +101,7 @@ public record OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, Immutab
}
@Override
- public OptionGroup.Builder collapsed(boolean collapsible) {
+ public Builder collapsed(boolean collapsible) {
this.collapsed = collapsible;
return this;
}
diff --git a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java
index 28e5886..4ea623b 100644
--- a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java
@@ -18,14 +18,39 @@ import java.util.List;
import java.util.function.BiFunction;
@ApiStatus.Internal
-public record PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YACLScreen, Screen> screen, Text tooltip) implements PlaceholderCategory {
+public final class PlaceholderCategoryImpl implements PlaceholderCategory {
+ private final Text name;
+ private final BiFunction<MinecraftClient, YACLScreen, Screen> screen;
+ private final Text tooltip;
+
+ public PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YACLScreen, Screen> screen, Text tooltip) {
+ this.name = name;
+ this.screen = screen;
+ this.tooltip = tooltip;
+ }
+
@Override
public @NotNull ImmutableList<OptionGroup> groups() {
return ImmutableList.of();
}
+ @Override
+ public @NotNull Text name() {
+ return name;
+ }
+
+ @Override
+ public BiFunction<MinecraftClient, YACLScreen, Screen> screen() {
+ return screen;
+ }
+
+ @Override
+ public @NotNull Text tooltip() {
+ return tooltip;
+ }
+
@ApiStatus.Internal
- public static final class BuilderImpl implements PlaceholderCategory.Builder {
+ public static final class BuilderImpl implements Builder {
private Text name;
private final List<Text> tooltipLines = new ArrayList<>();
@@ -33,7 +58,7 @@ public record PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YAC
private BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction;
@Override
- public PlaceholderCategory.Builder name(@NotNull Text name) {
+ public Builder name(@NotNull Text name) {
Validate.notNull(name, "`name` cannot be null");
this.name = name;
@@ -41,7 +66,7 @@ public record PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YAC
}
@Override
- public PlaceholderCategory.Builder tooltip(@NotNull Text... tooltips) {
+ public Builder tooltip(@NotNull Text... tooltips) {
Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
tooltipLines.addAll(List.of(tooltips));
@@ -49,7 +74,7 @@ public record PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YAC
}
@Override
- public PlaceholderCategory.Builder screen(@NotNull BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction) {
+ public Builder screen(@NotNull BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction) {
Validate.notNull(screenFunction, "`screenFunction` cannot be null");
this.screenFunction = screenFunction;