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())) {