修改启动页

master
zhangmeng 2023-03-21 11:18:31 +08:00
parent e678cb9294
commit 3ce02ad0da
3 changed files with 205 additions and 32 deletions

View File

@ -2,19 +2,32 @@ package com.zhangmeng.tools.views;
import com.zhangmeng.tools.utils.ImagePath;
import com.zhangmeng.tools.utils.ResourcesUtils;
import javafx.animation.*;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
/**
* @author :
* @version : 1.0
@ -25,12 +38,22 @@ public class LoadView extends Application {
public Label load_info_show;
@Override
public void start(Stage primaryStage) throws Exception {
private ScheduledService<Double> service;
AnchorPane fx = FXMLLoader.load(ResourcesUtils.getResource("load-start"));
private ProgressBar progressBar;
private Stage primaryStage;
private List<ParallelTransition> list = new ArrayList<>();
@Override
public void start(Stage stage) throws Exception {
primaryStage = stage;
AnchorPane fx = FXMLLoader.load(ResourcesUtils.getResource("load-start"));
ImageView bg_iv = (ImageView) fx.lookup("#bg_iv");
load_info_show = (Label) fx.lookup("#load_info_show");
progressBar = (ProgressBar) fx.lookup("#progressBar");
progressBar.setStyle("-fx-accent: #45c256");
Scene scene = new Scene(fx);
Image image = new Image(ImagePath.path(ImagePath.ImagePathType.Tools_ICON));
@ -42,38 +65,186 @@ public class LoadView extends Application {
primaryStage.setFullScreenExitHint("");
primaryStage.show();
// 核心代码
new Thread(() -> {
initSystem();// 1
Platform.runLater(() -> {// 2
try {
log.info("加载页面....");
HomeView home = new HomeView();
home.start(new Stage());
primaryStage.close();
} catch (Throwable e) {
e.printStackTrace();// 3
Node flowView = getFlowView(100, (int) scene.getWidth(), (int) scene.getHeight(), 2500);
fx.getChildren().add(flowView);
progressBar.progressProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (newValue != null) {
try {
if (newValue.doubleValue() >= 1) {
Thread.sleep(1500);
load_home();
} else {
if (newValue.doubleValue() == 0.1) {
showInfo("初始化目录...");
}
if (newValue.doubleValue() == 0.4) {
showInfo("初始化系统配置...");
}
if (newValue.doubleValue() >= 0.8) {
showInfo("版本检测...");
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}).start();
}
});
service = new ScheduledService<Double>() {
double i = 0;
@Override
protected Task<Double> createTask() {
return new Task<Double>() {
@Override
protected Double call() throws Exception {
return i = i + 0.1;
}
@Override
protected void updateValue(Double value) {
// try {
// if (value == 0.1){
// Thread.sleep(1500);
// }
//
// if (value == 0.4){
// Thread.sleep(1500);
// }
//
// if (value == 0.9){
// Thread.sleep(1500);
// }
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
progressBar.setProgress(value);
if (value >= 1) {
service.cancel();
}
}
};
}
};
service.setDelay(Duration.millis(0));
service.setPeriod(Duration.millis(500));
service.start();
}
// 初始化系统
private void initSystem() {
try {
showInfo("初始化目录...");
Thread.sleep(1500);
showInfo("初始化系统配置...");
Thread.sleep(1500);
showInfo("版本检测...");
Thread.sleep(1500);
} catch (Throwable e) {
e.printStackTrace();
}
public void load_home() {
Platform.runLater(() -> {// 2
try {
log.info("加载页面....");
HomeView home = new HomeView();
home.start(new Stage());
primaryStage.close();
} catch (Throwable e) {
e.printStackTrace();// 3
}
});
}
// 显示信息
public void showInfo(String info) {
public void showInfo(String info) {
Platform.runLater(() -> load_info_show.setText(info));
}
private Node getFlowView(int number, int w , int h , int z){
Random random = new Random();
List<ImageView> image_list = new ArrayList<>();
int location_x = 0 ;
int location_y = 0 ;
int location_z = 0 ;
for (int i = 0; i < number; i++) {
ImageView iv = new ImageView("image/雪花 (4).png");
iv.setFitWidth(50);
iv.setPreserveRatio(true);
if (random.nextBoolean()){
location_x = random.nextInt(w) + random.nextInt(300) + 300 ;
}else {
location_x = random.nextInt(w) - random.nextInt(300) - 300 ;
}
location_y = random.nextInt(20);
location_z = random.nextInt(z);
iv.setTranslateX(location_x);
iv.setTranslateY(location_y);
iv.setTranslateZ(location_z);
iv.setOpacity(0);
image_list.add(iv);
}
AnchorPane ap = new AnchorPane();
ap.setStyle("-fx-background-color: #FFB6C100");
ap.getChildren().addAll(image_list);
SubScene subScene = new SubScene(ap, w, h, true, SceneAntialiasing.BALANCED);
PerspectiveCamera camera = new PerspectiveCamera();
subScene.setCamera(camera);
image_list.forEach(new Consumer<ImageView>() {
@Override
public void accept(ImageView imageView) {
double time = random.nextDouble() * 10 + 5 ;
TranslateTransition tt = new TranslateTransition(Duration.seconds(time));
// tt.setNode(imageView);
tt.setFromX(imageView.getTranslateX());
tt.setFromY(imageView.getTranslateY());
// tt.setToX( imageView.getTranslateX() + 400);
// tt.setToY(imageView.getTranslateY() + 1300);
// tt.play();
tt.setByX(400);
tt.setByY(1300);
RotateTransition rt = new RotateTransition(Duration.seconds(time));
rt.setFromAngle(0);
rt.setToAngle(360);
FadeTransition ft1 = new FadeTransition(Duration.seconds(time / 2 + 2));
ft1.setFromValue(0);
ft1.setToValue(1);
FadeTransition ft2 = new FadeTransition(Duration.seconds(3));
ft2.setFromValue(1);
ft2.setToValue(0);
SequentialTransition st = new SequentialTransition();
st.getChildren().addAll(ft1,ft2);
ParallelTransition pt = new ParallelTransition();
pt.setNode(imageView);
pt.getChildren().addAll(tt,rt,st);
pt.setCycleCount(Animation.INDEFINITE);
pt.play();
list.add(pt);
}
});
return subScene;
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
@ -8,15 +9,16 @@
<AnchorPane prefHeight="649.0" prefWidth="1156.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.LoadStartController">
<children>
<ImageView fx:id="bg_iv" id="bg_iv" fitHeight="649.0" fitWidth="1156.0" layoutX="1.0" pickOnBounds="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<ImageView id="bg_iv" fx:id="bg_iv" fitHeight="649.0" fitWidth="1156.0" layoutX="1.0" pickOnBounds="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<image>
<Image url="@../static/bgimg/2041075.jpg" />
</image>
</ImageView>
<Label fx:id="load_info_show" layoutX="1082.0" layoutY="618.0" text="加载中......" textFill="#26852f" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="43.0">
<Label id="load_info_show" fx:id="load_info_show" layoutX="1052.0" layoutY="595.0" text="加载中......" textFill="#26852f" AnchorPane.bottomAnchor="30.0" AnchorPane.rightAnchor="24.0">
<font>
<Font size="18.0" />
</font>
</Label>
<ProgressBar id="progressBar" layoutY="646.0" prefHeight="10.0" prefWidth="1156.0" progress="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB