aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl/api
diff options
context:
space:
mode:
authorxander <xander@isxander.dev>2022-09-02 22:04:35 +0100
committerxander <xander@isxander.dev>2022-09-02 22:04:35 +0100
commit7f88ddf36ba7804211e8aae6b3723bd8f37c82c5 (patch)
tree791e5cb050aa1ea17bd86d0bdd64fa441b2ab123 /src/main/java/dev/isxander/yacl/api
parentdd24e4f8e84ed02913196c8ad6093275acc92219 (diff)
downloadYetAnotherConfigLib-7f88ddf36ba7804211e8aae6b3723bd8f37c82c5.tar.gz
YetAnotherConfigLib-7f88ddf36ba7804211e8aae6b3723bd8f37c82c5.tar.bz2
YetAnotherConfigLib-7f88ddf36ba7804211e8aae6b3723bd8f37c82c5.zip
implement keyboard-operation for all controllers
fix crash when focusing on option list with tab add tooltip to groups check that pending values actually applied on save, if not, error in log and the save button displays an error when trying to escape with unsaved changes, save button text goes green and bold YACLConstants file to change certain behaviours, could evolve into its own settings! update icon
Diffstat (limited to 'src/main/java/dev/isxander/yacl/api')
-rw-r--r--src/main/java/dev/isxander/yacl/api/ConfigCategory.java2
-rw-r--r--src/main/java/dev/isxander/yacl/api/OptionGroup.java32
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);
}
}
}