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:
@@ -1,6 +1,7 @@
|
||||
package seng302.visualiser.fxObjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Group;
|
||||
@@ -22,6 +23,12 @@ import javafx.scene.transform.Rotate;
|
||||
*/
|
||||
public class BoatObject extends Group {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SelectedBoatListener {
|
||||
|
||||
void notifySelected(BoatObject boatObject, Boolean isSelected);
|
||||
}
|
||||
|
||||
//Constants for drawing
|
||||
private static final double BOAT_HEIGHT = 15d;
|
||||
private static final double BOAT_WIDTH = 10d;
|
||||
@@ -44,6 +51,8 @@ public class BoatObject extends Group {
|
||||
private Boolean isBeingTracked = false;
|
||||
private boolean isPlayer = false;
|
||||
|
||||
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a BoatGroup with the default triangular boat polygon.
|
||||
*/
|
||||
@@ -287,6 +296,7 @@ public class BoatObject extends Group {
|
||||
// }
|
||||
|
||||
public void setIsSelected(Boolean isSelected) {
|
||||
updateListener(isSelected);
|
||||
this.isSelected = isSelected;
|
||||
this.isBeingTracked = isSelected;
|
||||
setLineGroupVisible(isSelected);
|
||||
@@ -381,4 +391,14 @@ public class BoatObject extends Group {
|
||||
// yVelocity = Math.sin(Math.toRadians(heading)) * velocity * scaleFactorY;
|
||||
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