Added chat functionality & timer back into the game + bug fixes

- Added chat back into the game
- Fixed a bug where the timer would show "race finished" when the race hadn't started
- Fixed a bug where resources weren't being deallocated when the game was closed

Tags: #story[1246]
This commit is contained in:
Michael Rausch
2017-09-12 01:31:38 +12:00
parent d223d393fa
commit 5dd936f8f1
11 changed files with 166 additions and 68 deletions
@@ -110,11 +110,6 @@ public class MessageFactory {
public static XMLMessage getRegattaXML() { public static XMLMessage getRegattaXML() {
//@TODO calculate lat/lng values //@TODO calculate lat/lng values
xmlGenerator.setRegattaTemplate(
new RegattaXMLTemplate(
"Party Parrot Test Server", "Bermuda Test Course",
57.6679590, 11.8503233)
);
return new XMLMessage( return new XMLMessage(
xmlGenerator.getRegattaAsXml(), xmlGenerator.getRegattaAsXml(),
@@ -240,6 +240,8 @@ public class ServerToClientThread implements Runnable {
xmlGenerator.setRaceTemplate(race); xmlGenerator.setRaceTemplate(race);
System.out.println(xmlGenerator.getRegatta().getName());
XMLMessage xmlMessage; XMLMessage xmlMessage;
xmlMessage = new XMLMessage(xmlGenerator.getRegattaAsXml(), XMLMessageSubType.REGATTA, xmlMessage = new XMLMessage(xmlGenerator.getRegattaAsXml(), XMLMessageSubType.REGATTA,
xmlGenerator.getRegattaAsXml().length()); xmlGenerator.getRegattaAsXml().length());
@@ -46,7 +46,7 @@ public class XMLGenerator {
/** /**
* Create an instance of the XML Generator * Create an instance of the XML Generator
*/ */
public XMLGenerator(){ public XMLGenerator() {
setupConfiguration(); setupConfiguration();
} }
@@ -175,4 +175,8 @@ public class XMLGenerator {
public static void setDefaultMapName(String mapName){ public static void setDefaultMapName(String mapName){
DEFAULT_REGATTA.setCourseName(mapName); DEFAULT_REGATTA.setCourseName(mapName);
} }
public RegattaXMLTemplate getRegatta() {
return regatta;
}
} }
@@ -217,11 +217,7 @@ public class GameClient {
raceView = fxmlLoader.getController(); raceView = fxmlLoader.getController();
ClientYacht player = allBoatsMap.get(socketThread.getClientId()); ClientYacht player = allBoatsMap.get(socketThread.getClientId());
raceView.loadRace(allBoatsMap, courseData, raceState, player); raceView.loadRace(allBoatsMap, courseData, raceState, player);
raceView.getSendPressedProperty().addListener((obs, old, isPressed) -> {
if (isPressed) {
formatAndSendChatMessage(raceView.readChatInput());
}
});
} }
@@ -338,6 +334,12 @@ public class GameClient {
ClientYacht player = allBoatsMap.get(socketThread.getClientId()); ClientYacht player = allBoatsMap.get(socketThread.getClientId());
raceView.loadRace(allBoatsMap, courseData, raceState, player); raceView.loadRace(allBoatsMap, courseData, raceState, player);
raceView.getSendPressedProperty().addListener((obs, old, isPressed) -> {
if (isPressed) {
formatAndSendChatMessage(raceView.readChatInput());
}
});
} }
} }
@@ -1,5 +1,6 @@
package seng302.visualiser.controllers; package seng302.visualiser.controllers;
import com.jfoenix.controls.JFXButton;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.ReadOnlyBooleanProperty;
@@ -67,7 +68,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@FXML @FXML
private CheckBox toggleFps; private CheckBox toggleFps;
@FXML @FXML
private Text timerLabel; private Label timerLabel;
@FXML @FXML
private StackPane contentAnchorPane; private StackPane contentAnchorPane;
private GridPane contentGridPane; private GridPane contentGridPane;
@@ -133,27 +134,27 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
// windArrow.setLayoutY(windArrowHolder.getHeight() / 2); // windArrow.setLayoutY(windArrowHolder.getHeight() / 2);
// selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView()); // selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
// chatInput.lengthProperty().addListener((obs, oldLen, newLen) -> { chatInput.lengthProperty().addListener((obs, oldLen, newLen) -> {
// if (newLen.intValue() > CHAT_LIMIT) { if (newLen.intValue() > CHAT_LIMIT) {
// chatInput.setText(chatInput.getText().substring(0, CHAT_LIMIT)); chatInput.setText(chatInput.getText().substring(0, CHAT_LIMIT));
// } }
});
chatHistory = new ChatHistory();
chatHistoryHolder.getChildren().addAll(chatHistory);
chatHistory.prefWidthProperty().bind(
chatHistoryHolder.widthProperty()
);
chatHistory.prefHeightProperty().bind(
chatHistoryHolder.heightProperty()
);
// chatHistory.setFitToWidth(true);
// chatHistory.setFitToHeight(true);
// chatHistory.textProperty().addListener((obs, oldValue, newValue) -> {
// chatHistory.setScrollTop(Double.MAX_VALUE);
// }); // });
// chatHistory = new ChatHistory(); rvAnchorPane.setOnMouseClicked((event) ->
// chatHistoryHolder.getChildren().addAll(chatHistory); rvAnchorPane.requestFocus()
// chatHistory.prefWidthProperty().bind( );
// chatHistoryHolder.widthProperty()
// );
// chatHistory.prefHeightProperty().bind(
// chatHistoryHolder.heightProperty()
// );
//// chatHistory.setFitToWidth(true);
//// chatHistory.setFitToHeight(true);
//// chatHistory.textProperty().addListener((obs, oldValue, newValue) -> {
//// chatHistory.setScrollTop(Double.MAX_VALUE);
//// });
// contentGridPane.setOnMouseClicked((event) ->
// contentGridPane.requestFocus()
// );
} }
public void loadRace ( public void loadRace (
@@ -230,13 +231,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
// gameView.enableZoom(); // gameView.enableZoom();
// } // }
// }); // });
// Platform.runLater(() -> { Platform.runLater(() -> {
// initializeUpdateTimer(); initializeUpdateTimer();
// initialiseFPSCheckBox(); // initialiseFPSCheckBox();
// initialiseAnnotationSlider(); // initialiseAnnotationSlider();
// initialiseBoatSelectionComboBox(); // initialiseBoatSelectionComboBox();
// initialiseSparkLine(); // initialiseSparkLine();
// }); });
} }
/** /**
@@ -417,7 +418,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override
public void run() { public void run() {
updateRaceTime(); Platform.runLater(() -> updateRaceTime());
} }
}, 0, 1000); }, 0, 1000);
} }
@@ -473,12 +474,11 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* Updates the clock for the race * Updates the clock for the race
*/ */
private void updateRaceTime() { private void updateRaceTime() {
// if (!raceState.isRaceStarted()) { if (raceState.getTimeTillStart() <= 0L && !raceState.isRaceStarted()) {
// timerLabel.setFill(Color.RED); timerLabel.setText("Race Finished!");
// timerLabel.setText("Race Finished!"); } else {
// } else { timerLabel.setText(raceState.getRaceTimeStr());
// timerLabel.setText(raceState.getRaceTimeStr()); }
// }
} }
/** /**
@@ -719,7 +719,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
public String readChatInput() { public String readChatInput() {
String chat = chatInput.getText(); String chat = chatInput.getText();
chatInput.clear(); chatInput.clear();
basePane.requestFocus(); rvAnchorPane.requestFocus();
return chat; return chat;
} }
@@ -91,6 +91,17 @@ public class ViewManager {
Sounds.stopMusic(); Sounds.stopMusic();
Sounds.playMenuMusic(); Sounds.playMenuMusic();
decorator.setOnCloseButtonAction(() -> {
try {
ServerAdvertiser.getInstance().unregister();
} catch (IOException e) {
logger.warn("Couldn't unregister server");
}
gameClient.stopGame();
System.exit(0);
});
} }
private void checkCompatibility() { private void checkCompatibility() {
@@ -207,8 +218,14 @@ public class ViewManager {
} }
}); });
Sounds.stopMusic(); while (loader.getController() == null){
Sounds.playRaceMusic(); try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return loader.getController(); return loader.getController();
} }
@@ -246,7 +246,6 @@ public class BoatObject extends Group {
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1))); wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
if (sailsIn) { if (sailsIn) {
boatAssets.showSail(); boatAssets.showSail();
System.out.println("heading = " + heading);
Double sailWindOffset = 30.0; Double sailWindOffset = 30.0;
Double upwindAngleLimit = 15.0; Double upwindAngleLimit = 15.0;
Double downwindAngleLimit = 10.0; //Upwind from normalised horizontal Double downwindAngleLimit = 10.0; //Upwind from normalised horizontal
+16
View File
@@ -0,0 +1,16 @@
#timerGrid{
-fx-background-color: rgba(255, 255, 255, 0.6);
}
#timerLabel{
-fx-font-size: 21px;
-fx-font-family: "Baloo";
}
#chatArea{
-fx-background-color: rgba(255, 255, 255, 0.6);
}
#raceInfoArea{
-fx-background-color: rgba(255, 255, 255, 0.6);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

+84 -21
View File
@@ -1,46 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?> <?import java.lang.String?>
<?import java.lang.*?> <?import javafx.geometry.Insets?>
<?import javafx.scene.layout.*?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="rvAnchorPane" maxHeight="1.7976931348623157E308" <AnchorPane fx:id="rvAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.RaceViewController">
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="1200.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="seng302.visualiser.controllers.RaceViewController">
<children> <children>
<StackPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" <StackPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="800.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
maxWidth="1.7976931348623157E308" prefHeight="800.0" prefWidth="1200.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
</StackPane> </StackPane>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="218.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="415.0" minWidth="10.0" prefWidth="359.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="554.0" minWidth="10.0" prefWidth="371.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="454.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="539.0" minWidth="10.0" prefWidth="271.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="349.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="191.0" minHeight="0.0" prefHeight="18.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="63.0" minHeight="0.0" prefHeight="63.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="485.0" minHeight="10.0" prefHeight="467.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="704.0" minHeight="10.0" prefHeight="603.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="172.0" minHeight="10.0" prefHeight="134.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<GridPane style="-fx-b: rgba(255,255,255,0.5);"> <GridPane id="timerGrid" fx:id="timerGrid" prefWidth="192.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="93.0" minWidth="10.0" prefWidth="47.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="161.0" minWidth="10.0" prefWidth="58.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="160.0" minWidth="10.0" prefWidth="151.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="288.0" minWidth="10.0" prefWidth="104.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<opaqueInsets>
<Insets />
</opaqueInsets>
<GridPane.margin>
<Insets left="10.0" right="200.0" top="10.0" />
</GridPane.margin>
<children>
<ImageView fitHeight="40.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<image>
<Image url="@../images/timer.png" />
</image>
<GridPane.margin> <GridPane.margin>
<Insets /> <Insets />
</GridPane.margin> </GridPane.margin>
</ImageView>
<Label fx:id="timerLabel" text="00:03:34" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font size="21.0" />
</font>
<GridPane.margin>
<Insets />
</GridPane.margin>
</Label>
</children>
</GridPane>
<GridPane GridPane.columnIndex="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
<GridPane id="chatArea" GridPane.columnIndex="2" GridPane.rowIndex="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="100.0" minHeight="10.0" prefHeight="100.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="62.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Pane fx:id="chatHistoryHolder" prefHeight="200.0" prefWidth="200.0" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS" />
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="288.0" minWidth="10.0" prefWidth="279.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="175.0" minWidth="10.0" prefWidth="82.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TextField fx:id="chatInput" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS" />
<Button fx:id="chatSend" mnemonicParsing="false" prefHeight="25.0" prefWidth="72.0" text="Send" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
</children>
</GridPane>
</children>
</GridPane> </GridPane>
</children> </children>
</GridPane> </GridPane>
</children> </children>
<stylesheets>
<String fx:value="/css/master.css" />
<String fx:value="/css/raceView.css" />
</stylesheets>
</AnchorPane> </AnchorPane>