Skip to content
Snippets Groups Projects
Commit 1cfd327f authored by Tran Peter's avatar Tran Peter
Browse files

update(splashscreen): fix exception, add styling #17

parent 2e22c68d
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!27Player can now place bombs that have a explosion radius that dont go through the wall.,!20Merge ui into development
Showing
with 115 additions and 42 deletions
......@@ -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() {
......
......@@ -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);
}
});
}
}
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);
......
......@@ -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
<?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>
{
"sfxVolume": 50,
"musicVolume": 2
"musicVolume": 0
}
\ No newline at end of file
{
"playerName": "Player1",
"accountPassword": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"accountType": "LOCAL"
"accountType": "ONLINE"
}
\ No newline at end of file
......@@ -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;
......
src/main/resources/textures/images/logo_transparent.png

1.63 MiB

src/main/resources/textures/images/logo_transparent_alt.png

1.61 MiB

src/main/resources/textures/images/throbber.gif

382 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment