mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
CSS on annotation selection and minor bug fixes. Changed annotation slider to only have None, important and All
#story[955]
This commit is contained in:
@@ -16,13 +16,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat.
|
||||
* It contains a single polygon for the boat, a group of lines to show it's path, a wake object and two text labels to
|
||||
* annotate the boat teams name and the boats velocity. The boat will update it's position onscreen everytime
|
||||
* UpdatePosition is called unless the window is minimized in which case it attempts to store animations and apply them
|
||||
* when the window is maximised.
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
|
||||
* dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path,
|
||||
* a wake object and two text labels to annotate the boat teams name and the boats velocity. The
|
||||
* boat will update it's position onscreen everytime UpdatePosition is called unless the window is
|
||||
* minimized in which case it attempts to store animations and apply them when the window is
|
||||
* maximised.
|
||||
*/
|
||||
public class BoatGroup extends RaceObject{
|
||||
public class BoatGroup extends RaceObject {
|
||||
|
||||
//Constants for drawing
|
||||
private static final double TEAMNAME_X_OFFSET = 10d;
|
||||
@@ -42,51 +43,56 @@ public class BoatGroup extends RaceObject{
|
||||
private Text teamNameObject;
|
||||
private Text velocityObject;
|
||||
private Wake wake;
|
||||
private boolean isSelected = false;
|
||||
private boolean isSelected = true; //Boats annotations are visible by default at the start
|
||||
//Handles boat moving when connecting to a stream
|
||||
private boolean setToInitialLocation = false;
|
||||
private boolean destinationSet;
|
||||
//Variables for handling minimization
|
||||
private Stage stage;
|
||||
private boolean isMaximized= true;
|
||||
private boolean isMaximized = true;
|
||||
private List<Line> lineStorage = new ArrayList<>();
|
||||
private int setCallCount = 5;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* BoatGroup to update.
|
||||
*
|
||||
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
|
||||
* to tell which BoatGroup to update.
|
||||
* @param color The colour of the boat polygon and the trailing line.
|
||||
*/
|
||||
public BoatGroup (Yacht boat, Color color){
|
||||
public BoatGroup(Yacht boat, Color color) {
|
||||
this.boat = boat;
|
||||
initChildren(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BoatGroup with the boat being the default polygon. The head of the boat should be at point (0,0).
|
||||
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which
|
||||
* BoatGroup to update.
|
||||
* Creates a BoatGroup with the boat being the default polygon. The head of the boat should be
|
||||
* at point (0,0).
|
||||
*
|
||||
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
|
||||
* to tell which BoatGroup to update.
|
||||
* @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.
|
||||
*/
|
||||
public BoatGroup (Yacht boat, Color color, double... points)
|
||||
{
|
||||
public BoatGroup(Yacht boat, Color color, double... points) {
|
||||
this.boat = boat;
|
||||
initChildren(color, points);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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) {
|
||||
boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
|
||||
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color));
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); //Toggle the selection of the boat
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
|
||||
teamNameObject = new Text(boat.getShortName());
|
||||
velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
@@ -106,17 +112,20 @@ public class BoatGroup extends RaceObject{
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private void initChildren (Color color) {
|
||||
private void initChildren(Color color) {
|
||||
initChildren(color,
|
||||
-BOAT_WIDTH / 2, BOAT_HEIGHT / 2,
|
||||
0.0, -BOAT_HEIGHT / 2,
|
||||
BOAT_WIDTH / 2, BOAT_HEIGHT / 2);
|
||||
-BOAT_WIDTH / 2, BOAT_HEIGHT / 2,
|
||||
0.0, -BOAT_HEIGHT / 2,
|
||||
BOAT_WIDTH / 2, BOAT_HEIGHT / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the boat and its children annotations from its current coordinates by specified amounts.
|
||||
* Moves the boat and its children annotations from its current coordinates by specified
|
||||
* amounts.
|
||||
*
|
||||
* @param dx The amount to move the X coordinate by
|
||||
* @param dy The amount to move the Y coordinate by
|
||||
*/
|
||||
@@ -134,21 +143,23 @@ public class BoatGroup extends RaceObject{
|
||||
|
||||
/**
|
||||
* Moves the boat and its children annotations to coordinates specified
|
||||
*
|
||||
* @param x The X coordinate to move the boat to
|
||||
* @param y The Y coordinate to move the boat to
|
||||
* @param rotation The heading in degrees from north the boat should rotate to.
|
||||
*/
|
||||
public void moveTo (double x, double y, double rotation) {
|
||||
public void moveTo(double x, double y, double rotation) {
|
||||
rotateTo(rotation);
|
||||
moveTo(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the boat and its children annotations to coordinates specified
|
||||
*
|
||||
* @param x The X coordinate to move the boat to
|
||||
* @param y The Y coordinate to move the boat to
|
||||
*/
|
||||
public void moveTo (double x, double y) {
|
||||
public void moveTo(double x, double y) {
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
teamNameObject.setLayoutX(x);
|
||||
@@ -162,9 +173,11 @@ public class BoatGroup extends RaceObject{
|
||||
|
||||
/**
|
||||
* Updates the position of all graphics in the BoatGroup based off of the given time interval.
|
||||
* @param timeInterval The interval, in milliseconds, the boat should update it's position based on.
|
||||
*
|
||||
* @param timeInterval The interval, in milliseconds, the boat should update it's position based
|
||||
* on.
|
||||
*/
|
||||
public void updatePosition (long timeInterval) {
|
||||
public void updatePosition(long timeInterval) {
|
||||
//Calculate the movement of the boat.
|
||||
if (isMaximized) {
|
||||
double dx = pixelVelocityX * timeInterval;
|
||||
@@ -177,10 +190,10 @@ public class BoatGroup extends RaceObject{
|
||||
distanceTravelled = 0;
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY()
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY()
|
||||
);
|
||||
l.getStrokeDashArray().setAll(3d, 7d);
|
||||
l.setStroke(boat.getColour());
|
||||
@@ -196,18 +209,21 @@ public class BoatGroup extends RaceObject{
|
||||
|
||||
/**
|
||||
* Sets the destination of the boat and the headng it should have once it reaches
|
||||
*
|
||||
* @param newXValue The X co-ordinate the boat needs to move to.
|
||||
* @param newYValue The Y co-ordinate the boat needs to move to.
|
||||
* @param rotation Rotation to move graphics to.
|
||||
* @param raceIds RaceID of the object to move.
|
||||
*/
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, double groundSpeed, int... raceIds) {
|
||||
public void setDestination(double newXValue, double newYValue, double rotation,
|
||||
double groundSpeed, int... raceIds) {
|
||||
if (hasRaceId(raceIds)) {
|
||||
if (setToInitialLocation) {
|
||||
destinationSet = true;
|
||||
boat.setVelocity(groundSpeed);
|
||||
if (currentRotation < 0)
|
||||
if (currentRotation < 0) {
|
||||
currentRotation = 360 - currentRotation;
|
||||
}
|
||||
double dx = newXValue - boatPoly.getLayoutX();
|
||||
double dy = newYValue - boatPoly.getLayoutY();
|
||||
//Check movement is reasonable. Assumes a 1000 * 1000 canvas
|
||||
@@ -228,7 +244,8 @@ public class BoatGroup extends RaceObject{
|
||||
rotationalVelocity = 0;
|
||||
wakeGenerationDelay--;
|
||||
} else {
|
||||
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity());
|
||||
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal,
|
||||
boat.getVelocity());
|
||||
}
|
||||
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
|
||||
} else {
|
||||
@@ -241,14 +258,14 @@ public class BoatGroup extends RaceObject{
|
||||
if (!isMaximized) {
|
||||
setToInitialLocation = false;
|
||||
wakeGenerationDelay = 2;
|
||||
if(setCallCount-- == 0) {
|
||||
if (setCallCount-- == 0) {
|
||||
setCallCount = 5;
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
newXValue,
|
||||
newYValue
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
newXValue,
|
||||
newYValue
|
||||
);
|
||||
l.getStrokeDashArray().setAll(3d, 7d);
|
||||
l.setStroke(boatPoly.getFill());
|
||||
@@ -261,32 +278,33 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
}
|
||||
|
||||
public void setDestination (double newXValue, double newYValue, double groundSpeed, int... raceIDs) {
|
||||
public void setDestination(double newXValue, double newYValue, double groundSpeed,
|
||||
int... raceIDs) {
|
||||
destinationSet = true;
|
||||
|
||||
if (hasRaceId(raceIDs)) {
|
||||
double rotation = Math.abs(
|
||||
Math.toDegrees(
|
||||
Math.atan(
|
||||
(newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX())
|
||||
)
|
||||
Math.toDegrees(
|
||||
Math.atan(
|
||||
(newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX())
|
||||
)
|
||||
)
|
||||
);
|
||||
setDestination(newXValue, newYValue, rotation, groundSpeed, raceIDs);
|
||||
}
|
||||
}
|
||||
|
||||
public void rotateTo (double rotation) {
|
||||
public void rotateTo(double rotation) {
|
||||
currentRotation = rotation;
|
||||
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||
}
|
||||
|
||||
public void forceRotation () {
|
||||
rotateTo (rotationalGoal);
|
||||
public void forceRotation() {
|
||||
rotateTo(rotationalGoal);
|
||||
wake.rotate(rotationalGoal);
|
||||
}
|
||||
|
||||
public void paintBoat (Color color) {
|
||||
public void paintBoat(Color color) {
|
||||
boatPoly.setFill(color);
|
||||
}
|
||||
|
||||
@@ -311,8 +329,9 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the boats isSelected property AS WELL as actually acting upon the value of that selection.
|
||||
* (Painting or not painting annotations)
|
||||
* This function sets the boats isSelected property AS WELL as actually acting upon the value of
|
||||
* that selection. (Painting or not painting annotations)
|
||||
*
|
||||
* @param isSelected A Boolean indicating whether or not the boat is selected
|
||||
*/
|
||||
public void setIsSelected(Boolean isSelected) {
|
||||
@@ -330,10 +349,11 @@ public class BoatGroup extends RaceObject{
|
||||
* @param raceIds The ID's to check the BoatGroup for.
|
||||
* @return True if the BoatGroup contains at east one of the given IDs, false otherwise.
|
||||
*/
|
||||
public boolean hasRaceId (int... raceIds) {
|
||||
public boolean hasRaceId(int... raceIds) {
|
||||
for (int id : raceIds) {
|
||||
if (id == boat.getSourceID())
|
||||
if (id == boat.getSourceID()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -343,31 +363,32 @@ public class BoatGroup extends RaceObject{
|
||||
*
|
||||
* @return An array containing all ID's associated with this RaceObject.
|
||||
*/
|
||||
public int[] getRaceIds () {
|
||||
return new int[] {boat.getSourceID()};
|
||||
public int[] getRaceIds() {
|
||||
return new int[]{boat.getSourceID()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Due to javaFX limitations annotations associated with a boat that you want to appear below all boats in the
|
||||
* Z-axis need to be pulled out of the BoatGroup and added to the parent group of the BoatGroups. This function
|
||||
* returns these annotations as a group.
|
||||
* Due to javaFX limitations annotations associated with a boat that you want to appear below
|
||||
* all boats in the Z-axis need to be pulled out of the BoatGroup and added to the parent group
|
||||
* of the BoatGroups. This function returns these annotations as a group.
|
||||
*
|
||||
* @return A group containing low priority annotations.
|
||||
*/
|
||||
public Group getLowPriorityAnnotations () {
|
||||
public Group getLowPriorityAnnotations() {
|
||||
Group group = new Group();
|
||||
group.getChildren().addAll(wake, lineGroup);
|
||||
group.getChildren().addAll(wake, lineGroup, teamNameObject, velocityObject);
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to let the BoatGroup know about the stage it is in. If it knows about it's stage then it will
|
||||
* listen to the iconified property of that stage and change it's behaviour upon minimization. Without setting the
|
||||
* Stage there is guarantee that the BoatGroup will draw properly when the stage is minimized.
|
||||
* Use this function to let the BoatGroup know about the stage it is in. If it knows about it's
|
||||
* stage then it will listen to the iconified property of that stage and change it's behaviour
|
||||
* upon minimization. Without setting the Stage there is guarantee that the BoatGroup will draw
|
||||
* properly when the stage is minimized.
|
||||
*
|
||||
* @param stage The stage that the BoatGroup is added to.
|
||||
*/
|
||||
public void setStage (Stage stage) {
|
||||
public void setStage(Stage stage) {
|
||||
/* TODO: 4/05/17 cir27 - Find a way to get the stage to this point. Need to pass it through multiple controllers.
|
||||
App.start() -> Controller.setContentPane -> RaceViewController -> CanvasController
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user