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.property.ReadOnlyObjectWrapper;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
@@ -40,6 +41,8 @@ public class RaceController extends Controller {
|
|||||||
Label timer;
|
Label timer;
|
||||||
@FXML
|
@FXML
|
||||||
Label FPS;
|
Label FPS;
|
||||||
|
@FXML
|
||||||
|
ComboBox<BoatInRace> visibleTrackSelect;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
TableView<BoatInRace> boatInfoTable;
|
TableView<BoatInRace> boatInfoTable;
|
||||||
@@ -165,6 +168,7 @@ public class RaceController extends Controller {
|
|||||||
startScreen.setVisible(false);
|
startScreen.setVisible(false);
|
||||||
ongoingRacePane.setVisible(true);
|
ongoingRacePane.setVisible(true);
|
||||||
|
|
||||||
|
visibleTrackSelect.setItems(FXCollections.observableArrayList(startingBoats));
|
||||||
|
|
||||||
initializeFPS();
|
initializeFPS();
|
||||||
initializeAnnotations();
|
initializeAnnotations();
|
||||||
@@ -191,6 +195,13 @@ public class RaceController extends Controller {
|
|||||||
FPS.setText((fps));
|
FPS.setText((fps));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void toggleTrackVisibility() {
|
||||||
|
visibleTrackSelect.getSelectionModel().getSelectedItem().setTrackVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up FPS display at bottom of screen
|
* Set up FPS display at bottom of screen
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ public class BoatInRace extends Boat {
|
|||||||
private StringProperty currentLegName;
|
private StringProperty currentLegName;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
|
|
||||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
||||||
private long nextValidTime = 0;
|
private long nextValidTime = 0;
|
||||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 2 seconds
|
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 2 seconds
|
||||||
private final int TRACK_POINT_LIMIT = 10;
|
private final int TRACK_POINT_LIMIT = 10;
|
||||||
|
private boolean trackVisible = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -272,4 +274,12 @@ public class BoatInRace extends Boat {
|
|||||||
public Queue<GPSCoordinate> getTrack() {
|
public Queue<GPSCoordinate> getTrack() {
|
||||||
return track;
|
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) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null && !boat.isFinished()) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
|
boat.addTrackPoint(boat.getCurrentPosition());
|
||||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||||
checkPosition(boat, totalTimeElapsed);
|
checkPosition(boat, totalTimeElapsed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
} else {
|
} else {
|
||||||
displayBoat(boat, 0);
|
displayBoat(boat, 0);
|
||||||
}
|
}
|
||||||
addTrackPoint(boat);
|
drawTrackPoint(boat);
|
||||||
|
|
||||||
if (raceAnno)
|
if (raceAnno)
|
||||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||||
@@ -289,10 +289,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addTrackPoint(BoatInRace boat) {
|
private void drawTrackPoint(BoatInRace boat) {
|
||||||
if (boat.addTrackPoint(boat.getCurrentPosition())) {
|
|
||||||
GraphCoordinate coordinate = this.map.convertGPS(boat.getCurrentPosition());
|
|
||||||
}
|
|
||||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
for (GPSCoordinate coordinate : boat.getTrack()) {
|
||||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
||||||
gc.setFill(boat.getColour());
|
gc.setFill(boat.getColour());
|
||||||
|
|||||||
@@ -71,12 +71,13 @@
|
|||||||
<children>
|
<children>
|
||||||
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||||
<children>
|
<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>
|
<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>
|
<children>
|
||||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<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" />
|
<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>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
Reference in New Issue
Block a user