mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
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:
@@ -110,11 +110,6 @@ public class MessageFactory {
|
||||
|
||||
public static XMLMessage getRegattaXML() {
|
||||
//@TODO calculate lat/lng values
|
||||
xmlGenerator.setRegattaTemplate(
|
||||
new RegattaXMLTemplate(
|
||||
"Party Parrot Test Server", "Bermuda Test Course",
|
||||
57.6679590, 11.8503233)
|
||||
);
|
||||
|
||||
return new XMLMessage(
|
||||
xmlGenerator.getRegattaAsXml(),
|
||||
|
||||
@@ -240,6 +240,8 @@ public class ServerToClientThread implements Runnable {
|
||||
|
||||
xmlGenerator.setRaceTemplate(race);
|
||||
|
||||
System.out.println(xmlGenerator.getRegatta().getName());
|
||||
|
||||
XMLMessage xmlMessage;
|
||||
xmlMessage = new XMLMessage(xmlGenerator.getRegattaAsXml(), XMLMessageSubType.REGATTA,
|
||||
xmlGenerator.getRegattaAsXml().length());
|
||||
|
||||
@@ -46,7 +46,7 @@ public class XMLGenerator {
|
||||
/**
|
||||
* Create an instance of the XML Generator
|
||||
*/
|
||||
public XMLGenerator(){
|
||||
public XMLGenerator() {
|
||||
setupConfiguration();
|
||||
}
|
||||
|
||||
@@ -175,4 +175,8 @@ public class XMLGenerator {
|
||||
public static void setDefaultMapName(String mapName){
|
||||
DEFAULT_REGATTA.setCourseName(mapName);
|
||||
}
|
||||
|
||||
public RegattaXMLTemplate getRegatta() {
|
||||
return regatta;
|
||||
}
|
||||
}
|
||||
@@ -217,11 +217,7 @@ public class GameClient {
|
||||
raceView = fxmlLoader.getController();
|
||||
ClientYacht player = allBoatsMap.get(socketThread.getClientId());
|
||||
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());
|
||||
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;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
@@ -67,7 +68,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
@FXML
|
||||
private CheckBox toggleFps;
|
||||
@FXML
|
||||
private Text timerLabel;
|
||||
private Label timerLabel;
|
||||
@FXML
|
||||
private StackPane contentAnchorPane;
|
||||
private GridPane contentGridPane;
|
||||
@@ -133,27 +134,27 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
// windArrow.setLayoutY(windArrowHolder.getHeight() / 2);
|
||||
|
||||
// selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
|
||||
// chatInput.lengthProperty().addListener((obs, oldLen, newLen) -> {
|
||||
// if (newLen.intValue() > CHAT_LIMIT) {
|
||||
// chatInput.setText(chatInput.getText().substring(0, CHAT_LIMIT));
|
||||
// }
|
||||
chatInput.lengthProperty().addListener((obs, oldLen, newLen) -> {
|
||||
if (newLen.intValue() > 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();
|
||||
// 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);
|
||||
//// });
|
||||
// contentGridPane.setOnMouseClicked((event) ->
|
||||
// contentGridPane.requestFocus()
|
||||
// );
|
||||
rvAnchorPane.setOnMouseClicked((event) ->
|
||||
rvAnchorPane.requestFocus()
|
||||
);
|
||||
}
|
||||
|
||||
public void loadRace (
|
||||
@@ -230,13 +231,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
// gameView.enableZoom();
|
||||
// }
|
||||
// });
|
||||
// Platform.runLater(() -> {
|
||||
// initializeUpdateTimer();
|
||||
Platform.runLater(() -> {
|
||||
initializeUpdateTimer();
|
||||
// initialiseFPSCheckBox();
|
||||
// initialiseAnnotationSlider();
|
||||
// initialiseBoatSelectionComboBox();
|
||||
// initialiseSparkLine();
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,7 +418,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateRaceTime();
|
||||
Platform.runLater(() -> updateRaceTime());
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
@@ -473,12 +474,11 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
* Updates the clock for the race
|
||||
*/
|
||||
private void updateRaceTime() {
|
||||
// if (!raceState.isRaceStarted()) {
|
||||
// timerLabel.setFill(Color.RED);
|
||||
// timerLabel.setText("Race Finished!");
|
||||
// } else {
|
||||
// timerLabel.setText(raceState.getRaceTimeStr());
|
||||
// }
|
||||
if (raceState.getTimeTillStart() <= 0L && !raceState.isRaceStarted()) {
|
||||
timerLabel.setText("Race Finished!");
|
||||
} else {
|
||||
timerLabel.setText(raceState.getRaceTimeStr());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -719,7 +719,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
public String readChatInput() {
|
||||
String chat = chatInput.getText();
|
||||
chatInput.clear();
|
||||
basePane.requestFocus();
|
||||
rvAnchorPane.requestFocus();
|
||||
return chat;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,17 @@ public class ViewManager {
|
||||
|
||||
Sounds.stopMusic();
|
||||
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() {
|
||||
@@ -207,8 +218,14 @@ public class ViewManager {
|
||||
}
|
||||
});
|
||||
|
||||
Sounds.stopMusic();
|
||||
Sounds.playRaceMusic();
|
||||
while (loader.getController() == null){
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,6 @@ public class BoatObject extends Group {
|
||||
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
|
||||
if (sailsIn) {
|
||||
boatAssets.showSail();
|
||||
System.out.println("heading = " + heading);
|
||||
Double sailWindOffset = 30.0;
|
||||
Double upwindAngleLimit = 15.0;
|
||||
Double downwindAngleLimit = 10.0; //Upwind from normalised horizontal
|
||||
|
||||
@@ -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 |
@@ -1,46 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import java.lang.String?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?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"
|
||||
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">
|
||||
<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">
|
||||
<children>
|
||||
<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">
|
||||
<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">
|
||||
|
||||
</StackPane>
|
||||
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="218.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="554.0" minWidth="10.0" prefWidth="371.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="539.0" minWidth="10.0" prefWidth="271.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="415.0" minWidth="10.0" prefWidth="359.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="454.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="349.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="191.0" minHeight="0.0" prefHeight="18.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="485.0" minHeight="10.0" prefHeight="467.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="63.0" minHeight="0.0" prefHeight="63.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="704.0" minHeight="10.0" prefHeight="603.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="172.0" minHeight="10.0" prefHeight="134.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<GridPane style="-fx-b: rgba(255,255,255,0.5);">
|
||||
<GridPane id="timerGrid" fx:id="timerGrid" prefWidth="192.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="93.0" minWidth="10.0" prefWidth="47.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="160.0" minWidth="10.0" prefWidth="151.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="161.0" minWidth="10.0" prefWidth="58.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="288.0" minWidth="10.0" prefWidth="104.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<GridPane.margin>
|
||||
<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>
|
||||
<Insets />
|
||||
</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>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
<stylesheets>
|
||||
<String fx:value="/css/master.css" />
|
||||
<String fx:value="/css/raceView.css" />
|
||||
</stylesheets>
|
||||
</AnchorPane>
|
||||
|
||||
Reference in New Issue
Block a user