From 6d7c36e31f7e79a40b6ee8e344c9cc1ae9570257 Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Tue, 23 May 2017 20:00:23 +1200 Subject: [PATCH] Updated code to check if boat is in the race before displaying in the leaderboard #story[923] --- .../controllers/RaceViewController.java | 44 ++++++++++++------- .../controllers/StartScreenController.java | 36 +++++++++++---- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index e83a651b..b3a01fa6 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -30,6 +30,7 @@ import seng302.models.stream.StreamParser; import java.io.IOException; import java.util.*; +import seng302.models.stream.XMLParser.RaceXMLObject.Participant; /** * 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 + * * @param importantAnnotationsState The current state of the selected annotations */ public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) { @@ -233,30 +235,41 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel positionVbox.getChildren().removeAll(); positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString()); + // list of racing boat id + ArrayList participants = StreamParser.getXmlObject().getRaceXML() + .getParticipants(); + ArrayList participantIDs = new ArrayList<>(); + for (Participant p : participants) { + participantIDs.add(p.getsourceID()); + } + if (StreamParser.isRaceStarted()) { for (Yacht boat : StreamParser.getBoatsPos().values()) { - if (boat.getBoatStatus() == 3) { // 3 is finish status - Text textToAdd = new Text(boat.getPosition() + ". " + - boat.getShortName() + " (Finished)"); - textToAdd.setFill(Paint.valueOf("#d3d3d3")); - positionVbox.getChildren().add(textToAdd); + if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing + if (boat.getBoatStatus() == 3) { // 3 is finish status + Text textToAdd = new Text(boat.getPosition() + ". " + + boat.getShortName() + " (Finished)"); + 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() + ". " + boat.getShortName() + " "); textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setStyle(""); 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 + * * @param bg The boat group to set the annotations for */ private void setBoatGroupImportantAnnotations(BoatGroup bg) { diff --git a/src/main/java/seng302/controllers/StartScreenController.java b/src/main/java/seng302/controllers/StartScreenController.java index 177cf907..22e5dd1b 100644 --- a/src/main/java/seng302/controllers/StartScreenController.java +++ b/src/main/java/seng302/controllers/StartScreenController.java @@ -2,6 +2,7 @@ package seng302.controllers; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.ResourceBundle; import java.util.Timer; import java.util.TimerTask; @@ -23,6 +24,7 @@ import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import seng302.models.Yacht; import seng302.models.stream.StreamParser; +import seng302.models.stream.XMLParser.RaceXMLObject.Participant; public class StartScreenController implements Initializable { @@ -56,12 +58,11 @@ public class StartScreenController implements Initializable { contentPane.getChildren().removeAll(); contentPane.getChildren().clear(); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); - contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); - } - catch(javafx.fxml.LoadException e){ + contentPane.getChildren() + .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); + } catch (javafx.fxml.LoadException e) { e.printStackTrace(); - } - catch(IOException e){ + } catch (IOException e) { e.printStackTrace(); } } @@ -161,10 +162,27 @@ public class StartScreenController implements Initializable { new PropertyValueFactory<>("position") ); - if (StreamParser.isRaceStarted()) { - data.addAll(StreamParser.getBoatsPos().values()); - } else { - data.addAll(StreamParser.getBoats().values()); + // check if the boat is racing + ArrayList participants = StreamParser.getXmlObject().getRaceXML() + .getParticipants(); + ArrayList 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(); }