From 5472765b95413e0fac2364085f26a7d1776b10d6 Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Fri, 12 May 2017 18:24:28 +1200 Subject: [PATCH 1/6] Removed unused methods in RaceViewController.java #story[923] --- .../controllers/RaceViewController.java | 126 ------------------ 1 file changed, 126 deletions(-) diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 433e47a2..d2e2ba11 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -51,8 +51,6 @@ public class RaceViewController extends Thread{ private ArrayList startingBoats = new ArrayList<>(); private boolean displayFps; private Timeline timerTimeline; - private Map timelineInfos = new HashMap<>(); - private ArrayList boatOrder = new ArrayList<>(); private Race race; private Stage stage; private Integer annotationLevel; @@ -66,12 +64,6 @@ public class RaceViewController extends Thread{ for (Yacht boat : race.getBoats()) { startingBoats.add(boat); } -// try{ -// initializeTimelines(); -// } -// catch (Exception e){ -// e.printStackTrace(); -// } includedCanvasController.setup(this); includedCanvasController.initializeCanvas(); @@ -79,10 +71,6 @@ public class RaceViewController extends Thread{ initializeSettings(); initialiseWindDirection(); initialisePositionVBox(); - //set wind direction!!!!!!! can't find another place to put my code --haoming -// double windDirection = new ConfigParser("/config/config.xml").getWindDirection(); -// windDirectionText.setText(String.format("%.1f°", windDirection)); -// windArrowText.setRotate(windDirection); includedCanvasController.timer.start(); selectAnnotationBtn.setOnAction(event -> { @@ -225,97 +213,6 @@ public class RaceViewController extends Thread{ } - /** - * Generates time line for each boat, and stores time time into timelineInfos hash map - */ - private void initializeTimelines() { - HashMap boat_events = race.getEvents(); - for (Yacht boat : boat_events.keySet()) { - startingBoats.add(boat); -// // x, y are the real time coordinates -// DoubleProperty x = new SimpleDoubleProperty(); -// DoubleProperty y = new SimpleDoubleProperty(); -// -// List keyFrames = new ArrayList<>(); -// List events = boat_events.get(boat); -// -// // iterates all events and convert each event to keyFrame, then add them into a list -// for (Event event : events) { -// if (event.getIsFinishingEvent()) { -// keyFrames.add( -// new KeyFrame(Duration.seconds(event.getTime()), -// onFinished -> {race.setBoatFinished(boat); handleEvent(event);}, -// new KeyValue(x, event.getThisMark().getLatitude()), -// new KeyValue(y, event.getThisMark().getLongitude()) -// ) -// ); -// } else { -// keyFrames.add( -// new KeyFrame(Duration.seconds(event.getTime()), -// onFinished ->{ -// handleEvent(event); -// boat.setHeading(event.getBoatHeading()); -// }, -// new KeyValue(x, event.getThisMark().getLatitude()), -// new KeyValue(y, event.getThisMark().getLongitude()) -// ) -// ); -// } -// } -// timelineInfos.put(boat, new TimelineInfo(new Timeline(keyFrames.toArray(new KeyFrame[keyFrames.size()])), x, y)); - } - setRaceDuration(); - } - - private void setRaceDuration(){ - Double maxDuration = 0.0; - Timeline maxTimeline = null; - - for (TimelineInfo timelineInfo : timelineInfos.values()) { - - Timeline timeline = timelineInfo.getTimeline(); - if (timeline.getTotalDuration().toMillis() >= maxDuration) { - maxDuration = timeline.getTotalDuration().toMillis(); - maxTimeline = timeline; - } - - // Timelines are paused by default - timeline.play(); - timeline.pause(); - } - - maxTimeline.setOnFinished(event -> { - race.setRaceFinished(); - loadRaceResultView(); - }); - } - - /** - * Play each boats timerTimeline - */ - public void playTimelines(){ - for (TimelineInfo timelineInfo : timelineInfos.values()){ - Timeline timeline = timelineInfo.getTimeline(); - - if (timeline.getStatus() == Animation.Status.PAUSED){ - timeline.play(); - } - } - } - - /** - * Pause each boats timerTimeline - */ - public void pauseTimelines(){ - for (TimelineInfo timelineInfo : timelineInfos.values()){ - Timeline timeline = timelineInfo.getTimeline(); - - if (timeline.getStatus() == Animation.Status.RUNNING){ - timeline.pause(); - } - } - } - /** * Display the list of boats in the order they finished the race */ @@ -335,29 +232,11 @@ public class RaceViewController extends Thread{ } } - public void handleEvent(Event event) { - Yacht boat = event.getBoat(); - boatOrder.remove(boat); - boat.setMarkLastPast(event.getMarkPosInRace()); - boatOrder.add(boat); - boatOrder.sort(new Comparator() { - @Override - public int compare(Yacht b1, Yacht b2) { - return b2.getMarkLastPast() - b1.getMarkLastPast(); - } - }); - showOrder(); - } - private void showOrder() { positionVbox.getChildren().clear(); positionVbox.getChildren().removeAll(); positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString()); -// for (Boat boat : boatOrder) { -// positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots")); -// } - for (Yacht boat : StreamParser.getBoatsPos().values()) { if (boat.getBoatStatus() == 3) { // 3 is finish status Text textToAdd = new Text(boat.getPosition() + ". " + @@ -424,15 +303,10 @@ public class RaceViewController extends Thread{ return race; } - public Map getTimelineInfos() { - return timelineInfos; - } - public ArrayList getStartingBoats(){ return startingBoats; } - private void setAnnotations(Integer annotationLevel) { switch (annotationLevel) { case 0: From 47880d09bc85df9592670d606b42b65a130c1e30 Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Fri, 12 May 2017 20:04:09 +1200 Subject: [PATCH 2/6] Implemented estimated time to next mark. Added checkbox for estimated time to next mark. To be fix: change from long to human readable time, update time every second #story[923] --- .../ImportantAnnotationController.java | 12 ++++++++++ .../controllers/RaceViewController.java | 12 +++++++++- src/main/java/seng302/models/BoatGroup.java | 22 ++++++++++++++++--- .../views/importantAnnotationSelectView.fxml | 3 ++- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/controllers/ImportantAnnotationController.java b/src/main/java/seng302/controllers/ImportantAnnotationController.java index e1a031cf..d5cd577e 100644 --- a/src/main/java/seng302/controllers/ImportantAnnotationController.java +++ b/src/main/java/seng302/controllers/ImportantAnnotationController.java @@ -28,6 +28,9 @@ public class ImportantAnnotationController implements Initializable { @FXML private CheckBox boatNameSelect; + @FXML + private CheckBox boatEstTimeToNextMarkSelect; + @FXML private AnchorPane annotationSelectWindow; @@ -87,6 +90,10 @@ public class ImportantAnnotationController implements Initializable { boatNameSelect.setSelected(importantAnnotations.get(key)); break; + case "BoatEstTimeToNextMark": + boatEstTimeToNextMarkSelect.setSelected(importantAnnotations.get(key)); + break; + default: break; } @@ -120,6 +127,11 @@ public class ImportantAnnotationController implements Initializable { sendUpdate(); }); + boatEstTimeToNextMarkSelect.setOnAction(event -> { + setAnnotation("BoatEstTimeToNextMark", boatEstTimeToNextMarkSelect.isSelected()); + sendUpdate(); + }); + closeButton.setOnAction(event -> stage.close()); } } diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index d2e2ba11..d6bcdc49 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -315,6 +315,7 @@ public class RaceViewController extends Thread{ BoatGroup bg = (BoatGroup) ro; bg.setTeamNameObjectVisible(false); bg.setVelocityObjectVisible(false); + bg.setEstTimeToNextMarkVisible(false); bg.setLineGroupVisible(false); bg.setWakeVisible(false); } @@ -326,6 +327,7 @@ public class RaceViewController extends Thread{ BoatGroup bg = (BoatGroup) ro; bg.setTeamNameObjectVisible(true); bg.setVelocityObjectVisible(false); + bg.setEstTimeToNextMarkVisible(false); bg.setLineGroupVisible(false); bg.setWakeVisible(false); } @@ -348,7 +350,14 @@ public class RaceViewController extends Thread{ bg.setVelocityObjectVisible(true); } else{ - bg.setTeamNameObjectVisible(false); + bg.setVelocityObjectVisible(false); + } + + if (importantAnnotations.containsKey("BoatEstTimeToNextMark") && importantAnnotations.get("BoatEstTimeToNextMark")) { + bg.setEstTimeToNextMarkVisible(true); + } + else{ + bg.setEstTimeToNextMarkVisible(false); } if (importantAnnotations.containsKey("BoatTrack") && importantAnnotations.get("BoatTrack")){ @@ -373,6 +382,7 @@ public class RaceViewController extends Thread{ BoatGroup bg = (BoatGroup) ro; bg.setTeamNameObjectVisible(true); bg.setVelocityObjectVisible(true); + bg.setEstTimeToNextMarkVisible(true); bg.setLineGroupVisible(true); bg.setWakeVisible(true); } diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 57dd48db..0a58d90e 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -23,9 +23,11 @@ public class BoatGroup extends RaceObject{ //Constants for drawing private static final double TEAMNAME_X_OFFSET = 10d; - private static final double TEAMNAME_Y_OFFSET = -15d; + private static final double TEAMNAME_Y_OFFSET = -29d; private static final double VELOCITY_X_OFFSET = 10d; - private static final double VELOCITY_Y_OFFSET = -5d; + private static final double VELOCITY_Y_OFFSET = -17d; + private static final double ESTTIMETONEXTMARK_X_OFFSET = 10d; + private static final double ESTTIMETONEXTMARK_Y_OFFSET = -5d; private static final double BOAT_HEIGHT = 15d; private static final double BOAT_WIDTH = 10d; //Variables for boat logic. @@ -38,6 +40,7 @@ public class BoatGroup extends RaceObject{ private Polygon boatPoly; private Text teamNameObject; private Text velocityObject; + private Text estTimeToNextMarkObject; private Wake wake; //Handles boat moving when connecting to a stream private boolean setToInitialLocation = false; @@ -83,6 +86,7 @@ public class BoatGroup extends RaceObject{ teamNameObject = new Text(boat.getShortName()); velocityObject = new Text(String.valueOf(boat.getVelocity())); + estTimeToNextMarkObject = new Text(String.valueOf(boat.getEstimateTimeAtNextMark())); teamNameObject.setX(TEAMNAME_X_OFFSET); teamNameObject.setY(TEAMNAME_Y_OFFSET); @@ -93,8 +97,12 @@ public class BoatGroup extends RaceObject{ velocityObject.relocate(velocityObject.getX(), velocityObject.getY()); destinationSet = false; + estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET); + estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET); + estTimeToNextMarkObject.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY()); + wake = new Wake(0, -BOAT_HEIGHT); - super.getChildren().addAll(teamNameObject, velocityObject, boatPoly); + super.getChildren().addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject); } /** @@ -120,6 +128,8 @@ public class BoatGroup extends RaceObject{ teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); velocityObject.setLayoutY(velocityObject.getLayoutY() + dy); + estTimeToNextMarkObject.setLayoutX(estTimeToNextMarkObject.getLayoutX() + dx); + estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy); wake.setLayoutX(wake.getLayoutX() + dx); wake.setLayoutY(wake.getLayoutY() + dy); rotateTo(rotation + currentRotation); @@ -148,6 +158,8 @@ public class BoatGroup extends RaceObject{ teamNameObject.setLayoutY(y); velocityObject.setLayoutX(x); velocityObject.setLayoutY(y); + estTimeToNextMarkObject.setLayoutX(x); + estTimeToNextMarkObject.setLayoutY(y); wake.setLayoutX(x); wake.setLayoutY(y); wake.rotate(currentRotation); @@ -287,6 +299,10 @@ public class BoatGroup extends RaceObject{ velocityObject.setVisible(visible); } + public void setEstTimeToNextMarkVisible(Boolean visible) { + estTimeToNextMarkObject.setVisible(visible); + } + public void setLineGroupVisible(Boolean visible) { lineGroup.setVisible(visible); } diff --git a/src/main/resources/views/importantAnnotationSelectView.fxml b/src/main/resources/views/importantAnnotationSelectView.fxml index fb88442d..da89b52a 100644 --- a/src/main/resources/views/importantAnnotationSelectView.fxml +++ b/src/main/resources/views/importantAnnotationSelectView.fxml @@ -15,7 +15,8 @@ - + +