From 77f87b1a546f6287b4c4e3d5a6d4373d0bae8d22 Mon Sep 17 00:00:00 2001 From: lzw-723 Date: Thu, 23 Mar 2023 15:01:00 +0800 Subject: [PATCH] support skip boot animation --- .../fxtools/ui/InitialLoadingPane.java | 77 ++++++++++--------- .../uicontroller/SettingsPageController.java | 5 ++ .../leewyatt/fxtools/utils/ToolSettings.java | 17 ++++ .../fxtools/utils/ToolSettingsUtil.java | 16 ++++ src/main/resources/fxml/settings-page.fxml | 1 + .../resources/language/language.properties | 3 +- .../resources/language/language_zh.properties | 3 +- 7 files changed, 84 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/leewyatt/fxtools/ui/InitialLoadingPane.java b/src/main/java/com/leewyatt/fxtools/ui/InitialLoadingPane.java index d3a1e07..f8d31b1 100644 --- a/src/main/java/com/leewyatt/fxtools/ui/InitialLoadingPane.java +++ b/src/main/java/com/leewyatt/fxtools/ui/InitialLoadingPane.java @@ -2,6 +2,8 @@ import com.leewyatt.fxtools.event.AnimFinishedEvent; import com.leewyatt.fxtools.event.EventBusUtil; +import com.leewyatt.fxtools.utils.ToolSettingsUtil; + import javafx.animation.*; import javafx.scene.Node; import javafx.scene.effect.DropShadow; @@ -29,7 +31,8 @@ public InitialLoadingPane(String skinStyle) { SVGPath icon = new SVGPath(); icon.setScaleX(2); icon.setScaleY(2); - icon.setContent("M10.3,7.3L8.2,5.2l0,0L7.8,4.5L7,3.9L6.1,4.8l0.6,0.8L7.4,6l0,0l2.1,2.1L9.2,8.4l1.4,1.4 c0.3,0.3,0.7,0.3,1,0L12,9.5c0.3-0.3,0.3-0.7,0-1l-1.4-1.4C10.6,7,10.3,7.3,10.3,7.3zM11.8,6.3c0.5-0.5,0.5-1.2,0.3-1.7l-0.9,1L10.6,5l0.9-1C11,3.7,10.3,3.8,9.8,4.3C9.4,4.6,9.2,5.2,9.4,5.7 L6.2,8.8C6.1,9,6.1,9.3,6.2,9.5l0,0l0.4,0.3c0.2,0.2,0.5,0.2,0.7,0l3.2-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10.3,0.3,2.7,0.3,2.7,0.3z"); icon.setFill(new LinearGradient( 0.0, 0.0, 1.0, 0.0, true, CycleMethod.NO_CYCLE, new Stop(0.0, new Color(0.11, 0.52, 0.93, 1.0)), @@ -37,58 +40,61 @@ public InitialLoadingPane(String skinStyle) { StackPane iconPane = new StackPane(icon); iconPane.setPrefSize(radius, radius); - iconPane.setStyle("-fx-background-color: "+("light".equalsIgnoreCase(skinStyle)?"white":"#2b2b2b")+";-fx-background-radius: "+radius/2.0+"px"); + iconPane.setStyle("-fx-background-color: " + ("light".equalsIgnoreCase(skinStyle) ? "white" : "#2b2b2b") + + ";-fx-background-radius: " + radius / 2.0 + "px"); iconPane.setEffect(new DropShadow()); - iconPane.setLayoutX((w-radius)/2.0); - iconPane.setLayoutY((h-radius)/2.0); + iconPane.setLayoutX((w - radius) / 2.0); + iconPane.setLayoutY((h - radius) / 2.0); getChildren().add(iconPane); iconPane.setOpacity(0.2); - //Color Animation 颜色动画, 暂时没有搭配得非常满意的颜色 - //DoubleProperty dp = new SimpleDoubleProperty(0.001); - //Timeline colorAnim = new Timeline(new KeyFrame(Duration.seconds(1.2),new KeyValue(dp, 0.98))); - //Random random = new Random(); - //int choose = random.nextInt(2); - //Color c1; - //Color c2; - //Color c3; - //if (choose == 0) { - // c1 = new Color(0.11, 0.52, 0.93, 1.0); - // c2= new Color(0.0549, 0.9294, 0.6353, 1.0); - // c3 = new Color(0.68, 0.05, 0.93, 1.0); - //}else { - // c1 = new Color(0.9735, 0.0, 0.99, 1.0); - // c2 = new Color(0.209, 0.5178, 0.95, 1.0); - // c3 = new Color(0.0174, 0.87, 0.87, 1.0); - //} + // Color Animation 颜色动画, 暂时没有搭配得非常满意的颜色 + // DoubleProperty dp = new SimpleDoubleProperty(0.001); + // Timeline colorAnim = new Timeline(new KeyFrame(Duration.seconds(1.2),new + // KeyValue(dp, 0.98))); + // Random random = new Random(); + // int choose = random.nextInt(2); + // Color c1; + // Color c2; + // Color c3; + // if (choose == 0) { + // c1 = new Color(0.11, 0.52, 0.93, 1.0); + // c2= new Color(0.0549, 0.9294, 0.6353, 1.0); + // c3 = new Color(0.68, 0.05, 0.93, 1.0); + // }else { + // c1 = new Color(0.9735, 0.0, 0.99, 1.0); + // c2 = new Color(0.209, 0.5178, 0.95, 1.0); + // c3 = new Color(0.0174, 0.87, 0.87, 1.0); + // } // - //dp.addListener((observable, oldValue, newValue) -> { - // LinearGradient p = new LinearGradient( - // 0.0, 0.0, 1.0, 1.0, true, CycleMethod.NO_CYCLE, - // new Stop(0.0, c1), - // new Stop(newValue.doubleValue(), c2), - // new Stop(1.0, c3)); - // icon.setFill(p); - //}); + // dp.addListener((observable, oldValue, newValue) -> { + // LinearGradient p = new LinearGradient( + // 0.0, 0.0, 1.0, 1.0, true, CycleMethod.NO_CYCLE, + // new Stop(0.0, c1), + // new Stop(newValue.doubleValue(), c2), + // new Stop(1.0, c3)); + // icon.setFill(p); + // }); Circle circle = new Circle(70); FadeTransition fadeTransition = new FadeTransition(Duration.seconds(1.5), iconPane); fadeTransition.setFromValue(0.2); fadeTransition.setToValue(1.0); - PathTransition pathTransition = new PathTransition(Duration.seconds(2), circle,iconPane); + PathTransition pathTransition = new PathTransition(Duration.seconds(2), circle, iconPane); ScaleTransition scaleTransition = scaleTransition(1.2, iconPane, 2, 2); - //ParallelTransition pt = new ParallelTransition(scaleTransition,colorAnim); - SequentialTransition animation = new SequentialTransition(fadeTransition,pathTransition,scaleTransition); + // ParallelTransition pt = new ParallelTransition(scaleTransition,colorAnim); + SequentialTransition animation = new SequentialTransition(fadeTransition, pathTransition, scaleTransition); animation.setInterpolator(Interpolator.EASE_IN); animation.setOnFinished(event -> { EventBusUtil.getDefault().post(new AnimFinishedEvent()); }); + // 加速跳过 + if (ToolSettingsUtil.getInstance().getSKipBootAnimation()) { + animation.setRate(10); + } animation.play(); - } - - public ScaleTransition scaleTransition(double duration, Node node, double byX, double byY) { ScaleTransition scaleTransition = new ScaleTransition(Duration.seconds(duration), node); scaleTransition.setByX(byX); @@ -96,5 +102,4 @@ public ScaleTransition scaleTransition(double duration, Node node, double byX, d return scaleTransition; } - } diff --git a/src/main/java/com/leewyatt/fxtools/uicontroller/SettingsPageController.java b/src/main/java/com/leewyatt/fxtools/uicontroller/SettingsPageController.java index b8a4d3e..3a33dd5 100644 --- a/src/main/java/com/leewyatt/fxtools/uicontroller/SettingsPageController.java +++ b/src/main/java/com/leewyatt/fxtools/uicontroller/SettingsPageController.java @@ -54,6 +54,9 @@ public class SettingsPageController { @FXML private CheckBox updateNotifyCheckBox; + @FXML + private CheckBox skipBootAnimationCheckbox; + public SettingsPageController() { EventBusUtil.getDefault().register(this); } @@ -96,6 +99,7 @@ void initialize() { threadField.setText(i+""); } }); + skipBootAnimationCheckbox.selectedProperty().addListener((ob, ov, nv) -> util.saveSkipBootAnimation(nv)); } private void showSettingsOnUI() { @@ -110,6 +114,7 @@ private void showSettingsOnUI() { showPreviewImageCheckbox.setSelected(util.getGeneratePreviewImg()); parseImageSizeCheckbox.setSelected(util.getParseImageSize()); threadField.setText(util.getThreadNum() + ""); + skipBootAnimationCheckbox.setSelected(util.getSKipBootAnimation()); } } diff --git a/src/main/java/com/leewyatt/fxtools/utils/ToolSettings.java b/src/main/java/com/leewyatt/fxtools/utils/ToolSettings.java index 3bf5459..c06e526 100644 --- a/src/main/java/com/leewyatt/fxtools/utils/ToolSettings.java +++ b/src/main/java/com/leewyatt/fxtools/utils/ToolSettings.java @@ -32,6 +32,8 @@ public class ToolSettings { public static final boolean DEFAULT_UPDATE_NOTIFY = true; + public static final boolean DEFAULT_SKIP_BOOT_ANIMATION = false; + /** * 默认皮肤 */ @@ -98,6 +100,13 @@ public class ToolSettings { private boolean updateNotify; + /** + * 是否跳过启动动画 + * true 跳过 + * false 不跳过 + */ + private boolean skipBootAnimation; + public ToolSettings() { } @@ -209,4 +218,12 @@ public boolean isUpdateNotify() { public void setUpdateNotify(boolean updateNotify) { this.updateNotify = updateNotify; } + + public boolean isSkipBootAnimation() { + return skipBootAnimation; + } + + public void setSkipBootAnimation(boolean skipBootAnimation) { + this.skipBootAnimation = skipBootAnimation; + } } diff --git a/src/main/java/com/leewyatt/fxtools/utils/ToolSettingsUtil.java b/src/main/java/com/leewyatt/fxtools/utils/ToolSettingsUtil.java index 155d1ab..6e3922c 100644 --- a/src/main/java/com/leewyatt/fxtools/utils/ToolSettingsUtil.java +++ b/src/main/java/com/leewyatt/fxtools/utils/ToolSettingsUtil.java @@ -46,6 +46,7 @@ private ToolSettingsUtil() { settings.setAutoSwitch(Boolean.parseBoolean(props.getProperty("autoSwitch", defaultSettings.isAutoSwitch() + ""))); settings.setAlwaysTop(Boolean.parseBoolean(props.getProperty("alwaysTop", defaultSettings.isAlwaysTop() + ""))); settings.setUpdateNotify(Boolean.parseBoolean(props.getProperty("updateNotify", defaultSettings.isUpdateNotify() + ""))); + settings.setSkipBootAnimation(Boolean.parseBoolean(props.getProperty("skipBootAnimation", defaultSettings.isSkipBootAnimation() + ""))); reader.close(); } } catch (IOException e) { @@ -70,6 +71,7 @@ private void initDefaultSettings() { defaultSettings.setAutoSwitch(ToolSettings.DEFAULT_AUTO_SWITCH); defaultSettings.setAlwaysTop(ToolSettings.DEFAULT_ALWAYS_TOP); defaultSettings.setUpdateNotify(ToolSettings.DEFAULT_UPDATE_NOTIFY); + defaultSettings.setSkipBootAnimation(ToolSettings.DEFAULT_SKIP_BOOT_ANIMATION); } public static ToolSettingsUtil getInstance() { @@ -94,6 +96,7 @@ public void saveSettings(ToolSettings newSettings) { settings.setAutoSwitch(newSettings.isAutoSwitch()); settings.setAlwaysTop(newSettings.isAlwaysTop()); settings.setUpdateNotify(newSettings.isUpdateNotify()); + settings.setSkipBootAnimation(newSettings.isSkipBootAnimation()); saveSettings(); } @@ -112,6 +115,7 @@ public void saveSettings() { props.setProperty("autoSwitch", settings.isAutoSwitch() + ""); props.setProperty("alwaysTop", settings.isAlwaysTop() + ""); props.setProperty("updateNotify",settings.isUpdateNotify()+""); + props.setProperty("skipBootAnimation",settings.isSkipBootAnimation()+""); try { FileWriter writer = new FileWriter(propertiesFile); props.store(writer, "Change settings"); @@ -313,5 +317,17 @@ public void saveUpdateNotify(boolean notify) { settings.setUpdateNotify(notify); saveSettings(); } + /* + * *************** + * 启动时是否跳过动画 + * *************** + */ + public boolean getSKipBootAnimation() { + return settings.isSkipBootAnimation(); + } + public void saveSkipBootAnimation(boolean skipBootAnimation) { + settings.setSkipBootAnimation(skipBootAnimation);; + saveSettings(); + } } \ No newline at end of file diff --git a/src/main/resources/fxml/settings-page.fxml b/src/main/resources/fxml/settings-page.fxml index dee14fd..23bd947 100644 --- a/src/main/resources/fxml/settings-page.fxml +++ b/src/main/resources/fxml/settings-page.fxml @@ -38,6 +38,7 @@ + diff --git a/src/main/resources/language/language.properties b/src/main/resources/language/language.properties index d9552bc..614e334 100644 --- a/src/main/resources/language/language.properties +++ b/src/main/resources/language/language.properties @@ -197,4 +197,5 @@ icon.allSize=All Size icon.only512=Only 512x512 carousel=Carousel carousel.autoSwitch=Auto Switch -colorPickerTips=Click to copy color \ No newline at end of file +colorPickerTips=Click to copy color +skipBootAnimation=Skip boot animation \ No newline at end of file diff --git a/src/main/resources/language/language_zh.properties b/src/main/resources/language/language_zh.properties index 165b14b..b9428ba 100644 --- a/src/main/resources/language/language_zh.properties +++ b/src/main/resources/language/language_zh.properties @@ -197,4 +197,5 @@ icon.allSize=\u591A\u79CD\u5C3A\u5BF8(\u591A\u56FE) icon.only512=512x512(\u4E00\u56FE) carousel=\u8F6E\u64AD\u56FE carousel.autoSwitch=\u81EA\u52A8\u5207\u6362 -colorPickerTips=\u70B9\u51FB\u590D\u5236\u989C\u8272 \ No newline at end of file +colorPickerTips=\u70B9\u51FB\u590D\u5236\u989C\u8272 +skipBootAnimation=\u8df3\u8fc7\u542f\u52a8\u52a8\u753b \ No newline at end of file