From 10df7a862b8439e55ffa5bff53c5d2189d23e827 Mon Sep 17 00:00:00 2001 From: mineDiamond Date: Sun, 8 Feb 2026 20:45:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=8C=89=E9=92=AE=E5=87=BA=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E7=89=88=E6=9C=AC=E7=9A=84?= =?UTF-8?q?bug=20(#5461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/versions/WorldListPage.java | 22 ++++++++++++++----- .../hmcl/ui/versions/WorldManagePage.java | 22 ++++++++++++------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java index 1e5676923..23778b9cc 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java @@ -22,6 +22,7 @@ import com.jfoenix.controls.JFXCheckBox; import com.jfoenix.controls.JFXListView; import com.jfoenix.controls.JFXPopup; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -53,6 +54,7 @@ import java.nio.file.Path; import java.time.Instant; import java.util.Arrays; import java.util.List; +import java.util.Optional; import static org.jackhuang.hmcl.ui.FXUtils.determineOptimalPopupPosition; import static org.jackhuang.hmcl.util.StringUtils.parseColorEscapes; @@ -67,6 +69,7 @@ public final class WorldListPage extends ListPageBase implements VersionP private List worlds; private Profile profile; private String instanceId; + private final BooleanProperty supportQuickPlay = new SimpleBooleanProperty(this, "supportQuickPlay", false); private int refreshCount = 0; @@ -121,6 +124,9 @@ public final class WorldListPage extends ListPageBase implements VersionP return; } + Optional gameVersion = profile.getRepository().getGameVersion(instanceId); + supportQuickPlay.set(World.supportQuickPlay(GameVersionNumber.asGameVersion(gameVersion))); + worlds = result; updateWorldList(); @@ -203,6 +209,10 @@ public final class WorldListPage extends ListPageBase implements VersionP return showAll; } + public ReadOnlyBooleanProperty supportQuickPlayProperty() { + return supportQuickPlay; + } + private final class WorldListPageSkin extends ToolbarListPageSkin { WorldListPageSkin() { @@ -269,6 +279,8 @@ public final class WorldListPage extends ListPageBase implements VersionP right.setAlignment(Pos.CENTER_RIGHT); btnLaunch = new JFXButton(); + btnLaunch.visibleProperty().bind(page.supportQuickPlayProperty()); + btnLaunch.managedProperty().bind(btnLaunch.visibleProperty()); right.getChildren().add(btnLaunch); btnLaunch.getStyleClass().add("toggle-icon4"); btnLaunch.setGraphic(SVG.ROCKET_LAUNCH.createIcon()); @@ -286,7 +298,7 @@ public final class WorldListPage extends ListPageBase implements VersionP btnMore.setOnAction(event -> { World world = getItem(); if (world != null) - showPopupMenu(world, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); + showPopupMenu(world, page.supportQuickPlayProperty().get(), JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); }); } @@ -302,7 +314,7 @@ public final class WorldListPage extends ListPageBase implements VersionP if (event.getButton() == MouseButton.PRIMARY) page.showManagePage(world); else if (event.getButton() == MouseButton.SECONDARY) - showPopupMenu(world, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); + showPopupMenu(world, page.supportQuickPlayProperty().get(), JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); }); } @@ -340,19 +352,19 @@ public final class WorldListPage extends ListPageBase implements VersionP // Popup Menu - public void showPopupMenu(World world, JFXPopup.PopupHPosition hPosition, double initOffsetX, double initOffsetY) { + public void showPopupMenu(World world, boolean supportQuickPlay, JFXPopup.PopupHPosition hPosition, double initOffsetX, double initOffsetY) { boolean worldLocked = world.isLocked(); PopupMenu popupMenu = new PopupMenu(); JFXPopup popup = new JFXPopup(popupMenu); - if (world.supportQuickPlay()) { + if (supportQuickPlay) { IconedMenuItem launchItem = new IconedMenuItem(SVG.ROCKET_LAUNCH, i18n("version.launch_and_enter_world"), () -> page.launch(world), popup); launchItem.setDisable(worldLocked); - popupMenu.getContent().add(launchItem); popupMenu.getContent().addAll( + launchItem, new IconedMenuItem(SVG.SCRIPT, i18n("version.launch_script"), () -> page.generateLaunchScript(world), popup), new MenuSeparator() ); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldManagePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldManagePage.java index 902116af0..e46d7c6b8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldManagePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldManagePage.java @@ -35,11 +35,13 @@ import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.util.ChunkBaseApp; import org.jackhuang.hmcl.util.StringUtils; +import org.jackhuang.hmcl.util.versioning.GameVersionNumber; import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.file.Path; +import java.util.Optional; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.logging.Logger.LOG; @@ -52,7 +54,8 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco private final World world; private final Path backupsDir; private final Profile profile; - private final String versionId; + private final String instanceId; + private final boolean supportQuickPlay; private FileChannel sessionLockChannel; private final ObjectProperty state; @@ -66,11 +69,11 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco private final TabHeader.Tab worldBackupsTab = new TabHeader.Tab<>("worldBackupsPage"); private final TabHeader.Tab datapackTab = new TabHeader.Tab<>("datapackListPage"); - public WorldManagePage(World world, Profile profile, String versionId) { + public WorldManagePage(World world, Profile profile, String instanceId) { this.world = world; - this.backupsDir = profile.getRepository().getBackupsDirectory(versionId); + this.backupsDir = profile.getRepository().getBackupsDirectory(instanceId); this.profile = profile; - this.versionId = versionId; + this.instanceId = instanceId; updateSessionLockChannel(); @@ -87,6 +90,9 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco this.state = new SimpleObjectProperty<>(new State(i18n("world.manage.title", StringUtils.parseColorEscapes(world.getWorldName())), null, true, true, true)); + Optional gameVersion = profile.getRepository().getGameVersion(instanceId); + supportQuickPlay = World.supportQuickPlay(GameVersionNumber.asGameVersion(gameVersion)); + this.addEventHandler(Navigator.NavigationEvent.EXITED, this::onExited); this.addEventHandler(Navigator.NavigationEvent.NAVIGATED, this::onNavigated); } @@ -144,11 +150,11 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco public void launch() { fireEvent(new PageCloseEvent()); - Versions.launchAndEnterWorld(profile, versionId, world.getFileName()); + Versions.launchAndEnterWorld(profile, instanceId, world.getFileName()); } public void generateLaunchScript() { - Versions.generateLaunchScriptForQuickEnterWorld(profile, versionId, world.getFileName()); + Versions.generateLaunchScriptForQuickEnterWorld(profile, instanceId, world.getFileName()); } @Override @@ -225,7 +231,7 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco AdvancedListBox toolbar = new AdvancedListBox(); BorderPane.setMargin(toolbar, new Insets(0, 0, 12, 0)); { - if (getSkinnable().world.supportQuickPlay()) { + if (getSkinnable().supportQuickPlay) { toolbar.addNavigationDrawerItem(i18n("version.launch"), SVG.ROCKET_LAUNCH, () -> getSkinnable().launch(), advancedListItem -> advancedListItem.disableProperty().bind(getSkinnable().readOnlyProperty())); } @@ -257,7 +263,7 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco PopupMenu managePopupMenu = new PopupMenu(); JFXPopup managePopup = new JFXPopup(managePopupMenu); - if (getSkinnable().world.supportQuickPlay()) { + if (getSkinnable().supportQuickPlay) { managePopupMenu.getContent().addAll( new IconedMenuItem(SVG.ROCKET_LAUNCH, i18n("version.launch"), () -> getSkinnable().launch(), managePopup), new IconedMenuItem(SVG.SCRIPT, i18n("version.launch_script"), () -> getSkinnable().generateLaunchScript(), managePopup),