From b17bba3629c8dfa3e9b79d29adbe9fe5b4fed4ec Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Thu, 18 May 2017 12:18:51 +1200 Subject: [PATCH 1/3] Fixed leaderboard on start screen and race view to show all boats correctly during pre-race. #story[923] --- .../seng302/controllers/RaceController.java | 13 +----- .../controllers/RaceViewController.java | 26 +++++++---- .../controllers/StartScreenController.java | 43 +++++++++++-------- src/main/java/seng302/models/Yacht.java | 18 +++++--- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/main/java/seng302/controllers/RaceController.java b/src/main/java/seng302/controllers/RaceController.java index d0ea0d42..4e40e001 100644 --- a/src/main/java/seng302/controllers/RaceController.java +++ b/src/main/java/seng302/controllers/RaceController.java @@ -2,7 +2,6 @@ package seng302.controllers; import seng302.models.Race; import seng302.models.Yacht; -import seng302.models.parsers.ConfigParser; import seng302.models.parsers.CourseParser; import seng302.models.parsers.StreamParser; @@ -18,6 +17,7 @@ import java.util.Random; * the CanvasController then uses the event data to make the animations */ public class RaceController { + Race race = null; public void initializeRace() { @@ -39,24 +39,13 @@ public class RaceController { public Race createRace(String configFile, String teamsConfigFile) throws Exception { Race race = new Race(); -// StreamParser.xmlObject - // Read team names from file -// TeamsParser tp = new TeamsParser(teamsConfigFile); - - // Read course from file -// ConfigParser config = new ConfigParser(configFile); ArrayList boatNames = new ArrayList<>(); -// ArrayList teams = tp.getBoats(); Map teams = StreamParser.getBoatsPos(); //get race size int numberOfBoats = teams.size(); - //get time scale -// double timeScale = config.getTimeScale(); -// race.setTimeScale(timeScale); - for (Yacht boat : teams.values()) { boatNames.add(boat.getBoatName()); race.addBoat(boat); diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index aa09d9d1..4cfa1d92 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -251,21 +251,31 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel positionVbox.getChildren().removeAll(); positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString()); - 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 (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); - } 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()) { Text textToAdd = new Text(boat.getPosition() + ". " + boat.getShortName() + " "); textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setStyle(""); positionVbox.getChildren().add(textToAdd); } - } } diff --git a/src/main/java/seng302/controllers/StartScreenController.java b/src/main/java/seng302/controllers/StartScreenController.java index 8a4d563b..39e44be1 100644 --- a/src/main/java/seng302/controllers/StartScreenController.java +++ b/src/main/java/seng302/controllers/StartScreenController.java @@ -25,6 +25,7 @@ import seng302.models.Yacht; import seng302.models.parsers.StreamParser; public class StartScreenController implements Initializable { + @FXML private GridPane gridPane; @FXML @@ -48,19 +49,18 @@ public class StartScreenController implements Initializable { private boolean switchedToRaceView = false; - private void setContentPane(String jfxUrl){ - try{ + private void setContentPane(String jfxUrl) { + try { // get the main controller anchor pane (MainView.fxml) AnchorPane contentPane = (AnchorPane) gridPane.getParent(); 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) { System.err.println(e.getCause()); - } - catch(IOException e){ + } catch (IOException e) { System.err.println(e); } } @@ -72,7 +72,8 @@ public class StartScreenController implements Initializable { } /** - * Running a timer to update the livestream status on welcome screen. Update interval is 1 second. + * Running a timer to update the livestream status on welcome screen. Update interval is 1 + * second. */ public void startStream() { if (StreamParser.isStreamStatus()) { @@ -102,8 +103,10 @@ public class StartScreenController implements Initializable { updateTeamList(); timeTillLive.setTextFill(Color.RED); switchToRaceViewButton.setDisable(false); - String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60); - String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60); + String timerMinute = Long + .toString(StreamParser.getTimeSinceStart() / 60); + String timerSecond = Long + .toString(StreamParser.getTimeSinceStart() % 60); if (timerSecond.length() == 1) { timerSecond = "0" + timerSecond; } @@ -114,8 +117,10 @@ public class StartScreenController implements Initializable { updateTeamList(); timeTillLive.setTextFill(Color.BLACK); switchToRaceViewButton.setDisable(false); - String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60); - String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60); + String timerMinute = Long + .toString(-1 * StreamParser.getTimeSinceStart() / 60); + String timerSecond = Long + .toString(-1 * StreamParser.getTimeSinceStart() % 60); if (timerSecond.length() == 1) { timerSecond = "0" + timerSecond; } @@ -142,19 +147,23 @@ public class StartScreenController implements Initializable { teamList.setItems(data); boatNameCol.setCellValueFactory( - new PropertyValueFactory<>("boatName") + new PropertyValueFactory<>("boatName") ); shortNameCol.setCellValueFactory( - new PropertyValueFactory<>("shortName") + new PropertyValueFactory<>("shortName") ); countryCol.setCellValueFactory( - new PropertyValueFactory<>("country") + new PropertyValueFactory<>("country") ); posCol.setCellValueFactory( - new PropertyValueFactory<>("position") + new PropertyValueFactory<>("position") ); - data.addAll(StreamParser.getBoatsPos().values()); + if (StreamParser.isRaceStarted()) { + data.addAll(StreamParser.getBoatsPos().values()); + } else { + data.addAll(StreamParser.getBoats().values()); + } teamList.refresh(); } } diff --git a/src/main/java/seng302/models/Yacht.java b/src/main/java/seng302/models/Yacht.java index e21384f9..fbfe952f 100644 --- a/src/main/java/seng302/models/Yacht.java +++ b/src/main/java/seng302/models/Yacht.java @@ -9,9 +9,10 @@ import java.text.SimpleDateFormat; * Yacht class for the racing boat. * * Class created to store more variables (eg. boat statuses) compared to the XMLParser boat class, - * also done outside Boat class because some old variables are not used anymore. + * also done outside Boat class because some old variables are not used anymore. */ public class Yacht { + // Used in boat group private Color colour; private double velocity; @@ -38,25 +39,27 @@ public class Yacht { * * @param boatName Create a yacht object with name. */ - public Yacht (String boatName) { + public Yacht(String boatName) { this.boatName = boatName; } /** * Used in BoatGroupTest. * - * @param boatName The name of the team sailing the boat + * @param boatName The name of the team sailing the boat * @param boatVelocity The speed of the boat in meters/second - * @param shortName A shorter version of the teams name + * @param shortName A shorter version of the teams name */ public Yacht(String boatName, double boatVelocity, String shortName, int id) { this.boatName = boatName; this.velocity = boatVelocity; this.shortName = shortName; this.sourceID = id; + this.position = "-"; } - public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) { + public Yacht(String boatType, Integer sourceID, String hullID, String shortName, + String boatName, String country) { this.boatType = boatType; this.sourceID = sourceID; this.hullID = hullID; @@ -68,18 +71,23 @@ public class Yacht { public String getBoatType() { return boatType; } + public Integer getSourceID() { return sourceID; } + public String getHullID() { return hullID; } + public String getShortName() { return shortName; } + public String getBoatName() { return boatName; } + public String getCountry() { return country; } From 2686dac62e74e2e1d4d207c1068b6fce17f3824d Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Tue, 23 May 2017 11:53:23 +1200 Subject: [PATCH 2/3] Fixed Yacht position initialise. TO-DO: check if the boat is participating before showing up on leaderboard. --- src/main/java/seng302/models/Yacht.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seng302/models/Yacht.java b/src/main/java/seng302/models/Yacht.java index b018319b..9644e5f1 100644 --- a/src/main/java/seng302/models/Yacht.java +++ b/src/main/java/seng302/models/Yacht.java @@ -55,7 +55,6 @@ public class Yacht { this.velocity = boatVelocity; this.shortName = shortName; this.sourceID = id; - this.position = "-"; } public Yacht(String boatType, Integer sourceID, String hullID, String shortName, @@ -66,6 +65,7 @@ public class Yacht { this.shortName = shortName; this.boatName = boatName; this.country = country; + this.position = "-"; } public String getBoatType() { From 6d7c36e31f7e79a40b6ee8e344c9cc1ae9570257 Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Tue, 23 May 2017 20:00:23 +1200 Subject: [PATCH 3/3] 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(); }