From 6e02d3e5334cd1adf5d904cfc534b2beaa19c871 Mon Sep 17 00:00:00 2001 From: alistairjmcintyre Date: Thu, 17 Aug 2017 01:20:16 +1200 Subject: [PATCH] Added some general UI improvements such as autofilling the color field of the form, and looked at how best to deal with response packets, as it should be part of the spec. tags: #story[1142] --- .../seng302/gameServer/ServerToClientThread.java | 3 +-- src/main/java/seng302/model/ClientYacht.java | 1 + src/main/java/seng302/model/Colors.java | 9 ++------- src/main/java/seng302/model/ServerYacht.java | 2 +- .../controllers/CustomizationController.java | 12 ++++++++++-- .../visualiser/controllers/LobbyController.java | 16 ++++++++++++++++ src/test/java/seng302/ColorsTest.java | 2 +- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/seng302/gameServer/ServerToClientThread.java b/src/main/java/seng302/gameServer/ServerToClientThread.java index 6686a767..5896b6b9 100644 --- a/src/main/java/seng302/gameServer/ServerToClientThread.java +++ b/src/main/java/seng302/gameServer/ServerToClientThread.java @@ -186,7 +186,6 @@ public class ServerToClientThread implements Runnable, Observer { long computedCrc = checksum.getValue(); long packetCrc = Message.bytesToLong(getBytes(4)); if (computedCrc == packetCrc) { - //System.out.println("RECEIVED A PACKET"); switch (PacketType.assignPacketType(type, payload)) { case BOAT_ACTION: BoatAction actionType = ServerPacketParser @@ -203,7 +202,6 @@ public class ServerToClientThread implements Runnable, Observer { break; case RACE_CUSTOMIZATION_REQUEST: - System.out.println("CUSTOMIZATION RECEIVED"); Long sourceID = Message .bytesToLong(Arrays.copyOfRange(payload, 0, 3)); CustomizeRequestType requestType = ServerPacketParser @@ -212,6 +210,7 @@ public class ServerToClientThread implements Runnable, Observer { GameState.customizePlayer(sourceID, requestType, Arrays.copyOfRange(payload, 6, payload.length)); GameState.setCustomizationFlag(); + //// TODO: 17/08/2017 ajm412: Send a response packet here. break; } } else { diff --git a/src/main/java/seng302/model/ClientYacht.java b/src/main/java/seng302/model/ClientYacht.java index 564754b0..709345bb 100644 --- a/src/main/java/seng302/model/ClientYacht.java +++ b/src/main/java/seng302/model/ClientYacht.java @@ -71,6 +71,7 @@ public class ClientYacht extends Observable { this.heading = 120.0; //In degrees this.currentVelocity = 0d; this.boatStatus = 1; + this.colour = Color.rgb(0, 0, 0, 1.0); } /** diff --git a/src/main/java/seng302/model/Colors.java b/src/main/java/seng302/model/Colors.java index 81829262..c3afef90 100644 --- a/src/main/java/seng302/model/Colors.java +++ b/src/main/java/seng302/model/Colors.java @@ -8,12 +8,7 @@ import javafx.scene.paint.Color; public enum Colors { RED, PERU, GOLD, GREEN, BLUE, PURPLE, DEEPPINK, GRAY; - static Integer index = 0; - - public static Color getColor() { - if (index == 8) { - index = 0; - } - return Color.valueOf(values()[index++].toString()); + public static Color getColor(Integer index) { + return Color.valueOf(values()[index].toString()); } } diff --git a/src/main/java/seng302/model/ServerYacht.java b/src/main/java/seng302/model/ServerYacht.java index e8b2b1e7..755f9946 100644 --- a/src/main/java/seng302/model/ServerYacht.java +++ b/src/main/java/seng302/model/ServerYacht.java @@ -68,7 +68,7 @@ public class ServerYacht extends Observable { this.heading = 120.0; //In degrees this.currentVelocity = 0d; //in mms-1 this.currentMarkSeqID = 0; - this.boatColor = Color.rgb(0, 0, 0); + this.boatColor = Colors.getColor(sourceId - 1); this.hasEnteredRoundingZone = false; this.hasPassedLine = false; diff --git a/src/main/java/seng302/visualiser/controllers/CustomizationController.java b/src/main/java/seng302/visualiser/controllers/CustomizationController.java index fc00f2a0..ea8db318 100644 --- a/src/main/java/seng302/visualiser/controllers/CustomizationController.java +++ b/src/main/java/seng302/visualiser/controllers/CustomizationController.java @@ -20,13 +20,12 @@ public class CustomizationController { @FXML private Button customizeSubmit; + private LobbyController lc; private ClientToServerThread socketThread; private Stage windowStage; public void initialize() { - boatColorPicker.setValue(new Color(0.0, 0.0, 0.0, 1.0)); - } public void setServerThread(ClientToServerThread ctsThread) { @@ -51,9 +50,14 @@ public class CustomizationController { colorArray[2] = (byte) blue; socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray); + lc.setPlayersColor(color); windowStage.close(); } + public void setLobbyController(LobbyController lc) { + this.lc = lc; + } + public void setStage(Stage stage) { this.windowStage = stage; } @@ -62,5 +66,9 @@ public class CustomizationController { this.nameField.setText(name); } + public void setPlayerColor(Color playerColor) { + this.boatColorPicker.setValue(playerColor); + } + } diff --git a/src/main/java/seng302/visualiser/controllers/LobbyController.java b/src/main/java/seng302/visualiser/controllers/LobbyController.java index fd3e272a..88d29062 100644 --- a/src/main/java/seng302/visualiser/controllers/LobbyController.java +++ b/src/main/java/seng302/visualiser/controllers/LobbyController.java @@ -16,10 +16,12 @@ import javafx.scene.control.Button; import javafx.scene.control.TextArea; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; import seng302.gameServer.GameStages; import seng302.gameServer.GameState; +import seng302.model.Colors; import seng302.model.RaceState; import seng302.visualiser.ClientToServerThread; @@ -86,6 +88,8 @@ public class LobbyController { private ClientToServerThread socketThread; + private Color playersColor; + private int MAX_NUM_PLAYERS = 8; private Integer playerID; @@ -154,9 +158,16 @@ public class LobbyController { CustomizationController cc = fxmlLoader.getController(); cc.setServerThread(this.socketThread); cc.setPlayerName(this.players.get(playerID - 1)); + + if (this.playersColor == null) { + this.playersColor = Colors.getColor(playerID - 1); + } + + cc.setPlayerColor(this.playersColor); customizeStage.setTitle("Customize Boat"); customizeStage.setScene(new Scene(root, 700, 450)); cc.setStage(customizeStage); // pass the stage through so it can be closed later. + cc.setLobbyController(this); customizeStage.show(); } catch (IOException e) { Logger.logMsg(4, "Failed to load Customization View from resources."); @@ -218,4 +229,9 @@ public class LobbyController { readyButton.setDisable(true); readyButton.setVisible(false); } + + public void setPlayersColor(Color playerColor) { + this.playersColor = playerColor; + } + } diff --git a/src/test/java/seng302/ColorsTest.java b/src/test/java/seng302/ColorsTest.java index 0b4b4238..389d3ede 100644 --- a/src/test/java/seng302/ColorsTest.java +++ b/src/test/java/seng302/ColorsTest.java @@ -12,7 +12,7 @@ public class ColorsTest { Color expectedColors[] = {Color.RED, Color.PERU, Color.GOLD, Color.GREEN, Color.BLUE, Color.PURPLE, Color.DEEPPINK, Color.GRAY}; for (int i = 0; i < 8; i++) { - Assert.assertEquals(expectedColors[i], Colors.getColor()); + Assert.assertEquals(expectedColors[i], Colors.getColor(i)); } } }