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

add(ui): add basic loading screen #14

parent b415ce38
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
......@@ -50,11 +50,7 @@ public class IntroController implements Initializable {
mediaPlayer.setOnEndOfMedia(() -> {
if (counter == videos.length - 1) {
try {
videoEnd();
} catch (IOException e) {
throw new RuntimeException(e);
}
videoEnd();
} else {
nextVideo();
}
......@@ -63,42 +59,20 @@ public class IntroController implements Initializable {
// TODO: make any button pressed work
introParent.setOnMouseClicked((mouseEvent) -> {
if (counter == videos.length - 1) {
try {
videoEnd();
} catch (IOException e) {
throw new RuntimeException(e);
}
videoEnd();
} else {
nextVideo();
}
});
}
private void videoEnd() throws IOException {
boolean isStartUp = true, noAccount = false, statsLoaded = false;
while (isStartUp) {
try {
persistence.loadPlayerAccount();
persistence.verifyPlayerAccount();
mediaPlayer.dispose();
isStartUp = false;
} catch (DatabaseException e) {
noAccount = true;
// TODO: reset player account if account fails to load in loadPlayerAccount()
}
if (noAccount) {
introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/PlayerCreateScene.fxml"))));
}
}
while (!statsLoaded) { // while loop because Martin said so
try {
persistence.loadPlayerStatistics();
statsLoaded = true;
} catch (DatabaseException e) {
log.error(e);
}
private void videoEnd() {
try {
mediaPlayer.dispose();
introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/LoadingScreen.fxml"))));
} catch (IOException e) {
throw new RuntimeException();
}
introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml"))));
}
private void nextVideo() {
......
package de.hdm_stuttgart.battlearena.Controller;
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException;
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import org.apache.logging.log4j.LogManager;
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
private Label tips;
@FXML
private BorderPane parent;
private int counter = 0;
private boolean statsLoaded = false;
private final String[] loadingTips = {
"Did you know, that since 2009, Martin isn't on the FBI list?",
"BattleArena is actually derived from the combination of the words 'Battle' and 'Arena'.",
"Yannik ist over 1,80m tall.",
"Electricity is a vital part to compute this game.",
"There is a typo in one of the tips.",
"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."};
private final List<String> shuffledTips = Arrays.asList(loadingTips);
private final Persistence persistence = Persistence.getInstance();
private static final Logger log = LogManager.getLogger(Persistence.class);
@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();
}
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);
setLoadingTips();
}
}
}
private void asd() throws IOException {
boolean isStartUp = true, noAccount = false;
while (isStartUp) {
try {
persistence.loadPlayerAccount();
persistence.verifyPlayerAccount();
isStartUp = false;
} catch (DatabaseException e) {
noAccount = true;
// TODO: reset player account if account fails to load in loadPlayerAccount()
}
if (noAccount) {
parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/PlayerCreateScene.fxml"))));
}
}
while (!statsLoaded) { // while loop because Martin said so
try {
persistence.loadPlayerStatistics();
statsLoaded = true;
} catch (DatabaseException e) {
log.error(e);
}
}
parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml"))));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.media.MediaView?>
<?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">
<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>
</children>
</VBox>
</children>
</StackPane>
</center>
</BorderPane>
{
"sfxVolume": 50,
"musicVolume": 0
"musicVolume": 2
}
\ No newline at end of file
......@@ -13,6 +13,10 @@
-fx-background-color: black;
}
/*#tips {*/
/* -fx-font-size: 60;*/
/*}*/
#mainMenu{
-fx-background-image: url("../textures/images/background.png");
-fx-background-size: cover;
......
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