Add option parenting, gate changes to sub-options when parent option is off
This commit is contained in:
parent
c7b6a9ed9e
commit
f036350b0a
|
|
@ -128,21 +128,8 @@ public class ModernFixEarlyConfig {
|
||||||
mixinsMissingMods.put(mixinClassName, requiredModId);
|
mixinsMissingMods.put(mixinClassName, requiredModId);
|
||||||
else if(isClientOnly && !ModernFixPlatformHooks.INSTANCE.isClient())
|
else if(isClientOnly && !ModernFixPlatformHooks.INSTANCE.isClient())
|
||||||
mixinsMissingMods.put(mixinClassName, "[not client]");
|
mixinsMissingMods.put(mixinClassName, "[not client]");
|
||||||
List<String> mixinOptionNames = dotSplitter.splitToList(mixinClassName);
|
String mixinCategoryName = "mixin." + mixinClassName.substring(0, mixinClassName.lastIndexOf('.'));
|
||||||
StringBuilder optionBuilder = new StringBuilder(mixinClassName.length());
|
mixinOptions.add(mixinCategoryName);
|
||||||
optionBuilder.append("mixin");
|
|
||||||
// mixin.core, mixin.safety can be top-level, everything else must have a subcategory
|
|
||||||
boolean allowTopLevel;
|
|
||||||
if(mixinOptionNames.size() > 0)
|
|
||||||
allowTopLevel = mixinOptionNames.get(0).equals("core") || mixinOptionNames.get(0).equals("safety");
|
|
||||||
else
|
|
||||||
allowTopLevel = false;
|
|
||||||
for(int i = 0; i < mixinOptionNames.size() - 1; i++) {
|
|
||||||
optionBuilder.append('.');
|
|
||||||
optionBuilder.append(mixinOptionNames.get(i));
|
|
||||||
if(i > 0 || allowTopLevel)
|
|
||||||
mixinOptions.add(optionBuilder.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
ModernFix.LOGGER.error("Error scanning file " + mixinPath, e);
|
ModernFix.LOGGER.error("Error scanning file " + mixinPath, e);
|
||||||
|
|
@ -202,6 +189,17 @@ public class ModernFixEarlyConfig {
|
||||||
this.options.putIfAbsent(optionName, option);
|
this.options.putIfAbsent(optionName, option);
|
||||||
this.optionsByCategory.put(OptionCategories.getCategoryForOption(optionName), option);
|
this.optionsByCategory.put(OptionCategories.getCategoryForOption(optionName), option);
|
||||||
}
|
}
|
||||||
|
for(Map.Entry<String, Option> entry : this.options.entrySet()) {
|
||||||
|
int idx = entry.getKey().lastIndexOf('.');
|
||||||
|
if(idx <= 0)
|
||||||
|
continue;
|
||||||
|
String potentialParentKey = entry.getKey().substring(0, idx);
|
||||||
|
Option potentialParent = this.options.get(potentialParentKey);
|
||||||
|
if(potentialParent != null) {
|
||||||
|
System.out.println(potentialParentKey + " -> " + entry.getKey());
|
||||||
|
entry.getValue().setParent(potentialParent);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Defines the default rules which can be configured by the user or other mods.
|
// Defines the default rules which can be configured by the user or other mods.
|
||||||
// You must manually add a rule for any new mixins not covered by an existing package rule.
|
// You must manually add a rule for any new mixins not covered by an existing package rule.
|
||||||
this.addMixinRule("launch.class_search_cache", true);
|
this.addMixinRule("launch.class_search_cache", true);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public class Option {
|
||||||
private Set<String> modDefined = null;
|
private Set<String> modDefined = null;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private boolean userDefined;
|
private boolean userDefined;
|
||||||
|
private Option parent = null;
|
||||||
|
|
||||||
public Option(String name, boolean enabled, boolean userDefined) {
|
public Option(String name, boolean enabled, boolean userDefined) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -37,10 +38,26 @@ public class Option {
|
||||||
this.modDefined.add(modId);
|
this.modDefined.add(modId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setParent(Option option) {
|
||||||
|
this.parent = option;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getParent() {
|
||||||
|
return this.parent;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return this.enabled;
|
return this.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this option will effectively be disabled (regardless of its own status)
|
||||||
|
* by the parent rule being disabled.
|
||||||
|
*/
|
||||||
|
public boolean isEffectivelyDisabledByParent() {
|
||||||
|
return this.parent != null && (!this.parent.enabled || this.parent.isEffectivelyDisabledByParent());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOverridden() {
|
public boolean isOverridden() {
|
||||||
return this.isUserDefined() || this.isModDefined();
|
return this.isUserDefined() || this.isModDefined();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,13 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
||||||
return baseComponent;
|
return baseComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateOptionEntryStatuses() {
|
||||||
|
for(Entry e : this.children()) {
|
||||||
|
if(e instanceof OptionEntry) {
|
||||||
|
((OptionEntry)e).updateStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public OptionList(ModernFixConfigScreen arg, Minecraft arg2) {
|
public OptionList(ModernFixConfigScreen arg, Minecraft arg2) {
|
||||||
super(arg2,arg.width + 45, arg.height, 43, arg.height - 32, 20);
|
super(arg2,arg.width + 45, arg.height, 43, arg.height - 32, 20);
|
||||||
|
|
@ -128,6 +135,7 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
||||||
this.option.setEnabled(!this.option.isEnabled(), !this.option.isUserDefined());
|
this.option.setEnabled(!this.option.isEnabled(), !this.option.isUserDefined());
|
||||||
ModernFix.LOGGER.error("Unable to save config", e);
|
ModernFix.LOGGER.error("Unable to save config", e);
|
||||||
}
|
}
|
||||||
|
OptionList.this.updateOptionEntryStatuses();
|
||||||
}, (btn, gfx, x, y) -> {
|
}, (btn, gfx, x, y) -> {
|
||||||
if(this.option.isModDefined()) {
|
if(this.option.isModDefined()) {
|
||||||
String disablingMods = String.join(", ", this.option.getDefiningMods());
|
String disablingMods = String.join(", ", this.option.getDefiningMods());
|
||||||
|
|
@ -140,8 +148,7 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(this.option.isModDefined())
|
updateStatus();
|
||||||
this.toggleButton.active = false;
|
|
||||||
this.helpButton = new Button(75, 0, 20, 20, new TextComponent("?"), (arg) -> {
|
this.helpButton = new Button(75, 0, 20, 20, new TextComponent("?"), (arg) -> {
|
||||||
Minecraft.getInstance().setScreen(new ModernFixOptionInfoScreen(mainScreen, optionName));
|
Minecraft.getInstance().setScreen(new ModernFixOptionInfoScreen(mainScreen, optionName));
|
||||||
});
|
});
|
||||||
|
|
@ -152,6 +159,10 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateStatus() {
|
||||||
|
this.toggleButton.active = !(this.option.isModDefined() || this.option.isEffectivelyDisabledByParent());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(PoseStack matrixStack, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean isMouseOver, float partialTicks) {
|
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(this.name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user