|
|
|
@ -1,5 +1,7 @@
|
|
|
|
package seng302.Controllers;
|
|
|
|
package seng302.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.animation.AnimationTimer;
|
|
|
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
@ -11,7 +13,6 @@ import javafx.scene.layout.AnchorPane;
|
|
|
|
import javafx.scene.layout.GridPane;
|
|
|
|
import javafx.scene.layout.GridPane;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import seng302.Model.BoatInRace;
|
|
|
|
import seng302.Model.BoatInRace;
|
|
|
|
import seng302.Model.Race;
|
|
|
|
|
|
|
|
import seng302.Model.RaceClock;
|
|
|
|
import seng302.Model.RaceClock;
|
|
|
|
import seng302.RaceXMLReader;
|
|
|
|
import seng302.RaceXMLReader;
|
|
|
|
|
|
|
|
|
|
|
|
@ -32,6 +33,8 @@ public class StartController extends Controller {
|
|
|
|
@FXML private TableColumn<BoatInRace, String> boatNameColumn;
|
|
|
|
@FXML private TableColumn<BoatInRace, String> boatNameColumn;
|
|
|
|
@FXML private TableColumn<BoatInRace, String> boatCodeColumn;
|
|
|
|
@FXML private TableColumn<BoatInRace, String> boatCodeColumn;
|
|
|
|
@FXML private Label timeZoneTime;
|
|
|
|
@FXML private Label timeZoneTime;
|
|
|
|
|
|
|
|
@FXML private Label timer;
|
|
|
|
|
|
|
|
@FXML private int PRERACE_TIME = 15000;
|
|
|
|
|
|
|
|
|
|
|
|
private RaceClock raceClock;
|
|
|
|
private RaceClock raceClock;
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,10 +59,8 @@ public class StartController extends Controller {
|
|
|
|
startRace(1);
|
|
|
|
startRace(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void startRace(Integer raceScale){
|
|
|
|
private void startRace(int raceScale){
|
|
|
|
start.setVisible(false);
|
|
|
|
countdownTimer(raceScale);
|
|
|
|
|
|
|
|
|
|
|
|
parent.beginRace(raceScale);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -95,7 +96,54 @@ public class StartController extends Controller {
|
|
|
|
raceClock = new RaceClock(raceXMLReader.getMark());
|
|
|
|
raceClock = new RaceClock(raceXMLReader.getMark());
|
|
|
|
timeZoneTime.textProperty().bind(raceClock.timeProperty());
|
|
|
|
timeZoneTime.textProperty().bind(raceClock.timeProperty());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Updates the calculated time to the timer label
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param time The calculated time from calcTimer() method
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void updateTime(String time) {
|
|
|
|
|
|
|
|
Platform.runLater(() -> {
|
|
|
|
|
|
|
|
timer.setText(time);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void countdownTimer(int scaleFactor) {
|
|
|
|
|
|
|
|
new AnimationTimer() {
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
|
|
|
|
|
|
|
long minutes;
|
|
|
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
|
|
|
long hours;
|
|
|
|
|
|
|
|
long timeLeft;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void handle(long arg0) {
|
|
|
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
|
|
|
|
if (timeLeft <= 0) {
|
|
|
|
|
|
|
|
updateTime("Race is starting...");
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
parent.beginRace(scaleFactor);
|
|
|
|
|
|
|
|
startWrapper.setVisible(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
|
|
|
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
|
|
|
hours = minutes / 60;
|
|
|
|
|
|
|
|
minutes = minutes % 60;
|
|
|
|
|
|
|
|
updateTime(String.format("Race Clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|