mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user