Fixed Boat selection and lost annotations (Estimated and Leg Time)

Trails and Wakes, however,  are still not re implemented yet.

story[923]
This commit is contained in:
William Muir
2017-05-18 14:41:08 +12:00
parent 0f79353936
commit a2123df0c5
2 changed files with 104 additions and 25 deletions
@@ -355,17 +355,17 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
bg.setWakeVisible(false); bg.setWakeVisible(false);
} }
//TODO fix boat annotations with new boatgroup //TODO fix boat annotations with new boatgroup
// if (importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK)) { if (importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK)) {
// bg.setEstTimeToNextMarkObjectVisible(true); bg.setEstTimeToNextMarkObjectVisible(true);
// } else { } else {
// bg.setEstTimeToNextMarkObjectVisible(false); bg.setEstTimeToNextMarkObjectVisible(false);
// } }
//
// if (importantAnnotations.getAnnotationState(Annotation.LEGTIME)) { if (importantAnnotations.getAnnotationState(Annotation.LEGTIME)) {
// bg.setLegTimeObjectVisible(true); bg.setLegTimeObjectVisible(true);
// } else { } else {
// bg.setLegTimeObjectVisible(false); bg.setLegTimeObjectVisible(false);
// } }
} }
private void setAnnotations(Integer annotationLevel) { private void setAnnotations(Integer annotationLevel) {
@@ -375,8 +375,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
for (BoatGroup bg : includedCanvasController.getBoatGroups()) { for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
bg.setTeamNameObjectVisible(false); bg.setTeamNameObjectVisible(false);
bg.setVelocityObjectVisible(false); bg.setVelocityObjectVisible(false);
// bg.setEstTimeToNextMarkObjectVisible(false); bg.setEstTimeToNextMarkObjectVisible(false);
// bg.setLegTimeObjectVisible(false); bg.setLegTimeObjectVisible(false);
bg.setLineGroupVisible(false); bg.setLineGroupVisible(false);
bg.setWakeVisible(false); bg.setWakeVisible(false);
} }
@@ -392,8 +392,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
for (BoatGroup bg : includedCanvasController.getBoatGroups()) { for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
bg.setTeamNameObjectVisible(true); bg.setTeamNameObjectVisible(true);
bg.setVelocityObjectVisible(true); bg.setVelocityObjectVisible(true);
// bg.setEstTimeToNextMarkObjectVisible(true); bg.setEstTimeToNextMarkObjectVisible(true);
// bg.setLegTimeObjectVisible(true); bg.setLegTimeObjectVisible(true);
bg.setLineGroupVisible(true); bg.setLineGroupVisible(true);
bg.setWakeVisible(true); bg.setWakeVisible(true);
} }
@@ -411,13 +411,12 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
for (BoatGroup bg : includedCanvasController.getBoatGroups()) { for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
//We need to iterate over all race groups to get the matching boat group belonging to this boat if we //We need to iterate over all race groups to get the matching boat group belonging to this boat if we
//are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup. //are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup.
//TODO fix boat selection with new boatgroup if (bg.getBoat().getHullID().equals(yacht.getHullID())) {
// if (bg.getBoat().getHullID().equals(yacht.getHullID())) { bg.setIsSelected(true);
// bg.setIsSelected(true); selectedBoat = yacht;
// selectedBoat = yacht; } else {
// } else { bg.setIsSelected(false);
// bg.setIsSelected(false); }
// }
} }
} }
+83 -3
View File
@@ -1,10 +1,18 @@
package seng302.models; package seng302.models;
import javafx.event.EventHandler;
import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon; import javafx.scene.shape.Polygon;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import seng302.models.stream.StreamParser;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/** /**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat. * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat.
@@ -17,9 +25,13 @@ public class BoatGroup extends Group{
//Constants for drawing //Constants for drawing
private static final double TEAMNAME_X_OFFSET = 10d; 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_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 LEGTIME_X_OFFSET = 10d;
private static final double LEGTIME_Y_OFFSET = 7d;
private static final double BOAT_HEIGHT = 15d; private static final double BOAT_HEIGHT = 15d;
private static final double BOAT_WIDTH = 10d; private static final double BOAT_WIDTH = 10d;
//Variables for boat logic. //Variables for boat logic.
@@ -34,8 +46,12 @@ public class BoatGroup extends Group{
private Polygon boatPoly; private Polygon boatPoly;
private Text teamNameObject; private Text teamNameObject;
private Text velocityObject; private Text velocityObject;
private Text estTimeToNextMarkObject;
private Text legTimeObject;
private Wake wake; private Wake wake;
private Boolean isSelected = true; //All boats are initalised as selected
/** /**
* Creates a BoatGroup with the default triangular boat polygon. * Creates a BoatGroup with the default triangular boat polygon.
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which * @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which
@@ -68,9 +84,30 @@ public class BoatGroup extends Group{
private void initChildren (Color color, double... points) { private void initChildren (Color color, double... points) {
boatPoly = new Polygon(points); boatPoly = new Polygon(points);
boatPoly.setFill(color); boatPoly.setFill(color);
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color));
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED);
teamNameObject = new Text(boat.getShortName()); teamNameObject = new Text(boat.getShortName());
teamNameObject.setCache(true);
teamNameObject.setCacheHint(CacheHint.SPEED);
velocityObject = new Text(String.valueOf(boat.getVelocity())); velocityObject = new Text(String.valueOf(boat.getVelocity()));
DateFormat format = new SimpleDateFormat("mm:ss");
String timeToNextMark = format
.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject = new Text("Next mark: " + timeToNextMark);
if (boat.getMarkRoundingTime() != null) {
String elapsedTime = format
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
legTimeObject = new Text("Last mark: " + elapsedTime);
} else {
legTimeObject = new Text("Last mark: -");
}
velocityObject.setCache(true);
velocityObject.setCacheHint(CacheHint.SPEED);
teamNameObject.setX(TEAMNAME_X_OFFSET); teamNameObject.setX(TEAMNAME_X_OFFSET);
teamNameObject.setY(TEAMNAME_Y_OFFSET); teamNameObject.setY(TEAMNAME_Y_OFFSET);
@@ -80,8 +117,19 @@ public class BoatGroup extends Group{
velocityObject.setY(VELOCITY_Y_OFFSET); velocityObject.setY(VELOCITY_Y_OFFSET);
velocityObject.relocate(velocityObject.getX(), velocityObject.getY()); velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET);
estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
estTimeToNextMarkObject
.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
legTimeObject.setX(LEGTIME_X_OFFSET);
legTimeObject.setY(LEGTIME_Y_OFFSET);
legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
wake = new Wake(0, -BOAT_HEIGHT); wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly); super.getChildren()
.addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject,
legTimeObject);
} }
/** /**
@@ -107,6 +155,10 @@ public class BoatGroup extends Group{
teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy);
velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx);
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy); velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
estTimeToNextMarkObject.setLayoutX(estTimeToNextMarkObject.getLayoutX() + dx);
estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy);
legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx);
legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy);
} }
@@ -123,6 +175,10 @@ public class BoatGroup extends Group{
teamNameObject.setLayoutY(y); teamNameObject.setLayoutY(y);
velocityObject.setLayoutX(x); velocityObject.setLayoutX(x);
velocityObject.setLayoutY(y); velocityObject.setLayoutY(y);
estTimeToNextMarkObject.setLayoutX(x);
estTimeToNextMarkObject.setLayoutY(y);
legTimeObject.setLayoutX(x);
legTimeObject.setLayoutY(y);
} }
public void rotateTo (double rotation) { public void rotateTo (double rotation) {
@@ -162,6 +218,17 @@ public class BoatGroup extends Group{
} }
public void setIsSelected(Boolean isSelected) {
this.isSelected = isSelected;
setTeamNameObjectVisible(isSelected);
setVelocityObjectVisible(isSelected);
setLineGroupVisible(isSelected);
setWakeVisible(isSelected);
setEstTimeToNextMarkObjectVisible(isSelected);
setLegTimeObjectVisible(isSelected);
}
public void setTeamNameObjectVisible(Boolean visible) { public void setTeamNameObjectVisible(Boolean visible) {
teamNameObject.setVisible(visible); teamNameObject.setVisible(visible);
@@ -171,6 +238,14 @@ public class BoatGroup extends Group{
velocityObject.setVisible(visible); velocityObject.setVisible(visible);
} }
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
estTimeToNextMarkObject.setVisible(visible);
}
public void setLegTimeObjectVisible(Boolean visible) {
legTimeObject.setVisible(visible);
}
public void setLineGroupVisible(Boolean visible) { public void setLineGroupVisible(Boolean visible) {
lineGroup.setVisible(visible); lineGroup.setVisible(visible);
} }
@@ -208,4 +283,9 @@ public class BoatGroup extends Group{
public boolean isStopped() { public boolean isStopped() {
return isStopped; return isStopped;
} }
@Override
public String toString() {
return boat.toString();
}
} }