From 307e79ecfc149cf0b3396c06bda29957e541ade0 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Wed, 20 Sep 2017 20:46:23 +1200 Subject: [PATCH] Completed working boat selection screen. When a user selects a different boat, it is sent to all other clients and updates accordingly. Boats are all shown with their correct models in game. #story[1274] --- src/main/java/seng302/model/ServerYacht.java | 4 ++ .../java/seng302/utilities/XMLParser.java | 4 +- .../java/seng302/visualiser/GameView3D.java | 3 +- .../controllers/LobbyController.java | 5 ++- .../visualiser/controllers/ViewManager.java | 2 + .../controllers/cells/PlayerCell.java | 6 ++- .../dialogs/BoatCustomizeController.java | 21 ++++++++-- .../fxObjects/assets_3D/BoatMeshType.java | 38 +++++++++++++++++++ .../fxObjects/assets_3D/BoatObject.java | 6 +-- .../fxObjects/assets_3D/ModelFactory.java | 5 ++- .../server_config/xml_templates/boats.ftlh | 2 +- .../seng302/utilities/BoatMeshTypeTest.java | 35 +++++++++++++++++ 12 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 src/test/java/seng302/utilities/BoatMeshTypeTest.java diff --git a/src/main/java/seng302/model/ServerYacht.java b/src/main/java/seng302/model/ServerYacht.java index da5aa37b..80566afd 100644 --- a/src/main/java/seng302/model/ServerYacht.java +++ b/src/main/java/seng302/model/ServerYacht.java @@ -424,4 +424,8 @@ public class ServerYacht { public void setBoatType(String boatType) { this.boatType = boatType; } + + public String getBoatType() { + return boatType; + } } diff --git a/src/main/java/seng302/utilities/XMLParser.java b/src/main/java/seng302/utilities/XMLParser.java index a903daaf..7a8bbac4 100644 --- a/src/main/java/seng302/utilities/XMLParser.java +++ b/src/main/java/seng302/utilities/XMLParser.java @@ -146,9 +146,7 @@ public class XMLParser { XMLParser.getNodeAttributeString(currentBoat, "BoatName"), XMLParser.getNodeAttributeString(currentBoat, "Country")); yacht.setColour(Color.web(getNodeAttributeString(currentBoat, "Color"))); - if (yacht.getBoatType().equals("Yacht")) { - competingBoats.put(yacht.getSourceId(), yacht); - } + competingBoats.put(yacht.getSourceId(), yacht); } } return competingBoats; diff --git a/src/main/java/seng302/visualiser/GameView3D.java b/src/main/java/seng302/visualiser/GameView3D.java index c5b52286..8cc6bb9b 100644 --- a/src/main/java/seng302/visualiser/GameView3D.java +++ b/src/main/java/seng302/visualiser/GameView3D.java @@ -30,6 +30,7 @@ import seng302.model.token.Token; import seng302.utilities.GeoUtility; import seng302.utilities.Sounds; import seng302.visualiser.fxObjects.MarkArrowFactory; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import seng302.visualiser.fxObjects.assets_3D.BoatObject; import seng302.visualiser.fxObjects.assets_3D.Marker3D; import seng302.visualiser.fxObjects.assets_3D.ModelFactory; @@ -459,7 +460,7 @@ public class GameView3D { final List wakes = new ArrayList<>(); for (ClientYacht clientYacht : yachts) { Color colour = clientYacht.getColour(); - newBoat = new BoatObject(); + newBoat = new BoatObject(BoatMeshType.getBoatMeshType(clientYacht.getBoatType())); newBoat.setFill(colour); boatObjects.put(clientYacht, newBoat); wakesGroup.getChildren().add(newBoat.getWake()); diff --git a/src/main/java/seng302/visualiser/controllers/LobbyController.java b/src/main/java/seng302/visualiser/controllers/LobbyController.java index a292fc8a..03af2d3a 100644 --- a/src/main/java/seng302/visualiser/controllers/LobbyController.java +++ b/src/main/java/seng302/visualiser/controllers/LobbyController.java @@ -130,7 +130,8 @@ public class LobbyController implements Initializable { controller.setPlayerName(this.playerBoats .get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) .getBoatName()); - controller.setCurrentBoat(BoatMeshType.DINGHY); + controller.setCurrentBoat(this.playerBoats.get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) + .getBoatType()); return customizationDialog; } @@ -204,7 +205,7 @@ public class LobbyController implements Initializable { FXMLLoader loader = new FXMLLoader( getClass().getResource("/views/cells/PlayerCell.fxml")); - loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour())); + loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour(), yacht.getBoatType())); try { pane = loader.load(); diff --git a/src/main/java/seng302/visualiser/controllers/ViewManager.java b/src/main/java/seng302/visualiser/controllers/ViewManager.java index 165d0c39..8e966813 100644 --- a/src/main/java/seng302/visualiser/controllers/ViewManager.java +++ b/src/main/java/seng302/visualiser/controllers/ViewManager.java @@ -278,6 +278,8 @@ public class ViewManager { stage.setMinHeight(500); stage.setMinWidth(800); + stage.setTitle("Party Parrots At Sea"); + stage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png"))); stage.setOnCloseRequest(e -> closeAll()); stage.setScene(scene); stage.show(); diff --git a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java index a8051f44..3f434a7f 100644 --- a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java +++ b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java @@ -24,11 +24,13 @@ public class PlayerCell { private String name; private Color boatColor; private Integer playerId; + private BoatMeshType boatype; - public PlayerCell(Integer playerId, String playerName, Color color) { + public PlayerCell(Integer playerId, String playerName, Color color, String boatType) { this.playerId = playerId; this.name = playerName; this.boatColor = color; + this.boatype = BoatMeshType.getBoatMeshType(boatType); } public void initialize() { @@ -37,7 +39,7 @@ public class PlayerCell { // Add Rotating Boat to Player Cell with players color on it. Group group = new Group(); boatPane.getChildren().add(group); - BoatModel bo = ModelFactory.boatIconView(BoatMeshType.PIRATE_SHIP, this.boatColor); + BoatModel bo = ModelFactory.boatIconView(this.boatype, this.boatColor); group.getChildren().add(bo.getAssets()); } diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java index 5690dc35..a418fe41 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java @@ -11,6 +11,7 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.scene.Group; +import javafx.scene.PointLight; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.CornerRadii; @@ -111,21 +112,35 @@ public class BoatCustomizeController implements Initializable{ this.lobbyController = lobbyController; } - public void setCurrentBoat(BoatMeshType boatType) { + public void setCurrentBoat(String boatType) { Group group = new Group(); - this.currentBoat = boatType; + this.currentBoat = BoatMeshType.getBoatMeshType(boatType); System.out.println(boatType.toString()); boatPane.setBackground(new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY))); boatPane.getChildren().add(group); - BoatModel bo = ModelFactory.boatCustomiseView(boatType, colorPicker.getValue()); + BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); group.getChildren().add(bo.getAssets()); + group.getChildren().add(new PointLight()); } public void nextBoat(ActionEvent actionEvent) { boatPane.getChildren().clear(); + Group group = new Group(); + boatPane.getChildren().add(group); + currentBoat = BoatMeshType.getNextBoatType(currentBoat); + BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); + group.getChildren().add(bo.getAssets()); + group.getChildren().add(new PointLight()); } public void prevBoat(ActionEvent actionEvent) { + boatPane.getChildren().clear(); + Group group = new Group(); + boatPane.getChildren().add(group); + currentBoat = BoatMeshType.getPrevBoatType(currentBoat); + BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); + group.getChildren().add(bo.getAssets()); + group.getChildren().add(new PointLight()); } private void RefreshBoat() { diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java index 290916a5..947a63f5 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java @@ -16,6 +16,7 @@ public enum BoatMeshType { final String hullFile, mastFile, sailFile, jibFile; final double mastOffset, sailOffset; final boolean fixedSail; + final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CAT_ATE_A_MERINGUE, PIRATE_SHIP}; BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, double sailOffset, String jibFile, boolean fixedSail) { @@ -27,4 +28,41 @@ public enum BoatMeshType { this.jibFile = jibFile; this.fixedSail = fixedSail; } + + public static BoatMeshType getBoatMeshType(String boatType) { + switch (boatType){ + case "DINGHY": + return DINGHY; + case "CAT_ATE_A_MERINGUE": + return CAT_ATE_A_MERINGUE; + case "PIRATE_SHIP": + return PIRATE_SHIP; + default: + return DINGHY; + } + } + + + //TODO kre39 make something not terrible to cycle through boat types + public static BoatMeshType getNextBoatType(BoatMeshType boatType) { + for (int i = 0; i < boatTypes.length; i++) { + if (i == boatTypes.length -1) { + return boatTypes[0]; + } else if (boatType == boatTypes[i]) { + return boatTypes[i+1]; + } + } + return boatType; + } + + public static BoatMeshType getPrevBoatType(BoatMeshType boatType) { + for (int i = 0; i < boatTypes.length; i++) { + if (i == 0 && boatType == boatTypes[i]) { + return boatTypes[boatTypes.length -1]; + } else if (boatType == boatTypes[i]) { + return boatTypes[i-1]; + } + } + return boatType; + } } diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java index 596a1401..abf969a8 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java @@ -11,7 +11,7 @@ import javafx.scene.transform.Rotate; /** * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 * dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path, - * a wake object and two text labels to annotate the boat teams name and the boats velocity. The + * a wake object and two text labels to annotate the boat teams name and the boatTypes velocity. The * boat will update it's position onscreen everytime UpdatePosition is called unless the window is * minimized in which case it attempts to store animations and apply them when the window is * maximised. @@ -35,8 +35,8 @@ public class BoatObject extends Group { /** * Creates a BoatGroup with the default triangular boat polygon. */ - public BoatObject() { - boatAssets = ModelFactory.boatGameView(BoatMeshType.PIRATE_SHIP, colour); + public BoatObject(BoatMeshType boatMeshType) { + boatAssets = ModelFactory.boatGameView(boatMeshType, colour); boatAssets.hideSail(); boatAssets.getAssets().getTransforms().addAll( rotation diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java index 502fa3c4..91f832ad 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java @@ -7,6 +7,7 @@ import javafx.geometry.Point3D; import javafx.scene.AmbientLight; import javafx.scene.CacheHint; import javafx.scene.Group; +import javafx.scene.PointLight; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Circle; @@ -18,7 +19,7 @@ import javafx.scene.transform.Translate; /** - * Factory class for creating 3D models of boats. + * Factory class for creating 3D models of boatTypes. */ public class ModelFactory { @@ -57,7 +58,7 @@ public class ModelFactory { boatAssets.getTransforms().addAll( new Scale(8.0, 8.0, 8.0), new Rotate(-70, new Point3D(1,0,0)), - new Translate(16,50, 0), + new Translate(16,50, 1), animationRotate ); diff --git a/src/main/resources/server_config/xml_templates/boats.ftlh b/src/main/resources/server_config/xml_templates/boats.ftlh index 8186e000..26fae383 100644 --- a/src/main/resources/server_config/xml_templates/boats.ftlh +++ b/src/main/resources/server_config/xml_templates/boats.ftlh @@ -12,7 +12,7 @@ <#list boats as boat> - diff --git a/src/test/java/seng302/utilities/BoatMeshTypeTest.java b/src/test/java/seng302/utilities/BoatMeshTypeTest.java new file mode 100644 index 00000000..baca1b14 --- /dev/null +++ b/src/test/java/seng302/utilities/BoatMeshTypeTest.java @@ -0,0 +1,35 @@ +package seng302.utilities; + +import org.junit.Assert; +import org.junit.Test; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; + +/** + * Basic tests for the next and previous methods + * Created by kre39 on 20/09/17. + */ +public class BoatMeshTypeTest { + + + @Test + public void testNextBoatMeshType() { + BoatMeshType currentBoat = BoatMeshType.DINGHY; + BoatMeshType nextBoat = BoatMeshType.getNextBoatType(currentBoat); + Assert.assertEquals(BoatMeshType.CAT_ATE_A_MERINGUE, nextBoat); + } + + @Test + public void testPreviousBoatMeshType() { + BoatMeshType currentBoat = BoatMeshType.CAT_ATE_A_MERINGUE; + BoatMeshType prevBoat = BoatMeshType.getPrevBoatType(currentBoat); + Assert.assertEquals(BoatMeshType.DINGHY, prevBoat); + } + + @Test + public void testGetBoatMeshType() { + BoatMeshType currentBoat = BoatMeshType.getBoatMeshType("DINGHY"); + Assert.assertEquals(BoatMeshType.DINGHY, currentBoat); + BoatMeshType wrongBoat = BoatMeshType.getBoatMeshType("NOT A REAL BOAT"); + Assert.assertEquals(BoatMeshType.DINGHY, wrongBoat); + } +}