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

update(splashscreen): update loading screen responsive layout and styling,...

update(splashscreen): update loading screen responsive layout and styling, move StartupThread.start() from IntroController to LoadingScreenController, move loadingData() into seperate class #17
parent 1cfd327f
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
......@@ -40,7 +40,6 @@ public class IntroController implements Initializable {
introParent.setStyle("-fx-background-color: black;");
introParent.setCursor(Cursor.NONE);
createMediaPlayer();
new StartupThread().start();
}
private void createMediaPlayer() {
......
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.FXMLLoader;
import javafx.scene.layout.BorderPane;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.Objects;
public class LoadingPersistence {
Persistence persistence = Persistence.getInstance();
private static final Logger log = LogManager.getLogger(Persistence.class);
public boolean loadingData(BorderPane parent, boolean statsLoaded, Thread tipsThread) 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);
}
}
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);
}
});
return statsLoaded;
}
}
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 de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.StartupThread;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Screen;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -20,11 +22,11 @@ public class LoadingScreenController implements Initializable {
private Label tips;
@FXML
private BorderPane parent;
@FXML
private ImageView logo, throbber;
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'.",
......@@ -46,9 +48,9 @@ public class LoadingScreenController implements Initializable {
};
private final List<String> shuffledTips = Arrays.asList(loadingTips);
private final Persistence persistence = Persistence.getInstance();
private static final Logger log = LogManager.getLogger(Persistence.class);
Rectangle2D screen = Screen.getPrimary().getVisualBounds();
Thread tipsThread = new Thread(() -> {
try {
setLoadingTips();
......@@ -60,7 +62,7 @@ public class LoadingScreenController implements Initializable {
Thread loadingDataThread = new Thread(() -> {
try {
Thread.sleep(4000);
loadingData();
statsLoaded = new LoadingPersistence().loadingData(parent, statsLoaded, tipsThread);
} catch (IOException e) {
throw new RuntimeException();
} catch (InterruptedException e) {
......@@ -70,11 +72,22 @@ public class LoadingScreenController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
new StartupThread().start();
Collections.shuffle(shuffledTips);
setImages();
tipsThread.start();
loadingDataThread.start();
}
private void setImages() {
logo.setTranslateY(screen.getHeight() * 0.08);
System.out.println(screen.getHeight());
logo.setFitWidth(screen.getWidth() * 0.3);
throbber.setFitWidth(screen.getWidth() * 0.07);
logo.setPreserveRatio(true);
throbber.setPreserveRatio(true);
}
private void setLoadingTips() throws InterruptedException {
while (!statsLoaded && counter < loadingTips.length) {
String nextTip = shuffledTips.get(counter);
......@@ -84,7 +97,7 @@ public class LoadingScreenController implements Initializable {
// check if statsLoaded is still false before sleeping
if (!statsLoaded) {
if (nextTip.length() > 60) {
Thread.sleep(5500);
Thread.sleep(6000);
} else {
Thread.sleep(3500);
}
......@@ -92,37 +105,4 @@ public class LoadingScreenController implements Initializable {
}
}
}
private void loadingData() 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);
}
}
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);
}
});
}
}
......@@ -32,6 +32,7 @@ public class Main extends Application {
public void start(Stage stage) throws Exception {
// loading font in start() because CSS can't handle whitespace in folder names
Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/AmaticSC-Bold.ttf"), 50);
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/Intro.fxml")));
......
File added
File added
......@@ -7,29 +7,12 @@
<?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.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<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>
<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">
<HBox alignment="BOTTOM_CENTER" BorderPane.alignment="BOTTOM_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>
......@@ -46,7 +29,7 @@
</HBox.margin>
</Label>
<Pane HBox.hgrow="ALWAYS" />
<ImageView fitHeight="180.0" fitWidth="180.0" pickOnBounds="true" preserveRatio="true">
<ImageView fx:id="throbber" fitHeight="180.0" fitWidth="180.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../textures/images/throbber.gif" />
</image>
......@@ -60,4 +43,11 @@
</BorderPane.margin>
</HBox>
</bottom>
<center>
<ImageView fx:id="logo" fitHeight="800.0" fitWidth="900.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
<image>
<Image url="@../textures/images/logo_transparent.png" />
</image>
</ImageView>
</center>
</BorderPane>
......@@ -7,11 +7,11 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<VBox fx:id="parent" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="50.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.StatisticsController">
<VBox fx:id="parent" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" 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.StatisticsController">
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="30.0" VBox.vgrow="ALWAYS">
<HBox alignment="CENTER" prefHeight="411.0" prefWidth="677.0" spacing="30.0" VBox.vgrow="ALWAYS">
<children>
<VBox alignment="CENTER_RIGHT" prefHeight="200.0" prefWidth="100.0" spacing="10.0" HBox.hgrow="ALWAYS">
<VBox alignment="CENTER_RIGHT" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Kills:" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Deaths:" />
......@@ -21,7 +21,7 @@
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Ingame time:" />
</children>
</VBox>
<VBox alignment="CENTER_LEFT" prefHeight="200.0" prefWidth="100.0" spacing="10.0" HBox.hgrow="ALWAYS">
<VBox alignment="CENTER_LEFT" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Text fx:id="kills" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
<Text fx:id="deaths" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
......@@ -38,11 +38,11 @@
<children>
<PieChart fx:id="kd" minHeight="-Infinity" minWidth="-Infinity" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="-200.0" />
<Insets bottom="-200.0" top="-250.0" />
</VBox.margin></PieChart>
<PieChart fx:id="wl" minHeight="-Infinity" minWidth="-Infinity" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="-40.0" />
<Insets bottom="-250.0" top="-40.0" />
</VBox.margin></PieChart>
</children>
</VBox>
......
......@@ -11,11 +11,13 @@
-fx-font-family: "Starship Shadow";
-fx-text-fill: white;
-fx-background-color: black;
-fx-font-size: 50 px;
}
/*#tips {*/
/* -fx-font-size: 60;*/
/*}*/
#tips {
-fx-font-family: "Amatic SC Bold";
-fx-font-size: 40 px;
}
#loadingScreen {
-fx-background-color: radial-gradient(focus-distance 0% , center 50% 50% , radius 45% , #a31c31, #542b27);
......@@ -27,7 +29,7 @@
}
#gameTitle {
-fx-font-size: 100;
-fx-font-size: 100 px;
}
.button {
......@@ -38,7 +40,7 @@
#btnLeft {
-fx-skin: none;
-fx-text-fill: white;
-fx-text-fill: #7a7a7a;
}
.accordion {
......
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