mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Got the boat's to track and center correctly.
As well as allowing selecting different boats to track them, doesn't work as intuitively as I would like but will need to sort out a boat selection feature first made specifically for the selection of only one boat. #story[1121]
This commit is contained in:
@@ -222,7 +222,6 @@ public class GameClient {
|
|||||||
* Updates the position of a boat. Boat and position are given in the provided data.
|
* Updates the position of a boat. Boat and position are given in the provided data.
|
||||||
*/
|
*/
|
||||||
private void updatePosition(PositionUpdateData positionData) {
|
private void updatePosition(PositionUpdateData positionData) {
|
||||||
raceView.getGameView().trackBoat();
|
|
||||||
if (positionData.getType() == DeviceType.YACHT_TYPE) {
|
if (positionData.getType() == DeviceType.YACHT_TYPE) {
|
||||||
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
|
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
|
||||||
Yacht yacht = allBoatsMap.get(positionData.getDeviceId());
|
Yacht yacht = allBoatsMap.get(positionData.getDeviceId());
|
||||||
@@ -230,6 +229,7 @@ public class GameClient {
|
|||||||
positionData.getLon(), positionData.getHeading(),
|
positionData.getLon(), positionData.getHeading(),
|
||||||
positionData.getGroundSpeed());
|
positionData.getGroundSpeed());
|
||||||
}
|
}
|
||||||
|
raceView.getGameView().trackBoat();
|
||||||
} else if (positionData.getType() == DeviceType.MARK_TYPE) {
|
} else if (positionData.getType() == DeviceType.MARK_TYPE) {
|
||||||
//CompoundMark mark = courseData.getCompoundMarks().get(positionData.getDeviceId());
|
//CompoundMark mark = courseData.getCompoundMarks().get(positionData.getDeviceId());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Point2D;
|
import javafx.geometry.Point2D;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
@@ -19,6 +20,7 @@ import javafx.scene.paint.Color;
|
|||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import seng302.gameServer.server.simulator.Boat;
|
||||||
import seng302.model.Colors;
|
import seng302.model.Colors;
|
||||||
import seng302.model.GeoPoint;
|
import seng302.model.GeoPoint;
|
||||||
import seng302.model.Limit;
|
import seng302.model.Limit;
|
||||||
@@ -66,6 +68,7 @@ public class GameView extends Pane {
|
|||||||
private Map<Yacht, BoatObject> boatObjects = new HashMap<>();
|
private Map<Yacht, BoatObject> boatObjects = new HashMap<>();
|
||||||
private Map<Yacht, AnnotationBox> annotations = new HashMap<>();
|
private Map<Yacht, AnnotationBox> annotations = new HashMap<>();
|
||||||
private ObservableList<Node> gameObjects;
|
private ObservableList<Node> gameObjects;
|
||||||
|
private BoatObject selectedBoat = null;
|
||||||
private Group annotationsGroup = new Group();
|
private Group annotationsGroup = new Group();
|
||||||
private Group wakesGroup = new Group();
|
private Group wakesGroup = new Group();
|
||||||
private Group boatObjectGroup = new Group();
|
private Group boatObjectGroup = new Group();
|
||||||
@@ -106,21 +109,27 @@ public class GameView extends Pane {
|
|||||||
|
|
||||||
public void trackBoat() {
|
public void trackBoat() {
|
||||||
if (this.getScaleX() > 1) {
|
if (this.getScaleX() > 1) {
|
||||||
double x = boatObjects.get(playerYacht).getBoatLayoutX();
|
boolean isBoatSelected = false;
|
||||||
double y = boatObjects.get(playerYacht).getBoatLayoutY();
|
for (BoatObject boat : boatObjects.values()) {
|
||||||
// System.out.println("x = " + x);
|
if (boat.getSelected()) {
|
||||||
// System.out.println("y = " + y);
|
isBoatSelected = true;
|
||||||
// this.setRotate(-playerYacht.getHeading());
|
selectedBoat = boat;
|
||||||
Point2D displacementX = findScaledXY(maxLonPoint);
|
double x = boat.getBoatLayoutX();
|
||||||
Point2D displacementY = findScaledXY(maxLatPoint);
|
double y = boat.getBoatLayoutY();
|
||||||
this.setLayoutX(-x + 250 + canvasWidth/2);
|
double displacementX = this.getWidth();
|
||||||
this.setLayoutY(-y + canvasHeight/2);
|
double displacementY = this.getHeight();
|
||||||
|
this.setLayoutX((-x + ((displacementX)/2.0)) * this.getScaleX());
|
||||||
|
this.setLayoutY((-y + ((displacementY)/2.0)) * this.getScaleY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isBoatSelected) {
|
||||||
|
this.setLayoutX(0);
|
||||||
|
this.setLayoutY(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setLayoutX(0);
|
this.setLayoutX(0);
|
||||||
this.setLayoutY(0);
|
this.setLayoutY(0);
|
||||||
}
|
}
|
||||||
// System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutX());
|
|
||||||
// System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutY());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameView () {
|
public GameView () {
|
||||||
@@ -584,6 +593,7 @@ public class GameView extends Pane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void selectBoat (Yacht selectedYacht) {
|
public void selectBoat (Yacht selectedYacht) {
|
||||||
|
selectedBoat = boatObjects.get(selectedYacht);
|
||||||
boatObjects.forEach((boat, group) ->
|
boatObjects.forEach((boat, group) ->
|
||||||
group.setIsSelected(boat == selectedYacht)
|
group.setIsSelected(boat == selectedYacht)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ public class BoatObject extends Group {
|
|||||||
private double distanceTravelled, lastRotation;
|
private double distanceTravelled, lastRotation;
|
||||||
private Point2D lastPoint;
|
private Point2D lastPoint;
|
||||||
private Paint colour = Color.BLACK;
|
private Paint colour = Color.BLACK;
|
||||||
private Boolean isSelected, destinationSet; //All boats are initialised as selected
|
private Boolean isSelected = false, destinationSet; //All boats are initialised as selected
|
||||||
|
private Boolean isBeingTracked = false;
|
||||||
private boolean isPlayer = false;
|
private boolean isPlayer = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,6 +288,7 @@ public class BoatObject extends Group {
|
|||||||
|
|
||||||
public void setIsSelected(Boolean isSelected) {
|
public void setIsSelected(Boolean isSelected) {
|
||||||
this.isSelected = isSelected;
|
this.isSelected = isSelected;
|
||||||
|
this.isBeingTracked = isSelected;
|
||||||
setLineGroupVisible(isSelected);
|
setLineGroupVisible(isSelected);
|
||||||
setWakeVisible(isSelected);
|
setWakeVisible(isSelected);
|
||||||
setLayLinesVisible(isSelected);
|
setLayLinesVisible(isSelected);
|
||||||
@@ -364,6 +366,14 @@ public class BoatObject extends Group {
|
|||||||
lastHeading = heading;
|
lastHeading = heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getBeingTracked() {
|
||||||
|
return isBeingTracked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSelected() {
|
||||||
|
return isSelected;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTrajectory(double heading, double velocity, double scaleFactorX, double scaleFactorY) {
|
public void setTrajectory(double heading, double velocity, double scaleFactorX, double scaleFactorY) {
|
||||||
// wake.setRotation(lastHeading - heading, velocity);
|
// wake.setRotation(lastHeading - heading, velocity);
|
||||||
// rotateTo(heading);
|
// rotateTo(heading);
|
||||||
|
|||||||
Reference in New Issue
Block a user