diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java index 53c4b54db..345f87760 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java @@ -24,6 +24,7 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.ui.construct.TwoLineListItem; +import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -34,7 +35,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; */ public class InstallerItem extends BorderPane { - public InstallerItem(String artifact, String version, Runnable upgrade, Consumer deleteCallback) { + public InstallerItem(String artifact, String version, @Nullable Runnable upgrade, @Nullable Consumer deleteCallback) { getStyleClass().add("two-line-list-item"); setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;"); JFXDepthManager.setDepth(this, 1); @@ -49,19 +50,24 @@ public class InstallerItem extends BorderPane { { HBox hBox = new HBox(); - JFXButton upgradeButton = new JFXButton(); - upgradeButton.setGraphic(SVG.update(Theme.blackFillBinding(), -1, -1)); - upgradeButton.getStyleClass().add("toggle-icon4"); - FXUtils.installFastTooltip(upgradeButton, i18n("install.change_version")); - upgradeButton.setOnMouseClicked(e -> upgrade.run()); + if (upgrade != null) { + JFXButton upgradeButton = new JFXButton(); + upgradeButton.setGraphic(SVG.update(Theme.blackFillBinding(), -1, -1)); + upgradeButton.getStyleClass().add("toggle-icon4"); + FXUtils.installFastTooltip(upgradeButton, i18n("install.change_version")); + upgradeButton.setOnMouseClicked(e -> upgrade.run()); + hBox.getChildren().add(upgradeButton); + } - JFXButton deleteButton = new JFXButton(); - deleteButton.setGraphic(SVG.close(Theme.blackFillBinding(), -1, -1)); - deleteButton.getStyleClass().add("toggle-icon4"); - deleteButton.setOnMouseClicked(e -> deleteCallback.accept(this)); + if (deleteCallback != null) { + JFXButton deleteButton = new JFXButton(); + deleteButton.setGraphic(SVG.close(Theme.blackFillBinding(), -1, -1)); + deleteButton.getStyleClass().add("toggle-icon4"); + deleteButton.setOnMouseClicked(e -> deleteCallback.accept(this)); + hBox.getChildren().add(deleteButton); + } hBox.setAlignment(Pos.CENTER_RIGHT); - hBox.getChildren().setAll(upgradeButton, deleteButton); setRight(hBox); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java index f89444096..f402d0e21 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java @@ -79,6 +79,7 @@ public class InstallerListPage extends ListPage { new InstallerItem("OptiFine", library.getVersion(), () -> { Controllers.getDecorator().startWizard(new UpdateInstallerWizardProvider(profile, gameVersion, version, "optifine", library)); }, removeAction.apply(library)))); + analyzer.get(FABRIC).ifPresent(library -> itemsProperty().add(new InstallerItem("Fabric", library.getVersion(), null, null))); }).start(); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java index 5aabc29fd..ac69feb6a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java @@ -69,7 +69,7 @@ public final class LibraryAnalyzer { FORGE(true, Pattern.compile("net\\.minecraftforge"), Pattern.compile("forge")), LITELOADER(true, Pattern.compile("com\\.mumfrey"), Pattern.compile("liteloader")), OPTIFINE(false, Pattern.compile("(net\\.)?optifine"), Pattern.compile(".*")), - FABRIC(true, Pattern.compile("net\\.fabricmc"), Pattern.compile(".*")); + FABRIC(true, Pattern.compile("net\\.fabricmc"), Pattern.compile("fabric-loader")); private final Pattern group, artifact; private final boolean modLoader;