From ea3cac88427561d2f83b813aa84da74a296cf8fa Mon Sep 17 00:00:00 2001 From: LostLuma Date: Tue, 16 Apr 2024 18:22:59 +0200 Subject: [PATCH 1/6] Display credits by role instead of bunching them together --- .../gui/widget/DescriptionListWidget.java | 25 ++++++++++-- .../terraformersmc/modmenu/util/mod/Mod.java | 10 ++++- .../util/mod/fabric/FabricDummyParentMod.java | 8 ++-- .../modmenu/util/mod/fabric/FabricMod.java | 38 +++++++++++++------ .../modmenu/util/mod/quilt/QuiltMod.java | 33 ++++++++++++---- 5 files changed, 86 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index b600be89..ae3fff48 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -22,7 +22,6 @@ import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.gui.widget.EntryListWidget; import net.minecraft.client.render.*; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -207,7 +206,8 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de children().add(new MojangCreditsEntry(line)); } } else if (!"java".equals(mod.getId())) { - List credits = mod.getCredits(); + var credits = mod.getCredits(); + if (!credits.isEmpty()) { children().add(emptyEntry); @@ -215,12 +215,29 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de children().add(new DescriptionEntry(line)); } - for (String credit : credits) { + var iterator = credits.entrySet().iterator(); + + while (iterator.hasNext()) { int indent = 8; - for (OrderedText line : textRenderer.wrapLines(Text.literal(credit), wrapWidth - 16)) { + var role = iterator.next(); + + for (var line : textRenderer.wrapLines(Text.literal(role.getKey() + ":"), wrapWidth - 16)) { children().add(new DescriptionEntry(line, indent)); indent = 16; } + + for (var contributor : role.getValue()) { + indent = 16; + + for (var line : textRenderer.wrapLines(Text.literal(contributor), wrapWidth - 24)) { + children().add(new DescriptionEntry(line, indent)); + indent = 24; + } + } + + if (iterator.hasNext()) { + children().add(emptyEntry); + } } } } diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java index 22c95d6a..d08f5238 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java @@ -68,11 +68,17 @@ default String getTranslatedDescription() { @NotNull List getAuthors(); + /** + * @return a mapping of contributors to their roles. + */ @NotNull - List getContributors(); + Map> getContributors(); + /** + * @return a mapping of roles to each contributor with that role. + */ @NotNull - List getCredits(); + SortedMap> getCredits(); @NotNull Set getBadges(); diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java index d7d32d73..dddcaaa5 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java @@ -89,13 +89,13 @@ public FabricDummyParentMod(FabricMod host, String id) { } @Override - public @NotNull List getContributors() { - return new ArrayList<>(); + public @NotNull Map> getContributors() { + return Map.of(); } @Override - public @NotNull List getCredits() { - return new ArrayList<>(); + public @NotNull SortedMap> getCredits() { + return new TreeMap<>(); } @Override diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java index 57acce9f..fb11a662 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java @@ -211,20 +211,36 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { } @Override - public @NotNull List getContributors() { - List authors = metadata.getContributors().stream().map(Person::getName).collect(Collectors.toList()); - if ("minecraft".equals(getId()) && authors.isEmpty()) { - return Lists.newArrayList(); + public @NotNull Map> getContributors() { + Map> contributors = new HashMap<>(); + + for (var contributor : this.metadata.getContributors()) { + contributors.put(contributor.getName(), List.of("Contributor")); } - return authors; + + return contributors; } - @NotNull - public List getCredits() { - List list = new ArrayList<>(); - list.addAll(getAuthors()); - list.addAll(getContributors()); - return list; + @Override + public @NotNull SortedMap> getCredits() { + SortedMap> credits = new TreeMap<>(); + + var authors = this.getAuthors(); + + if (!authors.isEmpty()) { + credits.put("Author", authors); + } + + var contributors = this.getContributors(); + + for (var contributor : contributors.entrySet()) { + for (var role : contributor.getValue()) { + credits.computeIfAbsent(role, key -> new ArrayList<>()); + credits.get(role).add(contributor.getKey()); // Add name + } + } + + return credits; } @Override diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java index d293d9d3..64c7b0ae 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java @@ -15,9 +15,15 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.stream.Collectors; public class QuiltMod extends FabricMod { @@ -51,17 +57,30 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set getContributors() { - List authors = metadata.contributors().stream().map(modContributor -> modContributor.name() + " (" + modContributor.role() + ")").collect(Collectors.toList()); - if ("minecraft".equals(getId()) && authors.isEmpty()) { - return Lists.newArrayList(); + public @NotNull Map> getContributors() { + Map> contributors = new HashMap<>(); + + for (var contributor : this.metadata.contributors()) { + contributors.put(contributor.name(), contributor.roles()); } - return authors; + + return contributors; } @Override - public @NotNull List getCredits() { - return this.getContributors(); + public @NotNull SortedMap> getCredits() { + SortedMap> credits = new TreeMap<>(); + + var contributors = this.getContributors(); + + for (var contributor : contributors.entrySet()) { + for (var role : contributor.getValue()) { + credits.computeIfAbsent(role, key -> new ArrayList<>()); + credits.get(role).add(contributor.getKey()); // Add name + } + } + + return credits; } From 135d0e7cd4679994496dfe4ea478095012cc946a Mon Sep 17 00:00:00 2001 From: LostLuma Date: Thu, 18 Apr 2024 18:23:42 +0200 Subject: [PATCH 2/6] Add newlines between credit groups, allow translating role names --- .../modmenu/gui/widget/DescriptionListWidget.java | 6 +++++- src/main/resources/assets/modmenu/lang/en_us.json | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index ae3fff48..10779a1b 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -219,9 +219,13 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de while (iterator.hasNext()) { int indent = 8; + var role = iterator.next(); + var rolename = role.getKey(); + + var name = Text.translatableWithFallback("modmenu.credits.role." + rolename.toLowerCase(), rolename); - for (var line : textRenderer.wrapLines(Text.literal(role.getKey() + ":"), wrapWidth - 16)) { + for (var line : textRenderer.wrapLines(name.append(Text.literal(":")), wrapWidth - 16)) { children().add(new DescriptionEntry(line, indent)); indent = 16; } diff --git a/src/main/resources/assets/modmenu/lang/en_us.json b/src/main/resources/assets/modmenu/lang/en_us.json index 1c42d9fb..e0df0b13 100644 --- a/src/main/resources/assets/modmenu/lang/en_us.json +++ b/src/main/resources/assets/modmenu/lang/en_us.json @@ -87,6 +87,13 @@ "modmenu.wiki": "Wiki", "modmenu.youtube": "YouTube", + "modmenu.credits.role.author": "Authors", + "modmenu.credits.role.contributor": "Contributors", + "modmenu.credits.role.translator": "Translators", + "modmenu.credits.role.maintainer": "Maintainers", + "modmenu.credits.role.playtester": "Playtesters", + "modmenu.credits.role.illustrator": "Illustrators", + "modmenu.modsFolder": "Open Mods Folder", "modmenu.configsFolder": "Open Configs Folder", From 99bb770d64438cf1bd90e6fb42e028a662ce8d57 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Thu, 18 Apr 2024 18:36:45 +0200 Subject: [PATCH 3/6] Fix minor code style issues --- .../modmenu/gui/widget/DescriptionListWidget.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index 10779a1b..e237804a 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -221,11 +221,11 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de int indent = 8; var role = iterator.next(); - var rolename = role.getKey(); + var roleName = role.getKey(); - var name = Text.translatableWithFallback("modmenu.credits.role." + rolename.toLowerCase(), rolename); + var component = Text.translatableWithFallback("modmenu.credits.role." + roleName.toLowerCase(), roleName); - for (var line : textRenderer.wrapLines(name.append(Text.literal(":")), wrapWidth - 16)) { + for (var line : textRenderer.wrapLines(component.append(Text.literal(":")), wrapWidth - 16)) { children().add(new DescriptionEntry(line, indent)); indent = 16; } From da857ce2a175843a2b1696a6091c7dd78c6a2af2 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Fri, 19 Apr 2024 04:10:12 +0200 Subject: [PATCH 4/6] Improve translation key generation and fallback role names --- .../gui/widget/DescriptionListWidget.java | 16 +++++++++++++--- .../resources/assets/modmenu/lang/en_us.json | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index e237804a..c1993f1b 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -223,9 +223,7 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de var role = iterator.next(); var roleName = role.getKey(); - var component = Text.translatableWithFallback("modmenu.credits.role." + roleName.toLowerCase(), roleName); - - for (var line : textRenderer.wrapLines(component.append(Text.literal(":")), wrapWidth - 16)) { + for (var line : textRenderer.wrapLines(this.creditsRoleText(roleName), wrapWidth - 16)) { children().add(new DescriptionEntry(line, indent)); indent = 16; } @@ -352,6 +350,18 @@ public void renderScrollBar(BufferBuilder bufferBuilder, Tessellator tessellator } } + private Text creditsRoleText(String roleName) { + // Replace spaces and dashes in role names with underscores if they exist + // Notably Quilted Fabric API does this with FabricMC as "Upstream Owner" + var translationKey = roleName.replaceAll("[\s-]", "_"); + + // Add an s to the default untranslated string if it ends in r since this + // Fixes common role names people use in English (e.g. Author -> Authors) + var fallback = roleName.endsWith("r") ? roleName + "s" : roleName; + + return Text.translatableWithFallback("modmenu.credits.role." + translationKey, fallback).append(Text.literal(":")); + } + protected class DescriptionEntry extends ElementListWidget.Entry { protected OrderedText text; protected int indent; diff --git a/src/main/resources/assets/modmenu/lang/en_us.json b/src/main/resources/assets/modmenu/lang/en_us.json index e0df0b13..11f13b63 100644 --- a/src/main/resources/assets/modmenu/lang/en_us.json +++ b/src/main/resources/assets/modmenu/lang/en_us.json @@ -93,6 +93,7 @@ "modmenu.credits.role.maintainer": "Maintainers", "modmenu.credits.role.playtester": "Playtesters", "modmenu.credits.role.illustrator": "Illustrators", + "modmenu.credits.role.owner": "Owners", "modmenu.modsFolder": "Open Mods Folder", "modmenu.configsFolder": "Open Configs Folder", From 666ced5e449515afa84ac093e7681fe9b362d36d Mon Sep 17 00:00:00 2001 From: LostLuma Date: Sun, 21 Apr 2024 19:04:14 +0200 Subject: [PATCH 5/6] Sort contributors within roles --- .../com/terraformersmc/modmenu/util/mod/Mod.java | 2 +- .../util/mod/fabric/FabricDummyParentMod.java | 2 +- .../modmenu/util/mod/fabric/FabricMod.java | 13 ++++++------- .../modmenu/util/mod/quilt/QuiltMod.java | 10 ++++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java index d08f5238..2bc845c5 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java @@ -78,7 +78,7 @@ default String getTranslatedDescription() { * @return a mapping of roles to each contributor with that role. */ @NotNull - SortedMap> getCredits(); + SortedMap> getCredits(); @NotNull Set getBadges(); diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java index dddcaaa5..39e3ac26 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java @@ -94,7 +94,7 @@ public FabricDummyParentMod(FabricMod host, String id) { } @Override - public @NotNull SortedMap> getCredits() { + public @NotNull SortedMap> getCredits() { return new TreeMap<>(); } diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java index fb11a662..fc6d8a3f 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java @@ -222,21 +222,20 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { } @Override - public @NotNull SortedMap> getCredits() { - SortedMap> credits = new TreeMap<>(); + public @NotNull SortedMap> getCredits() { + SortedMap> credits = new TreeMap<>(); var authors = this.getAuthors(); + var contributors = this.getContributors(); if (!authors.isEmpty()) { - credits.put("Author", authors); + contributors.put("Author", authors); } - var contributors = this.getContributors(); - for (var contributor : contributors.entrySet()) { for (var role : contributor.getValue()) { - credits.computeIfAbsent(role, key -> new ArrayList<>()); - credits.get(role).add(contributor.getKey()); // Add name + credits.computeIfAbsent(role, key -> new TreeSet<>(String.CASE_INSENSITIVE_ORDER)); + credits.get(role).add(contributor.getKey()); } } diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java index 64c7b0ae..ae69ba2e 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java @@ -23,7 +23,9 @@ import java.util.Map; import java.util.Set; import java.util.SortedMap; +import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; import java.util.stream.Collectors; public class QuiltMod extends FabricMod { @@ -68,15 +70,15 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set> getCredits() { - SortedMap> credits = new TreeMap<>(); + public @NotNull SortedMap> getCredits() { + SortedMap> credits = new TreeMap<>(); var contributors = this.getContributors(); for (var contributor : contributors.entrySet()) { for (var role : contributor.getValue()) { - credits.computeIfAbsent(role, key -> new ArrayList<>()); - credits.get(role).add(contributor.getKey()); // Add name + credits.computeIfAbsent(role, key -> new TreeSet<>(String.CASE_INSENSITIVE_ORDER)); + credits.get(role).add(contributor.getKey()); } } From a7378304090febe306057cbd5372ce1ee217bbb1 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Sun, 21 Apr 2024 20:07:20 +0200 Subject: [PATCH 6/6] Fix Fabric authors being credited wrong --- .../com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java index fc6d8a3f..72da944e 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java @@ -228,8 +228,8 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { var authors = this.getAuthors(); var contributors = this.getContributors(); - if (!authors.isEmpty()) { - contributors.put("Author", authors); + for (var author : authors) { + contributors.put(author, List.of("Author")); } for (var contributor : contributors.entrySet()) {