Fix enum entries

This commit is contained in:
JFronny 2021-06-10 18:44:43 +02:00
parent 08f6a9821b
commit 163b1524a8
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
3 changed files with 14 additions and 6 deletions

View File

@ -37,7 +37,16 @@ public class ConfigEnumEntry extends Entry<Integer> {
public boolean typeMatches(Entry<?> val) {
return val instanceof ConfigEnumEntry;
}
@Override
public void appendString(StringBuilder sb) {
sb.append(getValueName()).append('/').append(getValue()).append(" (").append(getDefaultName()).append('/').append(getDefault()).append(" of:");
for (Map.Entry<String, Integer> e : values.entrySet()) {
sb.append(' ').append(e.getKey()).append('/').append(e.getValue());
}
sb.append(')');
}
public void setFieldName(String s) {
if (s != null)
fieldName = s;

View File

@ -6,7 +6,7 @@ import io.gitlab.jfronny.respackopts.data.RpoError;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
//TODO implement equality checking for string/number variables
public class EqualityCondition implements Condition {
@Override
public boolean evaluate(JsonElement node) throws RpoError {
@ -15,7 +15,7 @@ public class EqualityCondition implements Condition {
Optional<Boolean> v = Optional.empty();
for (JsonElement jsonElement : node.getAsJsonArray()) {
boolean current = ConditionEvaluator.evaluate(jsonElement);
if (!v.isPresent())
if (v.isEmpty())
v = Optional.of(current);
if (current != v.get())
return false;

View File

@ -21,7 +21,6 @@ import net.minecraft.util.Language;
import java.util.Map;
import java.util.Optional;
//TODO fix enums always showing "reset" and not saving/loading properly from GUI
public class GuiFactory {
public void buildCategory(ConfigBranch source, String screenId, JfConfigCategory config, ConfigEntryBuilder entryBuilder, String namePrefix) {
String b = "respackopts.field." + screenId;
@ -43,8 +42,8 @@ public class GuiFactory {
}
else if (entry instanceof ConfigEnumEntry e) {
config.addEntry(entryBuilder.startDropdownMenu(getText(n, b),
DropdownMenuBuilder.TopCellElementBuilder.of(e.getValueName(), LiteralText::new),
new DropdownBoxEntry.DefaultSelectionCellCreator())
DropdownMenuBuilder.TopCellElementBuilder.of(e.getValueName(), s -> s, LiteralText::new),
new DropdownBoxEntry.DefaultSelectionCellCreator<>())
.setSuggestionMode(false)
.setDefaultValue(e.getDefaultName())
.setSelections(() -> e.values.keySet().iterator())