mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Fix issues caused by not updating the time since last mark value frequently. BoatAnnotations now has an update() function that must be called somewhat regularly.
This commit is contained in:
@@ -15,7 +15,6 @@ import javafx.scene.canvas.GraphicsContext;
|
|||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import seng302.fxObjects.AnnotationsThingThatNeedsABetterName;
|
|
||||||
import seng302.fxObjects.BoatGroup;
|
import seng302.fxObjects.BoatGroup;
|
||||||
import seng302.models.Colors;
|
import seng302.models.Colors;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package seng302.fxObjects;
|
|||||||
|
|
||||||
import javafx.scene.CacheHint;
|
import javafx.scene.CacheHint;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
@@ -12,8 +10,6 @@ import seng302.models.stream.StreamParser;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cir27 on 23/05/17.
|
* Created by cir27 on 23/05/17.
|
||||||
@@ -29,28 +25,26 @@ public class BoatAnnotations extends Group{
|
|||||||
private static final double LEGTIME_X_OFFSET = 18d;
|
private static final double LEGTIME_X_OFFSET = 18d;
|
||||||
private static final double LEGTIME_Y_OFFSET = 7d;
|
private static final double LEGTIME_Y_OFFSET = 7d;
|
||||||
|
|
||||||
// private Rectangle background = new Rectangle();
|
private Rectangle background = new Rectangle();
|
||||||
private Text teamNameObject;
|
private Text teamNameObject;
|
||||||
private Text velocityObject;
|
private Text velocityObject;
|
||||||
private Text estTimeToNextMarkObject;
|
private Text estTimeToNextMarkObject;
|
||||||
private Text legTimeObject;
|
private Text legTimeObject;
|
||||||
private List<Node> kids;
|
private Long lastMarkTime;
|
||||||
|
|
||||||
private boolean visible = true;
|
|
||||||
|
|
||||||
BoatAnnotations (Yacht boat, Color theme) {
|
BoatAnnotations (Yacht boat, Color theme) {
|
||||||
super.setCache(true);
|
super.setCache(true);
|
||||||
// background.setX(15d);
|
background.setX(15d);
|
||||||
// background.setY(-32d);
|
background.setY(-32d);
|
||||||
// background.setWidth(150);
|
background.setWidth(150);
|
||||||
// background.setHeight(55);
|
background.setHeight(55);
|
||||||
// background.setArcHeight(10);
|
background.setArcHeight(10);
|
||||||
// background.setArcWidth(10);
|
background.setArcWidth(10);
|
||||||
// background.setFill(new Color(1, 1, 1, 0.75));
|
background.setFill(new Color(1, 1, 1, 0.25));
|
||||||
// background.setStroke(theme);
|
background.setStroke(theme);
|
||||||
// background.setStrokeWidth(2);
|
background.setStrokeWidth(2);
|
||||||
// background.setCache(true);
|
background.setCache(true);
|
||||||
// background.setCacheHint(CacheHint.SPEED);
|
background.setCacheHint(CacheHint.SPEED);
|
||||||
|
|
||||||
teamNameObject = getTextObject(boat.getShortName(), theme);
|
teamNameObject = getTextObject(boat.getShortName(), theme);
|
||||||
teamNameObject.relocate(TEAMNAME_X_OFFSET, TEAMNAME_Y_OFFSET);
|
teamNameObject.relocate(TEAMNAME_X_OFFSET, TEAMNAME_Y_OFFSET);
|
||||||
@@ -81,23 +75,13 @@ public class BoatAnnotations extends Group{
|
|||||||
legTimeObject = getTextObject("Last mark: -", theme);
|
legTimeObject = getTextObject("Last mark: -", theme);
|
||||||
legTimeObject.relocate(LEGTIME_X_OFFSET, LEGTIME_Y_OFFSET);
|
legTimeObject.relocate(LEGTIME_X_OFFSET, LEGTIME_Y_OFFSET);
|
||||||
boat.getReadOnlyMarkRoundingProperty().addListener((obs, oldTime, newTime) -> {
|
boat.getReadOnlyMarkRoundingProperty().addListener((obs, oldTime, newTime) -> {
|
||||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
lastMarkTime = newTime.longValue();
|
||||||
String elapsedTime = format
|
|
||||||
.format(StreamParser.getCurrentTimeLong() - newTime.longValue());
|
|
||||||
legTimeObject.setText("Last mark: " + elapsedTime);
|
|
||||||
});
|
});
|
||||||
boat.getReadOnlyMarkRoundingProperty().addListener(obs ->
|
boat.getReadOnlyMarkRoundingProperty().addListener(obs ->
|
||||||
legTimeObject.setText("Last mark: - ")
|
legTimeObject.setText("Last mark: - ")
|
||||||
);
|
);
|
||||||
|
|
||||||
kids = new ArrayList<>();
|
super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, legTimeObject);
|
||||||
// kids.add(background);
|
|
||||||
kids.add(velocityObject);
|
|
||||||
kids.add(teamNameObject);
|
|
||||||
kids.add(estTimeToNextMarkObject);
|
|
||||||
kids.add(legTimeObject);
|
|
||||||
|
|
||||||
// super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, legTimeObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +94,7 @@ public class BoatAnnotations extends Group{
|
|||||||
private Text getTextObject(String defaultText, Color fill) {
|
private Text getTextObject(String defaultText, Color fill) {
|
||||||
Text text = new Text(defaultText);
|
Text text = new Text(defaultText);
|
||||||
text.setFill(fill);
|
text.setFill(fill);
|
||||||
// text.setCacheHint(CacheHint.SPEED);
|
text.setCacheHint(CacheHint.SPEED);
|
||||||
text.setCache(true);
|
text.setCache(true);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@@ -131,12 +115,14 @@ public class BoatAnnotations extends Group{
|
|||||||
legTimeObject.setVisible(visible);
|
legTimeObject.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleVisible() {
|
public void update () {
|
||||||
visible = !visible;
|
if (lastMarkTime != null) {
|
||||||
this.setVisible(visible);
|
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||||
|
String elapsedTime = format
|
||||||
|
.format(StreamParser.getCurrentTimeLong() - lastMarkTime);
|
||||||
|
legTimeObject.setText("Last mark: " + elapsedTime);
|
||||||
|
}else {
|
||||||
|
legTimeObject.setText("Last mark: - ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Node> getkiddies () {
|
|
||||||
return kids;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,8 +154,7 @@ public class BoatGroup extends Group {
|
|||||||
boatAnnotations = new BoatAnnotations(boat, color);
|
boatAnnotations = new BoatAnnotations(boat, color);
|
||||||
|
|
||||||
wake = new Wake(0, -BOAT_HEIGHT);
|
wake = new Wake(0, -BOAT_HEIGHT);
|
||||||
super.getChildren().addAll(boatPoly);
|
super.getChildren().addAll(boatPoly, boatAnnotations);
|
||||||
super.getChildren().addAll(boatAnnotations.getkiddies());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,12 +179,12 @@ public class BoatGroup extends Group {
|
|||||||
private 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);
|
||||||
// boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
||||||
// boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
|
boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
|
||||||
for (Node node : boatAnnotations.getkiddies()) {
|
// for (Node node : boatAnnotations.getkiddies()) {
|
||||||
node.setLayoutX(node.getLayoutX() + dx);
|
// node.setLayoutX(node.getLayoutX() + dx);
|
||||||
node.setLayoutY(node.getLayoutY() + dy);
|
// node.setLayoutY(node.getLayoutY() + dy);
|
||||||
}
|
// }
|
||||||
wake.setLayoutX(wake.getLayoutX() + dx);
|
wake.setLayoutX(wake.getLayoutX() + dx);
|
||||||
wake.setLayoutY(wake.getLayoutY() + dy);
|
wake.setLayoutY(wake.getLayoutY() + dy);
|
||||||
}
|
}
|
||||||
@@ -201,14 +200,14 @@ public class BoatGroup extends Group {
|
|||||||
rotateTo(rotation);
|
rotateTo(rotation);
|
||||||
boatPoly.setLayoutX(x);
|
boatPoly.setLayoutX(x);
|
||||||
boatPoly.setLayoutY(y);
|
boatPoly.setLayoutY(y);
|
||||||
// boatAnnotations.setLayoutX(x);
|
boatAnnotations.setLayoutX(x);
|
||||||
// boatAnnotations.setLayoutY(y);
|
boatAnnotations.setLayoutY(y);
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
for (Node n : boatAnnotations.getkiddies()) {
|
// for (Node n : boatAnnotations.getkiddies()) {
|
||||||
n.setLayoutX(x + 10 + i);
|
// n.setLayoutX(x + 10 + i);
|
||||||
n.setLayoutY(y + 10 + i);
|
// n.setLayoutY(y + 10 + i);
|
||||||
i += 10;
|
// i += 10;
|
||||||
}
|
// }
|
||||||
wake.setLayoutX(x);
|
wake.setLayoutX(x);
|
||||||
wake.setLayoutY(y);
|
wake.setLayoutY(y);
|
||||||
wake.rotate(rotation);
|
wake.rotate(rotation);
|
||||||
@@ -355,6 +354,7 @@ public class BoatGroup extends Group {
|
|||||||
lastTimeValid = timeValid;
|
lastTimeValid = timeValid;
|
||||||
isStopped = false;
|
isStopped = false;
|
||||||
lastRotation = rotation;
|
lastRotation = rotation;
|
||||||
|
boatAnnotations.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import javafx.scene.transform.Rotate;
|
|||||||
class Wake extends Group {
|
class Wake extends Group {
|
||||||
|
|
||||||
//The number of wakes
|
//The number of wakes
|
||||||
private int numWakes = 6;
|
private int numWakes = 8;
|
||||||
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
|
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
|
||||||
private final double MAX_DIFF = 75;
|
private final double MAX_DIFF = 75;
|
||||||
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
|
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
|
||||||
@@ -83,7 +83,7 @@ class Wake extends Group {
|
|||||||
for (Arc arc : arcs) {
|
for (Arc arc : arcs) {
|
||||||
arc.setRadiusX(rad);
|
arc.setRadiusX(rad);
|
||||||
arc.setRadiusY(rad);
|
arc.setRadiusY(rad);
|
||||||
rad += (12 / numWakes) + (velocity / 2);
|
rad += (10 / numWakes) + (velocity / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user