Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2830 #2838

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
private final TabHeader.Tab<DownloadListPage> modTab = new TabHeader.Tab<>("modTab");
private final TabHeader.Tab<DownloadListPage> modpackTab = new TabHeader.Tab<>("modpackTab");
private final TabHeader.Tab<DownloadListPage> resourcePackTab = new TabHeader.Tab<>("resourcePackTab");
private final TabHeader.Tab<DownloadListPage> customizationTab = new TabHeader.Tab<>("customizationTab");
private final TabHeader.Tab<DownloadListPage> worldTab = new TabHeader.Tab<>("worldTab");
private final TransitionPane transitionPane = new TransitionPane();
private final DownloadNavigator versionPageNavigator = new DownloadNavigator();
Expand All @@ -80,17 +79,16 @@ public DownloadPage() {
newGameTab.setNodeSupplier(loadVersionFor(() -> new VersionsPage(versionPageNavigator, i18n("install.installer.choose", i18n("install.installer.game")), "", DownloadProviders.getDownloadProvider(),
"game", versionPageNavigator::onGameSelected)));
modpackTab.setNodeSupplier(loadVersionFor(() -> {
ModpackDownloadListPage page = new ModpackDownloadListPage(Versions::downloadModpackImpl, false);
DownloadListPage page = HMCLLocalizedDownloadListPage.ofModPack(Versions::downloadModpackImpl, false);

JFXButton installLocalModpackButton = FXUtils.newRaisedButton(i18n("install.modpack"));
installLocalModpackButton.setOnAction(e -> Versions.importModpack());

page.getActions().add(installLocalModpackButton);
return page;
}));
modTab.setNodeSupplier(loadVersionFor(() -> new ModDownloadListPage((profile, version, file) -> download(profile, version, file, "mods"), true)));
resourcePackTab.setNodeSupplier(loadVersionFor(() -> new ResourcePackDownloadListPage((profile, version, file) -> download(profile, version, file, "resourcepacks"), true)));
customizationTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.CUSTOMIZATIONS)));
modTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofMod((profile, version, file) -> download(profile, version, file, "mods"), true)));
resourcePackTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofResourcePack((profile, version, file) -> download(profile, version, file, "resourcepacks"), true)));
worldTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.WORLDS)));
tab = new TabHeader(newGameTab, modpackTab, modTab, resourcePackTab, worldTab);

Expand Down Expand Up @@ -129,12 +127,6 @@ public DownloadPage() {
item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(resourcePackTab));
item.setOnAction(e -> tab.select(resourcePackTab));
})
// .addNavigationDrawerItem(item -> {
// item.setTitle(i18n("download.curseforge.customization"));
// item.setLeftGraphic(wrap(SVG::script));
// item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(customizationTab));
// item.setOnAction(e -> selectTabIfCurseForgeAvailable(customizationTab));
// })
.addNavigationDrawerItem(item -> {
item.setTitle(i18n("world"));
item.setLeftGraphic(wrap(SVG.EARTH));
Expand Down Expand Up @@ -212,9 +204,6 @@ private void loadVersions(Profile profile) {
if (resourcePackTab.isInitialized()) {
resourcePackTab.getNode().loadVersion(profile, null);
}
if (customizationTab.isInitialized()) {
customizationTab.getNode().loadVersion(profile, null);
}
if (worldTab.isInitialized()) {
worldTab.getNode().loadVersion(profile, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,60 @@
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;

public class ResourcePackDownloadListPage extends DownloadListPage {
public ResourcePackDownloadListPage(DownloadPage.DownloadCallback callback, boolean versionSelection) {
public final class HMCLLocalizedDownloadListPage extends DownloadListPage {
public static DownloadListPage ofMod(DownloadPage.DownloadCallback callback, boolean versionSelection) {
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);
}

public static DownloadListPage ofResourcePack(DownloadPage.DownloadCallback callback, boolean versionSelection) {
return new HMCLLocalizedDownloadListPage(callback, versionSelection, RemoteModRepository.Type.RESOURCE_PACK, CurseForgeRemoteModRepository.RESOURCE_PACKS, ModrinthRemoteModRepository.RESOURCE_PACKS);
}

private HMCLLocalizedDownloadListPage(DownloadPage.DownloadCallback callback, boolean versionSelection, RemoteModRepository.Type type, CurseForgeRemoteModRepository curseForge, ModrinthRemoteModRepository modrinth) {
super(null, callback, versionSelection);

repository = new Repository();
repository = new Repository(type, curseForge, modrinth);

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 {
private final RemoteModRepository.Type type;
private final CurseForgeRemoteModRepository curseForge;
private final ModrinthRemoteModRepository modrinth;

public Repository(Type type, CurseForgeRemoteModRepository curseForge, ModrinthRemoteModRepository modrinth) {
this.type = type;
this.curseForge = curseForge;
this.modrinth = modrinth;
}

@Override
protected RemoteModRepository getBackedRemoteModRepository() {
if ("mods.modrinth".equals(downloadSource.get())) {
return ModrinthRemoteModRepository.RESOURCE_PACKS;
return modrinth;
} else {
return CurseForgeRemoteModRepository.RESOURCE_PACKS;
return curseForge;
}
}

Expand All @@ -64,19 +96,17 @@ protected SortType getBackedRemoteModRepositorySortOrder() {

@Override
public Type getType() {
return Type.MOD;
return type;
}
}

@Override
protected String getLocalizedCategory(String category) {
String key;
if ("mods.modrinth".equals(downloadSource.get())) {
key = "modrinth.category." + category;
} else {
key = "curse.category." + category;
if (category.isEmpty()) {
return "";
}

String key = ("mods.modrinth".equals(downloadSource.get()) ? "modrinth" : "curse") + ".category." + category;
try {
return I18n.getResourceBundle().getString(key);
} catch (MissingResourceException e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Predicate;
Expand Down Expand Up @@ -323,18 +324,22 @@ class ModInfoDialog extends JFXDialogLayout {
setBody(description);

if (StringUtils.isNotBlank(modInfo.getModInfo().getId())) {
Lang.<Pair<String, RemoteModRepository>>immutableListOf(
pair("mods.curseforge", CurseForgeRemoteModRepository.MODS),
pair("mods.modrinth", ModrinthRemoteModRepository.MODS)
).forEach(item -> {
String text = item.getKey();
RemoteModRepository remoteModRepository = item.getValue();
for (int i = 0;i < 2;i ++) {
String text;
RemoteModRepository repository;
if (i == 0) {
text = "mods.curseforge";
repository = CurseForgeRemoteModRepository.MODS;
} else {
text = "mods.modrinth";
repository = ModrinthRemoteModRepository.MODS;
}

JFXHyperlink button = new JFXHyperlink(i18n(text));
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()) {
RemoteMod remoteMod = remoteModRepository.getModById(versionOptional.get().getModid());
RemoteMod remoteMod = repository.getModById(versionOptional.get().getModid());
FXUtils.runInFX(() -> {
for (ModLoaderType modLoaderType : versionOptional.get().getLoaders()) {
String loaderName;
Expand All @@ -357,15 +362,18 @@ class ModInfoDialog extends JFXDialogLayout {
default:
continue;
}
if (!title.getTags().contains(loaderName)) {
title.getTags().add(loaderName);
List<String> tags = title.getTags();
synchronized (tags) {
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
Expand All @@ -377,7 +385,7 @@ class ModInfoDialog extends JFXDialogLayout {
}).start();
button.setDisable(true);
getActions().add(button);
});
}
}

if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ download=Download
download.hint=Install games and modpacks or download mods, resource packs and worlds
download.code.404=File not found on the remote server: %s
download.content=Addons
download.curseforge.customization=Shaders, and game customization
download.curseforge.unavailable=HMCL nightly build does not support access to CurseForge, please use release version or beta version to download.
download.existing=The file cannot be saved because it already exists. You can use 'Save As' to save the file elsewhere.
download.external_link=Open Download Website
Expand Down
1 change: 0 additions & 1 deletion HMCL/src/main/resources/assets/lang/I18N_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ download=Descargar
download.hint=Instalar juegos y modpacks o descargar mods, paquetes de recursos y mapas
download.code.404=Archivo no encontrado en el servidor remoto: %s
download.content=Complementos
download.curseforge.customization=Luz y sombras, y personalización del juego
download.existing=El archivo no se puede guardar porque ya existe. Puedes usar 'Guardar como' para guardar el archivo en otro lugar.
download.external_link=Abrir sitio web
download.failed=Falló la descarga de %1$s, código de respuesta: %2$d
Expand Down