diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index e234934..3d6d5e1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -140,6 +140,7 @@ public class Client { String pos = msg.substring(0, msgIndex); try { position = Integer.parseInt(pos); + gameStateModel.setRoleFromPosition(position); } catch (NumberFormatException e) { LOGGER.warn("Position got scrabbled on the way here"); } @@ -155,6 +156,7 @@ public class Client { public void setPosition(int position) { this.position = position; + gameStateModel.setRoleFromPosition(position); } /** @@ -343,11 +345,15 @@ public class Client { switch (parameter) { case GuiParameters.night: //ClientGameInfoHandler; gameStateModel.setDayClone(false); + LOGGER.debug("----------------Night, Your role is:" + gameStateModel.getYourRole() + gameStateModel); chatApp.getGameController().setNoiseButtonInvisible(); + chatApp.getGameController().setVoteButtonVisibilityNight(); break; case GuiParameters.day: //ClientGameInfoHandler gameStateModel.setDayClone(true); + LOGGER.debug("----------------Day, Your role is:" + gameStateModel.getYourRole()+ gameStateModel); chatApp.getGameController().setNoiseButtonVisible(); + chatApp.getGameController().setVoteButtonVisibilityDay(); break; case GuiParameters.updateGameState: gameStateModel.setGSFromString(data); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/BGAnimation.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/BGAnimation.java index 99e8996..335a8bc 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/BGAnimation.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/BGAnimation.java @@ -10,9 +10,16 @@ import javafx.util.Duration; public class BGAnimation extends Transition { ImageView imageView; private static final Image bgFull = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/BG_small.jpg"); + int index; + int lastIndex; - BGAnimation(Duration duration, ImageView imageView) { + public BGAnimation(Duration duration, ImageView imageView) { + index = 0; + lastIndex = 1034; this.imageView = imageView; + imageView.setFitHeight(1950); + imageView.setFitWidth(6667.968); + imageView.setImage(bgFull); setCycleDuration(duration); setInterpolator(Interpolator.DISCRETE); @@ -20,6 +27,14 @@ public class BGAnimation extends Transition { @Override protected void interpolate(double frac) { + if(index == lastIndex) { + index = 0; + imageView.setX(0); + imageView.setY(0); + } + imageView.setX(index * -5); + imageView.setY(index * -1.07); + index++; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java index 4d9021c..b8e3677 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java @@ -74,6 +74,10 @@ public class ClientModel { } + public int getClientPosition() { + return client.getPosition(); + } + public void removeClientFromList(String id){ Iterator it = allClients.iterator(); while(it.hasNext()){ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java index 5a4a594..e4066e0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java @@ -28,7 +28,7 @@ public class GameStateModel { /** * A primitive clone of the passengerTrain in the GameState of the server. * in passengerTrainClone[0] the names of the passengers are stored, in passengerTrainClone[1] the roles - * (human/ghost/spectator). The indices of the array correspond with the positions + * (h/g/s). The indices of the array correspond with the positions */ private String[][] passengerTrainClone; @@ -41,8 +41,9 @@ public class GameStateModel { this.nrOfPlayers = 6; passengerTrainClone = new String[2][nrOfPlayers]; for(String role : passengerTrainClone[1]) { - role = ""; + role = "h"; } + yourRole = "h"; kickedOff = new boolean[nrOfPlayers]; isDayClone = false; } @@ -69,9 +70,12 @@ public class GameStateModel { public void setYourRole(String yourRole) { if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) { this.yourRole = yourRole; + } else { + this.yourRole = "h"; } } + public String getYourRole() { return yourRole; } @@ -125,4 +129,18 @@ public class GameStateModel { LOGGER.warn("data has wrong format"); } } + + /** + * Gets an integer and extracts the string from the passengerTrain[1] string at the index of the integer + * @param position the index of the array + */ + public void setRoleFromPosition(int position) { + String role = "h"; + try { + role = passengerTrainClone[1][position]; + } catch (Exception e) { + LOGGER.warn("Not an integer between 0-5"); + } + setYourRole(role); + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index 90ad993..d1a1ed1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -131,6 +131,73 @@ public class GameController implements Initializable { return chatAreaGame; } + public void setVoteButtonVisibilityDay(){ + Platform.runLater(new Runnable() { + @Override + public void run() { + LOGGER.debug(buttonRoom0); + if (gameStateModel.getYourRole().equals("h")) { + try { + buttonRoom0.setVisible(true); + buttonRoom1.setVisible(true); + buttonRoom2.setVisible(true); + buttonRoom3.setVisible(true); + buttonRoom4.setVisible(true); + buttonRoom5.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + + } else { + try { + buttonRoom0.setVisible(false); + buttonRoom1.setVisible(false); + buttonRoom2.setVisible(false); + buttonRoom3.setVisible(false); + buttonRoom4.setVisible(false); + buttonRoom5.setVisible(false); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + + public void setVoteButtonVisibilityNight(){ + Platform.runLater(new Runnable() { + @Override + public void run() { + LOGGER.debug(buttonRoom0); + if (gameStateModel.getYourRole().equals("g")) { + try { + buttonRoom0.setVisible(true); + buttonRoom1.setVisible(true); + buttonRoom2.setVisible(true); + buttonRoom3.setVisible(true); + buttonRoom4.setVisible(true); + buttonRoom5.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + + } else { + try { + buttonRoom0.setVisible(false); + buttonRoom1.setVisible(false); + buttonRoom2.setVisible(false); + buttonRoom3.setVisible(false); + buttonRoom4.setVisible(false); + buttonRoom5.setVisible(false); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + + /** * If button 0 is clicked, send the vote message 0 to the server */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 308ca63..4b18637 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -1,16 +1,19 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.BGAnimation; 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.client.gui.WheelsAnimation; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser; import java.net.URL; import java.util.HashMap; import java.util.Iterator; import java.util.ResourceBundle; +import javafx.animation.Animation; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.property.SimpleBooleanProperty; @@ -35,6 +38,7 @@ import javafx.scene.control.SplitPane; import javafx.scene.control.TextField; import javafx.scene.control.TitledPane; import javafx.scene.control.ToolBar; +import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; @@ -42,6 +46,7 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; +import javafx.util.Duration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -50,6 +55,9 @@ 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 backGroundAnimationPane; + @FXML private AnchorPane backGroundAnchorPane; @FXML @@ -144,6 +152,86 @@ public class LoungeSceneViewController implements Initializable { LOGGER.debug("cApp = " + cApp); LOGGER.debug("chatApp = " + chatApp); TrainAnimationDayController.setcApp(cApp); + ImageView bgAnimationView = new ImageView(); + bgAnimationView.setFitHeight(1950); + bgAnimationView.setFitWidth(6667.968); + + ClientListView.setItems(clients); + ClientListView.setCellFactory(param -> { + ListCell cell = new ListCell<>() { + Label name = new Label(); + Label id = new Label(); + HBox nameAndId = new HBox(name, id); + + { + nameAndId.setAlignment(Pos.CENTER_LEFT); + } + + /** + * The updateItem method should not be called by developers, but it is the + * best method for developers to override to allow for them to customise the + * visuals of the cell. To clarify, developers should never call this method + * in their code (they should leave it up to the UI control, such as the + * {@link ListView} control) to call this method. However, the purpose of + * having the updateItem method is so that developers, when specifying + * custom cell factories (again, like the ListView {@link + * ListView#cellFactoryProperty() cell factory}), the updateItem method can + * be overridden to allow for complete customisation of the cell. + * + *

It is very important that subclasses + * of Cell override the updateItem method properly, as failure to do so will + * lead to issues such as blank cells or cells with unexpected content + * appearing within them. Here is an example of how to properly override the + * updateItem method: + * + *

+         * protected void updateItem(T item, boolean empty) {
+         *     super.updateItem(item, empty);
+         *
+         *     if (empty || item == null) {
+         *         setText(null);
+         *         setGraphic(null);
+         *     } else {
+         *         setText(item.toString());
+         *     }
+         * }
+         * 
+ * + *

Note in this code sample two important points: + *

    + *
  1. We call the super.updateItem(T, boolean) method. If this is not + * done, the item and empty properties are not correctly set, and you are + * likely to end up with graphical issues.
  2. + *
  3. We test for the empty condition, and if true, we + * set the text and graphic properties to null. If we do not do this, + * it is almost guaranteed that end users will see graphical artifacts + * in cells unexpectedly.
  4. + *
+ * @param item The new item for the cell. + * + * @param empty whether or not this cell represents data from the list. If + * it is empty, then it does not represent any domain data, but + * is a cell + */ + @Override + protected void updateItem(ClientListItem item, boolean empty) { + super.updateItem(item, empty); + if (empty) { + setText(null); + setGraphic(null); + } else { + LOGGER.debug("In updateItem(item, empty) Method. Else branch -> nonnull item"); + name.setText(item.getName()); + name.setTextFill(Color.BLACK); + id.setText(String.valueOf(item.getId())); + id.setTextFill(Color.BLACK); + setGraphic(nameAndId); + } + } + }; + return cell; + }); + LobbyListView.setItems(lobbies); LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); LobbyListView.setCellFactory(param -> { @@ -237,6 +325,15 @@ public class LoungeSceneViewController implements Initializable { }; return cell; }); + Platform.runLater(new Runnable() { + @Override + public void run() { + backGroundAnimationPane.getChildren().add(bgAnimationView); + Animation backGround = new BGAnimation(Duration.millis(17), bgAnimationView); + backGround.setCycleCount(Animation.INDEFINITE); + backGround.play(); + } + }); LOGGER.debug("In Initialize 3 LobbyListView" + LobbyListView); LobbyListView.setPlaceholder(new Text("No open lobbies!")); LobbyListView.setVisible(true); diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml index f62b99e..cc365fa 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml @@ -12,15 +12,16 @@ + - + -