Everything works. Needs a bit of polish, and possibly look at boat shapes next.

tags: #story[1142]
This commit is contained in:
Alistair McIntyre
2017-08-16 20:38:11 +12:00
parent 02a7b804c1
commit 67f0c213c2
7 changed files with 61 additions and 18 deletions
@@ -60,6 +60,8 @@ public class GameState implements Runnable {
public static Double windDirection;
private static Double windSpeed;
private static Boolean customizationFlag;
private static String hostIpAddress;
private static List<Player> players;
private static Map<Integer, ServerYacht> yachts;
@@ -91,6 +93,7 @@ public class GameState implements Runnable {
yachts = new HashMap<>();
players = new ArrayList<>();
GameState.hostIpAddress = hostIpAddress;
customizationFlag = false;
currentStage = GameStages.LOBBYING;
isRaceStarted = false;
@@ -668,4 +671,16 @@ public class GameState implements Runnable {
public static void addMarkPassListener(NewMessageListener listener) {
markListeners.add(listener);
}
public static void setCustomizationFlag() {
customizationFlag = true;
}
public static Boolean getCustomizationFlag() {
return customizationFlag;
}
public static void resetCustomizationFlag() {
customizationFlag = false;
}
}
@@ -76,13 +76,13 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
} catch (InterruptedException e) {
serverLog("Interrupted exception in Main Server Thread thread sleep", 1);
}
if (GameState.getCurrentStage() == GameStages.LOBBYING) {
if (GameState.getCurrentStage() == GameStages.LOBBYING && GameState
.getCustomizationFlag()) {
// TODO: 16/08/17 ajm412: This can probably be done in a nicer way via those fancy functional interfaces.
for (ServerToClientThread thread : serverToClientThreads) {
thread.sendSetupMessages();
}
GameState.resetCustomizationFlag();
}
if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
@@ -211,7 +211,7 @@ public class ServerToClientThread implements Runnable, Observer {
new StreamPacket(type, payloadLength, timeStamp, payload));
GameState.customizePlayer(sourceID, requestType,
Arrays.copyOfRange(payload, 6, payload.length));
sendSetupMessages();
GameState.setCustomizationFlag();
break;
}
} else {
@@ -241,7 +241,7 @@ public class GameClient {
);
clientLobbyList.clear();
allBoatsMap.forEach((id, boat) ->
clientLobbyList.add(id + " " + boat.getBoatName())
clientLobbyList.add(boat.getBoatName())
);
break;
@@ -25,6 +25,8 @@ public class CustomizationController {
public void initialize() {
boatColorPicker.setValue(new Color(0.0, 0.0, 0.0, 1.0));
}
public void setServerThread(ClientToServerThread ctsThread) {
@@ -56,6 +58,9 @@ public class CustomizationController {
this.windowStage = stage;
}
public void setPlayerName(String name) {
this.nameField.setText(name);
}
}
@@ -149,9 +149,11 @@ public class LobbyController {
try {
FXMLLoader fxmlLoader = new FXMLLoader(LobbyController.class.getResource("/views/customizeView.fxml"));
root = fxmlLoader.load();
root.getStylesheets().add("/css/master.css");
Stage customizeStage = new Stage();
CustomizationController cc = fxmlLoader.getController();
cc.setServerThread(this.socketThread);
cc.setPlayerName(this.players.get(playerID - 1));
customizeStage.setTitle("Customize Boat");
customizeStage.setScene(new Scene(root, 700, 450));
cc.setStage(customizeStage); // pass the stage through so it can be closed later.
+34 -13
View File
@@ -1,25 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.CustomizationController">
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ColorPicker?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Text?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #2C2c36;"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="seng302.visualiser.controllers.CustomizationController">
<columnConstraints>
<ColumnConstraints fillWidth="false" halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints fillWidth="false" halignment="CENTER" hgrow="SOMETIMES"
maxWidth="1.7976931348623157E308" minWidth="1.0" percentWidth="10.0" prefWidth="1.0"/>
<ColumnConstraints fillWidth="false" halignment="CENTER" hgrow="SOMETIMES" maxWidth="299.0"
minWidth="10.0" percentWidth="30.0" prefWidth="299.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="299.0" minWidth="10.0" percentWidth="50.0"
prefWidth="154.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="123.0" minWidth="0.0" percentWidth="10.0"
prefWidth="122.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<TextField fx:id="nameField" GridPane.columnIndex="1" />
<ColorPicker fx:id="boatColorPicker" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Player Name" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Color" GridPane.rowIndex="1" />
<Button fx:id="customizeSubmit" mnemonicParsing="false" onAction="#submitCustomization" text="Submit" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
<TextField fx:id="nameField" maxWidth="200.0" minWidth="200.0" prefWidth="200.0"
GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1"
GridPane.valignment="CENTER"/>
<ColorPicker fx:id="boatColorPicker" prefWidth="200.0" style="-fx-background-color: eeeeee;"
GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2"
GridPane.valignment="CENTER"/>
<Text fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="Player Name"
GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Text fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Color"
GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Button fx:id="customizeSubmit" mnemonicParsing="false" onAction="#submitCustomization"
text="Submit" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3"
GridPane.valignment="CENTER"/>
</children>
</GridPane>