From ad5b74d8c7a357bdac6cadf0ac7806cb81458cc0 Mon Sep 17 00:00:00 2001 From: Burning_TNT <88144530+burningtnt@users.noreply.github.com> Date: Sun, 21 Jul 2024 00:58:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=202830=20=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=A8=A1=E7=BB=84=E6=9F=A5=E7=9C=8B=E4=BF=A1=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E9=94=99=E8=AF=AF=20(#2838)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Clean up duplicated codes in DownloadPage. * Remove useless codes. * Render the raw category when no i18n is provided. * Fix #2830. * Fix checkstyle. * format file * Remove the redundant lock. * Update ModListPageSkin * Update ModListPageSkin --------- Co-authored-by: Glavo --- .../HMCLLocalizedDownloadListPage.java | 15 +++++++- .../hmcl/ui/versions/ModListPageSkin.java | 37 +++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/HMCLLocalizedDownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/HMCLLocalizedDownloadListPage.java index a7cedd0c9..e00db972b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/HMCLLocalizedDownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/HMCLLocalizedDownloadListPage.java @@ -33,6 +33,14 @@ public final class HMCLLocalizedDownloadListPage extends DownloadListPage { return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MOD, CurseForgeRemoteModRepository.MODS, ModrinthRemoteModRepository.MODS); } + public static DownloadListPage ofCurseForgeMod(DownloadPage.DownloadCallback callback, boolean versionSelection) { + return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MOD, CurseForgeRemoteModRepository.MODS, null); + } + + public static DownloadListPage ofModrinthMod(DownloadPage.DownloadCallback callback, boolean versionSelection) { + return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MOD, null, ModrinthRemoteModRepository.MODS); + } + public static DownloadListPage ofModPack(DownloadPage.DownloadCallback callback, boolean versionSelection) { return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MODPACK, CurseForgeRemoteModRepository.MODPACKS, ModrinthRemoteModRepository.MODPACKS); } @@ -48,10 +56,13 @@ public final class HMCLLocalizedDownloadListPage extends DownloadListPage { supportChinese.set(true); downloadSources.get().setAll("mods.curseforge", "mods.modrinth"); - if (CurseForgeRemoteModRepository.isAvailable()) + if (curseForge != null) { downloadSource.set("mods.curseforge"); - else + } else if (modrinth != null) { downloadSource.set("mods.modrinth"); + } else { + throw new AssertionError("Should not be here."); + } } private class Repository extends LocalizedRemoteModRepository { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java index 497a383cc..188a72bb8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java @@ -33,7 +33,10 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; -import org.jackhuang.hmcl.mod.*; +import org.jackhuang.hmcl.mod.LocalModFile; +import org.jackhuang.hmcl.mod.ModLoaderType; +import org.jackhuang.hmcl.mod.RemoteMod; +import org.jackhuang.hmcl.mod.RemoteModRepository; import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository; import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository; import org.jackhuang.hmcl.setting.Profile; @@ -46,7 +49,10 @@ import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.animation.ContainerAnimations; import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.ui.construct.*; -import org.jackhuang.hmcl.util.*; +import org.jackhuang.hmcl.util.Holder; +import org.jackhuang.hmcl.util.Lazy; +import org.jackhuang.hmcl.util.Pair; +import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.i18n.I18n; import org.jackhuang.hmcl.util.io.CompressingUtils; import org.jackhuang.hmcl.util.io.FileUtils; @@ -58,6 +64,8 @@ import java.io.ByteArrayOutputStream; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; import java.util.Locale; import java.util.Optional; import java.util.function.Predicate; @@ -67,10 +75,10 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed; import static org.jackhuang.hmcl.ui.ToolbarListPageSkin.createToolbarButton2; import static org.jackhuang.hmcl.util.Lang.mapOf; -import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.Pair.pair; import static org.jackhuang.hmcl.util.StringUtils.isNotBlank; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; +import static org.jackhuang.hmcl.util.logging.Logger.LOG; class ModListPageSkin extends SkinBase { @@ -323,18 +331,16 @@ class ModListPageSkin extends SkinBase { setBody(description); if (StringUtils.isNotBlank(modInfo.getModInfo().getId())) { - Lang.>immutableListOf( + for (Pair item : Arrays.asList( pair("mods.curseforge", CurseForgeRemoteModRepository.MODS), pair("mods.modrinth", ModrinthRemoteModRepository.MODS) - ).forEach(item -> { - String text = item.getKey(); - RemoteModRepository remoteModRepository = item.getValue(); - - JFXHyperlink button = new JFXHyperlink(i18n(text)); + )) { + RemoteModRepository repository = item.getValue(); + JFXHyperlink button = new JFXHyperlink(i18n(item.getKey())); Task.runAsync(() -> { - Optional versionOptional = remoteModRepository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile()); + Optional versionOptional = repository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile()); if (versionOptional.isPresent()) { - RemoteMod remoteMod = remoteModRepository.getModById(versionOptional.get().getModid()); + RemoteMod remoteMod = repository.getModById(versionOptional.get().getModid()); FXUtils.runInFX(() -> { for (ModLoaderType modLoaderType : versionOptional.get().getLoaders()) { String loaderName; @@ -357,15 +363,16 @@ class ModListPageSkin extends SkinBase { default: continue; } - if (!title.getTags().contains(loaderName)) { - title.getTags().add(loaderName); + List tags = title.getTags(); + if (!tags.contains(loaderName)) { + tags.add(loaderName); } } button.setOnAction(e -> { fireEvent(new DialogCloseEvent()); Controllers.navigate(new DownloadPage( - new DownloadListPage(remoteModRepository), + repository instanceof CurseForgeRemoteModRepository ? HMCLLocalizedDownloadListPage.ofCurseForgeMod(null, false) : HMCLLocalizedDownloadListPage.ofModrinthMod(null, false), remoteMod, new Profile.ProfileVersion(ModListPageSkin.this.getSkinnable().getProfile(), ModListPageSkin.this.getSkinnable().getVersionId()), null @@ -377,7 +384,7 @@ class ModListPageSkin extends SkinBase { }).start(); button.setDisable(true); getActions().add(button); - }); + } } if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) {