diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java index 240ff559faba03d0a3bb21c1529cbd3466495087..e828c1eb2c84e89245f9a894c22589c966a4e940 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java @@ -40,7 +40,7 @@ public class IntroController implements Initializable { introParent.setStyle("-fx-background-color: black;"); introParent.setCursor(Cursor.NONE); createMediaPlayer(); - new StartupThread().run(); + new StartupThread().start(); } private void createMediaPlayer() { diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/LoadingScreenController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/LoadingScreenController.java index df510df0dc69624ce519434ff94c092f8ffae973..53fcba7a8221da511206c568771d89f9906b51d9 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/LoadingScreenController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/LoadingScreenController.java @@ -14,7 +14,6 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; import java.net.URL; import java.util.*; -import java.util.concurrent.TimeUnit; public class LoadingScreenController implements Initializable { @FXML @@ -35,51 +34,66 @@ public class LoadingScreenController implements Initializable { "Over 1000 people play games every day.", "A lot of people believe Nikola Tesla was the first to invent electricity but some clouds beat him to it.", "Monkeys usually don't have keys.", - "While you're reading this, you've wasted 2 seconds."}; + "While you're reading this, you've wasted 2 seconds.", + "If you die, you're dead.", + "If you take damage, you loose hp.", + "Did you know that Java is also an Island?", + "This loading screen might never end.", + "Get the BattleArena Ultimate-Edition for only 420,69€.", + "Press the left arrow key to move left.", + "To use the gravity-gun, close the game and start Half Life 2.", + "Buying this game was a good decision! (no refunds)." + }; private final List<String> shuffledTips = Arrays.asList(loadingTips); private final Persistence persistence = Persistence.getInstance(); private static final Logger log = LogManager.getLogger(Persistence.class); + Thread tipsThread = new Thread(() -> { + try { + setLoadingTips(); + } catch (InterruptedException e) { + log.info("Data finished loading"); + } + }); + Thread loadingDataThread = new Thread(() -> { + try { + Thread.sleep(4000); + loadingData(); + } catch (IOException e) { + throw new RuntimeException(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }); @Override public void initialize(URL url, ResourceBundle resourceBundle) { Collections.shuffle(shuffledTips); - Thread tipsThread = new Thread(() -> { - try { - setLoadingTips(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - }); tipsThread.start(); - Thread loadingStats = new Thread(() -> { - try { - TimeUnit.SECONDS.sleep(4); - asd(); - } catch (IOException e) { - throw new RuntimeException(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - }); - loadingStats.start(); + loadingDataThread.start(); } private void setLoadingTips() throws InterruptedException { - while (!statsLoaded) { - if (counter < loadingTips.length) { - String nextTip = shuffledTips.get(counter); - Platform.runLater(() -> tips.setText(nextTip)); // JavaFX method to queue a task that needs to be executed on the JavaFX application thread (update some ui components) - counter++; - TimeUnit.MILLISECONDS.sleep(3500); + while (!statsLoaded && counter < loadingTips.length) { + String nextTip = shuffledTips.get(counter); + Platform.runLater(() -> tips.setText(nextTip)); // JavaFX method to queue a task that needs to be executed on the JavaFX application thread (update ui components) + counter++; + +// check if statsLoaded is still false before sleeping + if (!statsLoaded) { + if (nextTip.length() > 60) { + Thread.sleep(5500); + } else { + Thread.sleep(3500); + } setLoadingTips(); } } } - private void asd() throws IOException { + private void loadingData() throws IOException { boolean isStartUp = true, noAccount = false; while (isStartUp) { try { @@ -102,6 +116,13 @@ public class LoadingScreenController implements Initializable { log.error(e); } } - parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml")))); + Platform.runLater(() -> tipsThread.interrupt()); + Platform.runLater(() -> { + try { + parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml")))); + } catch (IOException e) { + log.error("MenuBorderPane.fxml error ", e); + } + }); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/Utilities/ButtonTransition.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/Utilities/ButtonTransition.java index b129d469320cdd8549e234a3a5d6fae8901187ea..8e59516428834ab48bf7a9b2cfebb1760ad63308 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/Utilities/ButtonTransition.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/Utilities/ButtonTransition.java @@ -1,6 +1,7 @@ package de.hdm_stuttgart.battlearena.Controller.Utilities; import javafx.animation.ScaleTransition; +import javafx.application.Platform; import javafx.scene.control.Button; import javafx.scene.control.skin.ButtonSkin; import javafx.util.Duration; @@ -13,14 +14,20 @@ public class ButtonTransition extends ButtonSkin { fadeIn.setNode(button); fadeIn.setToX(1.1); fadeIn.setToY(1.1); - button.setOnMouseEntered(e -> fadeIn.playFromStart()); + +// this ensures that any JavaFX related code is run on the JavaFX application thread + button.setOnMouseEntered(e -> { + Platform.runLater(fadeIn::playFromStart); + }); // set transition for mouse exiting buttonButtonTransitionScale final ScaleTransition fadeOut = new ScaleTransition(Duration.millis(150)); fadeOut.setNode(button); fadeOut.setToX(1.0); fadeOut.setToY(1.0); - button.setOnMouseExited(e -> fadeOut.playFromStart()); + button.setOnMouseExited(e -> { + Platform.runLater(fadeOut::playFromStart); + }); button.setScaleX(1.0); button.setScaleY(1.0); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Main/Main.java b/src/main/java/de/hdm_stuttgart/battlearena/Main/Main.java index 5ba11eb60e0f13ae13883241d2a96279e5f58025..219c19322e4e2141950bf0cd922899231afa3fea 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Main/Main.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Main/Main.java @@ -33,7 +33,6 @@ public class Main extends Application { // loading font in start() because CSS can't handle whitespace in folder names Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 50); -// TODO: revert back to intro scene Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/Intro.fxml"))); Scene scene = new Scene(root); @@ -55,5 +54,11 @@ public class Main extends Application { stage.show(); log.debug("Project started successfully!"); + +// Exiting program if an exception occurs +// Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { +// log.error(throwable.getMessage()); +// System.exit(1); +// }); } } \ No newline at end of file diff --git a/src/main/resources/fxml/LoadingScreen.fxml b/src/main/resources/fxml/LoadingScreen.fxml index 78e7ff27e23056e83eb2e65c5429df671f2f3035..bd48630fffd342c2e679ec77d06796ef5b7bd3d0 100644 --- a/src/main/resources/fxml/LoadingScreen.fxml +++ b/src/main/resources/fxml/LoadingScreen.fxml @@ -1,27 +1,63 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> <?import javafx.scene.control.Label?> +<?import javafx.scene.image.Image?> +<?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.BorderPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.VBox?> -<?import javafx.scene.media.MediaView?> +<?import javafx.scene.shape.Rectangle?> <?import javafx.scene.text.Font?> -<BorderPane fx:id="parent" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.LoadingScreenController"> +<BorderPane id="loadingScreen" fx:id="parent" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.LoadingScreenController"> <center> <StackPane BorderPane.alignment="CENTER"> <children> <VBox alignment="CENTER"> <children> - <MediaView fx:id="mediaView" fitHeight="200.0" fitWidth="200.0" /> - <Label fx:id="tips" text="If you see this, then something went wrong lmao" textFill="WHITE"> - <font> - <Font size="60.0" /> - </font> - </Label> + <ImageView fitHeight="800.0" fitWidth="900.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@../textures/images/logo_transparent.png" /> + </image> + </ImageView> </children> </VBox> </children> </StackPane> </center> + <bottom> + <HBox alignment="CENTER" BorderPane.alignment="CENTER"> + <children> + <Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffffff00" height="180.0" stroke="TRANSPARENT" strokeType="INSIDE" width="180.0" HBox.hgrow="NEVER"> + <HBox.margin> + <Insets bottom="50.0" left="50.0" right="50.0" /> + </HBox.margin> + </Rectangle> + <Pane HBox.hgrow="ALWAYS" /> + <Label fx:id="tips" alignment="CENTER" contentDisplay="CENTER" text="If you see this, then something went wrong lmao" textFill="WHITE" wrapText="true"> + <font> + <Font name="Helvetica Neue LT Com 53 Extended" size="40.0" /> + </font> + <HBox.margin> + <Insets bottom="50.0" /> + </HBox.margin> + </Label> + <Pane HBox.hgrow="ALWAYS" /> + <ImageView fitHeight="180.0" fitWidth="180.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@../textures/images/throbber.gif" /> + </image> + <HBox.margin> + <Insets bottom="50.0" left="50.0" right="50.0" /> + </HBox.margin> + </ImageView> + </children> + <BorderPane.margin> + <Insets /> + </BorderPane.margin> + </HBox> + </bottom> </BorderPane> diff --git a/src/main/resources/player/appSettings.json b/src/main/resources/player/appSettings.json index cdc51fe76a1d65affefff9d418f5a2a69107c9db..ec5bc62a909f2065d81be4cfd6c494b9e10715fb 100644 --- a/src/main/resources/player/appSettings.json +++ b/src/main/resources/player/appSettings.json @@ -1,4 +1,4 @@ { "sfxVolume": 50, - "musicVolume": 2 + "musicVolume": 0 } \ No newline at end of file diff --git a/src/main/resources/player/playerAccount.json b/src/main/resources/player/playerAccount.json index 60070b6ed6a4c8153907eaf7e737e2e997fb3377..ad25fb8ab5d0aeda7756b512127b84937090f676 100644 --- a/src/main/resources/player/playerAccount.json +++ b/src/main/resources/player/playerAccount.json @@ -1,5 +1,5 @@ { "playerName": "Player1", "accountPassword": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", - "accountType": "LOCAL" + "accountType": "ONLINE" } \ No newline at end of file diff --git a/src/main/resources/styles/style.css b/src/main/resources/styles/style.css index 2eef5146f26fd1bce43332765cb4d41c5be9906e..70ef321a12193d4a5b6a9d0b943dcb295d41750c 100644 --- a/src/main/resources/styles/style.css +++ b/src/main/resources/styles/style.css @@ -17,6 +17,10 @@ /* -fx-font-size: 60;*/ /*}*/ +#loadingScreen { + -fx-background-color: radial-gradient(focus-distance 0% , center 50% 50% , radius 45% , #a31c31, #542b27); +} + #mainMenu{ -fx-background-image: url("../textures/images/background.png"); -fx-background-size: cover; diff --git a/src/main/resources/textures/images/logo_transparent.png b/src/main/resources/textures/images/logo_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..4aa46908f9c28d66b837bfc3d073aab080759127 Binary files /dev/null and b/src/main/resources/textures/images/logo_transparent.png differ diff --git a/src/main/resources/textures/images/logo_transparent_alt.png b/src/main/resources/textures/images/logo_transparent_alt.png new file mode 100644 index 0000000000000000000000000000000000000000..817ba0a2f3103c351277b8598614836c377ce058 Binary files /dev/null and b/src/main/resources/textures/images/logo_transparent_alt.png differ diff --git a/src/main/resources/textures/images/throbber.gif b/src/main/resources/textures/images/throbber.gif new file mode 100644 index 0000000000000000000000000000000000000000..45caf1ef603429f181feebcc5505f4b01f512728 Binary files /dev/null and b/src/main/resources/textures/images/throbber.gif differ