Skip to content

Commit

Permalink
Hide child libraries when libraries are hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Jul 16, 2023
1 parent d8ee48b commit 3480499
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/terraformersmc/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ public void onInitializeClient() {

// Initialize parent map
for (Mod mod : MODS.values()) {
if (mod.isHidden()) {
continue;
}
String parentId = mod.getParent();
if (parentId != null) {
Mod parent = MODS.getOrDefault(parentId, dummyParents.get(parentId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public void filter(String searchTerm, boolean refresh) {
filter(searchTerm, refresh, true);
}

private boolean hasVisibleChildMods(Mod parent) {
// All child mods shown, skip further checks
if (ModMenuConfig.SHOW_LIBRARIES.getValue()) {
return true;
}

List<Mod> children = ModMenu.PARENT_MAP.get(parent);
return !children.stream().allMatch(child -> child.getBadges().contains(Mod.Badge.LIBRARY));
}

private void filter(String searchTerm, boolean refresh, boolean search) {
this.clearEntries();
addedMods.clear();
Expand All @@ -129,6 +139,7 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
return false;
}
}

return !mod.isHidden();
}).collect(Collectors.toSet());

Expand All @@ -154,7 +165,7 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
}

if (!ModMenu.PARENT_MAP.values().contains(mod)) {
if (ModMenu.PARENT_MAP.keySet().contains(mod)) {
if (ModMenu.PARENT_MAP.keySet().contains(mod) && hasVisibleChildMods(mod)) {
//Add parent mods when not searching
List<Mod> children = ModMenu.PARENT_MAP.get(mod);
children.sort(ModMenuConfig.SORTING.getValue().getComparator());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.terraformersmc.modmenu.util.mod;

import com.terraformersmc.modmenu.ModMenu;
import com.terraformersmc.modmenu.config.ModMenuConfig;
import com.terraformersmc.modmenu.gui.ModsScreen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.Pair;
Expand Down Expand Up @@ -43,6 +44,11 @@ private static int passesFilters(ModsScreen screen, Mod mod, String query) {
String clientside = I18n.translate("modmenu.searchTerms.clientside");
String configurable = I18n.translate("modmenu.searchTerms.configurable");

// Libraries are currently hidden, ignore them entirely
if (!ModMenuConfig.SHOW_LIBRARIES.getValue() && mod.getBadges().contains(Mod.Badge.LIBRARY)) {
return 0;
}

// Some basic search, could do with something more advanced but this will do for now
if (modName.toLowerCase(Locale.ROOT).contains(query) // Search default mod name
|| modTranslatedName.toLowerCase(Locale.ROOT).contains(query) // Search localized mod name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class FabricMod implements Mod {

protected boolean childHasUpdate = false;

protected boolean hidesItself = false;

public FabricMod(ModContainer modContainer, Set<String> modpackMods) {
this.container = modContainer;
this.metadata = modContainer.getMetadata();
Expand Down Expand Up @@ -89,7 +87,6 @@ public FabricMod(ModContainer modContainer, Set<String> modpackMods) {
badgeNames.addAll(CustomValueUtil.getStringSet("badges", modMenuObject).orElse(new HashSet<>()));
links.putAll(CustomValueUtil.getStringMap("links", modMenuObject).orElse(new HashMap<>()));
allowsUpdateChecks = CustomValueUtil.getBoolean("update_checker", modMenuObject).orElse(true);
hidesItself = CustomValueUtil.getBoolean("hidden", modMenuObject).orElse(false);
}
this.modMenuData = new ModMenuData(
badgeNames,
Expand Down Expand Up @@ -335,7 +332,7 @@ public void setChildHasUpdate() {

@Override
public boolean isHidden() {
return this.hidesItself || ModMenuConfig.HIDDEN_MODS.getValue().contains(this.getId());
return ModMenuConfig.HIDDEN_MODS.getValue().contains(this.getId());
}

static class ModMenuData {
Expand Down

0 comments on commit 3480499

Please sign in to comment.