Render sub-options more nicely
This commit is contained in:
parent
f036350b0a
commit
5da78f7565
|
|
@ -46,6 +46,13 @@ public class Option {
|
|||
return this.parent;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
if(this.parent == null)
|
||||
return 0;
|
||||
else
|
||||
return this.parent.getDepth() + 1;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
|
@ -74,6 +81,13 @@ public class Option {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public String getSelfName() {
|
||||
if(this.parent == null)
|
||||
return this.name;
|
||||
else
|
||||
return this.name.substring(this.parent.getName().length() + 1);
|
||||
}
|
||||
|
||||
public void clearModsDefiningValue() {
|
||||
this.modDefined = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
||||
private final int maxNameWidth;
|
||||
private int maxNameWidth = 0;
|
||||
|
||||
private static final int DEPTH_OFFSET = 20;
|
||||
|
||||
private static final Component OPTION_ON = new TranslatableComponent("modernfix.option.on").withStyle(style -> style.withColor(ChatFormatting.GREEN));
|
||||
private static final Component OPTION_OFF = new TranslatableComponent("modernfix.option.off").withStyle(style -> style.withColor(ChatFormatting.RED));
|
||||
|
|
@ -31,9 +32,9 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
|||
|
||||
private ModernFixConfigScreen mainScreen;
|
||||
|
||||
private static MutableComponent getOptionComponent(String optionName) {
|
||||
String friendlyKey = "modernfix.option.name." + optionName;
|
||||
TextComponent baseComponent = new TextComponent(optionName);
|
||||
private static MutableComponent getOptionComponent(Option option) {
|
||||
String friendlyKey = "modernfix.option.name." + option.getName();
|
||||
TextComponent baseComponent = new TextComponent(option.getSelfName());
|
||||
if(I18n.exists(friendlyKey))
|
||||
return new TranslatableComponent(friendlyKey).withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, baseComponent)));
|
||||
else
|
||||
|
|
@ -48,12 +49,25 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
|||
}
|
||||
}
|
||||
|
||||
private final Set<Option> addedOptions = new HashSet<>();
|
||||
|
||||
private void addOption(Option option) {
|
||||
if(addedOptions.add(option)) {
|
||||
int w = this.minecraft.font.width(getOptionComponent(option)) + DEPTH_OFFSET * option.getDepth();
|
||||
this.maxNameWidth = Math.max(w, this.maxNameWidth);
|
||||
this.addEntry(new OptionEntry(option.getName(), option));
|
||||
ModernFixMixinPlugin.instance.config.getOptionMap().values().stream()
|
||||
.filter(subOption -> subOption.getParent() == option)
|
||||
.sorted(Comparator.comparing(Option::getName))
|
||||
.forEach(this::addOption);
|
||||
}
|
||||
}
|
||||
|
||||
public OptionList(ModernFixConfigScreen arg, Minecraft arg2) {
|
||||
super(arg2,arg.width + 45, arg.height, 43, arg.height - 32, 20);
|
||||
|
||||
this.mainScreen = arg;
|
||||
|
||||
int maxW = 0;
|
||||
Multimap<String, Option> optionsByCategory = ModernFixMixinPlugin.instance.config.getOptionCategoryMap();
|
||||
List<String> theCategories = OptionCategories.getCategoriesInOrder();
|
||||
for(String category : theCategories) {
|
||||
|
|
@ -61,21 +75,15 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
|||
this.addEntry(new CategoryEntry(new TranslatableComponent(categoryTranslationKey)
|
||||
.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableComponent(categoryTranslationKey + ".description"))))
|
||||
));
|
||||
List<Option> sortedKeys = optionsByCategory.get(category).stream().filter(key -> {
|
||||
optionsByCategory.get(category).stream().filter(key -> {
|
||||
int dotCount = 0;
|
||||
for(char c : key.getName().toCharArray()) {
|
||||
if(c == '.')
|
||||
dotCount++;
|
||||
}
|
||||
return dotCount >= 2;
|
||||
}).sorted(Comparator.comparing(Option::getName)).collect(Collectors.toList());
|
||||
for(Option option : sortedKeys) {
|
||||
int w = this.minecraft.font.width(getOptionComponent(option.getName()));
|
||||
maxW = Math.max(w, maxW);
|
||||
this.addEntry(new OptionEntry(option.getName(), option));
|
||||
}
|
||||
}).sorted(Comparator.comparing(Option::getName)).forEach(this::addOption);
|
||||
}
|
||||
this.maxNameWidth = maxW;
|
||||
}
|
||||
|
||||
protected int getScrollbarPosition() {
|
||||
|
|
@ -165,10 +173,10 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
|||
|
||||
@Override
|
||||
public void render(PoseStack matrixStack, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean isMouseOver, float partialTicks) {
|
||||
MutableComponent nameComponent = getOptionComponent(this.name);
|
||||
MutableComponent nameComponent = getOptionComponent(option);
|
||||
if(this.option.isUserDefined())
|
||||
nameComponent = nameComponent.withStyle(style -> style.withItalic(true)).append(new TranslatableComponent("modernfix.config.not_default"));
|
||||
float textX = (float)(left + 160 - OptionList.this.maxNameWidth);
|
||||
float textX = (float)(left + DEPTH_OFFSET * option.getDepth() + 160 - OptionList.this.maxNameWidth);
|
||||
float textY = (float)(top + height / 2 - 4);
|
||||
OptionList.this.minecraft.font.draw(matrixStack, nameComponent, textX, textY, 16777215);
|
||||
this.toggleButton.x = left + 175;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user