added a markpos value to event for use in displaying the team positions #story[426]

This commit is contained in:
Peter
2017-03-23 21:19:39 +13:00
parent 8578bc4a5b
commit bb8c681270
6 changed files with 61 additions and 46 deletions
@@ -0,0 +1,34 @@
package seng302.controllers;
import javafx.fxml.FXML;
import javafx.scene.layout.VBox;
import seng302.models.Boat;
import seng302.models.Event;
import java.util.*;
/**
* Created by ptg19 on 23/03/17.
*/
public class BoatPositionController {
@FXML
private VBox positionVbox;
private ArrayList<Boat> boatOrder = new ArrayList<>();
public void initialize() {
}
public void handleEvent(Event event){
Boat boat = event.getBoat();
boatOrder.remove(boat);
boat.setMarkLastPast(event.getMarkPosInRace());
boatOrder.add(boat);
boatOrder.sort(new Comparator<Boat>() {
@Override
public int compare(Boat b1, Boat b2) {
return b2.getMarkLastPast() - b1.getMarkLastPast();
}
});
}
}
@@ -51,6 +51,9 @@ public class CanvasController {
@FXML Pane raceTimer;
@FXML
BoatPositionController teamPositionsController;
private Animation.Status raceStatus = Animation.Status.PAUSED;
/**
@@ -135,7 +138,7 @@ public class CanvasController {
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
gc.clearRect(0, 0, 760, 360);
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
drawCourse();
@@ -205,7 +208,7 @@ public class CanvasController {
if (event.getIsFinishingEvent()) {
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
event1 -> race.setBoatFinished(boat),
onFinished -> {race.setBoatFinished(boat); teamPositionsController.handleEvent(event);},
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)
@@ -213,6 +216,7 @@ public class CanvasController {
} else {
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
onFinished -> teamPositionsController.handleEvent(event),
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)