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]
This commit is contained in:
alistairjmcintyre
2017-08-17 01:20:16 +12:00
parent 67f0c213c2
commit 6e02d3e533
7 changed files with 32 additions and 13 deletions
@@ -186,7 +186,6 @@ public class ServerToClientThread implements Runnable, Observer {
long computedCrc = checksum.getValue(); long computedCrc = checksum.getValue();
long packetCrc = Message.bytesToLong(getBytes(4)); long packetCrc = Message.bytesToLong(getBytes(4));
if (computedCrc == packetCrc) { if (computedCrc == packetCrc) {
//System.out.println("RECEIVED A PACKET");
switch (PacketType.assignPacketType(type, payload)) { switch (PacketType.assignPacketType(type, payload)) {
case BOAT_ACTION: case BOAT_ACTION:
BoatAction actionType = ServerPacketParser BoatAction actionType = ServerPacketParser
@@ -203,7 +202,6 @@ public class ServerToClientThread implements Runnable, Observer {
break; break;
case RACE_CUSTOMIZATION_REQUEST: case RACE_CUSTOMIZATION_REQUEST:
System.out.println("CUSTOMIZATION RECEIVED");
Long sourceID = Message Long sourceID = Message
.bytesToLong(Arrays.copyOfRange(payload, 0, 3)); .bytesToLong(Arrays.copyOfRange(payload, 0, 3));
CustomizeRequestType requestType = ServerPacketParser CustomizeRequestType requestType = ServerPacketParser
@@ -212,6 +210,7 @@ public class ServerToClientThread implements Runnable, Observer {
GameState.customizePlayer(sourceID, requestType, GameState.customizePlayer(sourceID, requestType,
Arrays.copyOfRange(payload, 6, payload.length)); Arrays.copyOfRange(payload, 6, payload.length));
GameState.setCustomizationFlag(); GameState.setCustomizationFlag();
//// TODO: 17/08/2017 ajm412: Send a response packet here.
break; break;
} }
} else { } else {
@@ -71,6 +71,7 @@ public class ClientYacht extends Observable {
this.heading = 120.0; //In degrees this.heading = 120.0; //In degrees
this.currentVelocity = 0d; this.currentVelocity = 0d;
this.boatStatus = 1; this.boatStatus = 1;
this.colour = Color.rgb(0, 0, 0, 1.0);
} }
/** /**
+2 -7
View File
@@ -8,12 +8,7 @@ import javafx.scene.paint.Color;
public enum Colors { public enum Colors {
RED, PERU, GOLD, GREEN, BLUE, PURPLE, DEEPPINK, GRAY; RED, PERU, GOLD, GREEN, BLUE, PURPLE, DEEPPINK, GRAY;
static Integer index = 0; public static Color getColor(Integer index) {
return Color.valueOf(values()[index].toString());
public static Color getColor() {
if (index == 8) {
index = 0;
}
return Color.valueOf(values()[index++].toString());
} }
} }
+1 -1
View File
@@ -68,7 +68,7 @@ public class ServerYacht extends Observable {
this.heading = 120.0; //In degrees this.heading = 120.0; //In degrees
this.currentVelocity = 0d; //in mms-1 this.currentVelocity = 0d; //in mms-1
this.currentMarkSeqID = 0; this.currentMarkSeqID = 0;
this.boatColor = Color.rgb(0, 0, 0); this.boatColor = Colors.getColor(sourceId - 1);
this.hasEnteredRoundingZone = false; this.hasEnteredRoundingZone = false;
this.hasPassedLine = false; this.hasPassedLine = false;
@@ -20,13 +20,12 @@ public class CustomizationController {
@FXML @FXML
private Button customizeSubmit; private Button customizeSubmit;
private LobbyController lc;
private ClientToServerThread socketThread; private ClientToServerThread socketThread;
private Stage windowStage; private Stage windowStage;
public void initialize() { public void initialize() {
boatColorPicker.setValue(new Color(0.0, 0.0, 0.0, 1.0));
} }
public void setServerThread(ClientToServerThread ctsThread) { public void setServerThread(ClientToServerThread ctsThread) {
@@ -51,9 +50,14 @@ public class CustomizationController {
colorArray[2] = (byte) blue; colorArray[2] = (byte) blue;
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray); socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
lc.setPlayersColor(color);
windowStage.close(); windowStage.close();
} }
public void setLobbyController(LobbyController lc) {
this.lc = lc;
}
public void setStage(Stage stage) { public void setStage(Stage stage) {
this.windowStage = stage; this.windowStage = stage;
} }
@@ -62,5 +66,9 @@ public class CustomizationController {
this.nameField.setText(name); this.nameField.setText(name);
} }
public void setPlayerColor(Color playerColor) {
this.boatColorPicker.setValue(playerColor);
}
} }
@@ -16,10 +16,12 @@ import javafx.scene.control.Button;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng302.gameServer.GameStages; import seng302.gameServer.GameStages;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.model.Colors;
import seng302.model.RaceState; import seng302.model.RaceState;
import seng302.visualiser.ClientToServerThread; import seng302.visualiser.ClientToServerThread;
@@ -86,6 +88,8 @@ public class LobbyController {
private ClientToServerThread socketThread; private ClientToServerThread socketThread;
private Color playersColor;
private int MAX_NUM_PLAYERS = 8; private int MAX_NUM_PLAYERS = 8;
private Integer playerID; private Integer playerID;
@@ -154,9 +158,16 @@ public class LobbyController {
CustomizationController cc = fxmlLoader.getController(); CustomizationController cc = fxmlLoader.getController();
cc.setServerThread(this.socketThread); cc.setServerThread(this.socketThread);
cc.setPlayerName(this.players.get(playerID - 1)); 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.setTitle("Customize Boat");
customizeStage.setScene(new Scene(root, 700, 450)); customizeStage.setScene(new Scene(root, 700, 450));
cc.setStage(customizeStage); // pass the stage through so it can be closed later. cc.setStage(customizeStage); // pass the stage through so it can be closed later.
cc.setLobbyController(this);
customizeStage.show(); customizeStage.show();
} catch (IOException e) { } catch (IOException e) {
Logger.logMsg(4, "Failed to load Customization View from resources."); Logger.logMsg(4, "Failed to load Customization View from resources.");
@@ -218,4 +229,9 @@ public class LobbyController {
readyButton.setDisable(true); readyButton.setDisable(true);
readyButton.setVisible(false); readyButton.setVisible(false);
} }
public void setPlayersColor(Color playerColor) {
this.playersColor = playerColor;
}
} }
+1 -1
View File
@@ -12,7 +12,7 @@ public class ColorsTest {
Color expectedColors[] = {Color.RED, Color.PERU, Color.GOLD, Color.GREEN, Color.BLUE, Color expectedColors[] = {Color.RED, Color.PERU, Color.GOLD, Color.GREEN, Color.BLUE,
Color.PURPLE, Color.DEEPPINK, Color.GRAY}; Color.PURPLE, Color.DEEPPINK, Color.GRAY};
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
Assert.assertEquals(expectedColors[i], Colors.getColor()); Assert.assertEquals(expectedColors[i], Colors.getColor(i));
} }
} }
} }