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.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import seng302.fxObjects.AnnotationsThingThatNeedsABetterName;
|
||||
import seng302.fxObjects.BoatGroup;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.Yacht;
|
||||
|
||||
@@ -2,9 +2,7 @@ package seng302.fxObjects;
|
||||
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.models.Yacht;
|
||||
@@ -12,8 +10,6 @@ import seng302.models.stream.StreamParser;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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_Y_OFFSET = 7d;
|
||||
|
||||
// private Rectangle background = new Rectangle();
|
||||
private Rectangle background = new Rectangle();
|
||||
private Text teamNameObject;
|
||||
private Text velocityObject;
|
||||
private Text estTimeToNextMarkObject;
|
||||
private Text legTimeObject;
|
||||
private List<Node> kids;
|
||||
|
||||
private boolean visible = true;
|
||||
private Long lastMarkTime;
|
||||
|
||||
BoatAnnotations (Yacht boat, Color theme) {
|
||||
super.setCache(true);
|
||||
// background.setX(15d);
|
||||
// background.setY(-32d);
|
||||
// background.setWidth(150);
|
||||
// background.setHeight(55);
|
||||
// background.setArcHeight(10);
|
||||
// background.setArcWidth(10);
|
||||
// background.setFill(new Color(1, 1, 1, 0.75));
|
||||
// background.setStroke(theme);
|
||||
// background.setStrokeWidth(2);
|
||||
// background.setCache(true);
|
||||
// background.setCacheHint(CacheHint.SPEED);
|
||||
background.setX(15d);
|
||||
background.setY(-32d);
|
||||
background.setWidth(150);
|
||||
background.setHeight(55);
|
||||
background.setArcHeight(10);
|
||||
background.setArcWidth(10);
|
||||
background.setFill(new Color(1, 1, 1, 0.25));
|
||||
background.setStroke(theme);
|
||||
background.setStrokeWidth(2);
|
||||
background.setCache(true);
|
||||
background.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
teamNameObject = getTextObject(boat.getShortName(), theme);
|
||||
teamNameObject.relocate(TEAMNAME_X_OFFSET, TEAMNAME_Y_OFFSET);
|
||||
@@ -81,23 +75,13 @@ public class BoatAnnotations extends Group{
|
||||
legTimeObject = getTextObject("Last mark: -", theme);
|
||||
legTimeObject.relocate(LEGTIME_X_OFFSET, LEGTIME_Y_OFFSET);
|
||||
boat.getReadOnlyMarkRoundingProperty().addListener((obs, oldTime, newTime) -> {
|
||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
String elapsedTime = format
|
||||
.format(StreamParser.getCurrentTimeLong() - newTime.longValue());
|
||||
legTimeObject.setText("Last mark: " + elapsedTime);
|
||||
lastMarkTime = newTime.longValue();
|
||||
});
|
||||
boat.getReadOnlyMarkRoundingProperty().addListener(obs ->
|
||||
legTimeObject.setText("Last mark: - ")
|
||||
);
|
||||
|
||||
kids = new ArrayList<>();
|
||||
// kids.add(background);
|
||||
kids.add(velocityObject);
|
||||
kids.add(teamNameObject);
|
||||
kids.add(estTimeToNextMarkObject);
|
||||
kids.add(legTimeObject);
|
||||
|
||||
// super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, 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) {
|
||||
Text text = new Text(defaultText);
|
||||
text.setFill(fill);
|
||||
// text.setCacheHint(CacheHint.SPEED);
|
||||
text.setCacheHint(CacheHint.SPEED);
|
||||
text.setCache(true);
|
||||
return text;
|
||||
}
|
||||
@@ -131,12 +115,14 @@ public class BoatAnnotations extends Group{
|
||||
legTimeObject.setVisible(visible);
|
||||
}
|
||||
|
||||
public void toggleVisible() {
|
||||
visible = !visible;
|
||||
this.setVisible(visible);
|
||||
public void update () {
|
||||
if (lastMarkTime != null) {
|
||||
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);
|
||||
|
||||
wake = new Wake(0, -BOAT_HEIGHT);
|
||||
super.getChildren().addAll(boatPoly);
|
||||
super.getChildren().addAll(boatAnnotations.getkiddies());
|
||||
super.getChildren().addAll(boatPoly, boatAnnotations);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,12 +179,12 @@ public class BoatGroup extends Group {
|
||||
private void moveGroupBy(double dx, double dy) {
|
||||
boatPoly.setLayoutX(boatPoly.getLayoutX() + dx);
|
||||
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
|
||||
// boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
||||
// boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
|
||||
for (Node node : boatAnnotations.getkiddies()) {
|
||||
node.setLayoutX(node.getLayoutX() + dx);
|
||||
node.setLayoutY(node.getLayoutY() + dy);
|
||||
}
|
||||
boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
||||
boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
|
||||
// for (Node node : boatAnnotations.getkiddies()) {
|
||||
// node.setLayoutX(node.getLayoutX() + dx);
|
||||
// node.setLayoutY(node.getLayoutY() + dy);
|
||||
// }
|
||||
wake.setLayoutX(wake.getLayoutX() + dx);
|
||||
wake.setLayoutY(wake.getLayoutY() + dy);
|
||||
}
|
||||
@@ -201,14 +200,14 @@ public class BoatGroup extends Group {
|
||||
rotateTo(rotation);
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
// boatAnnotations.setLayoutX(x);
|
||||
// boatAnnotations.setLayoutY(y);
|
||||
int i = 0;
|
||||
for (Node n : boatAnnotations.getkiddies()) {
|
||||
n.setLayoutX(x + 10 + i);
|
||||
n.setLayoutY(y + 10 + i);
|
||||
i += 10;
|
||||
}
|
||||
boatAnnotations.setLayoutX(x);
|
||||
boatAnnotations.setLayoutY(y);
|
||||
// int i = 0;
|
||||
// for (Node n : boatAnnotations.getkiddies()) {
|
||||
// n.setLayoutX(x + 10 + i);
|
||||
// n.setLayoutY(y + 10 + i);
|
||||
// i += 10;
|
||||
// }
|
||||
wake.setLayoutX(x);
|
||||
wake.setLayoutY(y);
|
||||
wake.rotate(rotation);
|
||||
@@ -355,6 +354,7 @@ public class BoatGroup extends Group {
|
||||
lastTimeValid = timeValid;
|
||||
isStopped = false;
|
||||
lastRotation = rotation;
|
||||
boatAnnotations.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import javafx.scene.transform.Rotate;
|
||||
class Wake extends Group {
|
||||
|
||||
//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.
|
||||
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.
|
||||
@@ -83,7 +83,7 @@ class Wake extends Group {
|
||||
for (Arc arc : arcs) {
|
||||
arc.setRadiusX(rad);
|
||||
arc.setRadiusY(rad);
|
||||
rad += (12 / numWakes) + (velocity / 2);
|
||||
rad += (10 / numWakes) + (velocity / 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user