修复下载安装整合包时启动器崩溃的问题 (#4813)
This commit is contained in:
@@ -23,13 +23,21 @@ import com.jfoenix.controls.events.JFXDialogEvent;
|
|||||||
import com.jfoenix.converters.DialogTransitionConverter;
|
import com.jfoenix.converters.DialogTransitionConverter;
|
||||||
import com.jfoenix.effects.JFXDepthManager;
|
import com.jfoenix.effects.JFXDepthManager;
|
||||||
import com.jfoenix.transitions.CachedTransition;
|
import com.jfoenix.transitions.CachedTransition;
|
||||||
import javafx.animation.*;
|
import javafx.animation.Interpolator;
|
||||||
|
import javafx.animation.KeyFrame;
|
||||||
|
import javafx.animation.KeyValue;
|
||||||
|
import javafx.animation.Timeline;
|
||||||
|
import javafx.animation.Transition;
|
||||||
import javafx.beans.DefaultProperty;
|
import javafx.beans.DefaultProperty;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.ObjectPropertyBase;
|
import javafx.beans.property.ObjectPropertyBase;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.css.*;
|
import javafx.css.CssMetaData;
|
||||||
|
import javafx.css.SimpleStyleableObjectProperty;
|
||||||
|
import javafx.css.Styleable;
|
||||||
|
import javafx.css.StyleableObjectProperty;
|
||||||
|
import javafx.css.StyleableProperty;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
@@ -39,7 +47,11 @@ import javafx.scene.SnapshotParameters;
|
|||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.image.WritableImage;
|
import javafx.scene.image.WritableImage;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.Background;
|
||||||
|
import javafx.scene.layout.BackgroundFill;
|
||||||
|
import javafx.scene.layout.CornerRadii;
|
||||||
|
import javafx.scene.layout.Region;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import org.jackhuang.hmcl.ui.animation.Motion;
|
import org.jackhuang.hmcl.ui.animation.Motion;
|
||||||
@@ -71,8 +83,7 @@ public class JFXDialog extends StackPane {
|
|||||||
|
|
||||||
private StackPane dialogContainer;
|
private StackPane dialogContainer;
|
||||||
private Region content;
|
private Region content;
|
||||||
private Transition showAnimation;
|
private Transition animation;
|
||||||
private Transition hideAnimation;
|
|
||||||
|
|
||||||
private final EventHandler<? super MouseEvent> closeHandler = e -> close();
|
private final EventHandler<? super MouseEvent> closeHandler = e -> close();
|
||||||
|
|
||||||
@@ -116,7 +127,6 @@ public class JFXDialog extends StackPane {
|
|||||||
/// - RIGHT
|
/// - RIGHT
|
||||||
/// - BOTTOM
|
/// - BOTTOM
|
||||||
/// - LEFT
|
/// - LEFT
|
||||||
///
|
|
||||||
public JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType, boolean overlayClose) {
|
public JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType, boolean overlayClose) {
|
||||||
setOverlayClose(overlayClose);
|
setOverlayClose(overlayClose);
|
||||||
initialize();
|
initialize();
|
||||||
@@ -141,8 +151,7 @@ public class JFXDialog extends StackPane {
|
|||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
|
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
|
||||||
this.transitionType.addListener((o, oldVal, newVal) -> {
|
this.transitionType.addListener((o, oldVal, newVal) -> {
|
||||||
showAnimation = getShowAnimation(transitionType.get());
|
animation = getShowAnimation(transitionType.get());
|
||||||
hideAnimation = getHideAnimation(transitionType.get());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
contentHolder = new StackPane();
|
contentHolder = new StackPane();
|
||||||
@@ -182,8 +191,7 @@ public class JFXDialog extends StackPane {
|
|||||||
// FIXME: need to be improved to consider only the parent boundary
|
// FIXME: need to be improved to consider only the parent boundary
|
||||||
offsetX = dialogContainer.getBoundsInLocal().getWidth();
|
offsetX = dialogContainer.getBoundsInLocal().getWidth();
|
||||||
offsetY = dialogContainer.getBoundsInLocal().getHeight();
|
offsetY = dialogContainer.getBoundsInLocal().getHeight();
|
||||||
showAnimation = getShowAnimation(transitionType.get());
|
animation = getShowAnimation(transitionType.get());
|
||||||
hideAnimation = getHideAnimation(transitionType.get());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,8 +281,8 @@ public class JFXDialog extends StackPane {
|
|||||||
dialogContainer.getChildren().add(this);
|
dialogContainer.getChildren().add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showAnimation != null) {
|
if (animation != null) {
|
||||||
showAnimation.play();
|
animation.play();
|
||||||
} else {
|
} else {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setOpacity(1);
|
setOpacity(1);
|
||||||
@@ -286,8 +294,12 @@ public class JFXDialog extends StackPane {
|
|||||||
* close the dialog
|
* close the dialog
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
if (hideAnimation != null) {
|
if (animation != null) {
|
||||||
hideAnimation.play();
|
animation.setRate(-2);
|
||||||
|
animation.play();
|
||||||
|
animation.setOnFinished(e -> {
|
||||||
|
closeDialog();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setOpacity(0);
|
setOpacity(0);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
@@ -336,20 +348,6 @@ public class JFXDialog extends StackPane {
|
|||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Transition getHideAnimation(DialogTransition transitionType) {
|
|
||||||
Transition animation = null;
|
|
||||||
if (contentHolder != null) {
|
|
||||||
animation = switch (transitionType) {
|
|
||||||
case CENTER -> new HideTransition();
|
|
||||||
case NONE -> null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (animation != null) {
|
|
||||||
animation.setOnFinished(finish -> closeDialog());
|
|
||||||
}
|
|
||||||
return animation;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetProperties() {
|
private void resetProperties() {
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
contentHolder.setTranslateX(0);
|
contentHolder.setTranslateX(0);
|
||||||
@@ -358,32 +356,6 @@ public class JFXDialog extends StackPane {
|
|||||||
contentHolder.setScaleY(1);
|
contentHolder.setScaleY(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class HideTransition extends CachedTransition {
|
|
||||||
private static final Interpolator INTERPOLATOR = Motion.EMPHASIZED_ACCELERATE;
|
|
||||||
|
|
||||||
public HideTransition() {
|
|
||||||
super(contentHolder, new Timeline(
|
|
||||||
new KeyFrame(Duration.ZERO,
|
|
||||||
new KeyValue(contentHolder.scaleXProperty(), 1, INTERPOLATOR),
|
|
||||||
new KeyValue(contentHolder.scaleYProperty(), 1, INTERPOLATOR),
|
|
||||||
new KeyValue(JFXDialog.this.opacityProperty(), 1, INTERPOLATOR),
|
|
||||||
new KeyValue(JFXDialog.this.visibleProperty(), true, Motion.LINEAR)
|
|
||||||
),
|
|
||||||
new KeyFrame(Motion.LONG2.subtract(Duration.millis(10)),
|
|
||||||
new KeyValue(JFXDialog.this.visibleProperty(), false, Motion.LINEAR),
|
|
||||||
new KeyValue(JFXDialog.this.opacityProperty(), 0, INTERPOLATOR)
|
|
||||||
),
|
|
||||||
new KeyFrame(Motion.LONG2,
|
|
||||||
new KeyValue(contentHolder.scaleXProperty(), INITIAL_SCALE, INTERPOLATOR),
|
|
||||||
new KeyValue(contentHolder.scaleYProperty(), INITIAL_SCALE, INTERPOLATOR)
|
|
||||||
))
|
|
||||||
);
|
|
||||||
// reduce the number to increase the shifting , increase number to reduce shifting
|
|
||||||
setCycleDuration(Duration.seconds(0.4));
|
|
||||||
setDelay(Duration.ZERO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class CenterTransition extends CachedTransition {
|
private final class CenterTransition extends CachedTransition {
|
||||||
private static final Interpolator INTERPOLATOR = Motion.EMPHASIZED_DECELERATE;
|
private static final Interpolator INTERPOLATOR = Motion.EMPHASIZED_DECELERATE;
|
||||||
|
|
||||||
@@ -401,6 +373,7 @@ public class JFXDialog extends StackPane {
|
|||||||
new KeyFrame(Motion.EXTRA_LONG4,
|
new KeyFrame(Motion.EXTRA_LONG4,
|
||||||
new KeyValue(contentHolder.scaleXProperty(), 1, INTERPOLATOR),
|
new KeyValue(contentHolder.scaleXProperty(), 1, INTERPOLATOR),
|
||||||
new KeyValue(contentHolder.scaleYProperty(), 1, INTERPOLATOR),
|
new KeyValue(contentHolder.scaleYProperty(), 1, INTERPOLATOR),
|
||||||
|
new KeyValue(JFXDialog.this.visibleProperty(), true, Motion.LINEAR),
|
||||||
new KeyValue(JFXDialog.this.opacityProperty(), 1, INTERPOLATOR)
|
new KeyValue(JFXDialog.this.opacityProperty(), 1, INTERPOLATOR)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
@@ -430,7 +403,6 @@ public class JFXDialog extends StackPane {
|
|||||||
/// - BOTTOM
|
/// - BOTTOM
|
||||||
/// - LEFT
|
/// - LEFT
|
||||||
/// - NONE
|
/// - NONE
|
||||||
///
|
|
||||||
private final StyleableObjectProperty<DialogTransition> transitionType = new SimpleStyleableObjectProperty<>(
|
private final StyleableObjectProperty<DialogTransition> transitionType = new SimpleStyleableObjectProperty<>(
|
||||||
StyleableProperties.DIALOG_TRANSITION,
|
StyleableProperties.DIALOG_TRANSITION,
|
||||||
JFXDialog.this,
|
JFXDialog.this,
|
||||||
@@ -526,8 +498,7 @@ public class JFXDialog extends StackPane {
|
|||||||
return onDialogClosedProperty().get();
|
return onDialogClosedProperty().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ObjectProperty<EventHandler<? super JFXDialogEvent>> onDialogOpenedProperty = new ObjectPropertyBase<>() {
|
||||||
private final ObjectProperty<EventHandler<? super JFXDialogEvent>> onDialogOpenedProperty = new ObjectPropertyBase<EventHandler<? super JFXDialogEvent>>() {
|
|
||||||
@Override
|
@Override
|
||||||
protected void invalidated() {
|
protected void invalidated() {
|
||||||
setEventHandler(JFXDialogEvent.OPENED, get());
|
setEventHandler(JFXDialogEvent.OPENED, get());
|
||||||
|
|||||||
Reference in New Issue
Block a user