fix: 修复快速启动按钮出现在不支持的版本的bug (#5461)

This commit is contained in:
mineDiamond
2026-02-08 20:45:57 +08:00
committed by GitHub
parent 9ea6a97aef
commit 10df7a862b
2 changed files with 31 additions and 13 deletions

View File

@@ -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<World> implements VersionP
private List<World> 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<World> implements VersionP
return;
}
Optional<String> 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<World> implements VersionP
return showAll;
}
public ReadOnlyBooleanProperty supportQuickPlayProperty() {
return supportQuickPlay;
}
private final class WorldListPageSkin extends ToolbarListPageSkin<World, WorldListPage> {
WorldListPageSkin() {
@@ -269,6 +279,8 @@ public final class WorldListPage extends ListPageBase<World> 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<World> 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<World> 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<World> 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()
);

View File

@@ -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> state;
@@ -66,11 +69,11 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco
private final TabHeader.Tab<WorldBackupsPage> worldBackupsTab = new TabHeader.Tab<>("worldBackupsPage");
private final TabHeader.Tab<DatapackListPage> 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<String> 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),