re-implemented existing functionality in UI

- Correct player count is shown in server list
- Servers now advertise their capacity and number of players connected
- Players can click join on the servers in the server list
- Direct connect works
- Can set max players / server name in host dialog
- Server starts correctly when host clicked
- Implemented boat customization
- Implemented 'begin race button', and disabled it for players that aren't hosts
- Added countdown timer in lobby
- Fixed bug where app wouldn't close

Tags: #story[1245]
This commit is contained in:
Michael Rausch
2017-09-08 18:00:09 +12:00
parent b35126ff4e
commit cf4f8813d2
23 changed files with 509 additions and 346 deletions
@@ -1,10 +1,15 @@
package seng302.visualiser.controllers;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXColorPicker;
import com.jfoenix.controls.JFXTextField;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import seng302.gameServer.messages.CustomizeRequestType;
import seng302.visualiser.ClientToServerThread;
import java.net.URL;
import java.util.ResourceBundle;
@@ -14,6 +19,19 @@ public class BoatCustomizeController implements Initializable{
@FXML
private JFXColorPicker colorPicker;
@FXML
private JFXButton submitBtn;
@FXML
private JFXTextField boatName;
private ClientToServerThread socketThread;
private LobbyController lobbyController;
public BoatCustomizeController(){
}
@FXML
void colorChanged(ActionEvent event) {
Color color = colorPicker.getValue();
@@ -22,5 +40,45 @@ public class BoatCustomizeController implements Initializable{
@Override
public void initialize(URL location, ResourceBundle resources) {
colorPicker.setValue(Color.BISQUE);
submitBtn.setOnMouseReleased(event -> {
submitCustomization();
lobbyController.closeCustomizationDialog();
});
}
@FXML
public void submitCustomization() {
socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, boatName.getText().getBytes());
// TODO: 16/08/17 ajm412: Turn colors into byte array.
Color color = colorPicker.getValue();
short red = (short) (color.getRed() * 255);
short green = (short) (color.getGreen() * 255);
short blue = (short) (color.getBlue() * 255);
byte[] colorArray = new byte[3];
colorArray[0] = (byte) red;
colorArray[1] = (byte) green;
colorArray[2] = (byte) blue;
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
lobbyController.closeCustomizationDialog();
}
public void setPlayerName(String name) {
this.boatName.setText(name);
}
public void setPlayerColor(Color playerColor) {
this.colorPicker.setValue(playerColor);
}
public void setServerThread(ClientToServerThread ctsThread) {
this.socketThread = ctsThread;
}
public void setParentController(LobbyController lobbyController){
this.lobbyController = lobbyController;
}
}
@@ -19,8 +19,12 @@ import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.model.Colors;
import seng302.model.RaceState;
import seng302.visualiser.ServerListener;
public class LobbyController implements Initializable {
@@ -31,7 +35,7 @@ public class LobbyController implements Initializable {
private ScrollPane playerListScrollpane;
@FXML
private JFXButton customizeButton, leaveLobbyButton;
private JFXButton customizeButton, leaveLobbyButton, beginRaceButton;
@FXML
private StackPane serverListMainStackPane;
@@ -43,39 +47,44 @@ public class LobbyController implements Initializable {
private Label mapName;
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
private RaceState raceState;
private JFXDialog customizationDialog;
@Override
public void initialize(URL location, ResourceBundle resources) {
leaveLobbyButton.setOnMouseReleased(event -> leaveLobby());
beginRaceButton.setOnMouseReleased(event -> beginRace());
Platform.runLater(() -> {
serverName.setText(ViewManager.getInstance().getProperty("serverName"));
mapName.setText(ViewManager.getInstance().getProperty("mapName"));
ViewManager.getInstance().getPlayerList().addListener((ListChangeListener<String>) c -> {
Platform.runLater(this::refreshPlayerList);
});
ViewManager.getInstance().getPlayerList().addListener((ListChangeListener<String>) c -> Platform.runLater(this::refreshPlayerList));
ViewManager.getInstance().getPlayerList().setAll(ViewManager.getInstance().getPlayerList().sorted());
});
Platform.runLater(() -> {
FXMLLoader dialogContent = new FXMLLoader(getClass().getResource(
"/views/dialogs/BoatCustomizeDialog.fxml"));
Integer playerId = ViewManager.getInstance().getGameClient().getServerThread().getClientId();
String name = ViewManager.getInstance().getGameClient().getPlayerNames().get(playerId - 1);
try {
JFXDialog dialog = new JFXDialog(serverListMainStackPane, dialogContent.load(),
DialogTransition.CENTER);
customizeButton.setOnAction(action -> dialog.show());
} catch (IOException e) {
e.printStackTrace();
}
Color playerColor = Colors.getColor( playerId - 1);
customizationDialog = ViewManager.getInstance().loadCustomizationDialog(serverListMainStackPane, this, playerColor, name);
customizeButton.setOnMouseReleased(event -> customizationDialog.show());
});
}
private void beginRace() {
beginRaceButton.setDisable(true);
customizeButton.setDisable(true);
GameState.setCurrentStage(GameStages.PRE_RACE);
GameState.resetStartTime();
Platform.runLater(()-> ViewManager.getInstance().getGameClient().startGame());
}
private void refreshPlayerList() {
playerListVBox.getChildren().clear();
@@ -90,6 +99,7 @@ public class LobbyController implements Initializable {
try {
pane = loader.load();
} catch (IOException e) {
// TODO replace with logger
e.printStackTrace();
}
@@ -102,8 +112,21 @@ public class LobbyController implements Initializable {
GameState.setCurrentStage(GameStages.CANCELLED);
// for (LobbyController_old.LobbyCloseListener readyListener : lobbyListeners)
// readyListener.notify(LobbyController_old.CloseStatus.LEAVE);
//TODO close threads and figure out what the above lines do;
ViewManager.getInstance().getGameClient().stopGame();
ViewManager.getInstance().goToStartView();
}
public void disableReadyButton() {
this.beginRaceButton.setDisable(true);
this.beginRaceButton.setText("Waiting for host...");
}
public void updateRaceState(RaceState raceState){
this.raceState = raceState;
this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr());
}
public void closeCustomizationDialog() {
customizationDialog.close();
}
}
@@ -229,7 +229,7 @@ public class LobbyController_old {
this.raceState = raceState;
/*if (this.customizeStage != null) {
this.customizeStage.close();
}*/ // TODO: 17/08/17 ajm412: close the customization window if the host starts the game while customizing
}*/ // TODO: 17/08/17 ajm412: close the customization window if the host starts the game while customizing
if (!customizeButton.isDisabled()) {
customizeButton.setDisable(true);
}
@@ -241,6 +241,7 @@ public class LobbyController_old {
readyButton.setVisible(false);
}
//TODO here newui
public void setPlayersColor(Color playerColor) {
this.playersColor = playerColor;
}
@@ -27,6 +27,7 @@ import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
@@ -64,7 +65,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@FXML
private Text timerLabel;
@FXML
private AnchorPane contentAnchorPane;
private StackPane contentAnchorPane;
@FXML
private AnchorPane rvAnchorPane;
@FXML
private Text windArrowText, windDirectionText;
@FXML
@@ -92,19 +95,21 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
public void initialize() {
// Load a default important annotation state
importantAnnotations = new ImportantAnnotationsState();
//importantAnnotations = new ImportantAnnotationsState();
//Formatting the y axis of the sparkline
// raceSparkLine.getYAxis().setRotate(180);
// raceSparkLine.getYAxis().setTickLabelRotation(180);
// raceSparkLine.getYAxis().setTranslateX(-5);
raceSparkLine.visibleProperty().setValue(false);
raceSparkLine.getYAxis().setAutoRanging(false);
sparklineYAxis.setTickMarkVisible(false);
//raceSparkLine.visibleProperty().setValue(false);
//raceSparkLine.getYAxis().setAutoRanging(false);
//sparklineYAxis.setTickMarkVisible(false);
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
//positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
//selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
rvAnchorPane.prefWidthProperty().bind(ViewManager.getInstance().getDecorator().widthProperty());
rvAnchorPane.prefHeightProperty().bind(ViewManager.getInstance().getDecorator().heightProperty());
}
public void loadRace (
@@ -133,8 +138,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
updateOrder(raceState.getPlayerPositions());
gameView = new GameView();
gameView.setFrameRateFXText(fpsDisplay);
Platform.runLater(() -> contentAnchorPane.getChildren().add(0, gameView));
//gameView.setFrameRateFXText(fpsDisplay);
Platform.runLater(() -> contentAnchorPane.getChildren().add(gameView));
gameView.setBoats(new ArrayList<>(participants.values()));
gameView.updateBorder(raceData.getCourseLimit());
gameView.updateCourse(
@@ -196,46 +201,46 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
}
private void initialiseFPSCheckBox() {
toggleFps.selectedProperty().addListener((obs, oldVal, newVal) ->
gameView.setFPSVisibility(toggleFps.isSelected())
);
// toggleFps.selectedProperty().addListener((obs, oldVal, newVal) ->
// gameView.setFPSVisibility(toggleFps.isSelected())
// );
}
private void initialiseAnnotationSlider() {
annotationSlider.setLabelFormatter(new StringConverter<Double>() {
@Override
public String toString(Double n) {
if (n == 0) {
return "None";
}
if (n == 1) {
return "Important";
}
if (n == 2) {
return "All";
}
return "All";
}
@Override
public Double fromString(String s) {
switch (s) {
case "None":
return 0d;
case "Important":
return 1d;
case "All":
return 2d;
default:
return 2d;
}
}
});
annotationSlider.setValue(2);
annotationSlider.valueProperty().addListener((obs, oldVal, newVal) ->
setAnnotations((int) annotationSlider.getValue())
);
// annotationSlider.setLabelFormatter(new StringConverter<Double>() {
// @Override
// public String toString(Double n) {
// if (n == 0) {
// return "None";
// }
// if (n == 1) {
// return "Important";
// }
// if (n == 2) {
// return "All";
// }
// return "All";
// }
//
// @Override
// public Double fromString(String s) {
// switch (s) {
// case "None":
// return 0d;
// case "Important":
// return 1d;
// case "All":
// return 2d;
//
// default:
// return 2d;
// }
// }
// });
// annotationSlider.setValue(2);
// annotationSlider.valueProperty().addListener((obs, oldVal, newVal) ->
// setAnnotations((int) annotationSlider.getValue())
// );
}
@@ -243,52 +248,52 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* Used to add any new yachts into the race that may have started late or not have had data received yet
*/
private void updateSparkLine(){
// TODO: 2/08/17 there is about 0 chance of this working. Once we are keeping track of boat positions it can be fixed.
// Collect the racing yachts that aren't already in the chart
sparkLineData.clear();
List<ClientYacht> sparkLineCandidates = new ArrayList<>(participants.values());
// Create a new data series for new yachts
sparkLineCandidates
.stream()
.filter(yacht -> yacht.getPosition() != null)
.forEach(yacht -> {
Series<String, Double> yachtData = new Series<>();
yachtData.setName(yacht.getSourceId().toString());
yachtData.getData().add(
new Data<>(
Integer.toString(yacht.getLegNumber()),
1.0 + participants.size() - yacht.getPosition()
)
);
sparkLineData.add(yachtData);
});
// Lambda function to sort the series in order of leg (later legs shown more to the right)
sparkLineData.sort((o1, o2) -> {
Integer leg1 = Integer.parseInt(o1.getData().get(o1.getData().size()-1).getXValue());
Integer leg2 = Integer.parseInt(o2.getData().get(o2.getData().size()-1).getXValue());
if (leg2 < leg1){
return 1;
} else {
return -1;
}
});
// Adds the new data series to the sparkline (and set the colour of the series)
Platform.runLater(() -> {
sparkLineData
.stream()
.filter(spark -> !raceSparkLine.getData().contains(spark))
.forEach(spark -> {
raceSparkLine.getData().add(spark);
spark.getNode().lookup(".chart-series-line").setStyle("-fx-stroke:" + getBoatColorAsRGB(spark.getName()));
});
});
// // TODO: 2/08/17 there is about 0 chance of this working. Once we are keeping track of boat positions it can be fixed.
// // Collect the racing yachts that aren't already in the chart
// sparkLineData.clear();
// List<ClientYacht> sparkLineCandidates = new ArrayList<>(participants.values());
// // Create a new data series for new yachts
// sparkLineCandidates
// .stream()
// .filter(yacht -> yacht.getPosition() != null)
// .forEach(yacht -> {
// Series<String, Double> yachtData = new Series<>();
// yachtData.setName(yacht.getSourceId().toString());
// yachtData.getData().add(
// new Data<>(
// Integer.toString(yacht.getLegNumber()),
// 1.0 + participants.size() - yacht.getPosition()
// )
// );
// sparkLineData.add(yachtData);
// });
//
// // Lambda function to sort the series in order of leg (later legs shown more to the right)
// sparkLineData.sort((o1, o2) -> {
// Integer leg1 = Integer.parseInt(o1.getData().get(o1.getData().size()-1).getXValue());
// Integer leg2 = Integer.parseInt(o2.getData().get(o2.getData().size()-1).getXValue());
// if (leg2 < leg1){
// return 1;
// } else {
// return -1;
// }
// });
//
// // Adds the new data series to the sparkline (and set the colour of the series)
// Platform.runLater(() -> {
// sparkLineData
// .stream()
// .filter(spark -> !raceSparkLine.getData().contains(spark))
// .forEach(spark -> {
// raceSparkLine.getData().add(spark);
// spark.getNode().lookup(".chart-series-line").setStyle("-fx-stroke:" + getBoatColorAsRGB(spark.getName()));
// });
// });
}
private void initialiseSparkLine() {
sparklineYAxis.setUpperBound(participants.size() + 1);
raceSparkLine.setCreateSymbols(false);
// sparklineYAxis.setUpperBound(participants.size() + 1);
// raceSparkLine.setCreateSymbols(false);
}
/**
@@ -381,8 +386,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* @param direction the from north angle of the wind.
*/
private void updateWindDirection(double direction) {
windDirectionText.setText(String.format("%.1f°", direction));
windArrowText.setRotate(direction);
// windDirectionText.setText(String.format("%.1f°", direction));
// windArrowText.setRotate(direction);
}
/**
@@ -390,7 +395,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* @param windSpeed Windspeed in knots.
*/
private void updateWindSpeed(double windSpeed) {
windSpeedText.setText("Speed: " + String.format("%.1f", windSpeed) + " Knots");
// windSpeedText.setText("Speed: " + String.format("%.1f", windSpeed) + " Knots");
}
@@ -402,7 +407,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
// timerLabel.setFill(Color.RED);
// timerLabel.setText("Race Finished!");
// } else {
timerLabel.setText(raceState.getRaceTimeStr());
// timerLabel.setText(raceState.getRaceTimeStr());
// }
}
@@ -411,28 +416,28 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* section
*/
private void updateOrder(ObservableList<ClientYacht> yachts) {
List<Text> vboxEntries = new ArrayList<>();
for (int i = 0; i < yachts.size(); i++) {
// System.out.println("yacht == null " + String.valueOf(yacht == null));
if (yachts.get(i).getBoatStatus() == BoatStatus.FINISHED
.getCode()) { // 3 is finish status
Text textToAdd = new Text(i + 1 + ". " +
yachts.get(i).getShortName() + " (Finished)");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
vboxEntries.add(textToAdd);
} else {
Text textToAdd = new Text(i + 1 + ". " +
yachts.get(i).getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
vboxEntries.add(textToAdd);
}
}
Platform.runLater(() ->
positionVbox.getChildren().setAll(vboxEntries)
);
// List<Text> vboxEntries = new ArrayList<>();
//
// for (int i = 0; i < yachts.size(); i++) {
//// System.out.println("yacht == null " + String.valueOf(yacht == null));
// if (yachts.get(i).getBoatStatus() == BoatStatus.FINISHED
// .getCode()) { // 3 is finish status
// Text textToAdd = new Text(i + 1 + ". " +
// yachts.get(i).getShortName() + " (Finished)");
// textToAdd.setFill(Paint.valueOf("#d3d3d3"));
// vboxEntries.add(textToAdd);
//
// } else {
// Text textToAdd = new Text(i + 1 + ". " +
// yachts.get(i).getShortName() + " ");
// textToAdd.setFill(Paint.valueOf("#d3d3d3"));
// textToAdd.setStyle("");
// vboxEntries.add(textToAdd);
// }
// }
// Platform.runLater(() ->
// positionVbox.getChildren().setAll(vboxEntries)
// );
}
@@ -533,15 +538,15 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* for the combobox to take action upon selection
*/
private void initialiseBoatSelectionComboBox() {
yachtSelectionComboBox.setItems(
FXCollections.observableArrayList(participants.values())
);
//Null check is if the listener is fired but nothing selected
yachtSelectionComboBox.valueProperty().addListener((obs, lastSelection, selectedBoat) -> {
if (selectedBoat != null) {
gameView.selectBoat(selectedBoat);
}
});
// yachtSelectionComboBox.setItems(
// FXCollections.observableArrayList(participants.values())
// );
// //Null check is if the listener is fired but nothing selected
// yachtSelectionComboBox.valueProperty().addListener((obs, lastSelection, selectedBoat) -> {
// if (selectedBoat != null) {
// gameView.selectBoat(selectedBoat);
// }
// });
}
/**
@@ -16,6 +16,7 @@ import javafx.scene.effect.DropShadow;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import seng302.gameServer.ServerDescription;
import seng302.visualiser.GameClient;
public class ServerCell implements Initializable {
@@ -39,7 +40,7 @@ public class ServerCell implements Initializable {
private String name;
private String mapNameString;
private Integer currPlayerCount;
private String currPlayerCount;
private String hostName;
private Integer portNumber;
@@ -47,7 +48,8 @@ public class ServerCell implements Initializable {
public ServerCell(ServerDescription server) {
this.name = server.getName();
this.currPlayerCount = server.spacesLeft();
this.currPlayerCount = server.getNumPlayers().toString() + "/" + server.getCapacity().toString();
this.mapNameString = server.getMapName();
this.hostName = server.getAddress();
@@ -57,7 +59,8 @@ public class ServerCell implements Initializable {
public void initialize(URL location, ResourceBundle resources) {
serverName.setText(name);
serverPlayerCount.setText(Integer.toString(currPlayerCount));
serverPlayerCount.setText(currPlayerCount);
mapName.setText(mapNameString);
serverConnButton.setOnMouseReleased(event -> joinServer());
}
@@ -65,12 +68,8 @@ public class ServerCell implements Initializable {
public void joinServer() {
// TODO: 7/09/17 ajm412: Connect to a server here with the values stored in the hostName/portNumber variables.
System.out.println("Connecting to " + serverName.getText());
try {
Parent root = FXMLLoader.load(StartScreenController.class.getResource("/views/LobbyView.fxml"));
ViewManager.getInstance().setScene(root);
} catch (IOException e) {
e.printStackTrace();
}
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
}
}
@@ -41,18 +41,11 @@ public class ServerCreationController implements Initializable {
}
public void createServer() {
try {
ServerDescription serverDescription = ViewManager.getInstance().getGameClient().runAsHost("localhost", 4941);
ViewManager.getInstance().setProperty("serverName", serverDescription.getName());
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
ServerDescription serverDescription = ViewManager.getInstance().getGameClient().runAsHost("localhost", 4941, serverName.getText(), (int) maxPlayers.getValue());
Parent root = FXMLLoader.load(StartScreenController.class.getResource("/views/LobbyView.fxml"));
ViewManager.getInstance().setScene(root);
} catch (IOException e) {
e.printStackTrace();
}
ViewManager.getInstance().setProperty("serverName", serverDescription.getName());
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
}
private void updateMaxPlayerLabel() {
@@ -18,6 +18,7 @@ import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import seng302.gameServer.ServerDescription;
import seng302.visualiser.GameClient;
import seng302.visualiser.ServerListener;
import seng302.visualiser.ServerListenerDelegate;
@@ -55,6 +56,7 @@ public class ServerListController implements Initializable, ServerListenerDelega
try {
ServerListener.getInstance().setDelegate(this);
System.out.println("Setting DH");
} catch (IOException e) {
logger.warn("Could not start Server Listener Delegate");
}
@@ -74,9 +76,8 @@ public class ServerListController implements Initializable, ServerListenerDelega
}
private void goToDirectConnectLobby() {
// TODO: 7/09/17 ajm412: Implement ability to connect to a lobby.
serverHostName.setText("Invalid Host Name or Port Number");
serverPortNumber.setText("");
// TODO: 7/09/17 Error handling
ViewManager.getInstance().getGameClient().runAsClient(serverHostName.getText(), Integer.parseInt(serverPortNumber.getText()));
}
@Override
@@ -41,7 +41,7 @@ public class StartScreenController_old implements Initializable {
@FXML
public void hostButtonPressed() {
gameClient = new GameClient(holder);
gameClient.runAsHost(getLocalHostIp(), 4942);
//gameClient.runAsHost(getLocalHostIp(), 4942);
}
/**
@@ -1,10 +1,17 @@
package seng302.visualiser.controllers;
import com.jfoenix.controls.JFXDecorator;
import com.jfoenix.controls.JFXDialog;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import seng302.model.ClientYacht;
import seng302.visualiser.GameClient;
import java.io.IOException;
@@ -17,12 +24,19 @@ public class ViewManager {
private JFXDecorator decorator;
private HashMap<String, String> props; //TODO is this the best way to do this??
private ObservableList<String> playerList;
private Logger logger = LoggerFactory.getLogger(ViewManager.class);
private ViewManager(){
props = new HashMap<>();
gameClient = new GameClient(decorator);
}
private FXMLLoader loadFxml(String fxmlLocation) {
return new FXMLLoader(
getClass().getResource(fxmlLocation)
);
}
public static ViewManager getInstance(){
if (instance == null){
instance = new ViewManager();
@@ -40,7 +54,7 @@ public class ViewManager {
}
public void setScene(Node scene){
decorator.setContent(scene);
Platform.runLater(() -> decorator.setContent(scene));
}
public void goToStartView() {
@@ -50,7 +64,6 @@ public class ViewManager {
} catch (IOException e) {
e.printStackTrace();
}
}
public GameClient getGameClient(){
@@ -72,4 +85,61 @@ public class ViewManager {
public ObservableList<String> getPlayerList(){
return playerList;
}
public LobbyController goToLobby(Boolean disableReadyButton){
FXMLLoader loader = loadFxml("/views/LobbyView.fxml");
try {
setScene(loader.load());
} catch (IOException e) {
logger.error("Could not load lobby view");
}
if (disableReadyButton){
LobbyController lobbyController = loader.getController();
lobbyController.disableReadyButton();
}
return loader.getController();
}
public RaceViewController loadRaceView() {
FXMLLoader loader = loadFxml("/views/RaceView.fxml");
try {
setScene(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
decorator.getScene().setOnKeyPressed((ke) -> gameClient.keyPressed(ke));
decorator.getScene().setOnKeyReleased((ke) -> gameClient.keyReleased(ke));
return loader.getController();
}
public JFXDialog loadCustomizationDialog(StackPane parent, LobbyController lobbyController, Color playerColor, String name) {
FXMLLoader dialog = loadFxml("/views/dialogs/BoatCustomizeDialog.fxml");
JFXDialog customizationDialog = null;
try {
customizationDialog = new JFXDialog(parent, dialog.load(),
JFXDialog.DialogTransition.CENTER);
} catch (IOException e) {
e.printStackTrace();
}
BoatCustomizeController controller = dialog.getController();
controller.setParentController(lobbyController);
controller.setPlayerColor(playerColor);
controller.setPlayerName(name);
controller.setServerThread(gameClient.getServerThread());
return customizationDialog;
}
}