Merge remote-tracking branch 'origin/Application' into Application
# Conflicts: # src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java
This commit is contained in:
commit
79528e4efc
@ -406,6 +406,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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,9 +444,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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -65,13 +65,17 @@ 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");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,20 +3,16 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
|||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
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.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;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.StringBinding;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.property.SimpleMapProperty;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
@ -28,7 +24,7 @@ import javafx.event.EventHandler;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.Node;
|
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;
|
||||||
@ -40,6 +36,7 @@ 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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -65,9 +62,9 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private AnchorPane gameAnchorPane;
|
private AnchorPane gameAnchorPane;
|
||||||
@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
|
||||||
@ -83,6 +80,9 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
private static ChatApp chatApp;
|
private static ChatApp chatApp;
|
||||||
private ChatApp cApp;
|
private ChatApp cApp;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@ -117,6 +117,171 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
ClientListView.setVisible(true);
|
ClientListView.setVisible(true);
|
||||||
ClientListView.setItems(client.getAllClients());
|
ClientListView.setItems(client.getAllClients());
|
||||||
addChatView();
|
addChatView();
|
||||||
|
|
||||||
|
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!"));
|
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
|
||||||
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
|
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
|
||||||
@Override
|
@Override
|
||||||
@ -182,12 +347,13 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds players to a lobby "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
* Adds players to a lobby
|
||||||
*
|
* "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);
|
||||||
}
|
}
|
||||||
@ -200,39 +366,21 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
* @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();
|
lobbies.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinGame(String lobbyID) {
|
public void joinGame(String lobbyID) {
|
||||||
@ -259,7 +407,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
* @param s
|
* @param s
|
||||||
*/
|
*/
|
||||||
public void addClientToList(String s) {
|
public void addClientToList(String s) {
|
||||||
ClientListView.getItems().add(new SimpleStringProperty(s));
|
clients.add(new ClientListItem(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newGame() {
|
public void newGame() {
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -104,7 +104,7 @@ public class JServerProtocolParser {
|
|||||||
break;
|
break;
|
||||||
case Protocol.leaveLobby:
|
case Protocol.leaveLobby:
|
||||||
h.leaveLobby();
|
h.leaveLobby();
|
||||||
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToStart + "$");
|
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$");
|
||||||
break;
|
break;
|
||||||
case Protocol.votedFor:
|
case Protocol.votedFor:
|
||||||
LOGGER.debug("Made it here");
|
LOGGER.debug("Made it here");
|
||||||
|
|||||||
Reference in New Issue
Block a user