- Config UI automatically skips to the layer of config where multiple options are available
- Removed range tooltips
- Config entries in UI list are now sorted by name, with config groups at priority
This commit is contained in:
simibubi 2021-06-09 16:53:54 +02:00
parent 169669680b
commit 971ce29b6a
2 changed files with 25 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package com.simibubi.create.foundation.config.ui; package com.simibubi.create.foundation.config.ui;
import java.awt.Color; import java.awt.Color;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -13,8 +14,11 @@ import org.lwjgl.glfw.GLFW;
import com.electronwill.nightconfig.core.AbstractConfig; import com.electronwill.nightconfig.core.AbstractConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig.Entry;
import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry;
import com.simibubi.create.foundation.config.ui.entries.BooleanEntry; import com.simibubi.create.foundation.config.ui.entries.BooleanEntry;
import com.simibubi.create.foundation.config.ui.entries.EnumEntry; import com.simibubi.create.foundation.config.ui.entries.EnumEntry;
import com.simibubi.create.foundation.config.ui.entries.NumberEntry; import com.simibubi.create.foundation.config.ui.entries.NumberEntry;
@ -236,6 +240,10 @@ public class SubMenuConfigScreen extends ConfigScreen {
if (obj instanceof AbstractConfig) { if (obj instanceof AbstractConfig) {
SubMenuEntry entry = new SubMenuEntry(this, humanKey, spec, (UnmodifiableConfig) obj); SubMenuEntry entry = new SubMenuEntry(this, humanKey, spec, (UnmodifiableConfig) obj);
list.children().add(entry); list.children().add(entry);
if (configGroup.valueMap()
.size() == 1)
ScreenOpener.open(
new SubMenuConfigScreen(parent, humanKey, type, spec, (UnmodifiableConfig) obj));
} else if (obj instanceof ForgeConfigSpec.ConfigValue<?>) { } else if (obj instanceof ForgeConfigSpec.ConfigValue<?>) {
ForgeConfigSpec.ConfigValue<?> configValue = (ForgeConfigSpec.ConfigValue<?>) obj; ForgeConfigSpec.ConfigValue<?> configValue = (ForgeConfigSpec.ConfigValue<?>) obj;
@ -261,6 +269,20 @@ public class SubMenuConfigScreen extends ConfigScreen {
} }
}); });
Collections.sort(list.children(),
(e, e2) -> {
int group = (e2 instanceof SubMenuEntry ? 1 : 0) - (e instanceof SubMenuEntry ? 1 : 0);
if (group == 0 && e instanceof LabeledEntry && e2 instanceof LabeledEntry) {
LabeledEntry le = (LabeledEntry) e;
LabeledEntry le2 = (LabeledEntry) e2;
return le.label.getComponent()
.getString()
.compareTo(le2.label.getComponent()
.getString());
}
return group;
});
//extras for server configs //extras for server configs
if (type != ModConfig.Type.SERVER) if (type != ModConfig.Type.SERVER)
return; return;

View file

@ -2,6 +2,7 @@ package com.simibubi.create.foundation.config.ui.entries;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -10,6 +11,7 @@ import javax.annotation.Nonnull;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import com.google.common.base.Predicates;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.config.ui.ConfigHelper; import com.simibubi.create.foundation.config.ui.ConfigHelper;
import com.simibubi.create.foundation.config.ui.ConfigScreen; import com.simibubi.create.foundation.config.ui.ConfigScreen;
@ -79,6 +81,7 @@ public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
} }
// add comment to tooltip // add comment to tooltip
labelTooltip.addAll(Arrays.stream(commentLines) labelTooltip.addAll(Arrays.stream(commentLines)
.filter(Predicates.not(s -> s.startsWith("Range")))
.map(StringTextComponent::new) .map(StringTextComponent::new)
.flatMap(stc -> TooltipHelper.cutTextComponent(stc, TextFormatting.GRAY, TextFormatting.GRAY) .flatMap(stc -> TooltipHelper.cutTextComponent(stc, TextFormatting.GRAY, TextFormatting.GRAY)
.stream()) .stream())