Added boat trails to the boat group, fixed annotations

- Set colours for the annotations
- Added boat trails back into the boat group
- Re-added time until next mark and time since last mark rounding

#story[923]
This commit is contained in:
Michael Rausch
2017-05-19 20:55:02 +12:00
parent aaf2e6a3f0
commit 937b309b07
5 changed files with 121 additions and 42 deletions
-2
View File
@@ -17,8 +17,6 @@ public class App extends Application {
primaryStage.setTitle("RaceVision"); primaryStage.setTitle("RaceVision");
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
primaryStage.setMaximized(true); primaryStage.setMaximized(true);
primaryStage.setFullScreenExitHint("");
primaryStage.setFullScreen(true);
primaryStage.show(); primaryStage.show();
@@ -181,7 +181,7 @@ public class CanvasController {
for (MarkGroup markGroup : markGroups) { for (MarkGroup markGroup : markGroups) {
for (int id : markGroup.getRaceIds()) { for (int id : markGroup.getRaceIds()) {
if (StreamParser.boatPositions.containsKey(id)) { if (StreamParser.boatPositions.containsKey(id)) {
UpdateMarkGroup(id, markGroup); updateMarkGroup(id, markGroup);
} }
} }
} }
@@ -214,7 +214,7 @@ public class CanvasController {
} }
} }
void UpdateMarkGroup (int raceId, MarkGroup markGroup) { void updateMarkGroup (int raceId, MarkGroup markGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(raceId); PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(raceId);
if (movementQueue.size() > 0){ if (movementQueue.size() > 0){
try { try {
+107 -26
View File
@@ -1,11 +1,14 @@
package seng302.models; package seng302.models;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.CacheHint; import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.input.MouseDragEvent; import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Line;
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;
@@ -50,6 +53,10 @@ public class BoatGroup extends Group{
private Text estTimeToNextMarkObject; private Text estTimeToNextMarkObject;
private Text legTimeObject; private Text legTimeObject;
private Wake wake; private Wake wake;
private Double distanceTravelled = 0.0;
private Point2D lastPoint;
private boolean destinationSet;
private Color textColor = Color.RED;
private Boolean isSelected = true; //All boats are initalised as selected private Boolean isSelected = true; //All boats are initalised as selected
@@ -62,6 +69,7 @@ public class BoatGroup extends Group{
public BoatGroup (Yacht boat, Color color){ public BoatGroup (Yacht boat, Color color){
this.boat = boat; this.boat = boat;
initChildren(color); initChildren(color);
this.textColor = color;
} }
/** /**
@@ -77,12 +85,31 @@ public class BoatGroup extends Group{
initChildren(color, points); initChildren(color, points);
} }
/**
* Return a text object with caching and a color applied
* @param defaultText The default text to display
* @param fill The text fill color
* @return The text object
*/
private Text getTextObject(String defaultText, Color fill){
Text text = new Text(defaultText);
text.setFill(fill);
text.setCacheHint(CacheHint.SPEED);
text.setCache(true);
return text;
}
/** /**
* Creates the javafx objects that will be the in the group by default. * Creates the javafx objects that will be the in the group by default.
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon. * @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon.
*/ */
private void initChildren (Color color, double... points) { private void initChildren (Color color, double... points) {
textColor = color;
destinationSet = false;
boatPoly = new Polygon(points); boatPoly = new Polygon(points);
boatPoly.setFill(color); boatPoly.setFill(color);
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE)); boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
@@ -91,24 +118,8 @@ public class BoatGroup extends Group{
boatPoly.setCache(true); boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED); boatPoly.setCacheHint(CacheHint.SPEED);
teamNameObject = getTextObject(boat.getShortName(), textColor);
teamNameObject = new Text(boat.getShortName()); velocityObject = getTextObject(boat.getVelocity().toString(), textColor);
teamNameObject.setCache(true);
teamNameObject.setCacheHint(CacheHint.SPEED);
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);
@@ -118,15 +129,23 @@ 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());
updateLastMarkRoundingTime();
updateTimeTillNextMark();
if (estTimeToNextMarkObject != null){
estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET); estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET);
estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET); estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
estTimeToNextMarkObject estTimeToNextMarkObject
.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY()); .relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
}
if (legTimeObject != null){
legTimeObject.setX(LEGTIME_X_OFFSET); legTimeObject.setX(LEGTIME_X_OFFSET);
legTimeObject.setY(LEGTIME_Y_OFFSET); legTimeObject.setY(LEGTIME_Y_OFFSET);
legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY()); legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
}
wake = new Wake(0, -BOAT_HEIGHT); wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren() super.getChildren()
.addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject, .addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject,
@@ -149,7 +168,7 @@ public class BoatGroup extends Group{
* @param dx The amount to move the X coordinate by * @param dx The amount to move the X coordinate by
* @param dy The amount to move the Y coordinate by * @param dy The amount to move the Y coordinate by
*/ */
public void moveGroupBy(double dx, double dy) { private void moveGroupBy(double dx, double dy) {
boatPoly.setLayoutX(boatPoly.getLayoutX() + dx); boatPoly.setLayoutX(boatPoly.getLayoutX() + dx);
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy); boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx); teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx);
@@ -160,7 +179,6 @@ public class BoatGroup extends Group{
estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy); estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy);
legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx); legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx);
legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy); legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy);
////////
wake.setLayoutX(wake.getLayoutX() + dx); wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy); wake.setLayoutY(wake.getLayoutY() + dy);
} }
@@ -171,7 +189,7 @@ public class BoatGroup extends Group{
* @param x The X coordinate to move the boat to * @param x The X coordinate to move the boat to
* @param y The Y coordinate to move the boat to * @param y The Y coordinate to move the boat to
*/ */
public void moveTo (double x, double y, double rotation) { private void moveTo(double x, double y, double rotation) {
rotateTo(rotation); rotateTo(rotation);
boatPoly.setLayoutX(x); boatPoly.setLayoutX(x);
boatPoly.setLayoutY(y); boatPoly.setLayoutY(y);
@@ -183,28 +201,86 @@ public class BoatGroup extends Group{
estTimeToNextMarkObject.setLayoutY(y); estTimeToNextMarkObject.setLayoutY(y);
legTimeObject.setLayoutX(x); legTimeObject.setLayoutX(x);
legTimeObject.setLayoutY(y); legTimeObject.setLayoutY(y);
/////////
wake.setLayoutX(x); wake.setLayoutX(x);
wake.setLayoutY(y); wake.setLayoutY(y);
wake.rotate(rotation); wake.rotate(rotation);
} }
public void rotateTo (double rotation) { private void rotateTo(double rotation) {
boatPoly.getTransforms().setAll(new Rotate(rotation)); boatPoly.getTransforms().setAll(new Rotate(rotation));
} }
/**
* Updates the time until next mark label, will create a label if one doesn't exist
*/
private void updateTimeTillNextMark(){
if (estTimeToNextMarkObject == null){
estTimeToNextMarkObject = getTextObject("", textColor);
}
DateFormat format = new SimpleDateFormat("mm:ss");
String timeToNextMark = format
.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
}
/**
* Updates the time since last mark rounding, will create a label if one doesn't exist
*/
private void updateLastMarkRoundingTime(){
if (legTimeObject == null){
legTimeObject = getTextObject("", textColor);
}
if (boat.getMarkRoundingTime() != null){
DateFormat format = new SimpleDateFormat("mm:ss");
String elapsedTime = format
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
legTimeObject.setText("Last mark: " + elapsedTime);
}
else{
legTimeObject.setText("Last mark: -");
}
}
public void move() { public void move() {
double dx = xIncrement * framesToMove;
double dy = yIncrement * framesToMove;
distanceTravelled += Math.abs(dx) + Math.abs(dy);
moveGroupBy(xIncrement, yIncrement); moveGroupBy(xIncrement, yIncrement);
framesToMove = framesToMove - 1; framesToMove = framesToMove - 1;
if (framesToMove <= 0){ if (framesToMove <= 0){
isStopped = true; isStopped = true;
} }
////////////
if (distanceTravelled > 70){
distanceTravelled = 0d;
if (lastPoint != null){
Line l = new Line(
lastPoint.getX(),
lastPoint.getY(),
boatPoly.getLayoutX(),
boatPoly.getLayoutY()
);
l.getStrokeDashArray().setAll(3d, 7d);
l.setStroke(boat.getColour());
l.setCache(true);
l.setCacheHint(CacheHint.SPEED);
lineGroup.getChildren().add(l);
}
if (destinationSet){
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
}
}
wake.updatePosition(1000/60); wake.updatePosition(1000/60);
} }
///////////
/** /**
* Calculates the rotational velocity required to reach the rotationalGoal from the currentRotation. * Calculates the rotational velocity required to reach the rotationalGoal from the currentRotation.
*/ */
@@ -248,8 +324,13 @@ public class BoatGroup extends Group{
xIncrement = dx/framesToMove; xIncrement = dx/framesToMove;
yIncrement = dy/framesToMove; yIncrement = dy/framesToMove;
destinationSet = true;
Double rotationalVelocity = calculateRotationalVelocity(rotation); Double rotationalVelocity = calculateRotationalVelocity(rotation);
updateTimeTillNextMark();
updateLastMarkRoundingTime();
if (Math.abs(rotationalVelocity) > 0.075) { if (Math.abs(rotationalVelocity) > 0.075) {
rotationalVelocity = 0.0; rotationalVelocity = 0.0;
wake.rotate(rotation); wake.rotate(rotation);
+1 -1
View File
@@ -6,7 +6,7 @@ import javafx.scene.paint.Color;
* Created by ryan_ on 16/03/2017. * Created by ryan_ on 16/03/2017.
*/ */
public enum Colors { public enum Colors {
RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE; RED, PERU, SEAGREEN, GREEN, BLUE, PURPLE;
static Integer index = 0; static Integer index = 0;
+1 -1
View File
@@ -151,7 +151,7 @@ public class Yacht {
this.colour = colour; this.colour = colour;
} }
public double getVelocity() { public Double getVelocity() {
return velocity; return velocity;
} }