From 8eec18450eb5fe5eae6fd2db50f655b8a099a3d8 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 9 Aug 2026 21:41:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=8D=E6=AC=A1=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=AE=9E=E4=BE=8B=E8=8F=9C=E5=8D=95=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=97=B6=E8=8F=9C=E5=8D=95=E9=87=8D=E6=96=B0=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#6633)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/instances/GameListPopupMenu.java | 17 ++++++++++++++++- .../org/jackhuang/hmcl/ui/main/MainPage.java | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/GameListPopupMenu.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/GameListPopupMenu.java index b95dd77da7..54c8d09ec0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/GameListPopupMenu.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/GameListPopupMenu.java @@ -33,6 +33,7 @@ import javafx.scene.control.ListView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; +import javafx.stage.WindowEvent; import org.jackhuang.hmcl.game.GameInstanceID; import org.jackhuang.hmcl.game.GameInstanceManifest; import org.jackhuang.hmcl.game.HMCLGameRepository; @@ -49,6 +50,18 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; /// @author Glavo public final class GameListPopupMenu extends StackPane { + private static final String KEY = GameListPopupMenu.class.getName() + ".popup"; + + public static boolean hideShowing(Node owner) { + JFXPopup popup = (JFXPopup) owner.getProperties().get(KEY); + if (popup != null && popup.isShowing()) { + popup.hide(); + return true; + } else { + return false; + } + } + /// Shows an instance selection popup relative to its owner. public static void show(Node owner, JFXPopup.PopupVPosition vAlign, JFXPopup.PopupHPosition hAlign, double initOffsetX, double initOffsetY, @@ -66,7 +79,9 @@ public final class GameListPopupMenu extends StackPane { .map(it -> new GameItem(repository, it.id())) .toList()); JFXPopup popup = new JFXPopup(menu); - popup.show(owner, vAlign, hAlign, initOffsetX, initOffsetY); + owner.getProperties().put(KEY, popup); + popup.addEventFilter(WindowEvent.WINDOW_HIDDEN, event -> owner.getProperties().remove(KEY, popup)); + popup.show(owner, vAlign, hAlign, initOffsetX, initOffsetY, true); return popup; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java index 72d5aff371..72cc6dea4b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java @@ -259,6 +259,10 @@ public final class MainPage extends StackPane implements DecoratorPage { menuButton = new JFXButton(); menuButton.getStyleClass().add("menu-button"); menuButton.setOnAction(e -> { + if (GameListPopupMenu.hideShowing(menuButton)) { + return; + } + JFXPopup popup = GameListPopupMenu.showAndGetPopup( menuButton, JFXPopup.PopupVPosition.BOTTOM,