Skip to content

Commit aba5085

Browse files
committed
add list option descriptions + warn with deprecated tooltips
1 parent 3b8e4e7 commit aba5085

7 files changed

Lines changed: 75 additions & 31 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ architectury {
1212
minecraft = libs.versions.minecraft.get()
1313
}
1414

15-
version = "3.0.0-beta.1+1.20"
15+
version = "3.0.0-beta.2+1.20"
1616

1717
val isBeta = "beta" in version.toString()
1818
val changelogText = rootProject.file("changelogs/${project.version}.md").takeIf { it.exists() }?.readText() ?: "No changelog provided."

changelogs/3.0.0-beta.2+1.20.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# YetAnotherConfigLib v3 Beta 2
2+
3+
## Changes
4+
5+
- List options now use the new option descriptions
6+
- All options now print a warning if using the old tooltip system
7+
8+
## Bug Fixes
9+
10+
- Fix animated images sometimes rendering incorrectly
11+
- Fix animated images flickering when reaching end of loop

common/src/main/java/dev/isxander/yacl/api/ListOption.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ interface Builder<T> {
6161
*/
6262
Builder<T> name(@NotNull Component name);
6363

64+
Builder<T> description(@NotNull OptionDescription description);
65+
6466
/**
6567
* Sets the tooltip to be used by the list. It is displayed like a normal
6668
* group when you hover over the name. Entries do not allow a tooltip.
@@ -70,6 +72,7 @@ interface Builder<T> {
7072
*
7173
* @param tooltips text lines - merged with a new-line on {@link dev.isxander.yacl.api.ListOption.Builder#build()}.
7274
*/
75+
@Deprecated
7376
Builder<T> tooltip(@NotNull Component... tooltips);
7477

7578
/**

common/src/main/java/dev/isxander/yacl/gui/ScrollableNavigationBar.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public void setScrollOffset(int scrollOffset) {
6161
layout.setX(layout.getX() - this.scrollOffset);
6262
}
6363

64+
public int getScrollOffset() {
65+
return scrollOffset;
66+
}
67+
6468
@Override
6569
public void setFocused(@Nullable GuiEventListener child) {
6670
super.setFocused(child);

common/src/main/java/dev/isxander/yacl/impl/ListOptionImpl.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.google.common.collect.ImmutableList;
44
import com.google.common.collect.ImmutableSet;
55
import dev.isxander.yacl.api.*;
6+
import dev.isxander.yacl.impl.utils.YACLConstants;
67
import net.minecraft.network.chat.Component;
7-
import net.minecraft.network.chat.MutableComponent;
88
import org.apache.commons.lang3.Validate;
99
import org.jetbrains.annotations.ApiStatus;
1010
import org.jetbrains.annotations.NotNull;
@@ -218,7 +218,8 @@ public ListOptionEntry<T> create(T initialValue) {
218218
@ApiStatus.Internal
219219
public static final class BuilderImpl<T> implements Builder<T> {
220220
private Component name = Component.empty();
221-
private final List<Component> tooltipLines = new ArrayList<>();
221+
private OptionDescription description = null;
222+
private OptionDescription.Builder legacyBuilder = null;
222223
private Function<ListOptionEntry<T>, Controller<T>> controllerFunction;
223224
private Binding<List<T>> binding = null;
224225
private final Set<OptionFlag> flags = new HashSet<>();
@@ -240,11 +241,23 @@ public Builder<T> name(@NotNull Component name) {
240241
return this;
241242
}
242243

244+
@Override
245+
public Builder<T> description(@NotNull OptionDescription description) {
246+
Validate.isTrue(legacyBuilder == null, "Cannot set description when deprecated `tooltip` method is used");
247+
Validate.notNull(description, "`description` must not be null");
248+
249+
this.description = description;
250+
return this;
251+
}
252+
243253
@Override
244254
public Builder<T> tooltip(@NotNull Component... tooltips) {
255+
Validate.isTrue(description == null, "Cannot use deprecated `tooltip` method when `description` in use.");
245256
Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
246257

247-
tooltipLines.addAll(List.of(tooltips));
258+
ensureLegacyDescriptionBuilder();
259+
260+
legacyBuilder.description(tooltips);
248261
return this;
249262
}
250263

@@ -328,16 +341,23 @@ public ListOption<T> build() {
328341
Validate.notNull(binding, "`binding` must not be null");
329342
Validate.notNull(initialValue, "`initialValue` must not be null");
330343

331-
MutableComponent concatenatedTooltip = Component.empty();
332-
boolean first = true;
333-
for (Component line : tooltipLines) {
334-
if (!first) concatenatedTooltip.append("\n");
335-
first = false;
344+
if (description == null) {
345+
if (ensureLegacyDescriptionBuilder())
346+
YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in list option {}. Use `description` instead.", name.getString());
336347

337-
concatenatedTooltip.append(line);
348+
description = legacyBuilder.name(name).build();
338349
}
339350

340-
return new ListOptionImpl<>(name, OptionDescription.createBuilder().name(name).description(concatenatedTooltip).build(), binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available, listeners);
351+
return new ListOptionImpl<>(name, description, binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available, listeners);
352+
}
353+
354+
private boolean ensureLegacyDescriptionBuilder() {
355+
if (legacyBuilder == null) {
356+
legacyBuilder = OptionDescription.createBuilder();
357+
return false;
358+
} else {
359+
return true;
360+
}
341361
}
342362
}
343363
}

common/src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import dev.isxander.yacl.api.Option;
66
import dev.isxander.yacl.api.OptionDescription;
77
import dev.isxander.yacl.api.OptionGroup;
8+
import dev.isxander.yacl.impl.utils.YACLConstants;
89
import net.minecraft.network.chat.Component;
9-
import net.minecraft.network.chat.ComponentContents;
10-
import net.minecraft.network.chat.MutableComponent;
1110
import org.apache.commons.lang3.Validate;
1211
import org.jetbrains.annotations.ApiStatus;
1312
import org.jetbrains.annotations.NotNull;
14-
import org.jetbrains.annotations.Nullable;
1513

1614
import java.util.ArrayList;
1715
import java.util.Collection;
@@ -132,16 +130,21 @@ public OptionGroup build() {
132130
Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`");
133131

134132
if (description == null) {
135-
ensureLegacyDescriptionBuilder();
133+
if (ensureLegacyDescriptionBuilder())
134+
YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in option group '{}'. Use `description` instead.", name != null ? name.getString() : "unnamed group");
135+
136136
description = legacyBuilder.name(name).build();
137137
}
138138

139139
return new OptionGroupImpl(name, description, ImmutableList.copyOf(options), collapsed, false);
140140
}
141141

142-
private void ensureLegacyDescriptionBuilder() {
142+
private boolean ensureLegacyDescriptionBuilder() {
143143
if (legacyBuilder == null) {
144144
legacyBuilder = OptionDescription.createBuilder();
145+
return false;
146+
} else {
147+
return true;
145148
}
146149
}
147150
}

common/src/main/java/dev/isxander/yacl/impl/OptionImpl.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.google.common.collect.ImmutableSet;
44
import dev.isxander.yacl.api.*;
5+
import dev.isxander.yacl.impl.utils.YACLConstants;
56
import net.minecraft.ChatFormatting;
6-
import net.minecraft.Util;
77
import net.minecraft.network.chat.Component;
88
import net.minecraft.network.chat.ComponentContents;
99
import net.minecraft.network.chat.MutableComponent;
@@ -291,24 +291,27 @@ public Option<T> build() {
291291
Validate.notNull(binding, "`binding` must not be null when building `Option`");
292292
Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags");
293293

294-
Function<T, Component> concatenatedTooltipGetter = value -> {
295-
MutableComponent concatenatedTooltip = Component.empty();
296-
boolean first = true;
297-
for (Function<T, Component> line : tooltipGetters) {
298-
Component lineComponent = line.apply(value);
294+
if (descriptionFunction == null) {
295+
if (!tooltipGetters.isEmpty())
296+
YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in option '{}'. Use `description` instead.", name.getString());
299297

300-
if (lineComponent.getContents() == ComponentContents.EMPTY)
301-
continue;
298+
Function<T, Component> concatenatedTooltipGetter = value -> {
299+
MutableComponent concatenatedTooltip = Component.empty();
300+
boolean first = true;
301+
for (Function<T, Component> line : tooltipGetters) {
302+
Component lineComponent = line.apply(value);
302303

303-
if (!first) concatenatedTooltip.append("\n");
304-
first = false;
304+
if (lineComponent.getContents() == ComponentContents.EMPTY)
305+
continue;
305306

306-
concatenatedTooltip.append(lineComponent);
307-
}
307+
if (!first) concatenatedTooltip.append("\n");
308+
first = false;
308309

309-
return concatenatedTooltip;
310-
};
311-
if (descriptionFunction == null) {
310+
concatenatedTooltip.append(lineComponent);
311+
}
312+
313+
return concatenatedTooltip;
314+
};
312315
descriptionFunction = opt -> OptionDescription.createBuilder().name(name).description(concatenatedTooltipGetter.apply(opt)).build();
313316
}
314317

0 commit comments

Comments
 (0)