From 3b36bbc88e04b349798229767c4fba967020d41b Mon Sep 17 00:00:00 2001 From: Burning_TNT <88144530+burningtnt@users.noreply.github.com> Date: Sat, 8 Jul 2023 23:01:27 +0800 Subject: [PATCH] Support viewing mods in ModListPage (#2366) --- .../hmcl/ui/versions/ModListPage.java | 8 +++ .../hmcl/ui/versions/ModListPageSkin.java | 53 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java index e72eb2c43..8a220c871 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java @@ -234,4 +234,12 @@ public final class ModListPage extends ListPageBase { } } - static class ModInfoDialog extends JFXDialogLayout { + class ModInfoDialog extends JFXDialogLayout { ModInfoDialog(ModInfoObject modInfo) { HBox titleContainer = new HBox(); @@ -313,6 +319,45 @@ class ModListPageSkin extends SkinBase { Label description = new Label(modInfo.getModInfo().getDescription().toString()); setBody(description); + if (StringUtils.isNotBlank(modInfo.getModInfo().getId())) { + Lang.>>>immutableListOf( + pair("mods.curseforge", pair( + CurseForgeRemoteModRepository.MODS, + (remoteVersion) -> Integer.toString(((CurseAddon.LatestFile) remoteVersion.getSelf()).getModId()) + )), + pair("mods.modrinth", pair( + ModrinthRemoteModRepository.MODS, + (remoteVersion) -> ((ModrinthRemoteModRepository.ProjectVersion) remoteVersion.getSelf()).getProjectId() + )) + ).forEach(item -> { + String text = item.getKey(); + RemoteModRepository remoteModRepository = item.getValue().getKey(); + Function projectIDProvider = item.getValue().getValue(); + + JFXHyperlink button = new JFXHyperlink(i18n(text)); + Task.runAsync(() -> { + Optional versionOptional = remoteModRepository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile()); + if (versionOptional.isPresent()) { + RemoteMod remoteMod = remoteModRepository.getModById(projectIDProvider.apply(versionOptional.get())); + FXUtils.runInFX(() -> { + button.setOnAction(e -> { + fireEvent(new DialogCloseEvent()); + Controllers.navigate(new DownloadPage( + new DownloadListPage(remoteModRepository), + remoteMod, + new Profile.ProfileVersion(ModListPageSkin.this.getSkinnable().getProfile(), ModListPageSkin.this.getSkinnable().getVersionId()), + null + )); + }); + button.setDisable(false); + }); + } + }).start(); + button.setDisable(true); + getActions().add(button); + }); + } + if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) { JFXHyperlink officialPageButton = new JFXHyperlink(i18n("mods.url")); officialPageButton.setOnAction(e -> {