From f48b8c837db34878b1ce500dc1f3dd0cf162a97c Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 1 Oct 2024 23:55:55 -0400 Subject: Improve Splash screen --- src/main/java/net/sowgro/npehero/Driver.java | 134 +++++++++++++-------- .../java/net/sowgro/npehero/levelapi/Levels.java | 16 +++ src/main/resources/net/sowgro/npehero/style.css | 9 +- 3 files changed, 111 insertions(+), 48 deletions(-) diff --git a/src/main/java/net/sowgro/npehero/Driver.java b/src/main/java/net/sowgro/npehero/Driver.java index 8725a5a..bd87a8b 100755 --- a/src/main/java/net/sowgro/npehero/Driver.java +++ b/src/main/java/net/sowgro/npehero/Driver.java @@ -2,20 +2,13 @@ package net.sowgro.npehero; import javafx.animation.*; import javafx.application.Application; -import javafx.beans.property.ReadOnlyObjectProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.concurrent.Task; -import javafx.concurrent.Worker; import javafx.geometry.Insets; import javafx.geometry.Pos; -import javafx.geometry.Rectangle2D; import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.scene.control.ListView; import javafx.scene.control.ProgressBar; import javafx.scene.control.ScrollPane; -import javafx.scene.effect.DropShadow; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; @@ -24,7 +17,7 @@ import javafx.scene.input.KeyEvent; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.text.Text; -import javafx.stage.Screen; +import javafx.scene.text.TextBoundsType; import javafx.stage.Stage; import javafx.stage.StageStyle; import javafx.util.Duration; @@ -64,13 +57,45 @@ public class Driver extends Application */ @Override public void start(Stage initStage) { - Label npehero = new Label("NPEHero"); - Label loading = new Label("Please Wait... "); - VBox splashBox = new VBox(npehero, loading); + // from main menu + Text npehero = new Text(); + npehero.setFill(Color.WHITE); + npehero.setBoundsType(TextBoundsType.VISUAL); + npehero.setText("NPE INC"); + npehero.getStyleClass().add("t0"); + + Text lessthan = new Text("<"); + lessthan.setBoundsType(TextBoundsType.VISUAL); + lessthan.getStyleClass().add("t0e"); + + Text greaterthan = new Text(">"); + greaterthan.setBoundsType(TextBoundsType.VISUAL); + greaterthan.getStyleClass().add("t0e"); + HBox title = new HBox(lessthan, npehero, greaterthan); + title.setSpacing(20); + title.setAlignment(Pos.CENTER); + // end from main menu + + ProgressBar progressBar = new ProgressBar(); + progressBar.prefWidthProperty().bind(title.widthProperty()); + progressBar.setMaxHeight(12); +// progressBar + +// Label npehero = new Label("NPEHero"); + Label loading = new Label("Loading NPEHero..."); + VBox splashBox = new VBox(title, loading, progressBar); splashBox.setPadding(new Insets(30)); + splashBox.getStyleClass().add("box"); + splashBox.setAlignment(Pos.CENTER); + splashBox.setSpacing(10); +// Rectangle background = new Rectangle(); +// background.setStrokeWidth(4); Scene splashScene = new Scene(splashBox); + splashBox.setBackground(null); + splashScene.getStylesheets().add(getClass().getResource("style.css").toExternalForm()); + splashScene.setFill(Color.TRANSPARENT); initStage.setScene(splashScene); - initStage.initStyle(StageStyle.UNDECORATED); + initStage.initStyle(StageStyle.TRANSPARENT); initStage.show(); Stack errors = new Stack<>(); @@ -108,7 +133,7 @@ public class Driver extends Application System.out.println("Loading levels..."); this.updateMessage("Loading levels..."); try { - Levels.readData(); + Levels.readData(this::updateMessage, this::updateProgress); System.out.println("Loaded " + Levels.list.size() + " levels (" + Levels.getValidList().size() + " valid)"); } catch (IOException e) { errors.push("Failed to load levels\n"); @@ -118,56 +143,64 @@ public class Driver extends Application }; task.setOnSucceeded(_ -> { - initStage.close(); + loading.textProperty().unbind(); + loading.setText("Launching..."); - Page last = new MainMenu(); - while (!errors.empty()) { - last = new ErrorDisplay(errors.pop(), last); - } - Driver.setMenu(last); + scheduleDelayedTask(Duration.seconds(0.1), () -> { + initStage.close(); + Page last = new MainMenu(); + while (!errors.empty()) { + last = new ErrorDisplay(errors.pop(), last); + } + Driver.setMenu(last); - primaryStage = new Stage(); + primaryStage = new Stage(); - primaryPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + primaryPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); - StackPane root = new StackPane(backgroundImage2, backgroundImage, primaryPane); - Scene primaryScene = new Scene(root, 800,600); + StackPane root = new StackPane(backgroundImage2, backgroundImage, primaryPane); + Scene primaryScene = new Scene(root, 800,600); - primaryPane.scaleXProperty().bind(Settings.guiScale); - primaryPane.scaleYProperty().bind(Settings.guiScale); - primaryPane.minHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); - primaryPane.minWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); - primaryPane.maxHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); - primaryPane.maxWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); + primaryPane.scaleXProperty().bind(Settings.guiScale); + primaryPane.scaleYProperty().bind(Settings.guiScale); + primaryPane.minHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); + primaryPane.minWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); + primaryPane.maxHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); + primaryPane.maxWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); // Cant figure out how to center this - backgroundImage.fitHeightProperty().bind(primaryScene.heightProperty()); - backgroundImage2.fitHeightProperty().bind(primaryScene.heightProperty()); - backgroundImage.setPreserveRatio(true); - backgroundImage2.setPreserveRatio(true); + backgroundImage.fitHeightProperty().bind(primaryScene.heightProperty()); + backgroundImage2.fitHeightProperty().bind(primaryScene.heightProperty()); + backgroundImage.setPreserveRatio(true); + backgroundImage2.setPreserveRatio(true); - primaryScene.getStylesheets().add(getClass().getResource("style.css").toExternalForm()); + primaryScene.getStylesheets().add(getClass().getResource("style.css").toExternalForm()); - primaryStage.setScene(primaryScene); - primaryStage.setTitle("NPE Hero"); + primaryStage.setScene(primaryScene); + primaryStage.setTitle("NPE Hero"); - primaryPane.getStyleClass().remove("scroll-pane"); + primaryPane.getStyleClass().remove("scroll-pane"); - setMenuBackground(); + setMenuBackground(); - Sound.playSong(Sound.MENU_SONG); + Sound.playSong(Sound.MENU_SONG); - primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> { //full screen stuff - if (KeyCode.F11.equals(event.getCode())) { - primaryStage.setFullScreen(!primaryStage.isFullScreen()); - } + primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> { //full screen stuff + if (KeyCode.F11.equals(event.getCode())) { + primaryStage.setFullScreen(!primaryStage.isFullScreen()); + } + }); + primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); + primaryStage.setFullScreenExitHint(""); + primaryStage.show(); + scheduleDelayedTask(Duration.millis(1), () -> { + primaryStage.setFullScreen(true); + }); }); - primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); - primaryStage.setFullScreenExitHint(""); - primaryStage.show(); }); - loading.textProperty().bind(task.messageProperty()); +// loading.textProperty().bind(task.messageProperty()); + progressBar.progressProperty().bind(task.progressProperty()); new Thread(task).start(); } @@ -234,4 +267,11 @@ public class Driver extends Application public static URL getResource(String fileName) { return Driver.class.getResource(fileName); } + + public void scheduleDelayedTask(Duration d, Runnable r) { + PauseTransition pt = new PauseTransition(); + pt.setDuration(d); + pt.setOnFinished(_ -> r.run()); + pt.play(); + } } diff --git a/src/main/java/net/sowgro/npehero/levelapi/Levels.java b/src/main/java/net/sowgro/npehero/levelapi/Levels.java index f4cdc1d..7a89ed1 100755 --- a/src/main/java/net/sowgro/npehero/levelapi/Levels.java +++ b/src/main/java/net/sowgro/npehero/levelapi/Levels.java @@ -18,6 +18,14 @@ import net.sowgro.npehero.Driver; */ public class Levels { + public interface MessageUpdaterLambda { + void updateMessage(String message); + } + + public interface ProgressUpdaterLambda { + void updateProgress(double workDone, double progress); + } + public static final ObservableList list = FXCollections.observableArrayList(); public static final HashMap problems = new HashMap<>(); @@ -31,18 +39,26 @@ public class Levels { * @throws IOException If there is a problem reading in the levels. */ public static void readData() throws IOException { + readData(_ -> {}, (_, _) -> {}); + } + public static void readData(MessageUpdaterLambda mu, ProgressUpdaterLambda pu) throws IOException { list.clear(); File[] fileList = dir.listFiles(); if (fileList == null) { throw new FileNotFoundException(); } + int i = 0; + int max = fileList.length; for (File file: fileList) { try { Level level = new Level(file); list.add(level); + i++; + mu.updateMessage("Loaded " + i + " Levels"); } catch (Exception e) { problems.put("Failed to load load level in folder '" + file.getName() + "'", e); } + pu.updateProgress(i, max); } list.sort(Comparator.naturalOrder()); } diff --git a/src/main/resources/net/sowgro/npehero/style.css b/src/main/resources/net/sowgro/npehero/style.css index 0697632..2897092 100755 --- a/src/main/resources/net/sowgro/npehero/style.css +++ b/src/main/resources/net/sowgro/npehero/style.css @@ -203,7 +203,7 @@ Slider:focused .thumb{ .t0 { -fx-font-size: 100; - -fx-fill: black; + /*-fx-fill: black;*/ } .t0e { @@ -275,3 +275,10 @@ CheckBox:selected > .box { -fx-underline: true; } +.progress-bar { + -fx-background-color: transparent; + -fx-fill: white; + -fx-padding: 0; + -fx-accent: white +} + -- cgit v1.2.3