RaceController scene separating

- removed a lot of unecessary parameters
- simplified set up functions
- racecontroller works on its own now
- made all the scenes visible by default

#story[1261]
main
Jessica Syder 8 years ago
parent 9f3cc53a63
commit a2b3ba44c0

@ -1,77 +0,0 @@
package visualiser.Controllers;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import visualiser.Controllers2.Controller2;
import visualiser.model.VisualiserBoat;
/**
* Finish Screen for when the race finishes.
*/
public class FinishController extends Controller2 {
@FXML
AnchorPane finishWrapper;
@FXML
TableView<VisualiserBoat> boatInfoTable;
@FXML
TableColumn<VisualiserBoat, String> boatRankColumn;
@FXML
TableColumn<VisualiserBoat, String> boatNameColumn;
@FXML
Label raceWinnerLabel;
/**
* The boats to display on the table.
*/
private ObservableList<VisualiserBoat> boats;
/**
* Sets up the finish table
* @param boats Boats to display
*/
private void setFinishTable(ObservableList<VisualiserBoat> boats) {
this.boats = boats;
//Set contents.
boatInfoTable.setItems(boats);
//Name.
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
//Rank/position.
boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().placingProperty());
//Winner label.
if (boats.size() > 0) {
raceWinnerLabel.setText("Winner: " + boatNameColumn.getCellObservableValue(0).getValue());
raceWinnerLabel.setWrapText(true);
}
}
/**
* Display the table
* @param boats boats to display on the table.
*/
public void enterFinish(ObservableList<VisualiserBoat> boats){
finishWrapper.setVisible(true);
setFinishTable(boats);
}
}

@ -39,7 +39,6 @@ import java.util.logging.Logger;
*/ */
public class HostController extends Controller2 { public class HostController extends Controller2 {
private @FXML ImageView imageView; private @FXML ImageView imageView;
private @FXML AnchorPane hostWrapper;
private @FXML AnchorPane imagePane; private @FXML AnchorPane imagePane;
private @FXML SplitPane splitPane; private @FXML SplitPane splitPane;
private @FXML AnchorPane specPane; private @FXML AnchorPane specPane;

@ -3,6 +3,7 @@ package visualiser.Controllers;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import visualiser.Controllers2.FinishController;
import visualiser.Controllers2.StartController; import visualiser.Controllers2.StartController;
import visualiser.Controllers2.TitleController; import visualiser.Controllers2.TitleController;
import visualiser.gameController.ControllerClient; import visualiser.gameController.ControllerClient;
@ -62,7 +63,7 @@ public class MainController extends Controller {
* @param boats The boats to display on the finish screen. * @param boats The boats to display on the finish screen.
*/ */
public void enterFinish(ObservableList<VisualiserBoat> boats) { public void enterFinish(ObservableList<VisualiserBoat> boats) {
finishController.enterFinish(boats); finishController.loadFinish(boats);
} }
// /** // /**
@ -120,10 +121,10 @@ public class MainController extends Controller {
// AnchorPane.setLeftAnchor(hostController.startWrapper(), 0.0); // AnchorPane.setLeftAnchor(hostController.startWrapper(), 0.0);
// AnchorPane.setRightAnchor(hostController.startWrapper(), 0.0); // AnchorPane.setRightAnchor(hostController.startWrapper(), 0.0);
AnchorPane.setTopAnchor(finishController.finishWrapper, 0.0); // AnchorPane.setTopAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setBottomAnchor(finishController.finishWrapper, 0.0); // AnchorPane.setBottomAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setLeftAnchor(finishController.finishWrapper, 0.0); // AnchorPane.setLeftAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setRightAnchor(finishController.finishWrapper, 0.0); // AnchorPane.setRightAnchor(finishController.finishWrapper, 0.0);
// AnchorPane.setTopAnchor(titleController.titleWrapper, 0.0); // AnchorPane.setTopAnchor(titleController.titleWrapper, 0.0);
// AnchorPane.setBottomAnchor(titleController.titleWrapper, 0.0); // AnchorPane.setBottomAnchor(titleController.titleWrapper, 0.0);

@ -1,6 +1,5 @@
package visualiser.Controllers; package visualiser.Controllers;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -14,15 +13,17 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.util.Callback; import javafx.util.Callback;
import network.Messages.Enums.RaceStatusEnum; import network.Messages.Enums.RaceStatusEnum;
import shared.model.Leg; import shared.model.Leg;
import visualiser.Controllers2.ArrowController; import visualiser.Controllers2.ArrowController;
import visualiser.Controllers2.Controller2; import visualiser.Controllers2.Controller2;
import visualiser.Controllers2.FinishController;
import visualiser.app.App;
import visualiser.gameController.ControllerClient; import visualiser.gameController.ControllerClient;
import visualiser.gameController.Keys.ControlKey; import visualiser.gameController.Keys.ControlKey;
import visualiser.gameController.Keys.KeyFactory;
import visualiser.model.*; import visualiser.model.*;
import java.io.IOException; import java.io.IOException;
@ -31,87 +32,64 @@ import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static visualiser.app.App.keyFactory;
/** /**
* Controller used to display a running race. * Controller used to display a running race.
*/ */
public class RaceController extends Controller2 { public class RaceController extends Controller2 {
/**
* The race object which describes the currently occurring race.
*/
private VisualiserRaceEvent visualiserRace; private VisualiserRaceEvent visualiserRace;
private VisualiserRaceState raceState;
/**
* Service for sending keystrokes to server
*/
private ControllerClient controllerClient; private ControllerClient controllerClient;
private boolean isHost;
/**
* The canvas that draws the race.
*/
private ResizableRaceCanvas raceCanvas; private ResizableRaceCanvas raceCanvas;
private KeyFactory keyFactory;
/** private boolean infoTableShow = true; // shown or hidden
* The sparkline graph. private boolean isHost;
*/
private Sparkline sparkline;
/** // note: it says it's not used but it is! do not remove :)
* state of the info table private @FXML ArrowController arrowController;
*/ private @FXML GridPane canvasBase;
private boolean infoTableShow; private @FXML SplitPane race;
private @FXML StackPane arrowPane;
private @FXML Label timer;
private @FXML Label FPS;
private @FXML Label timeZone;
private @FXML CheckBox showFPS;
private @FXML TableView<VisualiserBoat> boatInfoTable;
private @FXML TableColumn<VisualiserBoat, String> boatPlacingColumn;
private @FXML TableColumn<VisualiserBoat, String> boatTeamColumn;
private @FXML TableColumn<VisualiserBoat, Leg> boatMarkColumn;
private @FXML TableColumn<VisualiserBoat, Number> boatSpeedColumn;
private @FXML LineChart<Number, Number> sparklineChart;
private @FXML AnchorPane annotationPane;
/** /**
* The arrow controller. * Displays a specified race.
* Intended to be called on loading the scene.
* @param visualiserRace Object modelling the race.
* @param controllerClient Socket Client that manipulates the controller.
* @param isHost is user a host
*/ */
@FXML private ArrowController arrowController; public void startRace(VisualiserRaceEvent visualiserRace, ControllerClient controllerClient, Boolean isHost) {
this.visualiserRace = visualiserRace;
this.raceState = visualiserRace.getVisualiserRaceState();
this.controllerClient = controllerClient;
@FXML private GridPane canvasBase; this.isHost = isHost;
keyFactory.load();
@FXML private SplitPane race;
/** initKeypressHandler();
* This is the root node of the arrow control. initialiseRaceVisuals();
*/ }
@FXML private Pane arrow;
/** /**
* This is the pane we place the actual arrow control inside of. * Sets up the listener and actions that occur when a key is pressed.
*/ */
@FXML private StackPane arrowPane; public void initKeypressHandler() {
@FXML private Label timer;
@FXML private Label FPS;
@FXML private Label timeZone;
@FXML private CheckBox showFPS;
@FXML private TableView<VisualiserBoat> boatInfoTable;
@FXML private TableColumn<VisualiserBoat, String> boatPlacingColumn;
@FXML private TableColumn<VisualiserBoat, String> boatTeamColumn;
@FXML private TableColumn<VisualiserBoat, Leg> boatMarkColumn;
@FXML private TableColumn<VisualiserBoat, Number> boatSpeedColumn;
@FXML private LineChart<Number, Number> sparklineChart;
@FXML private AnchorPane annotationPane;
public void initialize() {
// KeyFactory keyFactory = KeyFactory.getFactory();
infoTableShow = true;
// Initialise keyboard handler
race.addEventFilter(KeyEvent.KEY_PRESSED, event -> { race.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
String codeString = event.getCode().toString(); String codeString = event.getCode().toString();
if (codeString.equals("TAB")){toggleTable();} if (codeString.equals("TAB")){toggleTable();}
// valid key pressed
ControlKey controlKey = keyFactory.getKey(codeString); ControlKey controlKey = keyFactory.getKey(codeString);
if(controlKey != null) { if(controlKey != null) {
try { try {
@ -123,6 +101,8 @@ public class RaceController extends Controller2 {
Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e); Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e);
} }
} }
// escape key
if(event.getCode() == KeyCode.ESCAPE) { if(event.getCode() == KeyCode.ESCAPE) {
try { try {
@ -132,12 +112,10 @@ public class RaceController extends Controller2 {
alert.setContentText("Do you wish to quit the race? You are the host"); alert.setContentText("Do you wish to quit the race? You are the host");
Optional<ButtonType> result = alert.showAndWait(); Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) { if (result.get() == ButtonType.OK) {
// parent.endEvent();
HostController hc = (HostController)loadScene( HostController hc = (HostController)loadScene(
"/visualiser/scenes/hostgame.fxml"); "hostgame.fxml");
hc.endEvent(); hc.endEvent();
race.setVisible(false); App.app.loadTitleScreen();
// App.app.showMainStage(App.getStage());
} }
} else { } else {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
@ -145,8 +123,7 @@ public class RaceController extends Controller2 {
alert.setContentText("Do you wish to quit the race?"); alert.setContentText("Do you wish to quit the race?");
Optional<ButtonType> result = alert.showAndWait(); Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) { if (result.get() == ButtonType.OK) {
race.setVisible(false); App.app.loadTitleScreen();
// App.app.showMainStage(App.getStage());
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -158,41 +135,25 @@ public class RaceController extends Controller2 {
}); });
} }
/** /**
* Initialises the various UI components to listen to the {@link #visualiserRace}. * Initialises the various UI components to listen to the {@link #visualiserRace}.
*/ */
private void initialiseRace() { private void initialiseRaceVisuals() {
//Fps display. // initialise displays
initialiseFps(this.visualiserRace); initialiseFps();
initialiseInfoTable();
//Information table. initialiseRaceCanvas();
initialiseInfoTable(this.visualiserRace); initialiseView3D();
initialiseRaceClock();
//Sparkline. raceTimer(); // start the timer
initialiseSparkline(this.visualiserRace); new Annotations(this.annotationPane, this.raceCanvas);
new Sparkline(this.raceState, this.sparklineChart);
//Arrow. timeZone.setText(this.raceState.getRaceClock().getTimeZone());
initialiseArrow(this.visualiserRace); arrowController.setWindProperty(this.raceState.windProperty());
//Race canvas.
initialiseRaceCanvas(this.visualiserRace);
initialiseView3D(this.visualiserRace);
//Race timezone label.
initialiseRaceTimezoneLabel(this.visualiserRace);
//Race clock.
initialiseRaceClock(this.visualiserRace);
//Start the race animation timer.
raceTimer();
} }
private void initialiseView3D(VisualiserRaceEvent race) { private void initialiseView3D() {
List<VisualiserBoat> boats = race.getVisualiserRaceState().getBoats(); List<VisualiserBoat> boats = raceState.getBoats();
for(VisualiserBoat boat: boats) { for(VisualiserBoat boat: boats) {
boat.positionProperty().addListener((o, prev, curr) -> { boat.positionProperty().addListener((o, prev, curr) -> {
System.out.println(boat.getCountry() + " is at " + curr.toString()); System.out.println(boat.getCountry() + " is at " + curr.toString());
@ -200,25 +161,12 @@ public class RaceController extends Controller2 {
} }
} }
/**
* Initialises the frame rate functionality. This allows for toggling the frame rate, and connect the fps label to the race's fps property.
* @param visualiserRace The race to connect the fps label to.
*/
private void initialiseFps(VisualiserRaceEvent visualiserRace) {
//On/off toggle.
initialiseFpsToggle();
//Label value.
initialiseFpsLabel(visualiserRace);
}
/** /**
* Initialises a listener for the fps toggle. * Initialises the frame rate functionality. This allows for toggling the
* frame rate, and connect the fps label to the race's fps property.
*/ */
private void initialiseFpsToggle() { private void initialiseFps() {
// fps toggle listener
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> { showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
if (showFPS.isSelected()) { if (showFPS.isSelected()) {
FPS.setVisible(true); FPS.setVisible(true);
@ -229,59 +177,44 @@ public class RaceController extends Controller2 {
} }
}); });
} // fps label display
this.visualiserRace.getFrameRateProperty().addListener((observable,
/** oldValue, newValue) -> {
* Initialises the fps label to update when the race fps changes. Platform.runLater(() ->
* @param visualiserRace The race to monitor the frame rate of. this.FPS.setText("FPS: " + newValue.toString()));
*/
private void initialiseFpsLabel(VisualiserRaceEvent visualiserRace) {
visualiserRace.getFrameRateProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> this.FPS.setText("FPS: " + newValue.toString()));
}); });
} }
/** /**
* Initialises the information table view to listen to a given race. * Initialises the information table view to listen to a given race.
* @param race Race to listen to.
*/ */
public void initialiseInfoTable(VisualiserRaceEvent race) { public void initialiseInfoTable() {
// list of boats to display data for
//Copy list of boats. ObservableList<VisualiserBoat> boats = FXCollections
ObservableList<VisualiserBoat> boats = FXCollections.observableArrayList(race.getVisualiserRaceState().getBoats()); .observableArrayList(this.visualiserRace.getVisualiserRaceState().getBoats());
SortedList<VisualiserBoat> sortedBoats = new SortedList<>(boats); SortedList<VisualiserBoat> sortedBoats = new SortedList<>(boats);
sortedBoats.comparatorProperty().bind(boatInfoTable.comparatorProperty()); sortedBoats.comparatorProperty().bind(boatInfoTable.comparatorProperty());
//Update copy when original changes. // update list when boat information changes
race.getVisualiserRaceState().getBoats().addListener((ListChangeListener.Change<? extends VisualiserBoat> c) -> Platform.runLater(() -> { this.visualiserRace.getVisualiserRaceState().getBoats().addListener(
boats.setAll(race.getVisualiserRaceState().getBoats()); (ListChangeListener.Change<? extends VisualiserBoat> c) -> Platform.runLater(() -> {
boats.setAll(this.visualiserRace.getVisualiserRaceState().getBoats());
})); }));
// set table data
//Set up table.
boatInfoTable.setItems(sortedBoats); boatInfoTable.setItems(sortedBoats);
//Set up each column.
//Name.
boatTeamColumn.setCellValueFactory( boatTeamColumn.setCellValueFactory(
cellData -> cellData.getValue().nameProperty() ); cellData -> cellData.getValue().nameProperty());
//Speed.
boatSpeedColumn.setCellValueFactory( boatSpeedColumn.setCellValueFactory(
cellData -> cellData.getValue().currentSpeedProperty() ); cellData -> cellData.getValue().currentSpeedProperty());
boatMarkColumn.setCellValueFactory(
cellData -> cellData.getValue().legProperty());
boatPlacingColumn.setCellValueFactory(
cellData -> cellData.getValue().placingProperty());
//Kind of ugly, but allows for formatting an observed speed. //Kind of ugly, but allows for formatting an observed speed.
boatSpeedColumn.setCellFactory( boatSpeedColumn.setCellFactory(
//Callback object.
new Callback<TableColumn<VisualiserBoat, Number>, TableCell<VisualiserBoat, Number>>() { new Callback<TableColumn<VisualiserBoat, Number>, TableCell<VisualiserBoat, Number>>() {
//Callback function.
@Override @Override
public TableCell<VisualiserBoat, Number> call(TableColumn<VisualiserBoat, Number> param) { public TableCell<VisualiserBoat, Number> call(TableColumn<VisualiserBoat, Number> param) {
//We return a table cell that populates itself with a Number, and formats it. //We return a table cell that populates itself with a Number, and formats it.
@ -290,30 +223,18 @@ public class RaceController extends Controller2 {
//Function to update the cell text. //Function to update the cell text.
@Override @Override
protected void updateItem(Number item, boolean empty) { protected void updateItem(Number item, boolean empty) {
if (item != null) { if (item != null) {
super.updateItem(item, empty); super.updateItem(item, empty);
setText(String.format("%.2fkn", item.doubleValue())); setText(String.format("%.2fkn", item.doubleValue()));
} }
} }
}; };
} }
});
} );
//Last mark.
boatMarkColumn.setCellValueFactory(
cellData -> cellData.getValue().legProperty() );
//Kind of ugly, but allows for turning an observed Leg into a string. //Kind of ugly, but allows for turning an observed Leg into a string.
boatMarkColumn.setCellFactory( boatMarkColumn.setCellFactory(
//Callback object.
new Callback<TableColumn<VisualiserBoat, Leg>, TableCell<VisualiserBoat, Leg>>() { new Callback<TableColumn<VisualiserBoat, Leg>, TableCell<VisualiserBoat, Leg>>() {
//Callback function.
@Override @Override
public TableCell<VisualiserBoat, Leg> call(TableColumn<VisualiserBoat, Leg> param) { public TableCell<VisualiserBoat, Leg> call(TableColumn<VisualiserBoat, Leg> param) {
//We return a table cell that populates itself with a Leg's name. //We return a table cell that populates itself with a Leg's name.
@ -322,133 +243,56 @@ public class RaceController extends Controller2 {
//Function to update the cell text. //Function to update the cell text.
@Override @Override
protected void updateItem(Leg item, boolean empty) { protected void updateItem(Leg item, boolean empty) {
if (item != null) { if (item != null) {
super.updateItem(item, empty); super.updateItem(item, empty);
setText(item.getName()); setText(item.getName());
} }
} }
}; };
} }
});
} );
//Current place within race.
boatPlacingColumn.setCellValueFactory(
cellData -> cellData.getValue().placingProperty() );
}
/**
* Initialises the {@link Sparkline}, and listens to a specified {@link VisualiserRaceEvent}.
* @param race The race to listen to.
*/
private void initialiseSparkline(VisualiserRaceEvent race) {
//The race.getBoats() we are passing in is sorted by position in race inside the race class.
this.sparkline = new Sparkline(this.visualiserRace.getVisualiserRaceState(), this.sparklineChart);
} }
/** /**
* Initialises the {@link ResizableRaceCanvas}, provides the race to read data from. * Initialises the {@link ResizableRaceCanvas}, provides the race to
* @param race Race to read data from. * read data from.
*/ */
private void initialiseRaceCanvas(VisualiserRaceEvent race) { private void initialiseRaceCanvas() {
//Create canvas. //Create canvas.
raceCanvas = new ResizableRaceCanvas(race.getVisualiserRaceState()); raceCanvas = new ResizableRaceCanvas(raceState);
//Set properties. //Set properties.
raceCanvas.setMouseTransparent(true); raceCanvas.setMouseTransparent(true);
raceCanvas.widthProperty().bind(canvasBase.widthProperty()); raceCanvas.widthProperty().bind(canvasBase.widthProperty());
raceCanvas.heightProperty().bind(canvasBase.heightProperty()); raceCanvas.heightProperty().bind(canvasBase.heightProperty());
//Draw it and show it. // draw and display
raceCanvas.draw(); raceCanvas.draw();
raceCanvas.setVisible(true); raceCanvas.setVisible(true);
//Add to scene.
canvasBase.getChildren().add(0, raceCanvas); canvasBase.getChildren().add(0, raceCanvas);
} }
/**
* Intialises the race time zone label with the race's time zone.
* @param race The race to get time zone from.
*/
private void initialiseRaceTimezoneLabel(VisualiserRaceEvent race) {
timeZone.setText(race.getVisualiserRaceState().getRaceClock().getTimeZone());
}
/** /**
* Initialises the race clock to listen to the specified race. * Initialises the race clock to listen to the specified race.
* @param race The race to listen to.
*/ */
private void initialiseRaceClock(VisualiserRaceEvent race) { private void initialiseRaceClock() {
raceState.getRaceClock().durationProperty().addListener((observable,
//RaceClock.duration isn't necessarily being changed in the javaFX thread, so we need to runlater the update. oldValue, newValue) -> {
race.getVisualiserRaceState().getRaceClock().durationProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> { Platform.runLater(() -> {
timer.setText(newValue); timer.setText(newValue);
}); });
}); });
} }
/**
* Displays a specified race.
* @param visualiserRace Object modelling the race.
* @param controllerClient Socket Client that manipulates the controller.
* @param isHost is user a host
*/
public void startRace(VisualiserRaceEvent visualiserRace, ControllerClient controllerClient, Boolean isHost) {
this.visualiserRace = visualiserRace;
this.controllerClient = controllerClient;
this.isHost = isHost;
initialiseRace();
//Display this controller.
race.setVisible(true);
// set up annotation displays
new Annotations(annotationPane, raceCanvas);
}
/** /**
* Transition from the race view to the finish view. * Transition from the race view to the finish view.
* @param boats boats there are in the race.
*/ */
public void finishRace(ObservableList<VisualiserBoat> boats) { public void finishRace() throws IOException {
race.setVisible(false); FinishController fc =
(FinishController)loadScene("/visualiser/scenes/finish.fxml");
// parent.enterFinish(boats); fc.loadFinish(raceState.getBoats());
try {
FinishController fc = (FinishController)loadScene
("/visualiser/scenes/finish.fxml");
fc.enterFinish(boats);
} catch (IOException e) {
e.printStackTrace();
}
} }
/**
* Initialises the arrow controller with data from the race to observe.
* @param race The race to observe.
*/
private void initialiseArrow(VisualiserRaceEvent race) {
arrowController.setWindProperty(race.getVisualiserRaceState().windProperty());
}
/** /**
* Timer which monitors the race. * Timer which monitors the race.
*/ */
@ -456,45 +300,30 @@ public class RaceController extends Controller2 {
new AnimationTimer() { new AnimationTimer() {
@Override @Override
public void handle(long arg0) { public void handle(long arg0) {
//Get the current race status.
RaceStatusEnum raceStatus = visualiserRace.getVisualiserRaceState().getRaceStatusEnum();
//If the race has finished, go to finish view. //If the race has finished, go to finish view.
if (raceStatus == RaceStatusEnum.FINISHED) { if (raceState.getRaceStatusEnum() == RaceStatusEnum.FINISHED) {
//Stop this timer. stop(); // stop the timer
stop(); try {
finishRace();
//Hide this, and display the finish controller. } catch (IOException e) {
finishRace(visualiserRace.getVisualiserRaceState().getBoats()); e.printStackTrace();
}
} else { } else {
//Otherwise, render the canvas. // refresh visual race display
raceCanvas.drawRace(); raceCanvas.drawRace();
//Sort the tableview. Doesn't automatically work for all columns.
boatInfoTable.sort(); boatInfoTable.sort();
} }
//Return to main screen if we lose connection. //Return to main screen if we lose connection.
if (!visualiserRace.getServerConnection().isAlive()) { if (!visualiserRace.getServerConnection().isAlive()) {
race.setVisible(false);
//parent.enterTitle();
try { try {
// App.app.showMainStage(App.getStage()); App.app.loadTitleScreen();
// } catch (IOException e) {
// e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
//TODO currently this doesn't work correctly - the title screen remains visible after clicking join game
//TODO we should display an error to the user //TODO we should display an error to the user
//TODO also need to "reset" any state (race, connections, etc...). //TODO also need to "reset" any state (race, connections, etc...).
} }
} }
}.start(); }.start();
} }
@ -505,25 +334,21 @@ public class RaceController extends Controller2 {
private void toggleTable() { private void toggleTable() {
double tablePercent = 1 - (boatPlacingColumn.getPrefWidth() + boatTeamColumn.getPrefWidth() + boatMarkColumn.getPrefWidth() + boatSpeedColumn.getPrefWidth())/race.getWidth(); double tablePercent = 1 - (boatPlacingColumn.getPrefWidth() + boatTeamColumn.getPrefWidth() + boatMarkColumn.getPrefWidth() + boatSpeedColumn.getPrefWidth())/race.getWidth();
if (infoTableShow){ if (infoTableShow) {
race.setDividerPositions(tablePercent); race.setDividerPositions(tablePercent);
arrowPane.setScaleX(0.5); arrowPane.setScaleX(0.5);
arrowPane.setScaleY(0.5); arrowPane.setScaleY(0.5);
arrowPane.setTranslateX(0 + (arrowPane.getScene().getWidth()/4)*tablePercent); arrowPane.setTranslateX(0 + (arrowPane.getScene().getWidth()/4)*tablePercent);
arrowPane.setTranslateY(0 - arrowPane.getScene().getHeight()/4); arrowPane.setTranslateY(0 - arrowPane.getScene().getHeight()/4);
} else {
}else{
race.setDividerPositions(1); race.setDividerPositions(1);
arrowPane.setScaleX(1); arrowPane.setScaleX(1);
arrowPane.setScaleY(1); arrowPane.setScaleY(1);
arrowPane.setTranslateX(0); arrowPane.setTranslateX(0);
arrowPane.setTranslateY(0); arrowPane.setTranslateY(0);
} }
boatInfoTable.refresh(); boatInfoTable.refresh();
infoTableShow = !infoTableShow; infoTableShow = !infoTableShow;
} }
} }

@ -0,0 +1,39 @@
package visualiser.Controllers2;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import visualiser.model.VisualiserBoat;
/**
* Finish Screen for when the race finishes.
*/
public class FinishController extends Controller2 {
private @FXML TableView<VisualiserBoat> boatInfoTable;
private @FXML TableColumn<VisualiserBoat, String> boatRankColumn;
private @FXML TableColumn<VisualiserBoat, String> boatNameColumn;
private @FXML Label raceWinnerLabel;
/**
* Display the table
* @param boats boats to display on the table.
*/
public void loadFinish(ObservableList<VisualiserBoat> boats) {
// set table contents
boatInfoTable.setItems(boats);
//Name.
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
//Rank/position.
boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().placingProperty());
//Winner label.
if (boats.size() > 0) {
raceWinnerLabel.setText("Winner: " +
boatNameColumn.getCellObservableValue(0).getValue());
raceWinnerLabel.setWrapText(true);
}
}
}

@ -1,4 +1,4 @@
package visualiser.Controllers; package visualiser.Controllers2;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.EventHandler; import javafx.event.EventHandler;
@ -14,7 +14,6 @@ import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.WindowEvent; import javafx.stage.WindowEvent;
import visualiser.Controllers2.Controller2;
import visualiser.gameController.Keys.ControlKey; import visualiser.gameController.Keys.ControlKey;
import visualiser.gameController.Keys.KeyFactory; import visualiser.gameController.Keys.KeyFactory;

@ -1,4 +1,4 @@
package visualiser.Controllers; package visualiser.Controllers2;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;

@ -12,7 +12,7 @@
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController"> <AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<children> <children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -1,9 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="finishWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.FinishController">
<AnchorPane fx:id="finishWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers2.FinishController">
<children> <children>
<GridPane fx:id="start" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="start" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -6,7 +6,7 @@
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane id="anchor" fx:id="anchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="471.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.KeyBindingsController"> <AnchorPane id="anchor" fx:id="anchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="471.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers2.KeyBindingsController">
<children> <children>
<Label fx:id="lblTitle" layoutX="172.0" layoutY="14.0" text="Key Bindings"> <Label fx:id="lblTitle" layoutX="172.0" layoutY="14.0" text="Key Bindings">
<font> <font>

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
@ -17,7 +12,7 @@
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="lobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.LobbyController"> <AnchorPane fx:id="lobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.LobbyController">
<children> <children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -6,7 +6,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.NotificationController"> <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers2.NotificationController">
<children> <children>
<Button fx:id="btnOk" layoutX="110.0" layoutY="65.0" mnemonicParsing="false" onAction="#ok" prefWidth="80.0" text="Ok" /> <Button fx:id="btnOk" layoutX="110.0" layoutY="65.0" mnemonicParsing="false" onAction="#ok" prefWidth="80.0" text="Ok" />
<Text fx:id="txtMessage" fill="RED" layoutY="23.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Warning!" textAlignment="CENTER" wrappingWidth="300.0"> <Text fx:id="txtMessage" fill="RED" layoutY="23.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Warning!" textAlignment="CENTER" wrappingWidth="300.0">

@ -22,7 +22,7 @@
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<SplitPane fx:id="race" dividerPositions="1.0" prefHeight="431.0" prefWidth="610.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceController"> <SplitPane fx:id="race" dividerPositions="1.0" prefHeight="431.0" prefWidth="610.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceController">
<items> <items>
<GridPane fx:id="canvasBase"> <GridPane fx:id="canvasBase">
<columnConstraints> <columnConstraints>

@ -1,9 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="startWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers2.StartController">
<AnchorPane fx:id="startWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers2.StartController">
<children> <children>
<GridPane fx:id="start" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="start" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

Loading…
Cancel
Save