修复 2830 本地模组查看信息时标签错误 (#2838)

* 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 <zjx001202@gmail.com>
This commit is contained in:
Burning_TNT 2024-07-21 00:58:33 +08:00 committed by GitHub
parent 5f84e8cfeb
commit ad5b74d8c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 17 deletions

View File

@ -33,6 +33,14 @@ public final class HMCLLocalizedDownloadListPage extends DownloadListPage {
return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MOD, CurseForgeRemoteModRepository.MODS, ModrinthRemoteModRepository.MODS); 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) { public static DownloadListPage ofModPack(DownloadPage.DownloadCallback callback, boolean versionSelection) {
return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.MODPACK, CurseForgeRemoteModRepository.MODPACKS, ModrinthRemoteModRepository.MODPACKS); 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); supportChinese.set(true);
downloadSources.get().setAll("mods.curseforge", "mods.modrinth"); downloadSources.get().setAll("mods.curseforge", "mods.modrinth");
if (CurseForgeRemoteModRepository.isAvailable()) if (curseForge != null) {
downloadSource.set("mods.curseforge"); downloadSource.set("mods.curseforge");
else } else if (modrinth != null) {
downloadSource.set("mods.modrinth"); downloadSource.set("mods.modrinth");
} else {
throw new AssertionError("Should not be here.");
}
} }
private class Repository extends LocalizedRemoteModRepository { private class Repository extends LocalizedRemoteModRepository {

View File

@ -33,7 +33,10 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane; 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.curse.CurseForgeRemoteModRepository;
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository; import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
import org.jackhuang.hmcl.setting.Profile; 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.ContainerAnimations;
import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.ui.animation.TransitionPane;
import org.jackhuang.hmcl.ui.construct.*; 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.i18n.I18n;
import org.jackhuang.hmcl.util.io.CompressingUtils; import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.FileUtils;
@ -58,6 +64,8 @@ import java.io.ByteArrayOutputStream;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; 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.FXUtils.onEscPressed;
import static org.jackhuang.hmcl.ui.ToolbarListPageSkin.createToolbarButton2; import static org.jackhuang.hmcl.ui.ToolbarListPageSkin.createToolbarButton2;
import static org.jackhuang.hmcl.util.Lang.mapOf; 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.Pair.pair;
import static org.jackhuang.hmcl.util.StringUtils.isNotBlank; import static org.jackhuang.hmcl.util.StringUtils.isNotBlank;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
class ModListPageSkin extends SkinBase<ModListPage> { class ModListPageSkin extends SkinBase<ModListPage> {
@ -323,18 +331,16 @@ class ModListPageSkin extends SkinBase<ModListPage> {
setBody(description); setBody(description);
if (StringUtils.isNotBlank(modInfo.getModInfo().getId())) { if (StringUtils.isNotBlank(modInfo.getModInfo().getId())) {
Lang.<Pair<String, RemoteModRepository>>immutableListOf( for (Pair<String, ? extends RemoteModRepository> item : Arrays.asList(
pair("mods.curseforge", CurseForgeRemoteModRepository.MODS), pair("mods.curseforge", CurseForgeRemoteModRepository.MODS),
pair("mods.modrinth", ModrinthRemoteModRepository.MODS) pair("mods.modrinth", ModrinthRemoteModRepository.MODS)
).forEach(item -> { )) {
String text = item.getKey(); RemoteModRepository repository = item.getValue();
RemoteModRepository remoteModRepository = item.getValue(); JFXHyperlink button = new JFXHyperlink(i18n(item.getKey()));
JFXHyperlink button = new JFXHyperlink(i18n(text));
Task.runAsync(() -> { Task.runAsync(() -> {
Optional<RemoteMod.Version> versionOptional = remoteModRepository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile()); Optional<RemoteMod.Version> versionOptional = repository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile());
if (versionOptional.isPresent()) { if (versionOptional.isPresent()) {
RemoteMod remoteMod = remoteModRepository.getModById(versionOptional.get().getModid()); RemoteMod remoteMod = repository.getModById(versionOptional.get().getModid());
FXUtils.runInFX(() -> { FXUtils.runInFX(() -> {
for (ModLoaderType modLoaderType : versionOptional.get().getLoaders()) { for (ModLoaderType modLoaderType : versionOptional.get().getLoaders()) {
String loaderName; String loaderName;
@ -357,15 +363,16 @@ class ModListPageSkin extends SkinBase<ModListPage> {
default: default:
continue; continue;
} }
if (!title.getTags().contains(loaderName)) { List<String> tags = title.getTags();
title.getTags().add(loaderName); if (!tags.contains(loaderName)) {
tags.add(loaderName);
} }
} }
button.setOnAction(e -> { button.setOnAction(e -> {
fireEvent(new DialogCloseEvent()); fireEvent(new DialogCloseEvent());
Controllers.navigate(new DownloadPage( Controllers.navigate(new DownloadPage(
new DownloadListPage(remoteModRepository), repository instanceof CurseForgeRemoteModRepository ? HMCLLocalizedDownloadListPage.ofCurseForgeMod(null, false) : HMCLLocalizedDownloadListPage.ofModrinthMod(null, false),
remoteMod, remoteMod,
new Profile.ProfileVersion(ModListPageSkin.this.getSkinnable().getProfile(), ModListPageSkin.this.getSkinnable().getVersionId()), new Profile.ProfileVersion(ModListPageSkin.this.getSkinnable().getProfile(), ModListPageSkin.this.getSkinnable().getVersionId()),
null null
@ -377,7 +384,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
}).start(); }).start();
button.setDisable(true); button.setDisable(true);
getActions().add(button); getActions().add(button);
}); }
} }
if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) { if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) {