Added server list updates, and added lobby

- Server list updates when a server is added/removed
- Player can host a server
- Lobby view shows players connected

Tags: #pair[mra106, hyi25] #story[1245]
This commit is contained in:
Michael Rausch
2017-09-07 19:20:36 +12:00
parent 8cc725616c
commit b35126ff4e
13 changed files with 280 additions and 170 deletions
@@ -3,16 +3,24 @@ package seng302.visualiser.controllers;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog;
import com.jfoenix.controls.JFXDialog.DialogTransition;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
public class LobbyController implements Initializable {
@@ -23,41 +31,43 @@ public class LobbyController implements Initializable {
private ScrollPane playerListScrollpane;
@FXML
private JFXButton customizeButton;
private JFXButton customizeButton, leaveLobbyButton;
@FXML
private StackPane serverListMainStackPane;
@FXML
private Label serverName;
@FXML
private Label mapName;
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
@Override
public void initialize(URL location, ResourceBundle resources) {
leaveLobbyButton.setOnMouseReleased(event -> leaveLobby());
Platform.runLater(() -> {
Integer max = 6;
for (int i = 0; i < max; i++) {
VBox pane = null;
FXMLLoader loader = new FXMLLoader(
getClass().getResource("/views/cells/PlayerCell.fxml"));
serverName.setText(ViewManager.getInstance().getProperty("serverName"));
mapName.setText(ViewManager.getInstance().getProperty("mapName"));
loader.setController(new PlayerCell("Player " + i));
ViewManager.getInstance().getPlayerList().addListener((ListChangeListener<String>) c -> {
Platform.runLater(this::refreshPlayerList);
});
try {
pane = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
playerListVBox.getChildren().add(pane);
}
ViewManager.getInstance().getPlayerList().setAll(ViewManager.getInstance().getPlayerList().sorted());
});
Platform.runLater(() -> {
FXMLLoader dialogContent = new FXMLLoader(getClass().getResource(
"/views/dialogs/BoatCustomizeDialog.fxml"));
"/views/dialogs/BoatCustomizeDialog.fxml"));
try {
JFXDialog dialog = new JFXDialog(serverListMainStackPane, dialogContent.load(),
DialogTransition.CENTER);
DialogTransition.CENTER);
customizeButton.setOnAction(action -> dialog.show());
} catch (IOException e) {
e.printStackTrace();
@@ -65,4 +75,35 @@ public class LobbyController implements Initializable {
});
}
private void refreshPlayerList() {
playerListVBox.getChildren().clear();
for (String player : ViewManager.getInstance().getPlayerList()) {
VBox pane = null;
FXMLLoader loader = new FXMLLoader(
getClass().getResource("/views/cells/PlayerCell.fxml"));
loader.setController(new PlayerCell(player));
try {
pane = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
playerListVBox.getChildren().add(pane);
}
}
public void leaveLobby() {
// TODO: 10/07/17 wmu16 - Finish function!
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().goToStartView();
}
}