Created finish view to see when a race finishes.
-Implemented FinishController -Fixed mock not sending Finish race status. #Story[782]
This commit is contained in:
@@ -31,7 +31,7 @@ public class Race implements Runnable {
|
||||
protected List<Leg> legs;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
protected int scaleFactor;
|
||||
protected int scaleFactor=25;
|
||||
protected int PRERACE_TIME = 180000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
||||
protected boolean countdownFinish = false;
|
||||
protected boolean runRace = true;
|
||||
@@ -40,6 +40,7 @@ public class Race implements Runnable {
|
||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||
private MockOutput mockOutput;
|
||||
private static int boatOffset = 0;
|
||||
private int finished = 0;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public class Race implements Runnable {
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.raceId = raceID;
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.scaleFactor = 50;
|
||||
this.mockOutput = mockOutput;
|
||||
|
||||
|
||||
@@ -131,7 +132,6 @@ public class Race implements Runnable {
|
||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||
|
||||
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
||||
System.out.println("Race status 2");
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
@@ -143,7 +143,6 @@ public class Race implements Runnable {
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
System.out.println("Race status 1");
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
@@ -178,7 +177,7 @@ public class Race implements Runnable {
|
||||
//Update the total elapsed time.
|
||||
totalTimeElapsed = currentTime - timeRaceStarted;
|
||||
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<BoatStatusMessage>();
|
||||
|
||||
finished = 0;
|
||||
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
||||
@@ -188,9 +187,19 @@ public class Race implements Runnable {
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
if (boat.getTimeFinished() > 0) {
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(), BoatStatus.FINISHED, boat.getCurrentLeg().getLegNumber()));
|
||||
finished++;
|
||||
} else {
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
}
|
||||
if (startingBoats.size()==finished){
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
||||
import seng302.Model.Boat;
|
||||
|
||||
import seng302.Model.Race;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* Created by zwu18 on 6/05/17.
|
||||
*/
|
||||
public class FinishController extends Controller {
|
||||
|
||||
@FXML
|
||||
AnchorPane finishWrapper;
|
||||
|
||||
@FXML
|
||||
TableView<Boat> boatInfoTable;
|
||||
|
||||
@FXML
|
||||
TableColumn<Boat, String> boatRankColumn;
|
||||
|
||||
@FXML
|
||||
TableColumn<Boat, String> boatNameColumn;
|
||||
|
||||
@FXML
|
||||
Label raceWinnerLabel;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setFinishTable(ObservableList<Boat> boats){
|
||||
boatInfoTable.setItems(boats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
|
||||
raceWinnerLabel.setText("Winner: "+ boatNameColumn.getCellObservableValue(0).getValue());
|
||||
raceWinnerLabel.setWrapText(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
}
|
||||
|
||||
public void enterFinish(ObservableList<Boat> boats){
|
||||
finishWrapper.setVisible(true);
|
||||
setFinishTable(boats);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
@@ -19,6 +22,8 @@ public class MainController extends Controller {
|
||||
RaceController raceController;
|
||||
@FXML
|
||||
ConnectionController connectionController;
|
||||
@FXML
|
||||
FinishController finishController;
|
||||
|
||||
public void beginRace(VisualiserInput visualiserInput) {
|
||||
raceController.startRace(visualiserInput);
|
||||
@@ -28,6 +33,8 @@ public class MainController extends Controller {
|
||||
startController.enterLobby(socket);
|
||||
}
|
||||
|
||||
public void enterFinish(ObservableList<Boat> boats) { finishController.enterFinish(boats); }
|
||||
|
||||
/**
|
||||
* Main Controller for the applications will house the menu and the displayed pane.
|
||||
*
|
||||
@@ -39,6 +46,7 @@ public class MainController extends Controller {
|
||||
startController.setParent(this);
|
||||
raceController.setParent(this);
|
||||
connectionController.setParent(this);
|
||||
finishController.setParent(this);
|
||||
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
|
||||
|
||||
@@ -35,6 +35,8 @@ public class RaceController extends Controller {
|
||||
//user saved data for annotation display
|
||||
private ArrayList<Boolean> presetAnno;
|
||||
|
||||
private ObservableList<Boat> startingBoats;
|
||||
|
||||
ResizableRaceCanvas raceMap;
|
||||
ResizableRaceMap raceBoundaries;
|
||||
@FXML
|
||||
@@ -94,8 +96,8 @@ public class RaceController extends Controller {
|
||||
*/
|
||||
public void setInfoTable(Race race) {
|
||||
//boatInfoTable.getItems().clear();
|
||||
startingBoats = race.getStartingBoats();
|
||||
boatInfoTable.setItems(race.getStartingBoats());
|
||||
|
||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||
@@ -154,6 +156,11 @@ public class RaceController extends Controller {
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
public void finishRace(ObservableList<Boat> boats){
|
||||
race.setVisible(false);
|
||||
parent.enterFinish(boats);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value for the race clock label
|
||||
|
||||
@@ -108,6 +108,7 @@ public class StartController extends Controller implements Observer {
|
||||
DateFormat timerFormat = new SimpleDateFormat("'Race Clock:' -HH:mm:ss");
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
System.out.println(raceStat);
|
||||
timeLeft = startTime - currentTime;
|
||||
raceStat = visualiserInput.getRaceStatus().getRaceStatus();
|
||||
raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus());
|
||||
@@ -118,7 +119,11 @@ public class StartController extends Controller implements Observer {
|
||||
startWrapper.setVisible(false);
|
||||
start.setVisible(false);
|
||||
|
||||
} else {
|
||||
}
|
||||
else if (raceStat==4 || raceStat==8) {
|
||||
updateTime("Race has ended. Waiting for next race.");
|
||||
}
|
||||
else if (raceStat==10 || raceStat==1){
|
||||
updateTime(timerFormat.format(currentTime));
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
|
||||
@@ -67,10 +67,11 @@ public class StreamedRace extends Race {
|
||||
|
||||
if (boatStatus == BoatStatus.DNF) {
|
||||
boat.setDnf(true);
|
||||
} else if (boatStatus == BoatStatus.FINISHED || legNumber > raceData.getLegs().size()) {
|
||||
} else if (boatStatus == BoatStatus.FINISHED || legNumber == raceData.getLegs().size()) {
|
||||
boatsFinished++;
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
boat.setFinished(true);
|
||||
System.out.println("Boat finished");
|
||||
}
|
||||
}
|
||||
//Update the boat display table in the GUI to reflect the leg change
|
||||
|
||||
@@ -5,6 +5,7 @@ import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Controllers.FinishController;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.RaceDataSource;
|
||||
@@ -25,6 +26,7 @@ public abstract class Race implements Runnable {
|
||||
protected ObservableList<Boat> startingBoats;
|
||||
protected List<Leg> legs;
|
||||
protected RaceController controller;
|
||||
protected FinishController finishController;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
|
||||
@@ -180,6 +182,7 @@ public abstract class Race implements Runnable {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the calculated fps to the fps label
|
||||
*
|
||||
@@ -211,8 +214,8 @@ public abstract class Race implements Runnable {
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
|
||||
if (boatsFinished < startingBoats.size()) {
|
||||
boatsFinished = 0;
|
||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||
|
||||
for (Boat boat : startingBoats) {
|
||||
@@ -221,9 +224,16 @@ public abstract class Race implements Runnable {
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
boat.addTrackPoint(boat.getCurrentPosition());
|
||||
}
|
||||
if (boat.isFinished()){
|
||||
boatsFinished++;
|
||||
}
|
||||
}
|
||||
//System.out.println(boatsFinished + ":" + startingBoats.size());
|
||||
if (timerEnabled)
|
||||
updateTime(calcTimer());
|
||||
} else {
|
||||
controller.finishRace(startingBoats);
|
||||
stop();
|
||||
}
|
||||
controller.updateMap(startingBoats);
|
||||
fps++;
|
||||
@@ -233,9 +243,7 @@ public abstract class Race implements Runnable {
|
||||
fps = 0;
|
||||
timeCurrent = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
@@ -258,6 +266,7 @@ public abstract class Race implements Runnable {
|
||||
*/
|
||||
protected void setControllerListeners() {
|
||||
if (controller != null) controller.setInfoTable(this);
|
||||
//if (finishController != null) finishController.setFinishTable(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<AnchorPane fx:id="finishWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.FinishController">
|
||||
<children>
|
||||
<GridPane fx:id="start" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="372.0" minWidth="10.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="250.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" prefWidth="200.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="241.0" minHeight="10.0" prefHeight="116.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="383.0" minHeight="10.0" prefHeight="48.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="261.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="53.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<TableView fx:id="boatInfoTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
|
||||
<placeholder>
|
||||
<Label text="Initial lineup..." />
|
||||
</placeholder>
|
||||
<columns>
|
||||
<TableColumn fx:id="boatRankColumn" prefWidth="120.0" style="-fx-font-size: 16;" text="Ranking" />
|
||||
<TableColumn fx:id="boatNameColumn" prefWidth="367.0" style="-fx-font-size: 16;" text="Team" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label fx:id="raceFinishLabel" alignment="CENTER" text="Race Finished" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="raceWinnerLabel" alignment="CENTER" maxWidth="1.7976931348623157E308" text="Winner" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -7,5 +7,6 @@
|
||||
<fx:include fx:id="race" source="race.fxml" />
|
||||
<fx:include fx:id="start" source="start.fxml" />
|
||||
<fx:include fx:id="connection" source="connect.fxml" />
|
||||
<fx:include fx:id="finish" source="finish.fxml" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@@ -44,14 +44,14 @@
|
||||
</TableView>
|
||||
<Label fx:id="timeZoneTime" contentDisplay="CENTER" text="Local time..." GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
||||
<Label fx:id="timer" text=" " GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
|
||||
<Label fx:id="raceStartLabel" text="Starting time..." GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
|
||||
<Label fx:id="raceTitleLabel" text="Welcome to RaceVision" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="raceStatusLabel" alignment="CENTER" text="Race Status:" textAlignment="CENTER" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
<Label fx:id="raceStartLabel" text="Starting time..." GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
|
||||
<Label fx:id="raceTitleLabel" text="Welcome to RaceVision" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="raceStatusLabel" alignment="CENTER" text="Race Status:" textAlignment="CENTER" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</AnchorPane>
|
||||
Reference in New Issue
Block a user