diff options
Diffstat (limited to 'src/main/java/dev/isxander/yacl/api')
| -rw-r--r-- | src/main/java/dev/isxander/yacl/api/ConfigCategory.java | 2 | ||||
| -rw-r--r-- | src/main/java/dev/isxander/yacl/api/OptionGroup.java | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/ConfigCategory.java b/src/main/java/dev/isxander/yacl/api/ConfigCategory.java index 5aafc62..9f2f954 100644 --- a/src/main/java/dev/isxander/yacl/api/ConfigCategory.java +++ b/src/main/java/dev/isxander/yacl/api/ConfigCategory.java @@ -138,7 +138,7 @@ public interface ConfigCategory { Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); List<OptionGroup> combinedGroups = new ArrayList<>(); - combinedGroups.add(new OptionGroupImpl(Text.empty(), ImmutableList.copyOf(rootOptions), true)); + combinedGroups.add(new OptionGroupImpl(Text.empty(), Text.empty(), ImmutableList.copyOf(rootOptions), true)); combinedGroups.addAll(groups); Validate.notEmpty(combinedGroups, "at least one option must be added to build `ConfigCategory`"); diff --git a/src/main/java/dev/isxander/yacl/api/OptionGroup.java b/src/main/java/dev/isxander/yacl/api/OptionGroup.java index 6a302c4..9376b8e 100644 --- a/src/main/java/dev/isxander/yacl/api/OptionGroup.java +++ b/src/main/java/dev/isxander/yacl/api/OptionGroup.java @@ -2,6 +2,7 @@ package dev.isxander.yacl.api; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.impl.OptionGroupImpl; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.NotNull; @@ -23,6 +24,11 @@ public interface OptionGroup { Text name(); /** + * Tooltip displayed on hover. + */ + Text tooltip(); + + /** * List of all options in the group */ @NotNull ImmutableList<Option<?>> options(); @@ -42,6 +48,7 @@ public interface OptionGroup { class Builder { private Text name = Text.empty(); + private final List<Text> tooltipLines = new ArrayList<>(); private final List<Option<?>> options = new ArrayList<>(); private Builder() { @@ -61,6 +68,20 @@ public interface OptionGroup { } /** + * Sets the tooltip to be used by the option group. + * Can be invoked twice to append more lines. + * No need to wrap the text yourself, the gui does this itself. + * + * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. + */ + public Builder tooltip(@NotNull Text... tooltips) { + Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); + + tooltipLines.addAll(List.of(tooltips)); + return this; + } + + /** * Adds an option to group. * To construct an option, use {@link Option#createBuilder(Class)} * @@ -89,7 +110,16 @@ public interface OptionGroup { public OptionGroup build() { Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`"); - return new OptionGroupImpl(name, ImmutableList.copyOf(options), false); + MutableText concatenatedTooltip = Text.empty(); + boolean first = true; + for (Text line : tooltipLines) { + if (!first) concatenatedTooltip.append("\n"); + first = false; + + concatenatedTooltip.append(line); + } + + return new OptionGroupImpl(name, concatenatedTooltip, ImmutableList.copyOf(options), false); } } } |
