Updated code to check if boat is in the race before displaying in the leaderboard

#story[923]
This commit is contained in:
Zhi You Tan
2017-05-23 20:00:23 +12:00
parent 2686dac62e
commit 6d7c36e31f
2 changed files with 56 additions and 24 deletions
@@ -30,6 +30,7 @@ import seng302.models.stream.StreamParser;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
/** /**
* Created by ptg19 on 29/03/17. * Created by ptg19 on 29/03/17.
@@ -82,6 +83,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
/** /**
* The important annotations have been changed, update this view * The important annotations have been changed, update this view
*
* @param importantAnnotationsState The current state of the selected annotations * @param importantAnnotationsState The current state of the selected annotations
*/ */
public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) { public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) {
@@ -233,30 +235,41 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
positionVbox.getChildren().removeAll(); positionVbox.getChildren().removeAll();
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString()); positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
// list of racing boat id
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
.getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
}
if (StreamParser.isRaceStarted()) { if (StreamParser.isRaceStarted()) {
for (Yacht boat : StreamParser.getBoatsPos().values()) { for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (boat.getBoatStatus() == 3) { // 3 is finish status if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing
Text textToAdd = new Text(boat.getPosition() + ". " + if (boat.getBoatStatus() == 3) { // 3 is finish status
boat.getShortName() + " (Finished)"); Text textToAdd = new Text(boat.getPosition() + ". " +
textToAdd.setFill(Paint.valueOf("#d3d3d3")); boat.getShortName() + " (Finished)");
positionVbox.getChildren().add(textToAdd); textToAdd.setFill(Paint.valueOf("#d3d3d3"));
positionVbox.getChildren().add(textToAdd);
} else { } else {
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd);
}
}
}
} else {
for (Yacht boat : StreamParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing
Text textToAdd = new Text(boat.getPosition() + ". " + Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " "); boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle(""); textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd); positionVbox.getChildren().add(textToAdd);
} }
}
} else {
for (Yacht boat : StreamParser.getBoats().values()) {
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd);
} }
} }
} }
@@ -338,6 +351,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
/** /**
* Display the important annotations for a specific BoatGroup * Display the important annotations for a specific BoatGroup
*
* @param bg The boat group to set the annotations for * @param bg The boat group to set the annotations for
*/ */
private void setBoatGroupImportantAnnotations(BoatGroup bg) { private void setBoatGroupImportantAnnotations(BoatGroup bg) {
@@ -2,6 +2,7 @@ package seng302.controllers;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@@ -23,6 +24,7 @@ import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import seng302.models.Yacht; import seng302.models.Yacht;
import seng302.models.stream.StreamParser; import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
public class StartScreenController implements Initializable { public class StartScreenController implements Initializable {
@@ -56,12 +58,11 @@ public class StartScreenController implements Initializable {
contentPane.getChildren().removeAll(); contentPane.getChildren().removeAll();
contentPane.getChildren().clear(); contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentPane.getChildren()
} .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
catch(javafx.fxml.LoadException e){ } catch (javafx.fxml.LoadException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (IOException e) {
catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -161,10 +162,27 @@ public class StartScreenController implements Initializable {
new PropertyValueFactory<>("position") new PropertyValueFactory<>("position")
); );
if (StreamParser.isRaceStarted()) { // check if the boat is racing
data.addAll(StreamParser.getBoatsPos().values()); ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
} else { .getParticipants();
data.addAll(StreamParser.getBoats().values()); ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
}
// add boats to the start screen list
if (StreamParser.isRaceStarted()) { // if race is started, use StreamParser.getBoatsPos()
for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
} else { // else use StreamParser.getBoats()
for (Yacht boat : StreamParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
} }
teamList.refresh(); teamList.refresh();
} }