added cell factories for the lists

This commit is contained in:
Sebastian Lenzlinger 2022-05-01 13:32:11 +02:00
parent 505577817e
commit 5244742c84
7 changed files with 310 additions and 109 deletions

View File

@ -341,11 +341,11 @@ public class Client {
* @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler} * @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler}
* can be empty * can be empty
* @param data some information in a string, separators can be $ or : * @param data some information in a string, separators can be $ or :
* TODO(Seraina&Sebi): evtl. auslagern? * TODO(Seraina&Sebi): evtl. auslagern?
*/ */
public void sendToGUI(String parameter, String data) { public void sendToGUI(String parameter, String data) {
try { try {
if(!parameter.equals(GuiParameters.updateGameState)) { if (!parameter.equals(GuiParameters.updateGameState)) {
LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data); LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data);
} }
switch (parameter) { switch (parameter) {
@ -366,7 +366,7 @@ public class Client {
int position = Integer.parseInt(data); int position = Integer.parseInt(data);
determineNoiseDisplay(position); determineNoiseDisplay(position);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("Not a position given for noise " +e.getMessage()); LOGGER.warn("Not a position given for noise " + e.getMessage());
} }
break; break;
case GuiParameters.listOfLobbies: case GuiParameters.listOfLobbies:
@ -404,6 +404,7 @@ public class Client {
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("Communication with GUI currently not possible: " + e.getMessage()); LOGGER.warn("Communication with GUI currently not possible: " + e.getMessage());
LOGGER.debug(e.getCause() + " " + e.getStackTrace().toString());
} }
@ -441,9 +442,8 @@ public class Client {
ObservableList<SimpleStringProperty> list = new SimpleListProperty<>(); ObservableList<SimpleStringProperty> list = new SimpleListProperty<>();
int n = arr.length; int n = arr.length;
for (int i = 0; i < n; i = i + 1) { for (int i = 0; i < n; i = i + 1) {
list.add(new SimpleStringProperty(arr[i])); loungeSceneViewController.addClientToList(arr[i]);
} }
loungeSceneViewController.updateClientListView(list);
} }
/** /**

View File

@ -65,17 +65,21 @@ public class JClientProtocolParser {
c.changeUsername(msg.substring(6)); c.changeUsername(msg.substring(6));
break; break;
case Protocol.printToGUI: case Protocol.printToGUI:
LOGGER.info("First line of printToGui case!");
String substring = msg.substring(6); String substring = msg.substring(6);
LOGGER.debug("Following parameters where recieved: " + substring);
int index = substring.indexOf("$"); int index = substring.indexOf("$");
LOGGER.debug("Index of $: " + index);
String parameter = ""; String parameter = "";
String data = substring; String data = substring;
try { try {
parameter = substring.substring(0,index); parameter = substring.substring(0, index);
data = substring.substring(index+1); data = substring.substring(index + 1);
LOGGER.debug("Parameter: " + parameter + ". Data: " + data);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("No parameter in PTGUI"); LOGGER.warn("No parameter in PTGUI");
} }
c.sendToGUI(parameter,data); c.sendToGUI(parameter, data);
break; break;
case Protocol.positionOfClient: case Protocol.positionOfClient:
try { try {
@ -85,7 +89,7 @@ public class JClientProtocolParser {
LOGGER.warn(msg.substring(6)); LOGGER.warn(msg.substring(6));
} }
break; break;
default: default:
System.out.println("Received unknown command: " + msg); System.out.println("Received unknown command: " + msg);
} }
} }

View File

@ -6,13 +6,18 @@ import javafx.beans.property.SimpleStringProperty;
public class ClientListItem { public class ClientListItem {
private SimpleStringProperty name; private SimpleStringProperty name;
private final SimpleIntegerProperty id; private final int id;
public ClientListItem(SimpleStringProperty name, SimpleIntegerProperty id) { private static int uid = 0;
this.name = name; public ClientListItem(String name, int id) {
this.name = new SimpleStringProperty(name);
this.id = id; this.id = id;
} }
public ClientListItem(String name) {
this(name, uid++);
}
@Override @Override
public String toString(){ public String toString(){
return name + " ID: " + id; return name + " ID: " + id;
@ -31,10 +36,10 @@ public class ClientListItem {
} }
public int getId() { public int getId() {
return id.get(); return id;
} }
public SimpleIntegerProperty idProperty() { public int clientID() {
return id; return id;
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.Set;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -13,61 +14,100 @@ import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ToggleButton; import javafx.scene.control.ToggleButton;
public class LobbyListItem implements Observable { public class LobbyListItem {
private final SimpleStringProperty lobbyID; private final SimpleStringProperty lobbyID;
private final SimpleStringProperty adminName; private final SimpleStringProperty adminName;
private ObservableList<SimpleStringProperty> clientsInLobby; private ObservableList<SimpleStringProperty> clientsInLobby;
private final Button button;
private SimpleBooleanProperty ownedByClient; private SimpleBooleanProperty ownedByClient;
private SimpleBooleanProperty isOpen; private SimpleBooleanProperty isOpen;
public LobbyListItem(SimpleStringProperty lobbyID, SimpleStringProperty adminName, private final int MAX_CAPACITY = 6;
ObservableList<SimpleStringProperty> clientsInLobby, Button button, private SimpleIntegerProperty noOfPlayersInLobby;
SimpleBooleanProperty ownedByClient) {
public LobbyListItem(SimpleStringProperty lobbyID,
SimpleStringProperty adminName,
SimpleBooleanProperty ownedByClient, SimpleBooleanProperty isOpen,
SimpleIntegerProperty noOfPlayersInLobby) {
this.lobbyID = lobbyID; this.lobbyID = lobbyID;
this.adminName = adminName; this.adminName = adminName;
this.clientsInLobby = clientsInLobby; this.clientsInLobby = clientsInLobby;
this.button = button; this.ownedByClient = ownedByClient;
this.isOpen = isOpen;
this.noOfPlayersInLobby = noOfPlayersInLobby;
} }
/** public String getLobbyID() {
* Adds an {@link InvalidationListener} which will be notified whenever the {@code Observable} return lobbyID.get();
* becomes invalid. If the same listener is added more than once, then it will be notified more
* than once. That is, no check is made to ensure uniqueness.
* <p>
* Note that the same actual {@code InvalidationListener} instance may be safely registered for
* different {@code Observables}.
* <p>
* The {@code Observable} stores a strong reference to the listener which will prevent the
* listener from being garbage collected and may result in a memory leak. It is recommended to
* either unregister a listener by calling {@link #removeListener(InvalidationListener)
* removeListener} after use or to use an instance of {@link WeakInvalidationListener} avoid this
* situation.
*
* @param listener The listener to register
* @throws NullPointerException if the listener is null
* @see #removeListener(InvalidationListener)
*/
@Override
public void addListener(InvalidationListener listener) {
} }
/** public SimpleStringProperty lobbyIDProperty() {
* Removes the given listener from the list of listeners, that are notified whenever the value of return lobbyID;
* the {@code Observable} becomes invalid. }
* <p>
* If the given listener has not been previously registered (i.e. it was never added) then this
* method call is a no-op. If it had been previously added then it will be removed. If it had been
* added more than once, then only the first occurrence will be removed.
*
* @param listener The listener to remove
* @throws NullPointerException if the listener is null
* @see #addListener(InvalidationListener)
*/
@Override
public void removeListener(InvalidationListener listener) {
public void setLobbyID(String lobbyID) {
this.lobbyID.set(lobbyID);
}
public String getAdminName() {
return adminName.get();
}
public SimpleStringProperty adminNameProperty() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName.set(adminName);
}
public ObservableList<SimpleStringProperty> getClientsInLobby() {
return clientsInLobby;
}
public void setClientsInLobby(
ObservableList<SimpleStringProperty> clientsInLobby) {
this.clientsInLobby = clientsInLobby;
}
public boolean isOwnedByClient() {
return ownedByClient.get();
}
public SimpleBooleanProperty ownedByClientProperty() {
return ownedByClient;
}
public void setOwnedByClient(boolean ownedByClient) {
this.ownedByClient.set(ownedByClient);
}
public boolean isIsOpen() {
return isOpen.get();
}
public SimpleBooleanProperty isOpenProperty() {
return isOpen;
}
public void setIsOpen(boolean isOpen) {
this.isOpen.set(isOpen);
}
public int getMAX_CAPACITY() {
return MAX_CAPACITY;
}
public int getNoOfPlayersInLobby() {
return noOfPlayersInLobby.get();
}
public SimpleIntegerProperty noOfPlayersInLobbyProperty() {
return noOfPlayersInLobby;
}
public void setNoOfPlayersInLobby(int noOfPlayersInLobby) {
this.noOfPlayersInLobby.set(noOfPlayersInLobby);
} }
} }

View File

@ -1,10 +1,12 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.ChangeNameButtonPressedEventHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.ChangeNameButtonPressedEventHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonPressedEventHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonPressedEventHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -12,6 +14,8 @@ import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.binding.StringBinding; import javafx.beans.binding.StringBinding;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleMapProperty; import javafx.beans.property.SimpleMapProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
@ -24,6 +28,7 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
@ -34,19 +39,24 @@ import javafx.scene.control.ToolBar;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LoungeSceneViewController implements Initializable { public class LoungeSceneViewController implements Initializable {
public static final Logger LOGGER = LogManager.getLogger(JServerProtocolParser.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML @FXML
public Button leaveLobbyButton; public Button leaveLobbyButton;
@FXML @FXML
public Button newGameButton; public Button newGameButton;
@FXML @FXML
private ListView<HBox> LobbyListView; private ListView<LobbyListItem> LobbyListView;
@FXML @FXML
private ListView<SimpleStringProperty> ClientListView; private ListView<ClientListItem> ClientListView;
@FXML @FXML
private Button ChangeNameButton; private Button ChangeNameButton;
@FXML @FXML
@ -63,6 +73,9 @@ public class LoungeSceneViewController implements Initializable {
public static ClientModel client; public static ClientModel client;
public static ChatApp chatApp; public static ChatApp chatApp;
ObservableList<ClientListItem> clients = FXCollections.observableArrayList();
ObservableList<LobbyListItem> lobbies = FXCollections.observableArrayList();
private ObservableMap<String, ObservableList<String>> lobbyToMemberssMap; private ObservableMap<String, ObservableList<String>> lobbyToMemberssMap;
private HashMap<String, String> clientToLobbyMap; private HashMap<String, String> clientToLobbyMap;
@ -85,81 +98,218 @@ public class LoungeSceneViewController implements Initializable {
ChangeNameButton.setOnAction(event -> changeName()); ChangeNameButton.setOnAction(event -> changeName());
LeaveServerButton.setOnAction(event -> leaveServer()); LeaveServerButton.setOnAction(event -> leaveServer());
newGameButton.setOnAction(event -> newGame()); newGameButton.setOnAction(event -> newGame());
LobbyListView.setVisible(true);
ClientListView.setVisible(true);
ClientListView.setItems(client.getAllClients());
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
@Override
public void onChanged(Change<? extends SimpleStringProperty> c) {
List<SimpleStringProperty> removed = (List<SimpleStringProperty>) c.getRemoved();
for(SimpleStringProperty player: removed) {
ClientListView.setItems(clients);
ClientListView.setCellFactory(param -> {
ListCell<ClientListItem> cell = new ListCell<>() {
Label name = new Label();
Label id = new Label();
HBox nameAndId = new HBox(name, id);
{
nameAndId.setAlignment(Pos.CENTER_LEFT);
} }
}
/**
* The updateItem method should not be called by developers, but it is the
* best method for developers to override to allow for them to customise the
* visuals of the cell. To clarify, developers should never call this method
* in their code (they should leave it up to the UI control, such as the
* {@link ListView} control) to call this method. However, the purpose of
* having the updateItem method is so that developers, when specifying
* custom cell factories (again, like the ListView {@link
* ListView#cellFactoryProperty() cell factory}), the updateItem method can
* be overridden to allow for complete customisation of the cell.
*
* <p>It is <strong>very important</strong> that subclasses
* of Cell override the updateItem method properly, as failure to do so will
* lead to issues such as blank cells or cells with unexpected content
* appearing within them. Here is an example of how to properly override the
* updateItem method:
*
* <pre>
* protected void updateItem(T item, boolean empty) {
* super.updateItem(item, empty);
*
* if (empty || item == null) {
* setText(null);
* setGraphic(null);
* } else {
* setText(item.toString());
* }
* }
* </pre>
*
* <p>Note in this code sample two important points:
* <ol>
* <li>We call the super.updateItem(T, boolean) method. If this is not
* done, the item and empty properties are not correctly set, and you are
* likely to end up with graphical issues.</li>
* <li>We test for the <code>empty</code> condition, and if true, we
* set the text and graphic properties to null. If we do not do this,
* it is almost guaranteed that end users will see graphical artifacts
* in cells unexpectedly.</li>
* </ol>
* @param item The new item for the cell.
*
* @param empty whether or not this cell represents data from the list. If
* it is empty, then it does not represent any domain data, but
* is a cell
*/
@Override
protected void updateItem(ClientListItem item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
LOGGER.debug("In updateItem(item, empty) Method. Else branch -> nonnull item");
name.setText(item.getName());
id.setText(String.valueOf(item.getId()));
setGraphic(nameAndId);
}
}
};
return cell;
}); });
LobbyListView.setItems(lobbies);
LobbyListView.setCellFactory(param -> {
ListCell<LobbyListItem> cell = new ListCell<>() {
Label lobbyID = new Label();
Label adminName = new Label();
Label lobbyIsOpen = new Label();
Label noOfPlayersInLobby = new Label();
Button startOrJoin = new Button();
HBox head = new HBox(lobbyID, adminName, noOfPlayersInLobby, lobbyIsOpen, startOrJoin);
VBox playerList = new VBox();
TitledPane headParent = new TitledPane(head.toString(), playerList);
{
head.setAlignment(Pos.CENTER_LEFT);
playerList.setAlignment(Pos.CENTER_LEFT);
headParent.setCollapsible(true);
}
/**
* The updateItem method should not be called by developers, but it is the
* best method for developers to override to allow for them to customise the
* visuals of the cell. To clarify, developers should never call this method
* in their code (they should leave it up to the UI control, such as the
* {@link ListView} control) to call this method. However, the purpose of
* having the updateItem method is so that developers, when specifying
* custom cell factories (again, like the ListView {@link
* ListView#cellFactoryProperty() cell factory}), the updateItem method can
* be overridden to allow for complete customisation of the cell.
*
* <p>It is <strong>very important</strong> that subclasses
* of Cell override the updateItem method properly, as failure to do so will
* lead to issues such as blank cells or cells with unexpected content
* appearing within them. Here is an example of how to properly override the
* updateItem method:
*
* <pre>
* protected void updateItem(T item, boolean empty) {
* super.updateItem(item, empty);
*
* if (empty || item == null) {
* setText(null);
* setGraphic(null);
* } else {
* setText(item.toString());
* }
* }
* </pre>
*
* <p>Note in this code sample two important points:
* <ol>
* <li>We call the super.updateItem(T, boolean) method. If this is not
* done, the item and empty properties are not correctly set, and you are
* likely to end up with graphical issues.</li>
* <li>We test for the <code>empty</code> condition, and if true, we
* set the text and graphic properties to null. If we do not do this,
* it is almost guaranteed that end users will see graphical artifacts
* in cells unexpectedly.</li>
* </ol>
* @param item The new item for the cell.
*
* @param empty whether or not this cell represents data from the list. If
* it is empty, then it does not represent any domain data, but
* is a cell
*/
@Override
protected void updateItem(LobbyListItem item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic((null));
} else {
LOGGER.debug("In ELSE part of LobbyView Update item()");
lobbyID.setText(item.getLobbyID());
adminName.setText(item.getAdminName());
startOrJoin.setOnAction(event -> {
if (item.isOwnedByClient()) {
startGame();
} else {
joinGame(item.lobbyIDProperty().getName());
}
});
startOrJoin.setText(item.isOwnedByClient() ? "Start" : "Join");
setGraphic(headParent);
}
}
};
return cell;
});
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
} }
public void updateClientListView(ObservableList<SimpleStringProperty> names) { public void updateClientListView(ObservableList<ClientListItem> names) {
ObservableList<SimpleStringProperty> clientsLeft = ClientListView.getItems(); ObservableList<ClientListItem> clientsLeft = ClientListView.getItems();
clientsLeft.removeAll(names); clientsLeft.removeAll(names);
this.ClientListView.setItems(names); this.ClientListView.setItems(names);
for (SimpleStringProperty gone : clientsLeft) { for (ClientListItem gone : clientsLeft) {
//TODO //TODO
} }
} }
/** /**
* 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 * @param lobbyID
* @param player * @param player
*/ */
public void addPlayerToLobby(String lobbyID, String player) { public void addPlayerToLobby(String lobbyID, String player) {
LOGGER.debug("Lobby ID: " + lobbyID + " player: " + player);
ObservableList<String> members = lobbyToMemberssMap.get(lobbyID); ObservableList<String> members = lobbyToMemberssMap.get(lobbyID);
members.add(player); members.add(player);
} }
/** /**
* Used when a new lobby shall be added to the view. * Used when a new lobby shall be added to the view. "NLOBBY" {@link
* "NLOBBY" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} * ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
*
* @param lobbyID * @param lobbyID
* @param adminName * @param adminName
*/ */
public void newLobby(String lobbyID, String adminName) { public void newLobby(String lobbyID, String adminName) {
LOGGER.debug("New lobby with ID " + lobbyID + " and admin " + adminName);
SimpleStringProperty id = new SimpleStringProperty(lobbyID); SimpleStringProperty id = new SimpleStringProperty(lobbyID);
SimpleStringProperty admin = new SimpleStringProperty((adminName)); SimpleStringProperty admin = new SimpleStringProperty((adminName));
boolean ownedByClient = false;
Button startOrJoin; Button startOrJoin;
boolean ownedByClient = false;
if (adminName.equals(client.getUsername())) { if (adminName.equals(client.getUsername())) {
LOGGER.debug("Client is admin. Name: " + adminName);
ownedByClient = true; ownedByClient = true;
startOrJoin = new Button("Start");
startOrJoin.setOnAction(event -> startGame());
} else { } else {
startOrJoin = new Button("Join"); LOGGER.debug("Different admin case. ADMIN Name: " + adminName);
startOrJoin.setOnAction(event -> joinGame(lobbyID));
} }
HBox lobby = new HBox(); LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient),
Label idLabel = new Label(); new SimpleBooleanProperty(true), new SimpleIntegerProperty(0));
Label adminLabel = new Label(); LobbyListView.getItems().add(item);
idLabel.setText(lobbyID);
adminLabel.setText(adminName);
startOrJoin.setVisible(true);
lobby.getChildren().add(idLabel);
lobby.getChildren().add(adminLabel);
lobby.getChildren().add(startOrJoin);
ListView<String> members = new ListView<>();
members.setId("membersOfLobby");
if (ownedByClient) {
members.getItems().add("(you are admin) " + adminName);
} else {
members.getItems().add("(admin)" + adminName);
members.getItems().add(client.getUsername());
}
lobby.setId(lobbyID);
lobbyToMemberssMap.put(lobbyID, members.getItems());
lobby.setVisible(true);
LobbyListView.getItems().add(lobby);
} }
private void joinGame(String lobbyID) { private void joinGame(String lobbyID) {
@ -170,16 +320,21 @@ public class LoungeSceneViewController implements Initializable {
client.getClient().sendMsgToServer(Protocol.startANewGame); client.getClient().sendMsgToServer(Protocol.startANewGame);
} }
public void leaveLobby() {client.getClient().sendMsgToServer(Protocol.leaveLobby);} public void leaveLobby() {
client.getClient().sendMsgToServer(Protocol.leaveLobby);
}
public void leaveServer() {
client.getClient().sendMsgToServer(Protocol.clientQuitRequest);
}
public void leaveServer() {client.getClient().sendMsgToServer(Protocol.clientQuitRequest);}
/** /**
* Used to add a new player to the list of players. * Used to add a new player to the list of players. "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
* "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} *
* @param s * @param s
*/ */
public void addClientToList(String s) { public void addClientToList(String s) {
ClientListView.getItems().add(new SimpleStringProperty(s)); ClientListView.getItems().add(new ClientListItem(s));
} }
public void newGame() { public void newGame() {

View File

@ -48,10 +48,6 @@ public class GuiParameters {
*/ */
public static final String getMembersInLobby = "LMEMBS"; public static final String getMembersInLobby = "LMEMBS";
/**
* Tells Gui, that a new Lobby has been created. Form: {@code NLOBBY$<lobbyID>:<Admin Name>}
*/
public static final String changeToLobby = "LMEMBS";
/** /**
* Informs the GUI, that a vote is over * Informs the GUI, that a vote is over

View File

@ -477,6 +477,7 @@ public class ClientHandler implements Runnable {
Lobby newGame = new Lobby(this); Lobby newGame = new Lobby(this);
guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby() guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby()
.getLobbyID() + ":" + getClientUserName()); .getLobbyID() + ":" + getClientUserName());
LOGGER.debug("Lobby: " + getLobby().getLobbyID() + ". In method createNewLobby()");
} else { } else {
sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this)); sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this));
} }