Skip to content

Commit 1972e93

Browse files
committed
refactor!: Add properties to customEntry(), as state management requires rows to know their properties
1 parent dba9198 commit 1972e93

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

common/src/main/java/net/blay09/mods/balm/client/platform/config/screen/BalmConfigScreenSectionBuilder.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,25 @@ default BalmConfigScreenSectionBuilder button(Component label, Component tooltip
6161

6262
BalmConfigScreenSectionBuilder button(Component label, Component tooltip, Component buttonLabel, Consumer<BalmConfigScreen> onPress, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate);
6363

64-
default BalmConfigScreenSectionBuilder customEntry(BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory) {
65-
return customEntry(entryFactory, String::isEmpty);
64+
default BalmConfigScreenSectionBuilder customEntry(ConfiguredProperty<?> property, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory) {
65+
return customEntry(List.of(property), entryFactory);
6666
}
6767

68-
default BalmConfigScreenSectionBuilder customEntry(BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate) {
69-
return customEntry(entryFactory, filterPredicate, _ -> true);
68+
default BalmConfigScreenSectionBuilder customEntry(List<ConfiguredProperty<?>> properties, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory) {
69+
return customEntry(properties, entryFactory, String::isEmpty);
7070
}
7171

72-
BalmConfigScreenSectionBuilder customEntry(BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate);
72+
default BalmConfigScreenSectionBuilder customEntry(ConfiguredProperty<?> property, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate) {
73+
return customEntry(List.of(property), entryFactory, filterPredicate);
74+
}
75+
76+
default BalmConfigScreenSectionBuilder customEntry(List<ConfiguredProperty<?>> properties, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate) {
77+
return customEntry(properties, entryFactory, filterPredicate, _ -> true);
78+
}
79+
80+
default BalmConfigScreenSectionBuilder customEntry(ConfiguredProperty<?> property, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate) {
81+
return customEntry(List.of(property), entryFactory, filterPredicate, visibilityPredicate);
82+
}
83+
84+
BalmConfigScreenSectionBuilder customEntry(List<ConfiguredProperty<?>> properties, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate);
7385
}

common/src/main/java/net/blay09/mods/balm/client/platform/config/screen/internal/BalmConfigScreenCustomEntryRow.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
import net.blay09.mods.balm.client.platform.config.screen.BalmConfigScreenContext;
55
import net.blay09.mods.balm.client.platform.config.screen.BalmConfigScreenEntry;
66
import net.blay09.mods.balm.client.platform.config.screen.BalmConfigScreenRowState;
7+
import net.blay09.mods.balm.platform.config.schema.ConfiguredProperty;
78

9+
import java.util.List;
810
import java.util.function.BiFunction;
911
import java.util.function.Predicate;
1012

1113
public class BalmConfigScreenCustomEntryRow extends BalmConfigScreenRow {
1214
private final BiFunction<BalmConfigScreen, BalmConfigScreenRowState, BalmConfigScreenEntry> entryFactory;
15+
private final List<ConfiguredProperty<?>> properties;
1316
private final Predicate<String> filterPredicate;
1417

15-
public BalmConfigScreenCustomEntryRow(BiFunction<BalmConfigScreen, BalmConfigScreenRowState, BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate) {
18+
public BalmConfigScreenCustomEntryRow(List<ConfiguredProperty<?>> properties, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate) {
1619
super(visibilityPredicate);
20+
this.properties = properties;
1721
this.entryFactory = entryFactory;
1822
this.filterPredicate = filterPredicate;
1923
}
@@ -22,6 +26,11 @@ public BiFunction<BalmConfigScreen, BalmConfigScreenRowState, BalmConfigScreenEn
2226
return entryFactory;
2327
}
2428

29+
@Override
30+
public List<ConfiguredProperty<?>> properties() {
31+
return properties;
32+
}
33+
2534
@Override
2635
public boolean matchesFilter(String filter) {
2736
return filterPredicate.test(filter);

common/src/main/java/net/blay09/mods/balm/client/platform/config/screen/internal/BalmConfigScreenSectionBuilderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public BalmConfigScreenSectionBuilder button(Component label, Component tooltip,
4141
}
4242

4343
@Override
44-
public BalmConfigScreenSectionBuilder customEntry(BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate) {
45-
rows.add(new BalmConfigScreenCustomEntryRow(entryFactory::apply, filterPredicate, visibilityPredicate));
44+
public BalmConfigScreenSectionBuilder customEntry(List<ConfiguredProperty<?>> properties, BiFunction<BalmConfigScreen, BalmConfigScreenRowState, ? extends BalmConfigScreenEntry> entryFactory, Predicate<String> filterPredicate, Predicate<BalmConfigScreenContext> visibilityPredicate) {
45+
rows.add(new BalmConfigScreenCustomEntryRow(List.copyOf(properties), entryFactory::apply, filterPredicate, visibilityPredicate));
4646
return this;
4747
}
4848

0 commit comments

Comments
 (0)