Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.ui.FXUtils;

import java.util.Collection;

public class TwoLineListItem extends VBox {
private static final String DEFAULT_STYLE_CLASS = "two-line-list-item";

Expand Down Expand Up @@ -158,6 +160,15 @@ public Label getSubtitleLabel() {
return lblSubtitle;
}

private static Label createTag(String tag, PseudoClass pseudoClass) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag");
tagLabel.setMinWidth(Label.USE_PREF_SIZE);
if (pseudoClass != null)
tagLabel.pseudoClassStateChanged(pseudoClass, true);
return tagLabel;
}

private ObservableList<Label> tags;

public ObservableList<Label> getTags() {
Expand All @@ -183,18 +194,17 @@ public ObservableList<Label> getTags() {
}

public void addTag(String tag, PseudoClass pseudoClass) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag");
tagLabel.setMinWidth(Label.USE_PREF_SIZE);
if (pseudoClass != null)
tagLabel.pseudoClassStateChanged(pseudoClass, true);
getTags().add(tagLabel);
getTags().add(createTag(tag, pseudoClass));
}

public void addTag(String tag) {
addTag(tag, null);
}

public void addTags(Collection<String> tags) {
getTags().addAll(tags.stream().map(tag -> createTag(tag, null)).toList());
}

private static final PseudoClass WARNING_PSEUDO_CLASS = PseudoClass.getPseudoClass("warning");

public void addTagWarning(String tag) {
Expand Down
42 changes: 19 additions & 23 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ protected DownloadPageSkin(DownloadPage control) {
resolve:
for (RemoteAddon.Version modVersion : modVersions) {
if (getSkinnable().type == RemoteAddonRepository.Type.MOD) {
for (ModLoaderType loader : modVersion.loaders()) {
if (targetLoaders.contains(loader)) {
for (Either<ModLoaderType, String> loader : modVersion.loaders()) {
if (loader.hasLeft() && targetLoaders.contains(loader.left())) {
list.getContent().addAll(
ComponentList.createComponentListTitle(i18n("mods.download.recommend", gameVersion)),
new AddonItem(control.addon, modVersion, control)
Expand Down Expand Up @@ -452,28 +452,24 @@ private static final class AddonItem extends StackPane {
break;
}

for (ModLoaderType modLoaderType : dataItem.loaders()) {
switch (modLoaderType) {
case FORGE:
content.addTag(i18n("install.installer.forge"));
break;
case CLEANROOM:
content.addTag(i18n("install.installer.cleanroom"));
break;
case NEO_FORGE:
content.addTag(i18n("install.installer.neoforge"));
break;
case FABRIC:
content.addTag(i18n("install.installer.fabric"));
break;
case LITE_LOADER:
content.addTag(i18n("install.installer.liteloader"));
break;
case QUILT:
content.addTag(i18n("install.installer.quilt"));
break;
}
Set<String> tags = new LinkedHashSet<>();
for (Either<ModLoaderType, String> loader : dataItem.loaders()) {
String tag = loader.map(
loaderType -> switch (loaderType) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
default -> null;
},
s -> "bungeecord".equalsIgnoreCase(s) ? "BungeeCord" : StringUtils.removeDashAndCapitalizeWords(s)
);
if (tag != null) tags.add(tag);
}
content.addTags(tags);

descPane.getChildren().setAll(graphicPane, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
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.FXThread;
import org.jackhuang.hmcl.util.Lazy;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
Expand Down Expand Up @@ -477,25 +474,24 @@ final class ModInfoDialog extends JFXDialogLayout {
if (versionOptional.isPresent()) {
RemoteAddon remoteAddon = repository.getModById(DownloadProviders.getDownloadProvider(), versionOptional.get().modid());
FXUtils.runInFX(() -> {
for (ModLoaderType modLoaderType : versionOptional.get().loaders()) {
String loaderName = switch (modLoaderType) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
default -> null;
};
if (loaderName == null)
continue;
if (title.getTags()
.stream()
.noneMatch(it -> it.getText().equals(loaderName))) {
title.addTag(loaderName);
}
Set<String> tags = new LinkedHashSet<>();
for (Either<ModLoaderType, String> loader : versionOptional.get().loaders()) {
String tag = loader.map(
loaderType -> switch (loaderType) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
default -> null;
},
StringUtils::removeDashAndCapitalizeWords
);
if (tag != null) tags.add(tag);
}
title.addTags(tags);
Comment thread
ToobLac marked this conversation as resolved.
Outdated

button.setOnAction(e -> {
fireEvent(new DialogCloseEvent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jackhuang.hmcl.addon.repository.ModrinthRemoteAddonRepository;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.util.Either;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -204,7 +205,7 @@ public interface IVersion {

public record Version(IVersion self, String modid, String name, String version, String changelog,
Instant datePublished, VersionType versionType, File file, List<Dependency> dependencies,
List<String> gameVersions, List<ModLoaderType> loaders) {
List<String> gameVersions, List<Either<ModLoaderType, String>> loaders) {
}

public record File(Map<String, String> hashes, String url, String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jackhuang.hmcl.addon.RemoteAddon;
import org.jackhuang.hmcl.addon.RemoteAddonRepository;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.util.Either;
import org.jackhuang.hmcl.util.io.FileUtils;

import java.io.IOException;
Expand Down Expand Up @@ -202,7 +203,7 @@ public AddonUpdate checkUpdates(DownloadProvider downloadProvider, String gameVe
if (currentVersion.isEmpty()) return null;
List<RemoteAddon.Version> remoteVersions = repository.getRemoteVersionsById(downloadProvider, currentVersion.get().modid())
.filter(version -> version.gameVersions().contains(gameVersion))
.filter(version -> version.loaders().contains(getModLoaderType()))
.filter(version -> version.loaders().contains(Either.left(getModLoaderType())))
Comment thread
ToobLac marked this conversation as resolved.
.filter(version -> version.datePublished().compareTo(currentVersion.get().datePublished()) > 0)
.sorted(Comparator.comparing(RemoteAddon.Version::datePublished).reversed())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package org.jackhuang.hmcl.addon.mod;

import org.jackhuang.hmcl.util.Either;

import java.util.Locale;

public enum ModLoaderType {
UNKNOWN,
FORGE,
Expand All @@ -25,5 +29,17 @@ public enum ModLoaderType {
FABRIC,
QUILT,
LITE_LOADER,
LEGACY_FABRIC
LEGACY_FABRIC;

public static Either<ModLoaderType, String> toEither(String loader) {
return switch (loader.toLowerCase(Locale.ROOT)) {
case "fabric" -> Either.left(ModLoaderType.FABRIC);
case "forge" -> Either.left(ModLoaderType.FORGE);
case "neoforge" -> Either.left(ModLoaderType.NEO_FORGE);
case "quilt" -> Either.left(ModLoaderType.QUILT);
case "liteloader" -> Either.left(ModLoaderType.LITE_LOADER);
case "legacy-fabric" -> Either.left(ModLoaderType.LEGACY_FABRIC);
default -> Either.right(loader);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import org.jackhuang.hmcl.addon.RemoteAddonRepository;
import org.jackhuang.hmcl.addon.mod.ModLoaderType;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.MurmurHash2;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.io.HttpRequest;
import org.jackhuang.hmcl.util.io.JarUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
Expand Down Expand Up @@ -482,13 +479,11 @@ public RemoteAddon.Version toVersion() {
return RemoteAddon.Dependency.ofGeneral(RELATION_TYPE.get(dependency.relationType()), MODS, Integer.toString(dependency.modId()));
}).distinct().filter(Objects::nonNull).collect(Collectors.toList()),
gameVersions.stream().filter(GameVersionNumber::isKnown).toList(),
gameVersions.stream().flatMap(version -> {
if ("fabric".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FABRIC);
else if ("forge".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FORGE);
else if ("quilt".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.QUILT);
else if ("neoforge".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.NEO_FORGE);
else return Stream.empty();
}).collect(Collectors.toList())
gameVersions.stream().filter(s ->
!"client".equalsIgnoreCase(s)
&& !"server".equalsIgnoreCase(s)
&& !StringUtils.containsDigit(s)
).map(ModLoaderType::toEither).toList()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,7 @@ public Optional<RemoteAddon.Version> toVersion() {
return RemoteAddon.Dependency.ofGeneral(DEPENDENCY_TYPE.get(dependency.dependencyType), MODS, dependency.projectId);
}).filter(Objects::nonNull).collect(Collectors.toList()),
gameVersions,
loaders.stream().flatMap(loader -> {
if ("fabric".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.FABRIC);
else if ("forge".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.FORGE);
else if ("neoforge".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.NEO_FORGE);
else if ("quilt".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.QUILT);
else if ("liteloader".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.LITE_LOADER);
else return Stream.empty();
}).collect(Collectors.toList())
loaders.stream().map(ModLoaderType::toEither).toList()
));
}
}
Expand Down
Loading