修复对话框关闭动画缺失的问题 (#3676)

This commit is contained in:
Glavo 2025-03-01 21:01:51 +08:00 committed by GitHub
parent 0c7046d764
commit 318da840f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 15 deletions

View File

@ -20,24 +20,28 @@ package org.jackhuang.hmcl.ui.construct;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
import java.util.Stack;
import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.logging.Logger.LOG;
public class StackContainerPane extends StackPane { public class JFXDialogPane extends StackPane {
private final Stack<Node> stack = new Stack<>(); private final ArrayList<Node> stack = new ArrayList<>();
public int size() {
return stack.size();
}
public Optional<Node> peek() { public Optional<Node> peek() {
if (stack.isEmpty()) { if (stack.isEmpty()) {
return Optional.empty(); return Optional.empty();
} else { } else {
return Optional.of(stack.peek()); return Optional.of(stack.get(stack.size() - 1));
} }
} }
public void push(Node node) { public void push(Node node) {
stack.push(node); stack.add(node);
getChildren().setAll(node); getChildren().setAll(node);
LOG.info(this + " " + stack); LOG.info(this + " " + stack);
@ -48,7 +52,7 @@ public class StackContainerPane extends StackPane {
if (stack.isEmpty()) if (stack.isEmpty())
getChildren().setAll(); getChildren().setAll();
else else
getChildren().setAll(stack.peek()); getChildren().setAll(stack.get(stack.size() - 1));
LOG.info(this + " " + stack + ", removed: " + flag + ", object: " + node); LOG.info(this + " " + stack + ", removed: " + flag + ", object: " + node);
} }

View File

@ -51,7 +51,7 @@ import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
import org.jackhuang.hmcl.ui.construct.DialogAware; import org.jackhuang.hmcl.ui.construct.DialogAware;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import org.jackhuang.hmcl.ui.construct.Navigator; import org.jackhuang.hmcl.ui.construct.Navigator;
import org.jackhuang.hmcl.ui.construct.StackContainerPane; import org.jackhuang.hmcl.ui.construct.JFXDialogPane;
import org.jackhuang.hmcl.ui.wizard.Refreshable; import org.jackhuang.hmcl.ui.wizard.Refreshable;
import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.ui.wizard.WizardProvider;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -82,7 +82,7 @@ public class DecoratorController {
private final Navigator navigator; private final Navigator navigator;
private JFXDialog dialog; private JFXDialog dialog;
private StackContainerPane dialogPane; private JFXDialogPane dialogPane;
public DecoratorController(Stage stage, Node mainPage) { public DecoratorController(Stage stage, Node mainPage) {
decorator = new Decorator(stage); decorator = new Decorator(stage);
@ -380,7 +380,7 @@ public class DecoratorController {
return; return;
} }
dialog = new JFXDialog(); dialog = new JFXDialog();
dialogPane = new StackContainerPane(); dialogPane = new JFXDialogPane();
dialog.setContent(dialogPane); dialog.setContent(dialogPane);
decorator.capableDraggingWindow(dialog); decorator.capableDraggingWindow(dialog);
@ -423,18 +423,21 @@ public class DecoratorController {
.ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler<DialogCloseEvent>) handler)); .ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler<DialogCloseEvent>) handler));
if (dialog != null) { if (dialog != null) {
dialogPane.pop(node); JFXDialogPane pane = dialogPane;
if (node instanceof DialogAware) { if (pane.size() == 1 && pane.peek().orElse(null) == node) {
((DialogAware) node).onDialogClosed(); dialog.setOnDialogClosed(e -> pane.pop(node));
}
if (dialogPane.getChildren().isEmpty()) {
dialog.close(); dialog.close();
dialog = null; dialog = null;
dialogPane = null; dialogPane = null;
navigator.setDisable(false); navigator.setDisable(false);
} else {
pane.pop(node);
}
if (node instanceof DialogAware) {
((DialogAware) node).onDialogClosed();
} }
} }
} }