Adding functionality for removing lobby from view. ClientHandler, GuiParameters Client and LoungeView now atleast have
the correspondingly named functions. No functionality tested yet.
This commit is contained in:
parent
d7f12d760d
commit
62992ae84c
@ -402,6 +402,9 @@ public class Client {
|
|||||||
chatApp.getLoungeSceneViewController().clearLobbyPrint();
|
chatApp.getLoungeSceneViewController().clearLobbyPrint();
|
||||||
chatApp.getLoungeSceneViewController().addLobbyPrint(data);
|
chatApp.getLoungeSceneViewController().addLobbyPrint(data);
|
||||||
break;
|
break;
|
||||||
|
case GuiParameters.removeLobby:
|
||||||
|
removeLobbyFromGui(data);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
notificationTextDisplay(data);
|
notificationTextDisplay(data);
|
||||||
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||||
@ -414,6 +417,11 @@ public class Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeLobbyFromGui(String data) {
|
||||||
|
loungeSceneViewController.removeLobbyFromView(data);
|
||||||
|
LOGGER.debug("Made it into removeLobbyFromGui()");
|
||||||
|
}
|
||||||
|
|
||||||
private void addNewPlayerToGui(String data) {
|
private void addNewPlayerToGui(String data) {
|
||||||
loungeSceneViewController.addClientToList(data);
|
loungeSceneViewController.addClientToList(data);
|
||||||
LOGGER.debug("addNewPlayerToGui() seems to have finished");
|
LOGGER.debug("addNewPlayerToGui() seems to have finished");
|
||||||
|
|||||||
@ -50,7 +50,6 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextFlow highScore;
|
private TextFlow highScore;
|
||||||
@FXML
|
@FXML
|
||||||
@ -312,7 +311,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
LobbyListView.setVisible(true);
|
LobbyListView.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the gameView to the existing LobbyView
|
* Adds the gameView to the existing LobbyView
|
||||||
*/
|
*/
|
||||||
public void addGameView() {
|
public void addGameView() {
|
||||||
@ -365,10 +364,10 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds players to a lobby
|
* Adds players to a lobby "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
||||||
* "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
*
|
||||||
* @param lobbyID the Id the Player belongs to
|
* @param lobbyID the Id the Player belongs to
|
||||||
* @param player the player to be added
|
* @param player the player to be added
|
||||||
*/
|
*/
|
||||||
public void addPlayerToLobby(String lobbyID, String player) {
|
public void addPlayerToLobby(String lobbyID, String player) {
|
||||||
LOGGER.debug("Lobby ID: " + lobbyID + " player: " + player);
|
LOGGER.debug("Lobby ID: " + lobbyID + " player: " + player);
|
||||||
@ -376,13 +375,13 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Iterator<ClientListItem> itr = clients.iterator();
|
Iterator<ClientListItem> itr = clients.iterator();
|
||||||
while(itr.hasNext()){
|
while (itr.hasNext()) {
|
||||||
ClientListItem cl = itr.next();
|
ClientListItem cl = itr.next();
|
||||||
if(cl.getName().equals(player)){
|
if (cl.getName().equals(player)) {
|
||||||
LobbyListItem li = lobbyIDtoLobbyMop.get(lobbyID);
|
LobbyListItem li = lobbyIDtoLobbyMop.get(lobbyID);
|
||||||
li.getClientsInLobby().add(cl);
|
li.getClientsInLobby().add(cl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -392,7 +391,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
* Used when a new lobby shall be added to the view. "NLOBBY" {@link
|
* Used when a new lobby shall be added to the view. "NLOBBY" {@link
|
||||||
* ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
* ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
||||||
*
|
*
|
||||||
* @param lobbyID the ID of the new lobby
|
* @param lobbyID the ID of the new lobby
|
||||||
* @param adminName the name of the Lobby admin
|
* @param adminName the name of the Lobby admin
|
||||||
*/
|
*/
|
||||||
public void newLobby(String lobbyID, String adminName) {
|
public void newLobby(String lobbyID, String adminName) {
|
||||||
@ -411,7 +410,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
}
|
}
|
||||||
LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient),
|
LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient),
|
||||||
new SimpleBooleanProperty(true), new SimpleIntegerProperty(0));
|
new SimpleBooleanProperty(true), new SimpleIntegerProperty(0));
|
||||||
lobbyIDtoLobbyMop.put(lobbyID,item);
|
lobbyIDtoLobbyMop.put(lobbyID, item);
|
||||||
LOGGER.debug("In newLobby()2 LobbyListView" + LobbyListView);
|
LOGGER.debug("In newLobby()2 LobbyListView" + LobbyListView);
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -430,6 +429,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the joinLobby Protocol message
|
* Send the joinLobby Protocol message
|
||||||
|
*
|
||||||
* @param lobbyID the Lobby to be joinded
|
* @param lobbyID the Lobby to be joinded
|
||||||
*/
|
*/
|
||||||
public void joinGame(String lobbyID) {
|
public void joinGame(String lobbyID) {
|
||||||
@ -480,9 +480,10 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sould remove a client of a certain name from the ListView
|
* Sould remove a client of a certain name from the ListView
|
||||||
|
*
|
||||||
* @param name the name of the client to be removed
|
* @param name the name of the client to be removed
|
||||||
*/
|
*/
|
||||||
public void removeClientFromList(String name){
|
public void removeClientFromList(String name) {
|
||||||
Iterator<ClientListItem> it = clients.iterator();
|
Iterator<ClientListItem> it = clients.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String uid = it.next().getName();
|
String uid = it.next().getName();
|
||||||
@ -490,9 +491,10 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
it.remove();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeClientFromLobby(String s){
|
public void removeClientFromLobby(String s) {
|
||||||
//todo
|
//todo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,6 +546,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a String to the highScore Text Flow
|
* Adds a String to the highScore Text Flow
|
||||||
|
*
|
||||||
* @param data the String to be added
|
* @param data the String to be added
|
||||||
*/
|
*/
|
||||||
public void addHighScore(String data) {
|
public void addHighScore(String data) {
|
||||||
@ -553,7 +556,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
highScore.getChildren().clear();
|
highScore.getChildren().clear();
|
||||||
for(String argument : arguments) {
|
for (String argument : arguments) {
|
||||||
LOGGER.debug("HighScore " + argument);
|
LOGGER.debug("HighScore " + argument);
|
||||||
Text text = new Text(argument + System.lineSeparator());
|
Text text = new Text(argument + System.lineSeparator());
|
||||||
text.setFill(Color.BLACK);
|
text.setFill(Color.BLACK);
|
||||||
@ -565,15 +568,16 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a String to the lobbyPrint TextFlow
|
* Adds a String to the lobbyPrint TextFlow
|
||||||
|
*
|
||||||
* @param data the String to be added
|
* @param data the String to be added
|
||||||
* */
|
*/
|
||||||
public void addLobbyPrint(String data) {
|
public void addLobbyPrint(String data) {
|
||||||
String[] arguments = data.split("/n");
|
String[] arguments = data.split("/n");
|
||||||
LOGGER.debug(arguments.length);
|
LOGGER.debug(arguments.length);
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for(String argument : arguments) {
|
for (String argument : arguments) {
|
||||||
LOGGER.debug("HighScore " + argument);
|
LOGGER.debug("HighScore " + argument);
|
||||||
Text text = new Text(argument + System.lineSeparator());
|
Text text = new Text(argument + System.lineSeparator());
|
||||||
text.setFill(Color.BLACK);
|
text.setFill(Color.BLACK);
|
||||||
@ -594,5 +598,18 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeLobbyFromView(String data) {
|
||||||
|
Iterator<LobbyListItem> itr = lobbies.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
LobbyListItem item = itr.next();
|
||||||
|
if (item.getLobbyID().equals(data)) {
|
||||||
|
itr.remove();
|
||||||
|
LOGGER.debug(
|
||||||
|
"Made it into removeLobbyFromView if clause for lobby w/ ID: " + item.getLobbyID()
|
||||||
|
+ " for data passed: " + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -96,4 +96,9 @@ public class GuiParameters {
|
|||||||
* pan out
|
* pan out
|
||||||
*/
|
*/
|
||||||
public static final String updatePrintLobby = "PRLOBB";
|
public static final String updatePrintLobby = "PRLOBB";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells gui to remove a lobby from view. Form: {@code RMVLBY$<LobbyID>}
|
||||||
|
*/
|
||||||
|
public static final String removeLobby = "RMVLBY";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -516,6 +516,12 @@ public class ClientHandler implements Runnable {
|
|||||||
if (l != null) {
|
if (l != null) {
|
||||||
l.removePlayer(this);
|
l.removePlayer(this);
|
||||||
Game game = l.getGame();
|
Game game = l.getGame();
|
||||||
|
if(l.getAdmin().equals(getClientUserName())){
|
||||||
|
//Lobby closed because admin left. Lobby must be removed from gui view
|
||||||
|
guiUpdateAll(Protocol.printToGUI+"$"+GuiParameters.removeLobby+"$"+l.getLobbyID());
|
||||||
|
}else{
|
||||||
|
//client just leaves lobby
|
||||||
|
}
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
l.getGame().getGameState().handleClientDisconnect(this);
|
l.getGame().getGameState().handleClientDisconnect(this);
|
||||||
l.removeGameFromRunningGames(game);
|
l.removeGameFromRunningGames(game);
|
||||||
|
|||||||
Reference in New Issue
Block a user