From 971ce29b6a4e75a836d6cdf95a173804015ccf97 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 9 Jun 2021 16:53:54 +0200 Subject: [PATCH] Skip. - 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 --- .../config/ui/SubMenuConfigScreen.java | 22 +++++++++++++++++++ .../config/ui/entries/ValueEntry.java | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java index 2562f6038..0d59ea58d 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.config.ui; import java.awt.Color; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; @@ -13,8 +14,11 @@ import org.lwjgl.glfw.GLFW; import com.electronwill.nightconfig.core.AbstractConfig; 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.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.EnumEntry; import com.simibubi.create.foundation.config.ui.entries.NumberEntry; @@ -236,6 +240,10 @@ public class SubMenuConfigScreen extends ConfigScreen { if (obj instanceof AbstractConfig) { SubMenuEntry entry = new SubMenuEntry(this, humanKey, spec, (UnmodifiableConfig) obj); 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) { ForgeConfigSpec.ConfigValue configValue = (ForgeConfigSpec.ConfigValue) obj; @@ -260,6 +268,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 if (type != ModConfig.Type.SERVER) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java index 18cc5f30c..b2d1d039c 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.config.ui.entries; import java.util.Arrays; import java.util.List; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -10,6 +11,7 @@ import javax.annotation.Nonnull; import org.apache.commons.lang3.ArrayUtils; +import com.google.common.base.Predicates; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.config.ui.ConfigHelper; import com.simibubi.create.foundation.config.ui.ConfigScreen; @@ -79,6 +81,7 @@ public class ValueEntry extends ConfigScreenList.LabeledEntry { } // add comment to tooltip labelTooltip.addAll(Arrays.stream(commentLines) + .filter(Predicates.not(s -> s.startsWith("Range"))) .map(StringTextComponent::new) .flatMap(stc -> TooltipHelper.cutTextComponent(stc, TextFormatting.GRAY, TextFormatting.GRAY) .stream())