Trackpoints are only shown for the player's boat. #story[1098]

main
Joseph 8 years ago
parent 47fc55245c
commit d7e0bfa86c

@ -7,6 +7,7 @@ import shared.exceptions.BoatNotFoundException;
import shared.exceptions.MarkNotFoundException;
import shared.model.GPSCoordinate;
import shared.model.Mark;
import visualiser.model.ThisBoat;
import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceEvent;
import visualiser.model.VisualiserRaceState;
@ -95,7 +96,7 @@ public class BoatLocationCommand implements Command {
* @param boat The boat to add a track point to.
*/
private void attemptAddTrackPoint(VisualiserBoat boat) {
if (boat.getStatus() == BoatStatusEnum.RACING) {
if (boat.getStatus() == BoatStatusEnum.RACING && boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
boat.addTrackPoint(boat.getCurrentPosition(), visualiserRace.getRaceClock().getCurrentTime());
}
}

@ -27,8 +27,11 @@ import java.util.List;
*/
public class ResizableRaceCanvas extends ResizableCanvas {
private RaceMap map; // for converting GPSCoordinates to GraphCoordinates
private Image background;
/**
* The RaceMap used for converting GPSCoordinates to GraphCoordinates.
*/
private RaceMap map;
private Image sailsRight = new Image("/images/sailsRight.png");
private Image sailsLeft = new Image("/images/sailsLeft.png");
private Image sailsLuff = new Image("/images/sailsLuff.gif", 25, 10, false, false);
@ -47,12 +50,15 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private boolean annoTimeSinceLastMark = true;
private boolean annoGuideLine = false;
/**
* Constructs a {@link ResizableRaceCanvas} using a given {@link VisualiserRaceEvent}.
* @param visualiserRace The race that data is read from in order to be drawn.
*/
public ResizableRaceCanvas(VisualiserRaceEvent visualiserRace) {
super();
this.visualiserRace = visualiserRace;
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
@ -63,9 +69,14 @@ public class ResizableRaceCanvas extends ResizableCanvas {
double long2 = raceData.getMapBottomRight().getLongitude();
this.map = new RaceMap(
lat1, long1, lat2, long2, (int)getWidth(), (int)getHeight());
lat1, long1, lat2, long2,
(int) getWidth(), (int) getHeight() );
}
/**
* Toggle name display in annotation
*/
@ -116,8 +127,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
/**
* Rotates things displayed on the canvas. Note: this must be called in
* between gc.save() and gc.restore() else they will rotate everything
* Rotates things on the canvas Note: this must be called in between gc.save() and gc.restore() else they will rotate everything
*
* @param degrees Bearing degrees to rotate.
* @param px Pivot point x of rotation.
@ -128,6 +138,8 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
}
/**
* Draws a circle with a given diameter, centred on a given graph coordinate.
* @param center The center coordinate of the circle.
@ -139,8 +151,8 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillOval(
center.getX() - (diameter / 2),
center.getY() - (diameter / 2),
diameter, diameter
);
diameter, diameter );
}
/**
@ -155,6 +167,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.setStroke(paint);
gc.setFill(paint);
double endPointDiameter = 6;
//Draw first end-point.
@ -168,8 +181,8 @@ public class ResizableRaceCanvas extends ResizableCanvas {
graphCoordinateA.getX(),
graphCoordinateA.getY(),
graphCoordinateB.getX(),
graphCoordinateB.getY()
);
graphCoordinateB.getY() );
}
/**
@ -189,6 +202,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
drawCircle(graphCoordinate, pointDiameter);
}
/**
* Display given name and speed of boat at a graph coordinate
*
@ -204,6 +218,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
//The text to draw. Built during the function.
String text = "";
//Draw name if annotation is enabled.
if (annoName) {
text += String.format("%s ", name);
@ -229,6 +244,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
text += timeSinceLastMark;
}
//Offset by 20 pixels horizontally.
long xCoord = coordinate.getX() + 20;
long yCoord = coordinate.getY();
@ -247,11 +263,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillText(text, xCoord, yCoord);
}
/**
* Draws the label for a given boat. Includes name, abbreviation, speed, time since mark, and time to next mark.
* @param boat The boat to draw text for.
*/
private void drawBoatText(VisualiserBoat boat) {
drawText(
boat.getName(),
boat.getCountry(),
@ -259,8 +277,12 @@ public class ResizableRaceCanvas extends ResizableCanvas {
this.map.convertGPS(boat.getCurrentPosition()),
boat.getTimeToNextMarkFormatted(this.visualiserRace.getVisualiserRaceState().getRaceClock().getCurrentTime()),
boat.getTimeSinceLastMarkFormatted(this.visualiserRace.getVisualiserRaceState().getRaceClock().getCurrentTime()) );
}
/**
* Draws all of the boats on the canvas.
*/
@ -276,8 +298,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
drawWake(boat);
}
//Draw the boat.
drawBoat(boat);
//If the race hasn't started, we set the time since last mark to the current time, to ensure we don't start counting until the race actually starts.
if ((boat.getStatus() != BoatStatusEnum.RACING) && (boat.getStatus() == BoatStatusEnum.FINISHED)) {
@ -286,7 +306,12 @@ public class ResizableRaceCanvas extends ResizableCanvas {
//Draw boat label.
drawBoatText(boat);
//Draw track.
drawTrack(boat);
}
}
/**
@ -306,13 +331,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
double[] x = {
pos.getX() - 6,
pos.getX(),
pos.getX() + 6};
pos.getX() + 6 };
//The y coordinates of each vertex of the boat.
double[] y = {
pos.getY() + 12,
pos.getY() - 12,
pos.getY() + 12};
pos.getY() + 12 };
//The above shape is essentially a triangle 12px wide, and 24px long.
@ -342,13 +367,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
double[] x = {
pos.getX() - 9,
pos.getX(),
pos.getX() + 9};
pos.getX() + 9 };
//The y coordinates of each vertex of the boat.
double[] y = {
pos.getY() + 15,
pos.getY() - 15,
pos.getY() + 15};
pos.getY() + 15 };
//The above shape is essentially a triangle 24px wide, and 48 long.
@ -359,6 +384,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
rotate(boat.getBearing().degrees(), pos.getX(), pos.getY());
gc.fillPolygon(x, y, 3);
gc.restore();
}
/**
@ -431,13 +457,18 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* @param boat Boat to draw wake for.
*/
private void drawWake(VisualiserBoat boat) {
// Calculate either end of wake line.
//Calculate either end of wake line.
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
//Draw.
drawLine(wakeFrom, wakeTo, boat.getColor());
}
/**
* Draws all of the {@link Mark}s on the canvas.
*/
@ -448,21 +479,31 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
}
/**
* Draws a given mark on the canvas.
* @param mark The mark to draw.
*/
private void drawMark(Mark mark) {
GraphCoordinate markToDraw = this.map.convertGPS(mark.getPosition());
drawPoint(markToDraw, Color.LIMEGREEN);
//Calculate screen position.
GraphCoordinate mark1 = this.map.convertGPS(mark.getPosition());
//Draw.
drawPoint(mark1, Color.LIMEGREEN);
}
/**
* Draws the Race Map.
* Called when the canvas is resized.
*/
public void draw() {
clear(); // clear previous canvas
//Clear canvas.
clear();
//Update our RaceMap using new canvas size.
this.map.setWidth((int) getWidth());
@ -473,6 +514,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* Clears the canvas.
*/
@ -480,6 +522,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.clearRect(0, 0, getWidth(), getHeight());
}
/**
* Draws the race boundary.
*/
@ -520,8 +563,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
this.map.setGPSBotRight(visualiserRace.getVisualiserRaceState().getRaceDataSource().getMapBottomRight());
gc.setLineWidth(2);
clear(); // clear the previous canvas
clear();
//Race boundary.
drawBoundary();
//Guiding Line
@ -531,7 +576,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
//Boats.
drawBoats();
//Marks.
drawMarks();
}
/**
@ -671,9 +719,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
/**
* Draws all track points for a given boat. Colour is set by boat, opacity
* by track point. This checks if {@link #annoPath} is enabled.
* Draws all track points for a given boat. Colour is set by boat, opacity by track point.
* This checks if {@link #annoPath} is enabled.
* @param boat The boat to draw tracks for.
* @see TrackPoint
*/
@ -694,6 +743,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), point.getDiameter(), point.getDiameter());
}
}
}
}
}
Loading…
Cancel
Save