mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Implemented boat tracking when boat is selected by either clicking or selecting from sidebar combo box. Clicking tracked boat will cancel tracking, but using combobox will always result in one boat being selected.
#story[1121] #pair[wmu16, zyt10]
This commit is contained in:
@@ -107,29 +107,36 @@ public class GameView extends Pane {
|
|||||||
VERTICAL
|
VERTICAL
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trackBoat() {
|
private void trackBoat() {
|
||||||
if (this.getScaleX() > 1) {
|
if (selectedBoat != null) {
|
||||||
boolean isBoatSelected = false;
|
double x = selectedBoat.getBoatLayoutX();
|
||||||
for (BoatObject boat : boatObjects.values()) {
|
double y = selectedBoat.getBoatLayoutY();
|
||||||
if (boat.getSelected()) {
|
double displacementX = this.getWidth();
|
||||||
isBoatSelected = true;
|
double displacementY = this.getHeight();
|
||||||
selectedBoat = boat;
|
this.setLayoutX((-x + (displacementX / 2.0)) * this.getScaleX());
|
||||||
double x = boat.getBoatLayoutX();
|
this.setLayoutY((-y + (displacementY / 2.0)) * this.getScaleY());
|
||||||
double y = boat.getBoatLayoutY();
|
|
||||||
double displacementX = this.getWidth();
|
// boolean isBoatSelected = false;
|
||||||
double displacementY = this.getHeight();
|
// for (BoatObject boat : boatObjects.values()) {
|
||||||
// double displacementX = 1200d;
|
// if (boat.getSelected()) {
|
||||||
// double displacementY = 900d;
|
// isBoatSelected = true;
|
||||||
System.out.println("displacementY = " + displacementY);
|
// selectedBoat = boat;
|
||||||
System.out.println("displacementX = " + displacementX);
|
// double x = boat.getBoatLayoutX();
|
||||||
this.setLayoutX((-x + (displacementX/2.0)) * this.getScaleX());
|
// double y = boat.getBoatLayoutY();
|
||||||
this.setLayoutY((-y + (displacementY/2.0)) * this.getScaleY());
|
// double displacementX = this.getWidth();
|
||||||
}
|
// double displacementY = this.getHeight();
|
||||||
}
|
//// double displacementX = 1200d;
|
||||||
if (!isBoatSelected) {
|
//// double displacementY = 900d;
|
||||||
this.setLayoutX(0);
|
//// System.out.println("displacementY = " + displacementY);
|
||||||
this.setLayoutY(0);
|
//// System.out.println("displacementX = " + displacementX);
|
||||||
}
|
// 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);
|
||||||
@@ -181,9 +188,7 @@ public class GameView extends Pane {
|
|||||||
lastTime = now;
|
lastTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Platform.runLater(() ->
|
boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation());
|
||||||
boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation());
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -353,6 +358,22 @@ public class GameView extends Pane {
|
|||||||
// drawGoogleMap();
|
// drawGoogleMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setSelectedBoat(BoatObject bo, Boolean isSelected) {
|
||||||
|
if (this.selectedBoat == bo && !isSelected) {
|
||||||
|
this.selectedBoat = null;
|
||||||
|
boatObjects.forEach((boat, group) ->
|
||||||
|
group.setIsSelected(false)
|
||||||
|
);
|
||||||
|
} else if (isSelected) {
|
||||||
|
this.selectedBoat = bo;
|
||||||
|
for (BoatObject group : boatObjects.values()) {
|
||||||
|
if (group != bo) {
|
||||||
|
group.setIsSelected(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws all the boats.
|
* Draws all the boats.
|
||||||
* @param yachts The yachts to set in the race
|
* @param yachts The yachts to set in the race
|
||||||
@@ -363,6 +384,7 @@ public class GameView extends Pane {
|
|||||||
for (Yacht yacht : yachts) {
|
for (Yacht yacht : yachts) {
|
||||||
Paint colour = Colors.getColor();
|
Paint colour = Colors.getColor();
|
||||||
newBoat = new BoatObject();
|
newBoat = new BoatObject();
|
||||||
|
newBoat.addSelectedBoatListener(this::setSelectedBoat);
|
||||||
newBoat.setFill(colour);
|
newBoat.setFill(colour);
|
||||||
boatObjects.put(yacht, newBoat);
|
boatObjects.put(yacht, newBoat);
|
||||||
createAndBindAnnotationBox(yacht, colour);
|
createAndBindAnnotationBox(yacht, colour);
|
||||||
@@ -598,7 +620,6 @@ 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)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.geometry.Point2D;
|
import javafx.geometry.Point2D;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
@@ -22,6 +23,12 @@ import javafx.scene.transform.Rotate;
|
|||||||
*/
|
*/
|
||||||
public class BoatObject extends Group {
|
public class BoatObject extends Group {
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SelectedBoatListener {
|
||||||
|
|
||||||
|
void notifySelected(BoatObject boatObject, Boolean isSelected);
|
||||||
|
}
|
||||||
|
|
||||||
//Constants for drawing
|
//Constants for drawing
|
||||||
private static final double BOAT_HEIGHT = 15d;
|
private static final double BOAT_HEIGHT = 15d;
|
||||||
private static final double BOAT_WIDTH = 10d;
|
private static final double BOAT_WIDTH = 10d;
|
||||||
@@ -44,6 +51,8 @@ public class BoatObject extends Group {
|
|||||||
private Boolean isBeingTracked = false;
|
private Boolean isBeingTracked = false;
|
||||||
private boolean isPlayer = false;
|
private boolean isPlayer = false;
|
||||||
|
|
||||||
|
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a BoatGroup with the default triangular boat polygon.
|
* Creates a BoatGroup with the default triangular boat polygon.
|
||||||
*/
|
*/
|
||||||
@@ -287,6 +296,7 @@ public class BoatObject extends Group {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public void setIsSelected(Boolean isSelected) {
|
public void setIsSelected(Boolean isSelected) {
|
||||||
|
updateListener(isSelected);
|
||||||
this.isSelected = isSelected;
|
this.isSelected = isSelected;
|
||||||
this.isBeingTracked = isSelected;
|
this.isBeingTracked = isSelected;
|
||||||
setLineGroupVisible(isSelected);
|
setLineGroupVisible(isSelected);
|
||||||
@@ -381,4 +391,14 @@ public class BoatObject extends Group {
|
|||||||
// yVelocity = Math.sin(Math.toRadians(heading)) * velocity * scaleFactorY;
|
// yVelocity = Math.sin(Math.toRadians(heading)) * velocity * scaleFactorY;
|
||||||
lastHeading = heading;
|
lastHeading = heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateListener(Boolean isSelected) {
|
||||||
|
for (SelectedBoatListener sbl : selectedBoatListenerListeners) {
|
||||||
|
sbl.notifySelected(this, isSelected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSelectedBoatListener(SelectedBoatListener sbl) {
|
||||||
|
selectedBoatListenerListeners.add(sbl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user