diff --git a/src/main/java/seng302/visualiser/GameClient.java b/src/main/java/seng302/visualiser/GameClient.java index d0b7b2b7..7b3920d9 100644 --- a/src/main/java/seng302/visualiser/GameClient.java +++ b/src/main/java/seng302/visualiser/GameClient.java @@ -1,5 +1,15 @@ package seng302.visualiser; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -32,13 +42,11 @@ import seng302.utilities.Sounds; import seng302.utilities.StreamParser; import seng302.utilities.XMLGenerator; import seng302.utilities.XMLParser; -import seng302.visualiser.controllers.*; - -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.util.*; +import seng302.visualiser.controllers.FinishScreenViewController; +import seng302.visualiser.controllers.LobbyController; +import seng302.visualiser.controllers.LobbyController_old; +import seng302.visualiser.controllers.RaceViewController; +import seng302.visualiser.controllers.ViewManager; /** * This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated @@ -293,6 +301,9 @@ public class GameClient { clientLobbyList.add(boat.getBoatName()) ); raceState.setBoats(allBoatsMap.values()); + if (lobbyController != null) { + lobbyController.setBoats(allBoatsMap); + } break; case RACE_START_STATUS: @@ -512,4 +523,8 @@ public class GameClient { if (server != null) server.terminate(); if (socketThread != null) socketThread.setSocketToClose(); } + + public Map getAllBoatsMap() { + return allBoatsMap; + } } diff --git a/src/main/java/seng302/visualiser/controllers/LobbyController.java b/src/main/java/seng302/visualiser/controllers/LobbyController.java index 00ae8f5c..7608b252 100644 --- a/src/main/java/seng302/visualiser/controllers/LobbyController.java +++ b/src/main/java/seng302/visualiser/controllers/LobbyController.java @@ -2,14 +2,12 @@ package seng302.visualiser.controllers; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXDialog; - import java.io.IOException; import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.ResourceBundle; - import javafx.application.Platform; import javafx.collections.ListChangeListener; import javafx.fxml.FXML; @@ -23,6 +21,7 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import seng302.gameServer.GameStages; import seng302.gameServer.GameState; +import seng302.model.ClientYacht; import seng302.model.Colors; import seng302.model.Limit; import seng302.model.RaceState; @@ -30,7 +29,6 @@ import seng302.model.mark.CompoundMark; import seng302.model.mark.Corner; import seng302.model.stream.xml.parser.RaceXMLData; import seng302.utilities.Sounds; -import seng302.utilities.XMLGenerator; import seng302.visualiser.GameView; import seng302.visualiser.controllers.cells.PlayerCell; @@ -57,12 +55,15 @@ public class LobbyController implements Initializable { private RaceState raceState; private JFXDialog customizationDialog; public Color playersColor; + private Map playerBoats; private Double mapWidth, mapHeight; private GameView gameView; @Override public void initialize(URL location, ResourceBundle resources) { + this.playerBoats = ViewManager.getInstance().getGameClient().getAllBoatsMap(); + if (this.playersColor == null) { this.playersColor = Colors.getColor(ViewManager.getInstance().getGameClient().getServerThread().getClientId() - 1); } @@ -121,6 +122,10 @@ public class LobbyController implements Initializable { gameView.updateCourse(marks, corners); } + private void getPlayerColors() { + + } + /** * */ @@ -162,23 +167,28 @@ public class LobbyController implements Initializable { */ private void refreshPlayerList() { playerListVBox.getChildren().clear(); - - for (String player : ViewManager.getInstance().getPlayerList()) { + if (this.playerBoats == null || this.playerBoats.size() == 0) { + this.playerBoats = ViewManager.getInstance().getGameClient().getAllBoatsMap(); + } + // TODO: 12/09/2017 ajm412: Make it so that it only removes players who's details have changed. + for (Integer playerId : playerBoats.keySet()) { VBox pane = null; - FXMLLoader loader = new FXMLLoader( - getClass().getResource("/views/cells/PlayerCell.fxml")); + ClientYacht yacht = playerBoats.get(playerId); - loader.setController(new PlayerCell(player)); + FXMLLoader loader = new FXMLLoader( + getClass().getResource("/views/cells/PlayerCell.fxml")); + + loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour())); try { pane = loader.load(); } catch (IOException e) { - // TODO replace with logger e.printStackTrace(); } playerListVBox.getChildren().add(pane); + } } @@ -207,6 +217,10 @@ public class LobbyController implements Initializable { this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr()); } + public void setBoats(Map boats) { + this.playerBoats = boats; + } + public void closeCustomizationDialog() { customizationDialog.close(); } diff --git a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java index b66ba0e6..db8e1cd4 100644 --- a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java +++ b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java @@ -1,12 +1,21 @@ package seng302.visualiser.controllers.cells; +import javafx.animation.AnimationTimer; import javafx.fxml.FXML; +import javafx.geometry.Point3D; +import javafx.scene.Group; import javafx.scene.control.Label; -import javafx.scene.effect.DropShadow; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Scale; +import javafx.scene.transform.Translate; import seng302.utilities.Sounds; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; +import seng302.visualiser.fxObjects.assets_3D.BoatModel; +import seng302.visualiser.fxObjects.assets_3D.ModelFactory; public class PlayerCell { @@ -15,19 +24,64 @@ public class PlayerCell { private Label playerName; @FXML private GridPane playerListCell; + @FXML + private Pane boatPane; //---------FXML END---------// private String name; + private Integer boatAngle; + private Color boatColor; + private Integer playerId; - public PlayerCell(String playerName) { + public PlayerCell(Integer playerId, String playerName, Color color) { + this.playerId = playerId; this.name = playerName; + this.boatColor = color; + this.boatAngle = -45; } public void initialize() { playerName.setText(name); + + Group group = new Group(); + boatPane.getChildren().add(group); + + BoatModel bo = ModelFactory.boatIconView(BoatMeshType.DINGHY, this.boatColor); + bo.showSail(); + bo.rotateSail(45); + bo.getAssets().getTransforms().setAll( + new Scale(4, 4, 4), + new Translate(12, 14, 0), + new Rotate(270, new Point3D(1, 0, 0)), + new Rotate(-45, new Point3D(0, 0, 1)) + ); + + bo.setAnimation(new AnimationTimer() { + Group group = bo.getAssets(); + + @Override + public void handle(long now) { + ((Rotate) group.getTransforms().get(3)).setAngle(boatAngle++); + } + }); + + group.getChildren().add(bo.getAssets()); + + } + + public Integer getPlayerId() { + return playerId; + } + + public String getPlayerName() { + return name; + } + + public Color getBoatColor() { + return boatColor; } public void playButtonHoverSound(MouseEvent mouseEvent) { Sounds.playHoverSound(); } -} +} \ No newline at end of file diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/Model.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/Model.java index 1434c9c3..25b86626 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/Model.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/Model.java @@ -19,7 +19,7 @@ public class Model { } } - void setAnimation(AnimationTimer animation) { + public void setAnimation(AnimationTimer animation) { animationTimer = animation; if (animation != null) { animation.start(); diff --git a/src/main/resources/css/cells/PlayerCell.css b/src/main/resources/css/cells/PlayerCell.css index 588fb31a..3da722e2 100644 --- a/src/main/resources/css/cells/PlayerCell.css +++ b/src/main/resources/css/cells/PlayerCell.css @@ -1,10 +1,10 @@ #playerName { - -fx-text-fill: -fx-pp-dark-text-color; + -fx-text-fill: -fx-pp-light-text-color; -fx-font-size: 18px; } #playerListCell { - -fx-background-color: -fx-pp-front-color; + -fx-background-color: skyblue; -fx-effect: -fx-pp-dropshadow-light; } diff --git a/src/main/resources/views/cells/PlayerCell.fxml b/src/main/resources/views/cells/PlayerCell.fxml index 821bb04a..1e2efdff 100644 --- a/src/main/resources/views/cells/PlayerCell.fxml +++ b/src/main/resources/views/cells/PlayerCell.fxml @@ -1,15 +1,16 @@ - - - - - - - + + + + + + + + + minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0" + xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"> @@ -18,17 +19,19 @@ - + + - + -