You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.5 KiB
139 lines
4.5 KiB
package seng302.Controllers;
|
|
|
|
|
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.canvas.GraphicsContext;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.TableColumn;
|
|
import javafx.scene.control.TableView;
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.util.Callback;
|
|
import org.geotools.referencing.GeodeticCalculator;
|
|
import seng302.Constants;
|
|
import seng302.GPSCoordinate;
|
|
import seng302.Model.ResizableRaceCanvas;
|
|
import seng302.Model.*;
|
|
import seng302.RaceMap;
|
|
|
|
import java.awt.geom.Point2D;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.ResourceBundle;
|
|
|
|
/**
|
|
* Created by fwy13 on 15/03/2017.
|
|
*/
|
|
public class RaceController extends Controller{
|
|
@FXML
|
|
AnchorPane canvasBase;
|
|
|
|
ResizableRaceCanvas raceMap;
|
|
|
|
@FXML
|
|
Label timer;
|
|
|
|
@FXML
|
|
TableView<BoatInRace> boatInfoTable;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatPlacingColumn;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatTeamColumn;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatMarkColumn;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatSpeedColumn;
|
|
|
|
/**
|
|
* updates the ResizableRaceCanvas (raceMap) with most recent data
|
|
* @param boats boats that are to be displayed in the race
|
|
* @see ResizableRaceCanvas
|
|
*/
|
|
|
|
public void updateMap(ObservableList<BoatInRace> boats) {
|
|
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
|
|
raceMap.setBoats(boats.toArray(boatInRaces));
|
|
raceMap.drawRaceMap();
|
|
}
|
|
|
|
/**
|
|
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
|
* @param race Race to listen to.
|
|
*/
|
|
public void setInfoTable(Race race) {
|
|
//boatInfoTable.getItems().clear();
|
|
boatInfoTable.setItems(race.getStartingBoats());
|
|
|
|
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
|
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
|
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
|
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
|
@Override
|
|
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
|
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
|
BoatInRace[] boats = generateAC35Competitors();
|
|
|
|
raceMap = new ResizableRaceCanvas();
|
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
|
raceMap.setBoats(boats);
|
|
raceMap.drawRaceMap();
|
|
|
|
canvasBase.getChildren().add(raceMap);
|
|
|
|
ArrayList<Leg> legs = generateBermudaCourseLegs();
|
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
|
|
|
(new Thread(race)).start();
|
|
}
|
|
|
|
/**
|
|
* Function for the Bermuda Race.
|
|
* @return legs in the Bermuda Race.
|
|
*/
|
|
private ArrayList<Leg> generateBermudaCourseLegs() {
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0);
|
|
Leg leg2 = new Leg("Mark 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1);
|
|
Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2);
|
|
Leg leg4 = new Leg("Windward Gate to Leeward Gate", Constants.windwardGate1, Constants.leewardGate1, 3);
|
|
Leg leg5 = new Leg("Leeward Gate to Finish", Constants.leewardGate1, Constants.finishLineMarker1, 4);
|
|
legs.add(leg1); legs.add(leg2); legs.add(leg3); legs.add(leg4); legs.add(leg5);
|
|
return legs;
|
|
}
|
|
|
|
private BoatInRace[] generateAC35Competitors() {
|
|
|
|
BoatInRace[] boats = new BoatInRace[6];
|
|
|
|
|
|
int i = 0;
|
|
for (BoatInRace boat : Constants.OFFICIAL_AC35_COMPETITORS) {
|
|
boat.setCurrentPosition(Constants.startLineMarker1);
|
|
boats[i] = boat;
|
|
i++;
|
|
}
|
|
|
|
return boats;
|
|
|
|
}
|
|
|
|
public void setTimer(String time){
|
|
timer.setText(time);
|
|
}
|
|
|
|
|
|
}
|