Decoupled drawing and adding track points, added combobox selector for visible boats.
This commit is contained in:
@@ -4,6 +4,7 @@ package seng302.Controllers;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
@@ -40,6 +41,8 @@ public class RaceController extends Controller {
|
||||
Label timer;
|
||||
@FXML
|
||||
Label FPS;
|
||||
@FXML
|
||||
ComboBox<BoatInRace> visibleTrackSelect;
|
||||
|
||||
@FXML
|
||||
TableView<BoatInRace> boatInfoTable;
|
||||
@@ -165,6 +168,7 @@ public class RaceController extends Controller {
|
||||
startScreen.setVisible(false);
|
||||
ongoingRacePane.setVisible(true);
|
||||
|
||||
visibleTrackSelect.setItems(FXCollections.observableArrayList(startingBoats));
|
||||
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
@@ -191,6 +195,13 @@ public class RaceController extends Controller {
|
||||
FPS.setText((fps));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void toggleTrackVisibility() {
|
||||
visibleTrackSelect.getSelectionModel().getSelectedItem().setTrackVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up FPS display at bottom of screen
|
||||
*/
|
||||
|
||||
@@ -28,10 +28,12 @@ public class BoatInRace extends Boat {
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
|
||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
||||
private long nextValidTime = 0;
|
||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 2 seconds
|
||||
private final int TRACK_POINT_LIMIT = 10;
|
||||
private boolean trackVisible = false;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -272,4 +274,12 @@ public class BoatInRace extends Boat {
|
||||
public Queue<GPSCoordinate> getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
public boolean isTrackVisible() {
|
||||
return trackVisible;
|
||||
}
|
||||
|
||||
public void setTrackVisible(boolean trackVisible) {
|
||||
this.trackVisible = trackVisible;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +203,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
for (BoatInRace boat : startingBoats) {
|
||||
if (boat != null && !boat.isFinished()) {
|
||||
boat.addTrackPoint(boat.getCurrentPosition());
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
} else {
|
||||
displayBoat(boat, 0);
|
||||
}
|
||||
addTrackPoint(boat);
|
||||
drawTrackPoint(boat);
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
@@ -289,10 +289,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
private void addTrackPoint(BoatInRace boat) {
|
||||
if (boat.addTrackPoint(boat.getCurrentPosition())) {
|
||||
GraphCoordinate coordinate = this.map.convertGPS(boat.getCurrentPosition());
|
||||
}
|
||||
private void drawTrackPoint(BoatInRace boat) {
|
||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
||||
gc.setFill(boat.getColour());
|
||||
|
||||
@@ -71,12 +71,13 @@
|
||||
<children>
|
||||
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||
<children>
|
||||
<TitledPane fx:id="userControl" animated="false" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<TitledPane fx:id="userControl" animated="false" prefHeight="128.0" prefWidth="202.0" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="0.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
||||
<ComboBox fx:id="visibleTrackSelect" layoutX="3.0" layoutY="65.0" onAction="#toggleTrackVisibility" prefWidth="150.0" promptText="Visible tracks" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="55.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
||||
Reference in New Issue
Block a user