aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-04-21 22:59:08 +0100
committerisXander <xandersmith2008@gmail.com>2023-04-21 22:59:08 +0100
commit25f8d0bacf274870c512cb6b867a55af57714fb5 (patch)
treeb772d3ca4103eef7544c44b7248088b3a10e18ff /src
parent74bcc11c74f864eda2f5e48a3c038846c20065ba (diff)
downloadYetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.tar.gz
YetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.tar.bz2
YetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.zip
prioritise tooltip rendering above & filter empty tooltips
Diffstat (limited to 'src')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java11
-rw-r--r--src/client/java/dev/isxander/yacl/gui/YACLScreen.java4
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java4
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java4
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionImpl.java14
-rw-r--r--src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java3
6 files changed, 23 insertions, 17 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
index ec8e304..46503a6 100644
--- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
+++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
@@ -96,17 +96,6 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
return null;
}
- @Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- // on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus
- boolean clicked = super.mouseReleased(mouseX, mouseY, button);
-// if (getFocused() != null) {
-// this.getFocused().setFocused(null);
-//// this.setFocused(null);
-// }
- return clicked;
- }
-
/*
below code is licensed from cloth-config under LGPL3
modified to inherit vanilla's EntryListWidget and use yarn mappings
diff --git a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java
index 3b14544..d653d8c 100644
--- a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java
+++ b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java
@@ -276,8 +276,8 @@ public class YACLScreen extends Screen {
int aboveY = yAbove - height + 12;
int maxBelow = screenHeight - (belowY + height);
int minAbove = aboveY - height;
- int y = belowY;
- if (maxBelow < -8)
+ int y = aboveY;
+ if (minAbove < 8)
y = maxBelow > minAbove ? belowY : aboveY;
int x = Math.max(centerX - text.getWidth() / 2 - 12, -6);
diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
index b3d28b3..2d39eb9 100644
--- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
@@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.api.OptionGroup;
import dev.isxander.yacl.impl.utils.YACLConstants;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.ApiStatus;
@@ -121,6 +122,9 @@ public final class ConfigCategoryImpl implements ConfigCategory {
MutableComponent concatenatedTooltip = Component.empty();
boolean first = true;
for (Component line : tooltipLines) {
+ if (line.getContents() == ComponentContents.EMPTY)
+ continue;
+
if (!first) concatenatedTooltip.append("\n");
first = false;
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
index 0f883d9..68f53a0 100644
--- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
@@ -5,6 +5,7 @@ import dev.isxander.yacl.api.ListOption;
import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.api.OptionGroup;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.ApiStatus;
@@ -113,6 +114,9 @@ public final class OptionGroupImpl implements OptionGroup {
MutableComponent concatenatedTooltip = Component.empty();
boolean first = true;
for (Component line : tooltipLines) {
+ if (line.getContents() == ComponentContents.EMPTY)
+ continue;
+
if (!first) concatenatedTooltip.append("\n");
first = false;
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java
index 35ad620..644abc9 100644
--- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java
@@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.api.OptionFlag;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.ApiStatus;
@@ -195,9 +196,11 @@ public final class OptionImpl<T> implements Option<T> {
@Override
public Option.Builder<T> tooltip(@NotNull Component... tooltips) {
- Validate.notNull(tooltips, "`tooltips` cannot be empty");
+ var tooltipFunctions = Arrays.stream(tooltips)
+ .map(t -> (Function<T, Component>) opt -> t)
+ .toList();
- this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList());
+ this.tooltipGetters.addAll(tooltipFunctions);
return this;
}
@@ -277,10 +280,15 @@ public final class OptionImpl<T> implements Option<T> {
MutableComponent concatenatedTooltip = Component.empty();
boolean first = true;
for (Function<T, Component> line : tooltipGetters) {
+ Component lineComponent = line.apply(value);
+
+ if (lineComponent.getContents() == ComponentContents.EMPTY)
+ continue;
+
if (!first) concatenatedTooltip.append("\n");
first = false;
- concatenatedTooltip.append(line.apply(value));
+ concatenatedTooltip.append(lineComponent);
}
return concatenatedTooltip;
diff --git a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java
index 1ab4f1d..18d2a3c 100644
--- a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java
+++ b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java
@@ -57,7 +57,6 @@ public class GuiTest {
.group(OptionGroup.createBuilder()
.name(Component.literal("Boolean Controllers"))
.tooltip(Component.literal("Test!"))
- .collapsed(true)
.option(Option.createBuilder(boolean.class)
.name(Component.literal("Boolean Toggle"))
.tooltip(value -> Component.literal("A simple toggle button that contains the value '" + value + "'"))
@@ -72,6 +71,8 @@ public class GuiTest {
.option(Option.createBuilder(boolean.class)
.name(Component.literal("Custom Boolean Toggle"))
.tooltip(Component.literal("You can customize these controllers like this!"))
+ .tooltip(Component.empty())
+ .tooltip(opt -> Component.empty())
.binding(
defaults.customBooleanToggle,
() -> config.customBooleanToggle,