blob: ebad4ae33a8142fdcdb203bbe8194224e95e5889 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package dev.isxander.yacl.gui.controllers;
import dev.isxander.yacl.api.NameableEnum;
import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.gui.controllers.cycling.CyclingListController;
import net.minecraft.text.Text;
import net.minecraft.util.TranslatableOption;
import java.util.Arrays;
import java.util.function.Function;
@Deprecated
public class EnumController<T extends Enum<T>> extends CyclingListController<T> {
public static <T extends Enum<T>> Function<T, Text> getDefaultFormatter() {
return value -> {
if (value instanceof NameableEnum nameableEnum)
return nameableEnum.getDisplayName();
if (value instanceof TranslatableOption translatableOption)
return translatableOption.getText();
return Text.of(value.toString());
};
}
public EnumController(Option<T> option) {
this(option, getDefaultFormatter());
}
public EnumController(Option<T> option, Function<T, Text> valueFormatter) {
this(option, valueFormatter, option.typeClass().getEnumConstants());
}
public EnumController(Option<T> option, Function<T, Text> valueFormatter, T[] availableValues) {
super(option, Arrays.asList(availableValues), valueFormatter);
}
}
|