Added the Train as a Background to LobbyView and animated the wheels - still a bit wonky but it does work

This commit is contained in:
Seraina 2022-05-12 10:15:07 +02:00
parent 39e52b20aa
commit 7968523469
12 changed files with 271 additions and 6 deletions

View File

@ -31,6 +31,7 @@ public class ChatApp extends Application {
public Node chat;
public Node game;
public Node backgroundDay;
public ChatApp() {
super();
@ -159,10 +160,14 @@ public class ChatApp extends Application {
try {
URL chatResource = ChatApp.class.getResource("chat/ChatView.fxml");
URL gameResource = ChatApp.class.getResource("game/GameDayAll.fxml");
URL bgDayResource = ChatApp.class.getResource("TrainAnimationViewDay.fxml");
this.chat = FXMLLoader.load(Objects.requireNonNull(chatResource));
this.game = FXMLLoader.load(Objects.requireNonNull(gameResource));
this.backgroundDay = FXMLLoader.load(Objects.requireNonNull(bgDayResource));
LOGGER.debug(bgDayResource);
} catch (Exception e) {
LOGGER.warn(e.getMessage());
LOGGER.warn("There was an Exception while loading");
e.printStackTrace();
}
URL loungeResource = ChatApp.class.getResource(
"lounge/LoungeSceneView.fxml");

View File

@ -0,0 +1,70 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.animation.Animation;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.util.Duration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TrainAnimationDayController implements Initializable {
public static final Logger LOGGER = LogManager.getLogger(TrainAnimationDayController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML
private ImageView wheelsImageView;
@FXML
private ImageView shadowTrain;
@FXML
private ImageView wagonBGImageView;
@FXML
private ImageView wagonFloorImageView;
@FXML
private AnchorPane wheelsAnchorPane;
@FXML
private AnchorPane gameAnchorPane;
@FXML
private ImageView wagonFullImageView;
@FXML
private ImageView lokiImageView;
private ChatApp chatApp;
private static ChatApp cApp;
public TrainAnimationDayController(){
super();
LOGGER.debug("Empty TrainAnimationDayController() constructor was called");
}
public ChatApp getChatApp() {
return chatApp;
}
public void setChatApp(ChatApp chatApp) {
this.chatApp = chatApp;
}
public static void setcApp(ChatApp cApp) {
TrainAnimationDayController.cApp = cApp;
}
@Override
public void initialize(URL location, ResourceBundle resources) {
setChatApp(cApp);
Platform.runLater(new Runnable() {
@Override
public void run() {
Animation wheels = new WheelsAnimation(Duration.millis(1000), wheelsImageView);
wheels.setCycleCount(Animation.INDEFINITE);
wheels.play();
}
});
}
}

View File

@ -0,0 +1,82 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import javafx.animation.Animation;
import javafx.animation.Timeline.*;
import javafx.animation.Interpolator;
import javafx.animation.Transition;
import javafx.fxml.FXML;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class WheelsAnimation extends Transition {
public static final Logger LOGGER = LogManager.getLogger(WheelsAnimation.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
ImageView imageView;
private static final Image[] wheels = new Image[26];
private int index;
WheelsAnimation(Duration duration, ImageView imageView) {
this.imageView = imageView;
setCycleDuration(duration);
setInterpolator(Interpolator.LINEAR);
index = 1;
wheels[0] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0001.png");
wheels[1] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0002.png");
wheels[2] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0003.png");
wheels[3] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0004.png");
wheels[4] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0005.png");
wheels[5] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0006.png");
wheels[6] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0007.png");
wheels[7] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0008.png");
wheels[8] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0009.png");
wheels[9] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0010.png");
wheels[10] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0011.png");
wheels[11] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0012.png");
wheels[12] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0013.png");
wheels[13] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0014.png");
wheels[14] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0015.png");
wheels[15] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0016.png");
wheels[16] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0017.png");
wheels[17] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0018.png");
wheels[18] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0019.png");
wheels[19] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0020.png");
wheels[20] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0021.png");
wheels[21] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0022.png");
wheels[22] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0023.png");
wheels[23] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0024.png");
wheels[24] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0025.png");
wheels[25] = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/Wheels/Image0026.png");
}
@Override
protected void interpolate(double frac) {
if(index == 25) index = 0;
imageView.setImage(wheels[index]);
index++;
}
}

View File

@ -4,6 +4,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.LobbyListView;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.TrainAnimationDayController;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser;
import java.net.URL;
@ -49,7 +50,10 @@ public class LoungeSceneViewController implements Initializable {
public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML
private AnchorPane backGroundAnchorPane;
@FXML
private AnchorPane gameDisplayAnchorPane;
@FXML
private TextFlow highScore;
@FXML
@ -136,6 +140,8 @@ public class LoungeSceneViewController implements Initializable {
ClientListView.setVisible(true);
ClientListView.setItems(clients);
addChatView();
addBackgroundDay();
TrainAnimationDayController.setcApp(this.cApp);
ClientListView.setItems(clients);
ClientListView.setCellFactory(param -> {
@ -363,6 +369,20 @@ public class LoungeSceneViewController implements Initializable {
});
}
public void addBackgroundDay() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
LOGGER.debug("in addBackgroundDay() run()");
gameDisplayAnchorPane.getChildren().add(chatApp.backgroundDay);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Adds players to a lobby "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
*

View File

@ -0,0 +1,3 @@
*{
-fx-background-color: transparent;
}

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="1080.0" maxWidth="1920.0" minHeight="-Infinity" minWidth="-Infinity" stylesheets="@TrainAnimationDay.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.TrainAnimationDayController">
<children>
<ImageView fx:id="shadowTrain" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Shadow_Below_Train.png" />
</image>
</ImageView>
<ImageView fx:id="wagonBGImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Second_Wagon.png" />
</image>
</ImageView>
<ImageView fx:id="wagonFloorImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Empty_Wagon.png" />
</image>
</ImageView>
<AnchorPane fx:id="gameAnchorPane" />
<ImageView fx:id="wagonFullImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Full_Wagon.png" />
</image>
</ImageView>
<ImageView fx:id="lokiImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Loki.png" />
</image>
</ImageView>
<AnchorPane fx:id="wheelsAnchorPane">
<children>
<ImageView fx:id="wheelsImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true" />
</children></AnchorPane>
</children>
</StackPane>

View File

@ -5,7 +5,7 @@
.button{
}
.roomButtonGroup{
#roomButtonGroup{
-fx-background-color: transparent;
}
@ -16,7 +16,7 @@
-fx-animated: null;
}
.notificationText{
#notificationText{
-fx-alignment: center;
-fx-text-fill: black;
-fx-font-family: Bahnschrift;

View File

@ -10,9 +10,10 @@
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController">
<AnchorPane fx:id="backGroundAnchorPane" stylesheets="@loungStyle.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController">
<children>
<BorderPane fx:id="LoungeSceneBorderPane" layoutX="860.0" layoutY="440.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<AnchorPane fx:id="gameDisplayAnchorPane" />
<BorderPane fx:id="LoungeSceneBorderPane" layoutX="860.0" layoutY="440.0" stylesheets="@boarderPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<ToolBar fx:id="NTtBToolBar" prefHeight="77.0" BorderPane.alignment="CENTER">
<items>

View File

@ -0,0 +1,20 @@
*{
-fx-background-color: transparent;
}
#NTtBToolBar{
-fx-border-color: grey;
-fx-background-color: rgba(255,255,255,0.05);
}
.button{
-fx-border-color: darkgrey;
-fx-background-color: grey;
-fx-text-fill: white;
}
.button:pressed{
-fx-border-color: grey;
-fx-background-color: lightgrey;
-fx-text-fill: black;
}

View File

@ -0,0 +1,5 @@
#backGroundAnchorPane{
/*-fx-background-color: black;*/
/*-fx-background-image: url(../game/Day/Full_Wagon.png);*/
}

View File

@ -0,0 +1,3 @@
*{
-fx-background-color: transparent;
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane stylesheets="@wheelsAnimation.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ImageView fx:id="wheelsAnimationImageView" fitHeight="843.75" fitWidth="1500.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@game/Day/Wheels/Image0001.png" />
</image>
</ImageView>
</children>
</AnchorPane>