From 6e00128997826bc3c6832e5f1bbe0010b3b15aeb Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sat, 30 Apr 2022 19:29:57 +0200 Subject: [PATCH 01/33] added method for adding a lobby to lobbylistview --- .../dbis/cs108/multiplayer/client/Client.java | 12 +++++--- .../multiplayer/client/gui/ClientModel.java | 4 +++ .../client/gui/lounge/LobbyListItem.java | 15 ++++++---- .../gui/lounge/LoungeSceneViewController.java | 30 +++++++++++++++++-- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index d693491..c4ba5da 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -8,6 +8,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger; @@ -42,6 +43,7 @@ public class Client { private ClientModel clientModel; private GameStateModel gameStateModel; private GameController gameController; + private LoungeSceneViewController loungeSceneViewController; /** * Saves the position of the client, gets refreshed everytime the client gets a vote request. @@ -75,6 +77,8 @@ public class Client { clientPinger = new ClientPinger(this, this.socket); this.gameStateModel = new GameStateModel(); this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel); + this.loungeSceneViewController = new LoungeSceneViewController(); + LoungeSceneViewController.setClient(ChatApp.getClientModel()); } catch (IOException e) { e.printStackTrace(); } @@ -351,7 +355,7 @@ public class Client { //TODO break; case GuiParameters.listOfPLayers: - updateListOfClients(data); + updateListOfClients(data); //TODO break; //case GuiParameters.viewChangeToGame: (commented out due to compiling error) @@ -380,7 +384,7 @@ public class Client { int n = arr.length; for (int i = 0; i < n; i = i + 2) { list.add(new SimpleStringProperty(arr[i])); - ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i])); + loungeSceneViewController.addLobbyToList(new SimpleStringProperty(arr[i])); } } @@ -388,10 +392,10 @@ public class Client { String[] arr = data.split(":"); ObservableList list = new SimpleListProperty<>(); int n = arr.length; - for (int i = 0; i < n; i = i + 2) { + for (int i = 0; i < n; i = i + 1) { list.add(new SimpleStringProperty(arr[i])); } - ChatController.getClient().getAllClients().setAll(); + loungeSceneViewController.updateClientListView(list); } /** diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java index 9ad8909..4d9021c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java @@ -70,6 +70,10 @@ public class ClientModel { this.allClients.add(nameAndId); } + public void updateClientList(ObservableList clients) { + + } + public void removeClientFromList(String id){ Iterator it = allClients.iterator(); while(it.hasNext()){ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index 5259334..5cea625 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -1,19 +1,22 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; import java.util.Set; +import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.ObservableSet; import javafx.scene.control.Label; +import javafx.scene.control.ListCell; import javafx.scene.control.ToggleButton; -public class LobbyListItem { +public class LobbyListItem extends ListCell { - private final Label lobbyID; - private final Label adminName; - private Set clientsInLobby; + private final String lobbyID; + private final String adminName; + private ObservableSet clientsInLobby; private final ToggleButton button; - public LobbyListItem(Label lobbyID, Label adminName, - Set clientsInLobby, ToggleButton button) { + public LobbyListItem(String lobbyID, String adminName, + ObservableSet clientsInLobby, ToggleButton button) { this.lobbyID = lobbyID; this.adminName = adminName; this.clientsInLobby = clientsInLobby; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 29b8c26..facb03b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -6,6 +6,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonP import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import java.net.URL; import java.util.ResourceBundle; +import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.ObservableList; @@ -17,6 +18,7 @@ import javafx.scene.control.Button; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; +import javafx.scene.control.TitledPane; import javafx.scene.control.ToolBar; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; @@ -47,6 +49,11 @@ public class LoungeSceneViewController implements Initializable { public static ClientModel client; + public LoungeSceneViewController() { + super(); + + } + /** * Called to initialize a controller after its root element has been completely processed. @@ -74,8 +81,27 @@ public class LoungeSceneViewController implements Initializable { this.ClientListView.setItems(names); } - public void addLobby(LobbyListItem lobby) { - //TODO + /** + * Adds a lobby to the view + * @param lobbyID + * @param admin + * @param players + */ + public void addLobby(String lobbyID, String admin, String players) { + TitledPane lobbyObject = new TitledPane(); + lobbyObject.setId(lobbyID+admin); + lobbyObject.textProperty().setValue("Lobby Nr: " + lobbyID + " Admin: " + admin); + + ObservableList listOfPlayersInLobby = new SimpleListProperty<>(); + + String[] playersArr = players.split(":"); + int noOfPlayers = playersArr.length; + for(int i = 0; i < noOfPlayers; i++){ + listOfPlayersInLobby.add(new SimpleStringProperty(playersArr[i])); + } + ListView view = new ListView(listOfPlayersInLobby); + lobbyObject.contentProperty().set(view); + LobbyListView.getItems().add(lobbyObject); } public void addClientToList(String s) { From 9007870d19b95b1f764ae9a565e52836bd1802e4 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sat, 30 Apr 2022 22:18:15 +0200 Subject: [PATCH 02/33] In Client: added 3 new methods GuiParameters: added 3 new Params Lounge: added Maps, changed names and implemented methods --- .../dbis/cs108/multiplayer/client/Client.java | 43 +++++-- .../client/gui/lounge/LobbyListItem.java | 62 ++++++++- .../gui/lounge/LoungeSceneViewController.java | 120 ++++++++++++++---- .../multiplayer/helpers/GuiParameters.java | 18 ++- 4 files changed, 200 insertions(+), 43 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index c4ba5da..db76c8b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -327,7 +327,7 @@ public class Client { * @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler} * can be empty * @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) { try { @@ -355,18 +355,27 @@ public class Client { //TODO break; case GuiParameters.listOfPLayers: - updateListOfClients(data); + updateListOfClients(data); //TODO break; + case GuiParameters.getMembersInLobby: + updateLobbyMembers(data); + break; //case GuiParameters.viewChangeToGame: (commented out due to compiling error) - //TODO - //break; (commented out due to compiling error) + //TODO + //break; (commented out due to compiling error) //case GuiParameters.viewChangeToStart: (commented out due to compiling error) - //TODO - //break; (commented out due to compiling error) + //TODO + //break; (commented out due to compiling error) //case GuiParameters.viewChangeToLobby: (commented out due to compiling error) - //TODO - //break; (commented out due to compiling error) + //TODO + //break; (commented out due to compiling error) + case GuiParameters.addNewMemberToLobby: + addPlayerToLobby(data); + break; + case GuiParameters.newLobbyCreated: + makeNewLobby(data); + break; default: notificationTextDisplay(data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController? @@ -378,14 +387,30 @@ public class Client { } + private void makeNewLobby(String data) { + String[] params = data.split(":"); + loungeSceneViewController.newLobby(params[0], params[1]); + } + + private void addPlayerToLobby(String data) { + String[] params = data.split(":"); + loungeSceneViewController.addPlayerToLobby(params[0], params[1]); + } + + private void updateLobbyMembers(String data) { + String[] dataArr = data.split(":"); + String lobbyID = dataArr[0]; + String adminName = dataArr[1]; + } + private void updateListOfLobbies(String data) { String[] arr = data.split(":"); ObservableList list = new SimpleListProperty<>(); int n = arr.length; for (int i = 0; i < n; i = i + 2) { list.add(new SimpleStringProperty(arr[i])); - loungeSceneViewController.addLobbyToList(new SimpleStringProperty(arr[i])); } + //TODO } private void updateListOfClients(String data) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index 5cea625..b3286e1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -1,25 +1,73 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; import java.util.Set; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.ObservableList; import javafx.collections.ObservableSet; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ToggleButton; -public class LobbyListItem extends ListCell { +public class LobbyListItem implements Observable { - private final String lobbyID; - private final String adminName; - private ObservableSet clientsInLobby; - private final ToggleButton button; + private final SimpleStringProperty lobbyID; + private final SimpleStringProperty adminName; + private ObservableList clientsInLobby; + private final Button button; + private SimpleBooleanProperty ownedByClient; + private SimpleBooleanProperty isOpen; - public LobbyListItem(String lobbyID, String adminName, - ObservableSet clientsInLobby, ToggleButton button) { + public LobbyListItem(SimpleStringProperty lobbyID, SimpleStringProperty adminName, + ObservableList clientsInLobby, Button button, + SimpleBooleanProperty ownedByClient) { this.lobbyID = lobbyID; this.adminName = adminName; this.clientsInLobby = clientsInLobby; this.button = button; } + + /** + * Adds an {@link InvalidationListener} which will be notified whenever the {@code Observable} + * 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. + *

+ * Note that the same actual {@code InvalidationListener} instance may be safely registered for + * different {@code Observables}. + *

+ * 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) { + + } + + /** + * Removes the given listener from the list of listeners, that are notified whenever the value of + * the {@code Observable} becomes invalid. + *

+ * 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) { + + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index facb03b..7f3b1c7 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -5,16 +5,25 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.ChangeNameButtonPr import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonPressedEventHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.ResourceBundle; +import javafx.beans.binding.StringBinding; import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleMapProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.collections.ObservableMap; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; @@ -31,9 +40,9 @@ public class LoungeSceneViewController implements Initializable { public Button newGameButton; @FXML - private ListView LobbyListView; + private ListView LobbyListView; @FXML - private ListView ClientListView; + private ListView ClientListView; @FXML private Button ChangeNameButton; @FXML @@ -49,9 +58,12 @@ public class LoungeSceneViewController implements Initializable { public static ClientModel client; + private ObservableMap> lobbyToMemberssMap; + private HashMap clientToLobbyMap; + public LoungeSceneViewController() { super(); - + lobbyToMemberssMap = FXCollections.observableHashMap(); } @@ -71,39 +83,87 @@ public class LoungeSceneViewController implements Initializable { ClientListView.setItems(client.getAllClients()); LobbyListView.setPlaceholder(new Text("No open lobbies!")); - } + client.getAllClients().addListener(new ListChangeListener() { + @Override + public void onChanged(Change c) { + List removed = (List) c.getRemoved(); + for(SimpleStringProperty player: removed) { - public void updateLobbyListView() { - //TODO + } + } + }); } public void updateClientListView(ObservableList names) { + ObservableList clientsLeft = ClientListView.getItems(); + clientsLeft.removeAll(names); this.ClientListView.setItems(names); + for (SimpleStringProperty gone : clientsLeft) { + //TODO + } } /** - * Adds a lobby to the view + * Adds players to a lobby + * "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} * @param lobbyID - * @param admin - * @param players + * @param player */ - public void addLobby(String lobbyID, String admin, String players) { - TitledPane lobbyObject = new TitledPane(); - lobbyObject.setId(lobbyID+admin); - lobbyObject.textProperty().setValue("Lobby Nr: " + lobbyID + " Admin: " + admin); - - ObservableList listOfPlayersInLobby = new SimpleListProperty<>(); - - String[] playersArr = players.split(":"); - int noOfPlayers = playersArr.length; - for(int i = 0; i < noOfPlayers; i++){ - listOfPlayersInLobby.add(new SimpleStringProperty(playersArr[i])); - } - ListView view = new ListView(listOfPlayersInLobby); - lobbyObject.contentProperty().set(view); - LobbyListView.getItems().add(lobbyObject); + public void addPlayerToLobby(String lobbyID, String player) { + ObservableList members = lobbyToMemberssMap.get(lobbyID); + members.add(player); } + /** + * Used when a new lobby shall be added to the view. + * "NLOBBY" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} + * @param lobbyID + * @param adminName + */ + public void newLobby(String lobbyID, String adminName) { + SimpleStringProperty id = new SimpleStringProperty(lobbyID); + SimpleStringProperty admin = new SimpleStringProperty((adminName)); + boolean ownedByClient = false; + Button startOrJoin; + if (adminName.equals(client.getUsername())) { + ownedByClient = true; + startOrJoin = new Button("Start"); + startOrJoin.setOnAction(event -> startGame()); + } else { + startOrJoin = new Button("Join"); + startOrJoin.setOnAction(event -> joinGame(lobbyID)); + } + HBox lobby = new HBox(); + Label idLabel = new Label(); + Label adminLabel = new Label(); + idLabel.textProperty().bind(id); + adminLabel.textProperty().bind(admin); + lobby.getChildren().add(idLabel); + lobby.getChildren().add(adminLabel); + lobby.getChildren().add(startOrJoin); + ListView 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()); + LobbyListView.getItems().add(lobby); + } + + private void joinGame(String lobbyID) { + client.getClient().sendMsgToServer(Protocol.joinLobby + "$" + lobbyID); + } + + private void startGame() { + client.getClient().sendMsgToServer(Protocol.startANewGame); + } + + ; + public void addClientToList(String s) { ClientListView.getItems().add(new SimpleStringProperty(s)); } @@ -112,6 +172,7 @@ public class LoungeSceneViewController implements Initializable { client.getClient().sendMsgToServer(Protocol.createNewLobby); } + public void changeName() { TextField name = new TextField("Enter new name!"); this.NTtBToolBar.getItems().add(name); @@ -124,6 +185,17 @@ public class LoungeSceneViewController implements Initializable { }); } + public void removePlayer(String id) { + Iterator it = client.getAllClients().iterator(); + while (it.hasNext()) { + String uid = it.next().getValue(); + if (uid.equals(id)) { + it.remove(); + break; + } + } + } + /** * Utility to set the client model for this class * diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java index 5af59de..bbc4f1b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java @@ -43,8 +43,20 @@ public class GuiParameters { /** - * Tells, Gui, who the members of a specified Lobby are. - * Form: {@code LMEMBS$$$..} + * Tells Gui, who the members of a specified Lobby are. + * Form: {@code LMEMBS$:::<..>} */ - public static String changeToLobby = "LMEMBS"; + public static final String getMembersInLobby = "LMEMBS"; + + /** + * Tells Gui, that a new Lobby has been created. + * Form: {@code NLOBBY$:} + */ + public static final String newLobbyCreated = "NLOBBY"; + + /** + * Tells Gui, to add a player to a lobby. + * Form: {@code NMEMB$:} + */ + public static final String addNewMemberToLobby = "NMEMB"; } From f4ccb6894ac45d2b3cf704fd4ef8dfc809d33eee Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 00:24:52 +0200 Subject: [PATCH 03/33] Had to change some things around, now notificationText and the bell pop up works, as well as voting and noise notification --- OgGhostWinners.txt | 1 + .../unibas/dmi/dbis/cs108/BudaLogConfig.java | 2 +- .../dmi/dbis/cs108/gamelogic/GameState.java | 2 +- .../dbis/cs108/multiplayer/client/Client.java | 35 ++- .../client/JClientProtocolParser.java | 10 +- .../client/gui/{chat => }/ChatApp.java | 46 ++- .../cs108/multiplayer/client/gui/GUI.java | 1 - .../client/gui/chat/ChatController.java | 1 + .../client/gui/game/GameController.java | 277 ++++++++++++------ .../cs108/multiplayer/helpers/Protocol.java | 6 + .../multiplayer/server/ClientHandler.java | 10 +- .../client/gui/game/GameDayAll.fxml | 7 +- 12 files changed, 263 insertions(+), 135 deletions(-) rename src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/{chat => }/ChatApp.java (71%) diff --git a/OgGhostWinners.txt b/OgGhostWinners.txt index 223b783..914ddb5 100644 --- a/OgGhostWinners.txt +++ b/OgGhostWinners.txt @@ -1 +1,2 @@ B +serai diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/BudaLogConfig.java b/src/main/java/ch/unibas/dmi/dbis/cs108/BudaLogConfig.java index 0ee0b70..dc9f6c1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/BudaLogConfig.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/BudaLogConfig.java @@ -19,7 +19,7 @@ public class BudaLogConfig { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); - loggerConfig.setLevel(Level.INFO); // change level here + loggerConfig.setLevel(Level.DEBUG); // change level here ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig. } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java index 06f041e..1d0c725 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java @@ -167,7 +167,7 @@ public class GameState { } else if (array[i].getIsGhost()) { print[i] = array[i].getName() + ":g:" + array[i].getKickedOff(); } else { - print[i] = "| " + array[i].getName() + ":h:" + array[i].getKickedOff(); + print[i] = array[i].getName() + ":h:" + array[i].getKickedOff(); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index d693491..27673fa 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -5,7 +5,7 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GUI; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger; @@ -41,7 +41,6 @@ public class Client { private GUI chatGui; private ClientModel clientModel; private GameStateModel gameStateModel; - private GameController gameController; /** * Saves the position of the client, gets refreshed everytime the client gets a vote request. @@ -70,11 +69,11 @@ public class Client { systemName = username; } sendMsgToServer(Protocol.clientLogin + "$" + systemName); - this.chatApp = new ChatApp(new ClientModel(systemName, this)); - this.chatGui = new GUI(this.chatApp); clientPinger = new ClientPinger(this, this.socket); this.gameStateModel = new GameStateModel(); - this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel); + this.chatApp = new ChatApp(new ClientModel(systemName, this)); + ChatApp.setGameController(new GameController(ChatApp.getClientModel(), gameStateModel)); + this.chatGui = new GUI(this.chatApp); } catch (IOException e) { e.printStackTrace(); } @@ -146,6 +145,9 @@ public class Client { } + public void setPosition(int position) { + this.position = position; + } /** * Starts a thread which listens for incoming chat messages / other messages that the user has to @@ -327,6 +329,7 @@ public class Client { */ public void sendToGUI(String parameter, String data) { try { + LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data); switch (parameter) { case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler gameStateModel.setDayClone(false); @@ -336,14 +339,14 @@ public class Client { break; case GuiParameters.updateGameState: gameStateModel.setGSFromString(data); - gameController.updateRoomLabels(); + chatApp.getGameController().updateRoomLabels(); break; case GuiParameters.noiseHeardAtPosition: try { int position = Integer.parseInt(data); determineNoiseDisplay(position); } catch (Exception e) { - LOGGER.warn("Not a position given for noise"); + LOGGER.warn("Not a position given for noise " +e.getMessage()); } break; case GuiParameters.listOfLobbies: @@ -380,7 +383,7 @@ public class Client { int n = arr.length; for (int i = 0; i < n; i = i + 2) { list.add(new SimpleStringProperty(arr[i])); - ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i])); + //ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i])); } } @@ -403,9 +406,9 @@ public class Client { public void notificationTextDisplay(String data) { new Thread(() -> { try { - gameController.addMessageToNotificationText(data); + chatApp.getGameController().addMessageToNotificationText(data); Thread.sleep(3000); - gameController.clearNotificationText(); + chatApp.getGameController().clearNotificationText(); } catch (InterruptedException e) { LOGGER.warn(e.getMessage()); } @@ -416,17 +419,17 @@ public class Client { public void determineNoiseDisplay(int position) { switch (position) { case 0: - gameController.noiseDisplay0(); + chatApp.getGameController().noiseDisplay0(); case 1: - gameController.noiseDisplay1(); + chatApp.getGameController().noiseDisplay1(); case 2: - gameController.noiseDisplay2(); + chatApp.getGameController().noiseDisplay2(); case 3: - gameController.noiseDisplay3(); + chatApp.getGameController().noiseDisplay3(); case 4: - gameController.noiseDisplay4(); + chatApp.getGameController().noiseDisplay4(); case 5: - gameController.noiseDisplay5(); + chatApp.getGameController().noiseDisplay5(); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 2ad6979..58d8b98 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import java.io.OutputStreamWriter; import org.apache.logging.log4j.LogManager; @@ -61,17 +62,20 @@ public class JClientProtocolParser { break; case Protocol.printToGUI: String substring = msg.substring(6); - int index = msg.indexOf("$"); + int index = substring.indexOf("$"); String parameter = ""; String data = substring; try { - parameter = msg.substring(0,index); - data = msg.substring(index+1); + parameter = substring.substring(0,index); + data = substring.substring(index+1); } catch (Exception e) { LOGGER.warn("No parameter in PTGUI"); } c.sendToGUI(parameter,data); break; + case Protocol.positionOfClient: + int position = Integer.parseInt(msg.substring(6)); + GameController.getClient().getClient().setPosition(position); default: System.out.println("Received unknown command"); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java similarity index 71% rename from src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java rename to src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java index 84e7947..2aa522c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java @@ -1,11 +1,14 @@ -package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; 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.chat.ChatController; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; import java.net.URL; import java.util.Objects; import javafx.application.Application; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; @@ -19,7 +22,9 @@ public class ChatApp extends Application { private static ClientModel clientModel; private static ChatController chatController; + private static GameController gameController; private ClientModel cModel; + private GameController gameC; public ChatApp() { super(); @@ -50,10 +55,27 @@ public class ChatApp extends Application { this.cModel = cModel; } + public void setGameC(GameController gameC) { + this.gameC = gameC; + } + public ClientModel getcModel() { return cModel; } + public static void setGameController( + GameController gameController) { + ChatApp.gameController = gameController; + } + + public GameController getGameController() { + return gameController; + } + + public GameController getGameC() { + return gameC; + } + public static void setClientModel(ClientModel clientM) { clientModel = clientM; } @@ -83,16 +105,16 @@ public class ChatApp extends Application { @Override public void start(Stage primaryStage) throws Exception { this.setcModel(clientModel); - URL resource = ChatApp.class.getResource( - "ChatView.fxml"); - if (resource == null) { - System.out.println("File wasnt found"); - } - //ChatApp chatApp = new ChatApp(new ClientModel()); + this.setGameC(gameController); + gameC.setClient(cModel); + gameC.setGameStateModel(GameController.getGameStateModel()); + URL chatResource = ChatApp.class.getResource( + "chat/ChatView.fxml"); + URL gameResource = ChatApp.class.getResource( + "game/GameDayAll.fxml"); try { Parent root = FXMLLoader.load( - Objects.requireNonNull(ChatApp.class.getResource( - "ChatView.fxml"))); + Objects.requireNonNull(gameResource)); // TODO bin chatController.getChatPaneRoot() border to root border for rezising Scene scene = new Scene(root); scene.setRoot(root); @@ -100,11 +122,15 @@ public class ChatApp extends Application { } catch (Exception e) { e.printStackTrace(); } + primaryStage.setResizable(false); + Node chat = FXMLLoader.load( + Objects.requireNonNull(chatResource)); + primaryStage.setTitle("Night Train To Budapest"); primaryStage.setResizable(true); - primaryStage.setTitle("Chat"); primaryStage.show(); + } public static void main(String[] args) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java index 06a9d30..e06bd0b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java @@ -1,7 +1,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import javafx.application.Application; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java index 16f186f..3248849 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java @@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.utils.ChatLabelConfigurator; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index c5112b3..2a72312 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -1,44 +1,33 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client; +import static javafx.scene.AccessibleRole.PARENT; + +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; -import javafx.event.EventHandler; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import java.net.URL; import java.util.ResourceBundle; import javafx.application.Platform; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.ListChangeListener; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.control.SplitPane; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Background; import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class GameController { +public class GameController implements Initializable{ public static final Logger LOGGER = LogManager.getLogger(GameController.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); @@ -47,13 +36,27 @@ public class GameController { private static GameStateModel gameStateModel; - + public GameController() { + super(); + } //TODO(Seraina, Sebi): Same issue as ChatController? do with setters? public GameController(ClientModel c, GameStateModel g) { client = c; gameStateModel = g; } + public void setClient(ClientModel c) { + client = c; + } + + public static ClientModel getClient() { + return client; + } + + public static GameStateModel getGameStateModel() { + return gameStateModel; + } + @FXML private AnchorPane gameBG; @FXML @@ -102,14 +105,25 @@ public class GameController { @FXML private Button noiseButton; @FXML - private TextFlow notificationText; + public TextFlow notificationText; + @FXML + private AnchorPane chatAreaGame; + + + public void addToChatArea(Node n) { + chatAreaGame.getChildren().add(n); + } + + public AnchorPane getChatAreaGame() { + return chatAreaGame; + } /** * If button 0 is clicked, send the vote message 0 to the server */ public void sendVote0() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 0); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 0); } /** @@ -117,7 +131,7 @@ public class GameController { */ public void sendVote1() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 1); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1); } /** @@ -125,7 +139,7 @@ public class GameController { */ public void sendVote2() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 2); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2); } /** @@ -133,7 +147,7 @@ public class GameController { */ public void sendVote3() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 3); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3); } /** @@ -141,7 +155,7 @@ public class GameController { */ public void sendVote4() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 4); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4); } /** @@ -149,15 +163,21 @@ public class GameController { */ public void sendVote5() { client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 5); + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5); } /** * Sends a noise message, to the server, should be a gui message? */ public void noise() { + LOGGER.info("Do you even get here"); + LOGGER.info(client.getClient()); + LOGGER.info(client.getClient().getPosition()); + if(client.getClient() == null) { + LOGGER.info("But why???"); + } client.getClient().sendMsgToServer( - Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + GuiParameters.noiseHeardAtPosition + "$" + Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$" +GuiParameters.noiseHeardAtPosition + "$" + client.getClient().getPosition()); //TODO: Test!! } @@ -166,13 +186,22 @@ public class GameController { * @param msg the message to be displayed */ public void addMessageToNotificationText(String msg){ + LOGGER.trace("addMessage " + msg); Text notification = new Text(msg); - try { - notificationText.getChildren().clear(); - notificationText.getChildren().add(notification); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + notification.setFill(Color.BLACK); + notification.setStyle("-fx-font: 50 arial;"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + notificationText.getChildren().add(notification); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + e.printStackTrace(); + } + } + }); + //TODO: Wait for a certain time, then clear all again } @@ -180,17 +209,25 @@ public class GameController { * Clears all children from notificationText TextFlow */ public void clearNotificationText() { - try { - notificationText.getChildren().clear(); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + LOGGER.trace("clear notify"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + notificationText.getChildren().clear(); + } catch (Exception e) { + LOGGER.debug("Not yet initialized"); + } + } + }); + } /** * Updates the labels of the rooms accordingly to the datastructures in GameStateModel */ public void updateRoomLabels() { + LOGGER.debug("roomlables update"); String[] names = gameStateModel.getPassengerTrainClone()[0]; String[] roles = gameStateModel.getPassengerTrainClone()[1]; Text name0 = new Text(names[0]); @@ -206,106 +243,152 @@ public class GameController { Text role4 = new Text(roles[4]); Text role5 = new Text(roles[5]); - try { - lableRoom0.getChildren().clear(); - lableRoom0.getChildren().add(name0); - lableRoom0.getChildren().add(role0); - lableRoom1.getChildren().clear(); - lableRoom1.getChildren().add(name1); - lableRoom1.getChildren().add(role1); - lableRoom2.getChildren().clear(); - lableRoom2.getChildren().add(name2); - lableRoom2.getChildren().add(role2); - lableRoom3.getChildren().clear(); - lableRoom3.getChildren().add(name3); - lableRoom3.getChildren().add(role3); - lableRoom4.getChildren().clear(); - lableRoom4.getChildren().add(name4); - lableRoom4.getChildren().add(role4); - lableRoom5.getChildren().clear(); - lableRoom5.getChildren().add(name5); - lableRoom5.getChildren().add(role5); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + lableRoom0.getChildren().clear(); + lableRoom0.getChildren().add(name0); + lableRoom0.getChildren().add(role0); + lableRoom1.getChildren().clear(); + lableRoom1.getChildren().add(name1); + lableRoom1.getChildren().add(role1); + lableRoom2.getChildren().clear(); + lableRoom2.getChildren().add(name2); + lableRoom2.getChildren().add(role2); + lableRoom3.getChildren().clear(); + lableRoom3.getChildren().add(name3); + lableRoom3.getChildren().add(role3); + lableRoom4.getChildren().clear(); + lableRoom4.getChildren().add(name4); + lableRoom4.getChildren().add(role4); + lableRoom5.getChildren().clear(); + lableRoom5.getChildren().add(name5); + lableRoom5.getChildren().add(role5); + } catch (Exception e) { + LOGGER.trace("Not yet initialized"); + } + } + }); + } + + public Image loadBellImage(){ + Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png"); + return bell; } /** * Adds an image of a bell on top of button0 */ public void noiseDisplay0(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + LOGGER.debug("noise0 called"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + noiseImage0.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } /** * Adds an image of a bell on top of button1 */ public void noiseDisplay1(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + LOGGER.debug("noise1 called"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + noiseImage1.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); } /** * Adds an image of a bell on top of button2 */ public void noiseDisplay2(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + LOGGER.debug("noise2 called"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + noiseImage2.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage());; + } + } + }); } /** * Adds an image of a bell on top of button3 */ - public void noiseDisplay3(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + public void noiseDisplay3() { + LOGGER.debug("noise3 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + LOGGER.debug("hello"); + noiseImage3.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); } /** * Adds an image of a bell on top of button4 */ - public void noiseDisplay4(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + public void noiseDisplay4() { + LOGGER.debug("noise4 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + LOGGER.debug("hello"); + noiseImage4.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); } /** * Adds an image of a bell on top of button5 */ public void noiseDisplay5(){ - Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); - try { - noiseImage0.setImage(bell); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); - } + LOGGER.debug("noise5 called"); + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + noiseImage5.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); } - - public void setGameStateModel( GameStateModel gameStateModel) { GameController.gameStateModel = gameStateModel; } + + @Override + public void initialize(URL location, ResourceBundle resources) { + ChatApp.setGameController(this); + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java index b9e3ae1..6d08971 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java @@ -207,5 +207,11 @@ public class Protocol { */ public static final String printToGUI = "PTGUI"; + /** + * Sends an information to client at which position in the train from the game (0 to 5) they sit, as soon as the game starts + * {@code POSOF$position} + */ + public static final String positionOfClient = "POSOF"; + } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java index 27a47ed..0024bed 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java @@ -376,9 +376,13 @@ public class ClientHandler implements Runnable { } LOGGER.debug("Vote is:" + vote); if (vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid - getLobby().getGame().getGameState().getClientVoteData().setVote(position, vote); - LOGGER.debug("Player vote: " + vote); - getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position, true); + try { + getLobby().getGame().getGameState().getClientVoteData().setVote(position, vote); + LOGGER.debug("Player vote: " + vote); + getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position, true); + } catch (NullPointerException e) { + LOGGER.info("Client not in Lobby"); + } } } diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml index 18eaabb..0862993 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml @@ -9,7 +9,7 @@ - + @@ -107,10 +107,11 @@ - - + + From 27c31967e5ee8ced9048db98123d82f5663a75aa Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 03:05:32 +0200 Subject: [PATCH 04/33] The game is now playable wia the game gui, there are still some quirks to work out, especially timing wise and with the POSOF network message --- OgGhostWinners.txt | 1 + .../gamelogic/ClientGameInfoHandler.java | 4 +- .../unibas/dmi/dbis/cs108/gamelogic/Game.java | 14 ++- .../dmi/dbis/cs108/gamelogic/GameState.java | 2 + .../gamelogic/ServerGameInfoHandler.java | 20 ++-- .../dmi/dbis/cs108/gamelogic/Timer.java | 2 +- .../dmi/dbis/cs108/gamelogic/VoteHandler.java | 8 +- .../dbis/cs108/multiplayer/client/Client.java | 23 +++- .../client/JClientProtocolParser.java | 13 ++- .../client/gui/GameStateModel.java | 1 + .../client/gui/game/GameController.java | 101 ++++++++++++++++-- .../multiplayer/helpers/GuiParameters.java | 19 +++- .../client/gui/game/GameDayAll.fxml | 28 ++--- 13 files changed, 184 insertions(+), 52 deletions(-) diff --git a/OgGhostWinners.txt b/OgGhostWinners.txt index 914ddb5..50bb8fd 100644 --- a/OgGhostWinners.txt +++ b/OgGhostWinners.txt @@ -1,2 +1,3 @@ B serai +serai diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java index 0ed9285..b7717f0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java @@ -17,8 +17,8 @@ public class ClientGameInfoHandler { public static final String ghostVoteRequest = "Vote on who to ghostify!"; public static final String humanVoteRequest = "Vote for a ghost to kick off!"; public static final String noiseNotification = "Someone passed by you "; - public static final String gameOverHumansWin = "Game over: humans win!"; - public static final String gameOverGhostsWin = "Game over: ghosts win!"; + public static final String gameOverHumansWin = "Game over, humans win!"; + public static final String gameOverGhostsWin = "Game over, ghosts win!"; //relevant for gui public static final String itsNightTime = "Please wait, ghosts are active"; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java index 657a200..b5c9a17 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java @@ -95,7 +95,7 @@ public class Game implements Runnable { passenger.send(GuiParameters.updateGameState, getGame()); } try { - Thread.sleep(4000); //TODO: Is this a good intervall? + Thread.sleep(2000); //TODO: Is this a good intervall? } catch (InterruptedException e) { e.printStackTrace(); } @@ -148,19 +148,22 @@ public class Game implements Runnable { } LOGGER.info(gameState.toString()); gameStateModelUpdater(); //TODO: does that work? - + for(Passenger passenger : gameState.getPassengerTrain()) { + passenger.send(Protocol.positionOfClient + "$" + passenger.getPosition(), this); + } + lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.night + "$"); i = 0; while (isOngoing) {//game cycle TODO: maybe check that more often inside game loop?! if (!isDay) { LOGGER.info("NIGHT"); gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this); setDay(true); - lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsDayTime + "$"); + lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.day + "$"); } else { LOGGER.info("DAY"); gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this); setDay(false); - lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsNightTime + "$"); + lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.night + "$"); } if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) || gameOverCheck.equals( ClientGameInfoHandler.gameOverHumansWin)) { @@ -169,6 +172,9 @@ public class Game implements Runnable { } lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$"); lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck); + isOngoing = false; + Timer.ghostAfterVoteTimer(); + isOngoing = true; lobby.removeGameFromRunningGames(this); lobby.addGameToFinishedGames(this); return; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java index 1d0c725..f93005c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameState.java @@ -174,6 +174,7 @@ public class GameState { for (int i = 0; i < array.length; i++) { stringBuilder.append("$").append(print[i]); } + stringBuilder.append("$"); return stringBuilder.toString(); } @@ -194,6 +195,7 @@ public class GameState { for (int i = 0; i < array.length; i++) { stringBuilder.append("$").append(print[i]); } + stringBuilder.append("$"); return stringBuilder.toString(); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java index 54eb4de..5337714 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java @@ -30,12 +30,10 @@ public class ServerGameInfoHandler { public static String format(String msg, Passenger passenger, Game game) { switch (msg) { case ClientGameInfoHandler.ghostVoteRequest: - msg = Protocol.serverRequestsGhostVote + "$" + passenger.getPosition() + "$" - + game.gameState.toString(); + msg = Protocol.serverRequestsGhostVote + "$" + passenger.getPosition() + "$"; break; case ClientGameInfoHandler.humanVoteRequest: - msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$" - + game.gameState.humanToString(); + msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$"; break; default: msg = Protocol.printToClientConsole + "$" + msg; @@ -56,11 +54,11 @@ public class ServerGameInfoHandler { switch (msg) { case ClientGameInfoHandler.ghostVoteRequest: case ClientGameInfoHandler.itsNightTime: - msg = Protocol.printToClientConsole + "$Ghosts are voting: " + game.gameState.toString(); + msg = Protocol.printToClientConsole + "$Ghosts are voting"; break; case ClientGameInfoHandler.humanVoteRequest: case ClientGameInfoHandler.itsDayTime: - msg = Protocol.printToClientConsole + "$Humans are voting:" + game.gameState.toString(); + msg = Protocol.printToClientConsole + "$Humans are voting"; break; case GuiParameters.updateGameState: msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString(); @@ -114,9 +112,10 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": String outMsg = npc.getName() + ": " + noiseRandomizer(); //TODO: add likelyhood + Timer.ghostAfterVoteTimer(); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); - game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition - + "$" + npc.getPosition() + "$"); + game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + + "$" + npc.getPosition()); break; case ClientGameInfoHandler.ghostVoteRequest: npc.vote(game); @@ -138,9 +137,10 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": String outMsg = npc.getName() + ": " + noiseRandomizer(); + Timer.ghostAfterVoteTimer(); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); - game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition - + "$" + npc.getPosition() + "$"); + game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + + "$" + npc.getPosition()); break; case ClientGameInfoHandler.humanVoteRequest: npc.vote(game); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java index e5eef8e..d52ec23 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java @@ -22,7 +22,7 @@ public class Timer { * The length of time in seconds after the ghost vote during which the ghosts visually walk to / * from their victim and the timespan within which humans will hear a noise. After this, the day starts. */ - public static final int ghostAfterVoteTime = 7; + public static final int ghostAfterVoteTime = 4; /** * The maximum length of the human vote in the day, in seconds */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java index 377def6..07d3ce3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java @@ -2,6 +2,8 @@ package ch.unibas.dmi.dbis.cs108.gamelogic; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; +import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; +import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -66,7 +68,7 @@ public class VoteHandler { } } LOGGER.info("Most votes for: " + newGhostPosition); - + Timer.ghostAfterVoteTimer(); for(Passenger passenger : passengers) { if(passenger.getIsGhost() || passenger.getIsSpectator()) { passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game); @@ -85,7 +87,7 @@ public class VoteHandler { walk by is being updated. Finally, each passenger receives information about how often he heard something during this night. The player who's just been ghostified is ignored since he didn't participate in this night's ghostification. */ - + Timer.ghostAfterVoteTimer(); int[] noiseAmount = new int[6]; for (int i = 0; i < passengers.length; i++) { if (passengers[i].getIsGhost() && i != newGhostPosition) { @@ -152,6 +154,7 @@ public class VoteHandler { } Timer.humanVoteTimer(game); + game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.VoteIsOver + "$"); int currentMax = humanVoteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game); @@ -170,6 +173,7 @@ public class VoteHandler { ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game); } } + Timer.ghostAfterVoteTimer(); if (passengers[voteIndex].getIsGhost()) { // if player is a ghost if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win System.out.println(ClientGameInfoHandler.gameOverHumansWin); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index 27673fa..7a9b84a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -14,6 +14,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; +import com.google.inject.Guice; import java.net.InetAddress; import java.net.Socket; import java.io.*; @@ -329,13 +330,17 @@ public class Client { */ public void sendToGUI(String parameter, String data) { try { - LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data); + if(!parameter.equals(GuiParameters.updateGameState)) { + LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data); + } switch (parameter) { - case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler + case GuiParameters.night: //ClientGameInfoHandler gameStateModel.setDayClone(false); + chatApp.getGameController().setNoiseButtonInvisible(); break; - case ClientGameInfoHandler.itsDayTime: //ClientGameInfoHandler + case GuiParameters.day: //ClientGameInfoHandler gameStateModel.setDayClone(true); + chatApp.getGameController().setNoiseButtonVisible(); break; case GuiParameters.updateGameState: gameStateModel.setGSFromString(data); @@ -353,6 +358,9 @@ public class Client { //updateListOfLobbies(data); (commented out due to compiling error) //TODO break; + case GuiParameters.VoteIsOver: + chatApp.getGameController().clearAllNoiseDisplay(); + break; case GuiParameters.listOfPLayers: updateListOfClients(data); //TODO @@ -407,7 +415,7 @@ public class Client { new Thread(() -> { try { chatApp.getGameController().addMessageToNotificationText(data); - Thread.sleep(3000); + Thread.sleep(5000); chatApp.getGameController().clearNotificationText(); } catch (InterruptedException e) { LOGGER.warn(e.getMessage()); @@ -417,19 +425,26 @@ public class Client { } public void determineNoiseDisplay(int position) { + LOGGER.debug(position); switch (position) { case 0: chatApp.getGameController().noiseDisplay0(); + break; case 1: chatApp.getGameController().noiseDisplay1(); + break; case 2: chatApp.getGameController().noiseDisplay2(); + break; case 3: chatApp.getGameController().noiseDisplay3(); + break; case 4: chatApp.getGameController().noiseDisplay4(); + break; case 5: chatApp.getGameController().noiseDisplay5(); + break; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 58d8b98..275db4e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -40,6 +40,9 @@ public class JClientProtocolParser { break; case Protocol.printToClientConsole: System.out.println(msg.substring(6)); + if (!msg.substring(6).equals("Your vote was invalid")) { + c.notificationTextDisplay(msg.substring(6)); + } break; case Protocol.printToClientChat: //todo: handle chat separately from console. @@ -74,9 +77,13 @@ public class JClientProtocolParser { c.sendToGUI(parameter,data); break; case Protocol.positionOfClient: - int position = Integer.parseInt(msg.substring(6)); - GameController.getClient().getClient().setPosition(position); - default: + try { + int position = Integer.parseInt(msg.substring(6)); + GameController.getClient().getClient().setPosition(position); + } catch (Exception e) { + LOGGER.warn(msg.substring(6)); + } + default: System.out.println("Received unknown command"); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java index 5a4a594..164419e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java @@ -117,6 +117,7 @@ public class GameStateModel { j = right.indexOf(':'); roles[i] = right.substring(0, j); kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1)); + LOGGER.info(kickedOff[i]); i++; } setPassengerTrainClone(names, roles); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index 2a72312..22f5a5c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -181,6 +181,14 @@ public class GameController implements Initializable{ + client.getClient().getPosition()); //TODO: Test!! } + public void setNoiseButtonInvisible() { + noiseButton.setVisible(false); + } + + public void setNoiseButtonVisible() { + noiseButton.setVisible(true); + } + /** * Takes a given message and displays it in the notificationText Flow in the game Scene * @param msg the message to be displayed @@ -197,7 +205,6 @@ public class GameController implements Initializable{ notificationText.getChildren().add(notification); } catch (Exception e) { LOGGER.debug(e.getMessage()); - e.printStackTrace(); } } }); @@ -214,7 +221,7 @@ public class GameController implements Initializable{ @Override public void run() { try { - notificationText.getChildren().clear(); + notificationText.getChildren().remove(0); } catch (Exception e) { LOGGER.debug("Not yet initialized"); } @@ -230,18 +237,73 @@ public class GameController implements Initializable{ LOGGER.debug("roomlables update"); String[] names = gameStateModel.getPassengerTrainClone()[0]; String[] roles = gameStateModel.getPassengerTrainClone()[1]; + boolean[] kickedOff = gameStateModel.getKickedOff(); Text name0 = new Text(names[0]); + name0.setStyle("-fx-font: 25 arial;"); + name0.setFill(Color.WHITE); Text name1 = new Text(names[1]); + name1.setStyle("-fx-font: 25 arial;"); + name1.setFill(Color.WHITE); Text name2 = new Text(names[2]); + name2.setStyle("-fx-font: 25 arial;"); + name2.setFill(Color.WHITE); Text name3 = new Text(names[3]); + name3.setStyle("-fx-font: 25 arial;"); + name3.setFill(Color.WHITE); Text name4 = new Text(names[4]); + name4.setStyle("-fx-font: 25 arial;"); + name4.setFill(Color.WHITE); Text name5 = new Text(names[5]); - Text role0 = new Text(roles[0]); - Text role1 = new Text(roles[1]); - Text role2 = new Text(roles[2]); - Text role3 = new Text(roles[3]); - Text role4 = new Text(roles[4]); - Text role5 = new Text(roles[5]); + name5.setStyle("-fx-font: 25 arial;"); + name5.setFill(Color.WHITE); + Text role0; + if(kickedOff[0]) { + role0 = new Text("\nkicked off"); + } else { + role0 = new Text("\n" + roles[0]); + } + role0.setStyle("-fx-font: 25 arial;"); + role0.setFill(Color.WHITE); + Text role1; + if(kickedOff[1]) { + role1 = new Text("\nkicked off"); + } else { + role1 = new Text("\n" + roles[0]); + } + role1.setStyle("-fx-font: 25 arial;"); + role1.setFill(Color.WHITE); + Text role2; + if(kickedOff[2]) { + role2 = new Text("\nkicked off"); + } else { + role2 = new Text("\n" + roles[0]); + } + role2.setStyle("-fx-font: 25 arial;"); + role2.setFill(Color.WHITE); + Text role3; + if(kickedOff[3]) { + role3 = new Text("\nkicked off"); + } else { + role3 = new Text("\n" + roles[0]); + } + role3.setStyle("-fx-font: 25 arial;"); + role3.setFill(Color.WHITE); + Text role4; + if(kickedOff[4]) { + role4 = new Text("\nkicked off"); + } else { + role4 = new Text("\n" + roles[0]); + } + role4.setStyle("-fx-font: 25 arial;"); + role4.setFill(Color.WHITE); + Text role5; + if(kickedOff[5]) { + role5 = new Text("\nkicked off"); + } else { + role5 = new Text("\n" + roles[0]); + } + role5.setStyle("-fx-font: 25 arial;"); + role5.setFill(Color.WHITE); Platform.runLater(new Runnable(){ @Override @@ -368,7 +430,7 @@ public class GameController implements Initializable{ /** * Adds an image of a bell on top of button5 */ - public void noiseDisplay5(){ + public void noiseDisplay5() { LOGGER.debug("noise5 called"); Platform.runLater(new Runnable(){ @Override @@ -382,6 +444,27 @@ public class GameController implements Initializable{ }); } + /** + * Clears all bells from the view + */ + public void clearAllNoiseDisplay() { + Platform.runLater(new Runnable(){ + @Override + public void run() { + try { + noiseImage0.setImage(null); + noiseImage1.setImage(null); + noiseImage2.setImage(null); + noiseImage3.setImage(null); + noiseImage4.setImage(null); + noiseImage5.setImage(null); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + public void setGameStateModel( GameStateModel gameStateModel) { GameController.gameStateModel = gameStateModel; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java index 5af59de..4bbba46 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java @@ -40,11 +40,24 @@ public class GuiParameters { */ public static final String viewChangeToGame = "VCGAME"; - - /** * Tells, Gui, who the members of a specified Lobby are. * Form: {@code LMEMBS$$$..} */ - public static String changeToLobby = "LMEMBS"; + public static final String changeToLobby = "LMEMBS"; + + /** + * Informs the GUI, that a vote is over + */ + public static final String VoteIsOver = "VOTEOVER"; + + /** + * Informes Gui, that its the night + */ + public static final String night = "NIGHT"; + /** + * Informes Gui, that its the day + */ + public static final String day = "DAY"; + } diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml index 0862993..8c6467c 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml @@ -13,14 +13,14 @@ - + - - - - - - + + + + + + - + - - - - - - + + + + + + From 2e9a47cbd483e8e8952684b4e220191ec21df273 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 08:52:58 +0200 Subject: [PATCH 05/33] Fever dream --- .../dbis/cs108/multiplayer/client/Client.java | 17 ++- .../client/JClientProtocolParser.java | 6 +- .../cs108/multiplayer/client/gui/GUI.java | 15 +- .../multiplayer/client/gui/chat/ChatApp.java | 10 +- .../client/gui/lounge/LoungeApp.java | 128 ++++++++++++++++++ .../gui/lounge/LoungeSceneViewController.java | 31 ++++- .../multiplayer/helpers/GuiParameters.java | 28 ++-- .../multiplayer/server/ClientHandler.java | 33 ++++- .../server/JServerProtocolParser.java | 8 +- .../client/gui/lounge/LoungeSceneView.fxml | 4 +- 10 files changed, 243 insertions(+), 37 deletions(-) create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index db76c8b..c8498d9 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -8,6 +8,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger; @@ -39,10 +40,15 @@ public class Client { public ClientPinger clientPinger; private ChatApp chatApp; - private GUI chatGui; + //private GUI chatGui; private ClientModel clientModel; private GameStateModel gameStateModel; private GameController gameController; + + private GUI gui; + + private LoungeApp loungeApp; + //private GUI loungeGui; private LoungeSceneViewController loungeSceneViewController; /** @@ -73,10 +79,13 @@ public class Client { } sendMsgToServer(Protocol.clientLogin + "$" + systemName); this.chatApp = new ChatApp(new ClientModel(systemName, this)); - this.chatGui = new GUI(this.chatApp); + //this.chatGui = new GUI(this.chatApp); clientPinger = new ClientPinger(this, this.socket); this.gameStateModel = new GameStateModel(); this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel); + this.loungeApp = new LoungeApp(ChatApp.getClientModel()); + //this.loungeGui = new GUI(this.loungeApp); + this.gui = new GUI(this.chatApp,this.loungeApp); this.loungeSceneViewController = new LoungeSceneViewController(); LoungeSceneViewController.setClient(ChatApp.getClientModel()); } catch (IOException e) { @@ -257,7 +266,7 @@ public class Client { cP.start(); client.userInputListener(); //this one blocks. //Start the GUI - GUI gui = new GUI(client.chatApp); + GUI gui = new GUI(client.chatApp,client.loungeApp); Thread guiThread = new Thread(gui); guiThread.start(); LOGGER.info("7"); @@ -287,7 +296,7 @@ public class Client { cP.start(); client.userInputListener(); //this one blocks. LOGGER.info("7.1"); - Thread guiThread = new Thread(client.chatGui); + Thread guiThread = new Thread(client.gui); LOGGER.info("8"); guiThread.start(); LOGGER.info("9"); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 2ad6979..a91a6b0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -61,12 +61,12 @@ public class JClientProtocolParser { break; case Protocol.printToGUI: String substring = msg.substring(6); - int index = msg.indexOf("$"); + int index = substring.indexOf("$"); String parameter = ""; String data = substring; try { - parameter = msg.substring(0,index); - data = msg.substring(index+1); + parameter = substring.substring(0,index); + data = substring.substring(index+1); } catch (Exception e) { LOGGER.warn("No parameter in PTGUI"); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java index 06a9d30..04eee0f 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java @@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeApp; import javafx.application.Application; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -12,12 +13,21 @@ public class GUI implements Runnable { public static final BudaLogConfig l = new BudaLogConfig(LOGGER); private ChatApp chatApp; - + private LoungeApp loungeApp; public GUI(ChatApp chatApp) { this.chatApp = chatApp; } + public GUI(LoungeApp loungeApp) { + this.loungeApp = loungeApp; + } + + public GUI(ChatApp chatApp, + LoungeApp loungeApp) { + this.chatApp = chatApp; + this.loungeApp = loungeApp; + } /** * When an object implementing interface {@code Runnable} is used to create a thread, starting the @@ -32,6 +42,7 @@ public class GUI implements Runnable { @Override public void run() { LOGGER.info("here"); - Application.launch(this.chatApp.getClass()); + //Application.launch(this.chatApp.getClass()); + Application.launch(this.loungeApp.getClass()); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java index 84e7947..2cc693d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java @@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; 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.lounge.LoungeSceneViewController; import java.net.URL; import java.util.Objects; import javafx.application.Application; @@ -21,6 +22,8 @@ public class ChatApp extends Application { private static ChatController chatController; private ClientModel cModel; + private static LoungeSceneViewController loungeSceneViewController; + public ChatApp() { super(); LOGGER.info("Empty ChatApp constructor got called: "); @@ -66,6 +69,10 @@ public class ChatApp extends Application { return chatController; } + public static void setLoungeSceneViewController(LoungeSceneViewController controller) { + loungeSceneViewController = controller; + } + /** * The main entry point for all JavaFX applications. The start method is called after the init @@ -94,6 +101,7 @@ public class ChatApp extends Application { Objects.requireNonNull(ChatApp.class.getResource( "ChatView.fxml"))); // TODO bin chatController.getChatPaneRoot() border to root border for rezising + Scene scene = new Scene(root); scene.setRoot(root); primaryStage.setScene(scene); @@ -101,7 +109,7 @@ public class ChatApp extends Application { e.printStackTrace(); } primaryStage.setResizable(true); - primaryStage.setTitle("Chat"); + primaryStage.setTitle("Lounge"); primaryStage.show(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java new file mode 100644 index 0000000..ce2df98 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java @@ -0,0 +1,128 @@ +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.chat.ChatApp; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; +import java.net.URL; +import java.util.Objects; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Class for debugging the lounge gui scene + */ +public class LoungeApp extends Application { + + public static final Logger LOGGER = LogManager.getLogger(ChatApp.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + + private static ClientModel clientModel; + private static ChatController chatController; + private ClientModel cModel; + + private static LoungeSceneViewController loungeSceneViewController; + + public LoungeApp() { + super(); + LOGGER.info("Empty ChatApp constructor got called: "); + } + + public LoungeApp(ClientModel clientM) { + clientModel = clientM; + chatController = new ChatController(clientM); + } + + /** + * Sets the ChatController for the Application, needs to be static, but only one application can + * be launched per programm + * + * @param chatC the ChatController to be linked to this chatApp + */ + public static void setChatController(ChatController chatC) { + chatController = chatC; + } + + /** + * Sets the non-static ClientModel field of this class + * + * @param cModel the non static ClientModel to be added + */ + public void setcModel(ClientModel cModel) { + this.cModel = cModel; + } + + public ClientModel getcModel() { + return cModel; + } + + public static void setClientModel(ClientModel clientM) { + clientModel = clientM; + } + + public static ClientModel getClientModel() { + return clientModel; + } + + public ChatController getChatController() { + return chatController; + } + + public static void setLoungeSceneViewController(LoungeSceneViewController controller) { + loungeSceneViewController = controller; + } + + + /** + * The main entry point for all JavaFX applications. The start method is called after the init + * method has returned, and after the system is ready for the application to begin running. + * + *

+ * NOTE: This method is called on the JavaFX Application Thread. + *

+ * + * @param primaryStage the primary stage for this application, onto which the application scene + * can be set. Applications may create other stages, if needed, but they will + * not be primary stages. + * @throws Exception if something goes wrong + */ + @Override + public void start(Stage primaryStage) throws Exception { + this.setcModel(clientModel); + URL resource = ChatApp.class.getResource( + "LoungeSceneView.fxml"); + if (resource == null) { + LOGGER.info("File wasnt found. Name: LoungeSceneView.fxml"); + } + //ChatApp chatApp = new ChatApp(new ClientModel()); + try { + Parent root = FXMLLoader.load( + Objects.requireNonNull(LoungeApp.class.getResource( + "LoungeSceneView.fxml"))); + // TODO bin chatController.getChatPaneRoot() border to root border for rezising +// loungeSceneViewController.getChatAreaHBox().getChildren() +// .add(FXMLLoader.load(Objects.requireNonNull(ChatApp.class.getResource("ChatView.fxml")))); + Scene scene = new Scene(root); + scene.setRoot(root); + primaryStage.setScene(scene); + } catch (Exception e) { + e.printStackTrace(); + } + primaryStage.setResizable(true); + primaryStage.setTitle("Lounge"); + primaryStage.show(); + + + } + + public static void main(String[] args) { + launch(args); + } + +} + diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 7f3b1c7..479d0a1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.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; @@ -9,6 +10,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; +import javafx.application.Application; import javafx.beans.binding.StringBinding; import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleMapProperty; @@ -57,6 +59,7 @@ public class LoungeSceneViewController implements Initializable { private ToolBar NTtBToolBar; public static ClientModel client; + public static ChatApp chatApp; private ObservableMap> lobbyToMemberssMap; private HashMap clientToLobbyMap; @@ -76,11 +79,13 @@ public class LoungeSceneViewController implements Initializable { */ @Override public void initialize(URL location, ResourceBundle resources) { + ChatApp.setLoungeSceneViewController(this); this.protocol = new Protocol(); ChangeNameButton.setOnAction(event -> changeName()); LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler()); 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() { @@ -136,8 +141,9 @@ public class LoungeSceneViewController implements Initializable { HBox lobby = new HBox(); Label idLabel = new Label(); Label adminLabel = new Label(); - idLabel.textProperty().bind(id); - adminLabel.textProperty().bind(admin); + idLabel.setText(lobbyID); + adminLabel.setText(adminName); + startOrJoin.setVisible(true); lobby.getChildren().add(idLabel); lobby.getChildren().add(adminLabel); lobby.getChildren().add(startOrJoin); @@ -151,6 +157,7 @@ public class LoungeSceneViewController implements Initializable { } lobby.setId(lobbyID); lobbyToMemberssMap.put(lobbyID, members.getItems()); + lobby.setVisible(true); LobbyListView.getItems().add(lobby); } @@ -164,6 +171,11 @@ public class LoungeSceneViewController implements Initializable { ; + /** + * Used to add a new player to the list of players. + * "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} + * @param s + */ public void addClientToList(String s) { ClientListView.getItems().add(new SimpleStringProperty(s)); } @@ -174,13 +186,14 @@ public class LoungeSceneViewController implements Initializable { public void changeName() { - TextField name = new TextField("Enter new name!"); + TextField name = new TextField(); + name.setPromptText("Enter new Nickname!"); this.NTtBToolBar.getItems().add(name); name.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { client.getClient().sendMsgToServer(Protocol.nameChange + "$" + name.getText()); - NTtBToolBar.getItems().remove(NTtBToolBar.getItems().size()); + NTtBToolBar.getItems().remove(name); } }); } @@ -204,4 +217,12 @@ public class LoungeSceneViewController implements Initializable { public static void setClient(ClientModel client) { LoungeSceneViewController.client = client; } + + public HBox getChatAreaHBox() { + return ChatAreaHBox; + } + + public void setChatAreaHBox(HBox chatAreaHBox) { + ChatAreaHBox = chatAreaHBox; + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java index bbc4f1b..a72c105 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java @@ -6,7 +6,8 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.helpers; public class GuiParameters { /** - * Tells GUI to update the gameStateModel, in the form {@code UPDATE$name:role:kickedOff$name:role:kickedOff} ... usw. + * Tells GUI to update the gameStateModel, in the form {@code UPDATE$name:role:kickedOff$name:role:kickedOff} + * ... usw. */ public static final String updateGameState = "UPDATE"; /** @@ -20,8 +21,8 @@ public class GuiParameters { public static final String listOfPLayers = "PLAYERS"; /** - * Tells Gui, that the passenger at position {@code position} has heard some noise - * Form: {@code NOISE$position$} + * Tells Gui, that the passenger at position {@code position} has heard some noise Form: {@code + * NOISE$position$} */ public static final String noiseHeardAtPosition = "NOISE"; @@ -41,22 +42,29 @@ public class GuiParameters { public static final String viewChangeToGame = "VCGAME"; - /** - * Tells Gui, who the members of a specified Lobby are. - * Form: {@code LMEMBS$:::<..>} + * Tells Gui, who the members of a specified Lobby are. Form: {@code LMEMBS$:::<..>} */ public static final String getMembersInLobby = "LMEMBS"; /** - * Tells Gui, that a new Lobby has been created. - * Form: {@code NLOBBY$:} + * Tells Gui, that a new Lobby has been created. Form: {@code NLOBBY$:} */ public static final String newLobbyCreated = "NLOBBY"; /** - * Tells Gui, to add a player to a lobby. - * Form: {@code NMEMB$:} + * Tells Gui, to add a player to a lobby. Form: {@code NMEMB$:} */ public static final String addNewMemberToLobby = "NMEMB"; + + /** + * Indicates a player changed their username. Form: {@code NCHANG$:} + */ + public static final String nameChanged = "NCHANG"; + + /** + * Indicates a player has joined the server. Form: {@code NPLOS$} + */ + public static final String newPlayerOnServer = "NPLOS"; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java index 27a47ed..3e554b2 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java @@ -5,6 +5,7 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow; import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler; import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore; +import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger; @@ -126,8 +127,12 @@ public class ClientHandler implements Runnable { */ public void changeUsername(String newName) { String helper = this.getClientUserName(); + String oldName = getClientUserName(); this.clientUserName = nameDuplicateChecker.checkName(newName); + guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.nameChanged + "$" + oldName + ":" + + getClientUserName()); sendMsgToClient(Protocol.changedUserName + "$" + newName); + broadcastAnnouncementToAll(helper + " has changed their nickname to " + clientUserName); try { getLobby().getGame().getGameState().changeUsername(helper, newName); @@ -245,6 +250,13 @@ public class ClientHandler implements Runnable { } } + public static void guiUpdateAll(String msg) { + System.out.println(msg); + for (ClientHandler client : connectedClients) { + client.sendMsgToClient(msg); + } + } + /** * Broadcasts a non-chat Message to all clients in the same lobby. This can be used for server * messages / announcements rather than chat messages. The message will be printed to the user @@ -306,7 +318,8 @@ public class ClientHandler implements Runnable { } /** - * Sends a given message to all connected client. The message has to already be protocol-formatted. + * Sends a given message to all connected client. The message has to already be + * protocol-formatted. * * @param msg the given message. Should already be protocol-formatted. */ @@ -317,7 +330,9 @@ public class ClientHandler implements Runnable { } /** - * Sends a Message to all clients in the same lobby. The message has to already be protocol-formatted. + * Sends a Message to all clients in the same lobby. The message has to already be + * protocol-formatted. + * * @param msg the given message. Should already be protocol-formatted. */ public void sendMsgToClientsInLobby(String msg) { @@ -456,6 +471,8 @@ public class ClientHandler implements Runnable { public void createNewLobby() { if (Lobby.clientIsInLobby(this) == -1) { Lobby newGame = new Lobby(this); + guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby() + .getLobbyID() + ":" + getClientUserName()); } else { sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this)); } @@ -472,6 +489,8 @@ public class ClientHandler implements Runnable { if (l != null) { if (l.getLobbyIsOpen()) { l.addPlayer(this); + guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.addNewMemberToLobby + "$" + i + ":" + + getClientUserName()); } else { sendAnnouncementToClient("The game in Lobby " + l.getLobbyID() + " has already started, or the lobby is already full."); @@ -567,11 +586,11 @@ public class ClientHandler implements Runnable { sendAnnouncementToClient("No Games"); } else { sendAnnouncementToClient("Open Games (i.e. open Lobbies):"); - for (Lobby l : Lobby.lobbies) { - if (l.getLobbyIsOpen()) { - sendAnnouncementToClient(" - Lobby Nr. " + l.getLobbyID()); - } + for (Lobby l : Lobby.lobbies) { + if (l.getLobbyIsOpen()) { + sendAnnouncementToClient(" - Lobby Nr. " + l.getLobbyID()); } + } sendAnnouncementToClient("Running Games:"); try { for (Game runningGame : Lobby.runningGames) { @@ -627,7 +646,7 @@ public class ClientHandler implements Runnable { public void sendHighScoreList() { String list = OgGhostHighScore.formatGhostHighscoreList(); String[] listarray = list.split("\\R"); - for (String s: listarray) { + for (String s : listarray) { sendAnnouncementToClient(s); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index 1ee67ab..b5d499e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -82,7 +82,6 @@ public class JServerProtocolParser { try { int i = Integer.parseInt(msg.substring(6, 7)); h.joinLobby(i); - h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$"); } catch (Exception e) { h.sendMsgToClient(Protocol.printToClientConsole + "$Invalid input. Please use JOINL$1 to join Lobby 1, for example."); @@ -90,7 +89,12 @@ public class JServerProtocolParser { break; case Protocol.createNewLobby: h.createNewLobby(); - h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby+ "$"); + h.sendMsgToClient( + Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby() + .getLobbyID() + ":" + h.getClientUserName()); + h.guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby() + .getLobbyID() + ":" + h.getClientUserName()); + LOGGER.info("Here"); break; case Protocol.listLobbies: h.listLobbies(); diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml index 52c4b4e..0de7e45 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml @@ -3,12 +3,10 @@ - - @@ -23,7 +21,7 @@
-
From a8fa462949875c3815b18ec3ca83822f4600c8bc Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 09:46:29 +0200 Subject: [PATCH 06/33] Fixed some wonky bugs, and added minimum vote time of 5 seconds to calm the game down a litte --- .../cs108/gamelogic/ServerGameInfoHandler.java | 14 ++++++++++---- .../ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java | 9 +++++++-- .../dmi/dbis/cs108/gamelogic/VoteHandler.java | 2 -- .../dmi/dbis/cs108/multiplayer/client/Client.java | 1 + .../multiplayer/client/JClientProtocolParser.java | 4 +++- .../multiplayer/client/gui/GameStateModel.java | 1 - .../client/gui/game/GameController.java | 10 +++++----- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java index 5337714..2edb598 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java @@ -36,7 +36,11 @@ public class ServerGameInfoHandler { msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$"; break; default: - msg = Protocol.printToClientConsole + "$" + msg; + if(!msg.contains("$")) { + msg = Protocol.printToClientConsole + "$" + msg; + } else { + msg = msg; + } } LOGGER.debug(msg); return msg; @@ -64,7 +68,11 @@ public class ServerGameInfoHandler { msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString(); break; default: - msg = Protocol.printToClientConsole + "$" + msg; + if(!msg.contains("$")) { + msg = Protocol.printToClientConsole + "$" + msg; + } else { + msg = msg; + } } LOGGER.debug(msg); return msg; @@ -112,7 +120,6 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": String outMsg = npc.getName() + ": " + noiseRandomizer(); //TODO: add likelyhood - Timer.ghostAfterVoteTimer(); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + "$" + npc.getPosition()); @@ -137,7 +144,6 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": String outMsg = npc.getName() + ": " + noiseRandomizer(); - Timer.ghostAfterVoteTimer(); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + "$" + npc.getPosition()); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java index d52ec23..cc888d9 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java @@ -39,6 +39,11 @@ public class Timer { */ public static final int interval = 1; + /** + * The minimal vote time, in seconds + */ + public static final int minVoteTime = 5; + /** * The timer for the ghost vote. Checks every {@code interval} seconds if every ghost has already voted. * If all have voted or if the {@code ghostVoteTime} value is reached, the timer ends @@ -47,7 +52,7 @@ public class Timer { public static void ghostVoteTimer(Game game) { int counter = 0; while(counter < ghostVoteTime) { - if(haveAllGhostsVoted(game)) { //if all ghost have voted + if(haveAllGhostsVoted(game) && counter > minVoteTime) { //if all ghost have voted return; } try { @@ -62,7 +67,7 @@ public class Timer { public static void humanVoteTimer(Game game) { int counter = 0; while (counter < humanVoteTime) { - if (haveAllHumansVoted(game)) return; + if (haveAllHumansVoted(game) && counter > minVoteTime) return; try { Thread.sleep(interval*1000); } catch (InterruptedException e) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java index 07d3ce3..e7a7a0a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java @@ -68,7 +68,6 @@ public class VoteHandler { } } LOGGER.info("Most votes for: " + newGhostPosition); - Timer.ghostAfterVoteTimer(); for(Passenger passenger : passengers) { if(passenger.getIsGhost() || passenger.getIsSpectator()) { passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game); @@ -87,7 +86,6 @@ public class VoteHandler { walk by is being updated. Finally, each passenger receives information about how often he heard something during this night. The player who's just been ghostified is ignored since he didn't participate in this night's ghostification. */ - Timer.ghostAfterVoteTimer(); int[] noiseAmount = new int[6]; for (int i = 0; i < passengers.length; i++) { if (passengers[i].getIsGhost() && i != newGhostPosition) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index f396a6f..36fe472 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -346,6 +346,7 @@ public class Client { break; case GuiParameters.day: //ClientGameInfoHandler gameStateModel.setDayClone(true); + chatApp.getGameController().setNoiseButtonVisible(); break; case GuiParameters.updateGameState: gameStateModel.setGSFromString(data); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 275db4e..41dbad6 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -39,6 +39,7 @@ public class JClientProtocolParser { c.clientPinger.setGotPingBack(true); break; case Protocol.printToClientConsole: + LOGGER.debug(msg); System.out.println(msg.substring(6)); if (!msg.substring(6).equals("Your vote was invalid")) { c.notificationTextDisplay(msg.substring(6)); @@ -83,8 +84,9 @@ public class JClientProtocolParser { } catch (Exception e) { LOGGER.warn(msg.substring(6)); } + break; default: - System.out.println("Received unknown command"); + System.out.println("Received unknown command: " + msg); } } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java index 164419e..5a4a594 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GameStateModel.java @@ -117,7 +117,6 @@ public class GameStateModel { j = right.indexOf(':'); roles[i] = right.substring(0, j); kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1)); - LOGGER.info(kickedOff[i]); i++; } setPassengerTrainClone(names, roles); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index 22f5a5c..30f84c5 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -268,7 +268,7 @@ public class GameController implements Initializable{ if(kickedOff[1]) { role1 = new Text("\nkicked off"); } else { - role1 = new Text("\n" + roles[0]); + role1 = new Text("\n" + roles[1]); } role1.setStyle("-fx-font: 25 arial;"); role1.setFill(Color.WHITE); @@ -276,7 +276,7 @@ public class GameController implements Initializable{ if(kickedOff[2]) { role2 = new Text("\nkicked off"); } else { - role2 = new Text("\n" + roles[0]); + role2 = new Text("\n" + roles[2]); } role2.setStyle("-fx-font: 25 arial;"); role2.setFill(Color.WHITE); @@ -284,7 +284,7 @@ public class GameController implements Initializable{ if(kickedOff[3]) { role3 = new Text("\nkicked off"); } else { - role3 = new Text("\n" + roles[0]); + role3 = new Text("\n" + roles[3]); } role3.setStyle("-fx-font: 25 arial;"); role3.setFill(Color.WHITE); @@ -292,7 +292,7 @@ public class GameController implements Initializable{ if(kickedOff[4]) { role4 = new Text("\nkicked off"); } else { - role4 = new Text("\n" + roles[0]); + role4 = new Text("\n" + roles[4]); } role4.setStyle("-fx-font: 25 arial;"); role4.setFill(Color.WHITE); @@ -300,7 +300,7 @@ public class GameController implements Initializable{ if(kickedOff[5]) { role5 = new Text("\nkicked off"); } else { - role5 = new Text("\n" + roles[0]); + role5 = new Text("\n" + roles[5]); } role5.setStyle("-fx-font: 25 arial;"); role5.setFill(Color.WHITE); From 505577817e757c766a53cc33027129349669d2ee Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 10:46:58 +0200 Subject: [PATCH 07/33] Made loungeView a sensible size and added a button and made it at the moment the main scene --- .../dbis/cs108/multiplayer/client/Client.java | 10 ++--- .../cs108/multiplayer/client/gui/ChatApp.java | 38 ++++++++++++------- .../cs108/multiplayer/client/gui/GUI.java | 14 +++---- .../client/gui/lounge/LoungeApp.java | 2 +- .../gui/lounge/LoungeSceneViewController.java | 12 +++--- .../client/gui/lounge/LoungeSceneView.fxml | 19 +++++----- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index 12ed944..6aa94b0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -80,16 +80,14 @@ public class Client { } sendMsgToServer(Protocol.clientLogin + "$" + systemName); this.chatApp = new ChatApp(new ClientModel(systemName, this)); - //this.chatGui = new GUI(this.chatApp); + this.gui = new GUI(this.chatApp); clientPinger = new ClientPinger(this, this.socket); this.gameStateModel = new GameStateModel(); this.chatApp = new ChatApp(new ClientModel(systemName, this)); ChatApp.setGameController(new GameController(ChatApp.getClientModel(), gameStateModel)); - this.chatGui = new GUI(this.chatApp); + this.gui = new GUI(this.chatApp); this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel); this.loungeApp = new LoungeApp(ChatApp.getClientModel()); - //this.loungeGui = new GUI(this.loungeApp); - this.gui = new GUI(this.chatApp,this.loungeApp); this.loungeSceneViewController = new LoungeSceneViewController(); LoungeSceneViewController.setClient(ChatApp.getClientModel()); } catch (IOException e) { @@ -273,7 +271,7 @@ public class Client { cP.start(); client.userInputListener(); //this one blocks. //Start the GUI - GUI gui = new GUI(client.chatApp,client.loungeApp); + GUI gui = new GUI(client.chatApp); Thread guiThread = new Thread(gui); guiThread.start(); LOGGER.info("7"); @@ -372,7 +370,7 @@ public class Client { } break; case GuiParameters.listOfLobbies: - //updateListOfLobbies(data); (commented out due to compiling error) + updateListOfLobbies(data); //TODO break; case GuiParameters.VoteIsOver: diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java index a89f608..064dd54 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java @@ -1,7 +1,10 @@ -package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; 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.chat.ChatController; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController; import java.net.URL; import java.util.Objects; import javafx.application.Application; @@ -23,8 +26,8 @@ public class ChatApp extends Application { private static GameController gameController; private ClientModel cModel; private GameController gameC; - private static LoungeSceneViewController loungeSceneViewController; + private LoungeSceneViewController lSVController; public ChatApp() { super(); @@ -59,6 +62,11 @@ public class ChatApp extends Application { this.gameC = gameC; } + public void setlSVController( + LoungeSceneViewController lSVController) { + this.lSVController = lSVController; + } + public ClientModel getcModel() { return cModel; } @@ -88,6 +96,10 @@ public class ChatApp extends Application { return chatController; } + public LoungeSceneViewController getlSVController() { + return lSVController; + } + public static void setLoungeSceneViewController(LoungeSceneViewController controller) { loungeSceneViewController = controller; } @@ -110,33 +122,33 @@ public class ChatApp extends Application { public void start(Stage primaryStage) throws Exception { this.setcModel(clientModel); this.setGameC(gameController); + this.setlSVController(loungeSceneViewController); gameC.setClient(cModel); gameC.setGameStateModel(GameController.getGameStateModel()); URL chatResource = ChatApp.class.getResource( "chat/ChatView.fxml"); URL gameResource = ChatApp.class.getResource( "game/GameDayAll.fxml"); + URL loungeResource = ChatApp.class.getResource( + "lounge/LoungeSceneView.fxml"); try { - Parent root = FXMLLoader.load( - Objects.requireNonNull(gameResource)); + Parent lounge = FXMLLoader.load( + Objects.requireNonNull(loungeResource)); + Node chat = FXMLLoader.load(Objects.requireNonNull(chatResource)); + Node game = FXMLLoader.load(Objects.requireNonNull(gameResource)); // TODO bin chatController.getChatPaneRoot() border to root border for rezising - Scene scene = new Scene(root); - scene.setRoot(root); + Scene scene = new Scene(lounge); + scene.setRoot(lounge); primaryStage.setScene(scene); } catch (Exception e) { e.printStackTrace(); } primaryStage.setResizable(false); - Node chat = FXMLLoader.load( - Objects.requireNonNull(chatResource)); + primaryStage.setTitle("Night Train To Budapest"); primaryStage.setResizable(true); - primaryStage.setTitle("Chat"); primaryStage.show(); - - - - } + } public static void main(String[] args) { launch(args); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java index f3049be..7263b12 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java @@ -1,7 +1,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp; import javafx.application.Application; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -12,21 +12,21 @@ public class GUI implements Runnable { public static final BudaLogConfig l = new BudaLogConfig(LOGGER); private ChatApp chatApp; - private LoungeApp loungeApp; + //private LoungeApp loungeApp; public GUI(ChatApp chatApp) { this.chatApp = chatApp; } - public GUI(LoungeApp loungeApp) { + /*public GUI(LoungeApp loungeApp) { this.loungeApp = loungeApp; - } + }*/ - public GUI(ChatApp chatApp, + /*public GUI(ChatApp chatApp, LoungeApp loungeApp) { this.chatApp = chatApp; this.loungeApp = loungeApp; - } + }*/ /** * When an object implementing interface {@code Runnable} is used to create a thread, starting the @@ -42,6 +42,6 @@ public class GUI implements Runnable { public void run() { LOGGER.info("here"); //Application.launch(this.chatApp.getClass()); - Application.launch(this.loungeApp.getClass()); + Application.launch(this.chatApp.getClass()); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java index ce2df98..ee9aa5b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeApp.java @@ -1,8 +1,8 @@ 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.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; import java.net.URL; import java.util.Objects; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 479d0a1..ac083a3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -1,7 +1,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; -import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.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; @@ -38,8 +38,10 @@ import javafx.scene.text.Text; public class LoungeSceneViewController implements Initializable { - Protocol protocol; + @FXML + public Button leaveLobbyButton; + @FXML public Button newGameButton; @FXML private ListView LobbyListView; @@ -80,9 +82,8 @@ public class LoungeSceneViewController implements Initializable { @Override public void initialize(URL location, ResourceBundle resources) { ChatApp.setLoungeSceneViewController(this); - this.protocol = new Protocol(); ChangeNameButton.setOnAction(event -> changeName()); - LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler()); + LeaveServerButton.setOnAction(event -> leaveServer()); newGameButton.setOnAction(event -> newGame()); LobbyListView.setVisible(true); ClientListView.setVisible(true); @@ -169,8 +170,9 @@ public class LoungeSceneViewController implements Initializable { client.getClient().sendMsgToServer(Protocol.startANewGame); } - ; + public void leaveLobby() {client.getClient().sendMsgToServer(Protocol.leaveLobby);} + public void leaveServer() {client.getClient().sendMsgToServer(Protocol.clientQuitRequest);} /** * Used to add a new player to the list of players. * "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml index 0de7e45..eff7e85 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml @@ -7,36 +7,37 @@ - + - + - + @@ -57,7 +57,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -86,7 +86,7 @@
- + diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml index 24670cd..81237cc 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml @@ -2,10 +2,10 @@ + - @@ -22,16 +22,21 @@
-
- + - + + + + + + From fdc7ba666893a7f8b333ee9d15a84b42984f4624 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 14:49:46 +0200 Subject: [PATCH 14/33] Debugging NewLobby() --- .../dbis/cs108/multiplayer/client/Client.java | 3 ++ .../client/gui/lounge/ClientListItem.java | 1 + .../client/gui/lounge/LobbyListItem.java | 13 ++++++++ .../gui/lounge/LoungeSceneViewController.java | 33 ++++++++++++++++--- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index a367275..625960a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -415,11 +415,14 @@ public class Client { private void makeNewLobby(String data) { String[] params = data.split(":"); loungeSceneViewController.newLobby(params[0], params[1]); + LOGGER.debug("makeNewLobby() seems to have finnished"); + } private void addPlayerToLobby(String data) { String[] params = data.split(":"); loungeSceneViewController.addPlayerToLobby(params[0], params[1]); + LOGGER.debug("addPlayerToLobby() seems to have finnished"); } private void updateLobbyMembers(String data) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java index 8c815ea..7a8c598 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java @@ -42,4 +42,5 @@ public class ClientListItem { public int clientID() { return id; } + } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index e3f4fbc..2b3bdd6 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -110,4 +110,17 @@ public class LobbyListItem { public void setNoOfPlayersInLobby(int noOfPlayersInLobby) { this.noOfPlayersInLobby.set(noOfPlayersInLobby); } + + @Override + public String toString() { + return "LobbyListItem{" + + "lobbyID=" + lobbyID + + ", adminName=" + adminName + + ", clientsInLobby=" + clientsInLobby + + ", ownedByClient=" + ownedByClient + + ", isOpen=" + isOpen + + ", MAX_CAPACITY=" + MAX_CAPACITY + + ", noOfPlayersInLobby=" + noOfPlayersInLobby + + '}'; + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 5a8a9b7..545c66c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -32,13 +32,14 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; import javafx.scene.text.Text; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class LoungeSceneViewController implements Initializable { - public static final Logger LOGGER = LogManager.getLogger(JServerProtocolParser.class); + public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); @FXML @@ -170,7 +171,9 @@ public class LoungeSceneViewController implements Initializable { } else { LOGGER.debug("In updateItem(item, empty) Method. Else branch -> nonnull item"); name.setText(item.getName()); + name.setTextFill(Color.BLACK); id.setText(String.valueOf(item.getId())); + id.setTextFill(Color.BLACK); setGraphic(nameAndId); } } @@ -261,7 +264,10 @@ public class LoungeSceneViewController implements Initializable { } }); startOrJoin.setText(item.isOwnedByClient() ? "Start" : "Join"); - setGraphic(headParent); + lobbyID.setTextFill(Color.BLACK); + adminName.setTextFill(Color.BLACK); + startOrJoin.setTextFill(Color.BLACK); + setGraphic(head); } } }; @@ -269,6 +275,7 @@ public class LoungeSceneViewController implements Initializable { }); LobbyListView.setPlaceholder(new Text("No open lobbies!")); + LobbyListView.setVisible(true); } public void addGameView(){ @@ -336,7 +343,16 @@ public class LoungeSceneViewController implements Initializable { } LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient), new SimpleBooleanProperty(true), new SimpleIntegerProperty(0)); - lobbies.add(item); + Platform.runLater(new Runnable() { + @Override + public void run() { + lobbies.add(item); + LOGGER.debug("within newLobby() run() thread"); + LOGGER.debug(item.toString()); + } + }); + LOGGER.debug("newLobby() in LoungeSceneViewController seems to have reached end."); + LOGGER.debug(lobbies.toString()); } public void joinGame(String lobbyID) { @@ -362,7 +378,16 @@ public class LoungeSceneViewController implements Initializable { * @param s */ public void addClientToList(String s) { - clients.add(new ClientListItem(s)); + ClientListItem cl = new ClientListItem(s); + Platform.runLater(new Runnable() { + @Override + public void run() { + clients.add(cl); + LOGGER.debug("in addClientToList() in run()"); + LOGGER.debug(cl.toString() + " in run()"); + } + }); + } public void newGame() { From 111bd67bd4f51c33d451d4dc1f718d6cf98ddce1 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 14:56:44 +0200 Subject: [PATCH 15/33] error correcting type refactor --- .../client/gui/lounge/LoungeSceneViewController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 85f9641..e09ebd9 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -335,7 +335,7 @@ public class LoungeSceneViewController implements Initializable { }); } - public void updateClientListView(ObservableList names) { + public void updateClientListView(ObservableList names) { ObservableList clientsLeft = ClientListView.getItems(); clientsLeft.removeAll(names); this.ClientListView.setItems(names); From 927416f224c9f1c8c23f8b67b50c5086f9e3046b Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:03:20 +0200 Subject: [PATCH 16/33] added MSG to add new client to the gui of whoever is on the server --- .../dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index 5bb18a5..9749ce3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -65,6 +65,7 @@ public class JServerProtocolParser { } catch (Exception e) { h.setUsernameOnLogin("U.N. Owen"); } + h.guiUpdateAll(Protocol.printToGUI+"$"+GuiParameters.newPlayerOnServer+"$"+h.getClientUserName()); break; case Protocol.nameChange: h.changeUsername(msg.substring(6)); From 578016d11d60e2a4e12eeb42c686c2a11d4da1c4 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:07:54 +0200 Subject: [PATCH 17/33] Added method to add new player to loungeview withing Client.java --- .../dmi/dbis/cs108/multiplayer/client/Client.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index 625960a..a2e6588 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -400,6 +400,8 @@ public class Client { case GuiParameters.newLobbyCreated: makeNewLobby(data); break; + case GuiParameters.newPlayerOnServer: + addNewPlayerToGui(data); default: notificationTextDisplay(data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController? @@ -412,17 +414,22 @@ public class Client { } + private void addNewPlayerToGui(String data) { + loungeSceneViewController.addClientToList(data); + LOGGER.debug("addNewPlayerToGui() seems to have finished"); + } + private void makeNewLobby(String data) { String[] params = data.split(":"); loungeSceneViewController.newLobby(params[0], params[1]); - LOGGER.debug("makeNewLobby() seems to have finnished"); + LOGGER.debug("makeNewLobby() seems to have finished"); } private void addPlayerToLobby(String data) { String[] params = data.split(":"); loungeSceneViewController.addPlayerToLobby(params[0], params[1]); - LOGGER.debug("addPlayerToLobby() seems to have finnished"); + LOGGER.debug("addPlayerToLobby() seems to have finished"); } private void updateLobbyMembers(String data) { From 58e2d693bbb2b4c830c1eda17714f160d3083cc4 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:15:06 +0200 Subject: [PATCH 18/33] added RMVLSt command to remove a client from gui --- .../gamelogic/klassenstruktur/HumanNPC.java | 20 +- .../dbis/cs108/multiplayer/client/Client.java | 10 +- .../client/gui/game/GameController.java | 821 +++++++++--------- .../client/gui/lounge/ClientListItem.java | 3 +- .../client/gui/lounge/LobbyListItem.java | 19 +- .../gui/lounge/LoungeSceneViewController.java | 34 +- .../multiplayer/helpers/GuiParameters.java | 6 + .../multiplayer/server/ClientHandler.java | 5 +- 8 files changed, 460 insertions(+), 458 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java index 32b6ee5..a1d5046 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java @@ -31,8 +31,9 @@ public class HumanNPC extends Human { } /** - * Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now, if the - * npc hasn't been kicked off 8(should never happen to a human though) + * Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now, if + * the npc hasn't been kicked off 8(should never happen to a human though) + * * @param msg the message that is sent to this player. * @param game the game the HumanNPC lives on (in game.gameState.passengerTrain) */ @@ -44,22 +45,23 @@ public class HumanNPC extends Human { } /** - * Currently returns a random integer for voting, but only for passengers that haven't been - * kicked off yet + * Currently returns a random integer for voting, but only for passengers that haven't been kicked + * off yet + * * @param game the game this NPC lives on */ public void vote(Game game) { Passenger[] passengers = game.getGameState().getPassengerTrain(); int kickedOffCounter = 0; - for(Passenger passenger : passengers) { - if(passenger.getKickedOff()) { + for (Passenger passenger : passengers) { + if (passenger.getKickedOff()) { kickedOffCounter++; } } int[] inGamePositions = new int[passengers.length - kickedOffCounter]; int i = 0; - for(Passenger passenger : passengers) { - if(!passenger.getKickedOff()) { + for (Passenger passenger : passengers) { + if (!passenger.getKickedOff()) { inGamePositions[i] = passenger.getPosition(); i++; } @@ -67,7 +69,7 @@ public class HumanNPC extends Human { int randomNr = (int) (Math.random() * inGamePositions.length); vote = inGamePositions[randomNr]; hasVoted = true; - game.getGameState().getClientVoteData().setHasVoted(position,hasVoted); + game.getGameState().getClientVoteData().setHasVoted(position, hasVoted); LOGGER.info("HumanNPC at Position: " + this.getPosition() + " has voted for: " + vote); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index a2e6588..db3bcd2 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -341,7 +341,7 @@ public class Client { * @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler} * can be empty * @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) { try { @@ -385,15 +385,15 @@ public class Client { break; case GuiParameters.viewChangeToGame: chatApp.getLoungeSceneViewController().addGameView(); - //TODO - break; + //TODO + break; /*case GuiParameters.viewChangeToStart: //TODO break;*/ case GuiParameters.viewChangeToLobby: chatApp.getLoungeSceneViewController().removeGameView(); - //TODO - break; + //TODO + break; case GuiParameters.addNewMemberToLobby: addPlayerToLobby(data); break; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index 30f84c5..bf29859 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -27,451 +27,456 @@ import javafx.scene.text.TextFlow; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class GameController implements Initializable{ - public static final Logger LOGGER = LogManager.getLogger(GameController.class); - public static final BudaLogConfig l = new BudaLogConfig(LOGGER); +public class GameController implements Initializable { - private static ClientModel client; + public static final Logger LOGGER = LogManager.getLogger(GameController.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); - private static GameStateModel gameStateModel; + private static ClientModel client; + + private static GameStateModel gameStateModel; - public GameController() { - super(); - } - //TODO(Seraina, Sebi): Same issue as ChatController? do with setters? - public GameController(ClientModel c, GameStateModel g) { - client = c; - gameStateModel = g; - } + public GameController() { + super(); + } - public void setClient(ClientModel c) { - client = c; - } + //TODO(Seraina, Sebi): Same issue as ChatController? do with setters? + public GameController(ClientModel c, GameStateModel g) { + client = c; + gameStateModel = g; + } - public static ClientModel getClient() { - return client; - } + public void setClient(ClientModel c) { + client = c; + } - public static GameStateModel getGameStateModel() { - return gameStateModel; - } + public static ClientModel getClient() { + return client; + } - @FXML - private AnchorPane gameBG; - @FXML + public static GameStateModel getGameStateModel() { + return gameStateModel; + } + + @FXML + private AnchorPane gameBG; + @FXML private Group roomButtonGroupDay; - @FXML + @FXML private Button buttonRoom0; - @FXML + @FXML private Button buttonRoom1; - @FXML + @FXML private Button buttonRoom2; - @FXML + @FXML private Button buttonRoom3; - @FXML + @FXML private Button buttonRoom4; - @FXML + @FXML private Button buttonRoom5; - @FXML - private HBox roomLables; - @FXML - private TextFlow lableRoom0; - @FXML - private TextFlow lableRoom1; - @FXML - private TextFlow lableRoom2; - @FXML - private TextFlow lableRoom3; - @FXML - private TextFlow lableRoom4; - @FXML - private TextFlow lableRoom5; - @FXML - private HBox notificationHBox; - @FXML - private ImageView noiseImage0; - @FXML - private ImageView noiseImage1; - @FXML - private ImageView noiseImage2; - @FXML - private ImageView noiseImage3; - @FXML - private ImageView noiseImage4; - @FXML - private ImageView noiseImage5; - @FXML - private Button noiseButton; - @FXML - public TextFlow notificationText; - @FXML - private AnchorPane chatAreaGame; + @FXML + private HBox roomLables; + @FXML + private TextFlow lableRoom0; + @FXML + private TextFlow lableRoom1; + @FXML + private TextFlow lableRoom2; + @FXML + private TextFlow lableRoom3; + @FXML + private TextFlow lableRoom4; + @FXML + private TextFlow lableRoom5; + @FXML + private HBox notificationHBox; + @FXML + private ImageView noiseImage0; + @FXML + private ImageView noiseImage1; + @FXML + private ImageView noiseImage2; + @FXML + private ImageView noiseImage3; + @FXML + private ImageView noiseImage4; + @FXML + private ImageView noiseImage5; + @FXML + private Button noiseButton; + @FXML + public TextFlow notificationText; + @FXML + private AnchorPane chatAreaGame; - public void addToChatArea(Node n) { - chatAreaGame.getChildren().add(n); - } - - public AnchorPane getChatAreaGame() { - return chatAreaGame; - } - - /** - * If button 0 is clicked, send the vote message 0 to the server - */ - public void sendVote0() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 0); - } - - /** - * If button 1 is clicked, send the vote message 0 to the server - */ - public void sendVote1() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1); - } - - /** - * If button 2 is clicked, send the vote message 0 to the server - */ - public void sendVote2() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2); - } - - /** - * If button 3 is clicked, send the vote message 0 to the server - */ - public void sendVote3() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3); - } - - /** - * If button 4 is clicked, send the vote message 0 to the server - */ - public void sendVote4() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4); - } - - /** - * If button 5 is clicked, send the vote message 0 to the server - */ - public void sendVote5() { - client.getClient() - .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5); - } - - /** - * Sends a noise message, to the server, should be a gui message? - */ - public void noise() { - LOGGER.info("Do you even get here"); - LOGGER.info(client.getClient()); - LOGGER.info(client.getClient().getPosition()); - if(client.getClient() == null) { - LOGGER.info("But why???"); + public void addToChatArea(Node n) { + chatAreaGame.getChildren().add(n); } - client.getClient().sendMsgToServer( - Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$" +GuiParameters.noiseHeardAtPosition + "$" - + client.getClient().getPosition()); //TODO: Test!! - } - public void setNoiseButtonInvisible() { - noiseButton.setVisible(false); - } - - public void setNoiseButtonVisible() { - noiseButton.setVisible(true); - } - - /** - * Takes a given message and displays it in the notificationText Flow in the game Scene - * @param msg the message to be displayed - */ - public void addMessageToNotificationText(String msg){ - LOGGER.trace("addMessage " + msg); - Text notification = new Text(msg); - notification.setFill(Color.BLACK); - notification.setStyle("-fx-font: 50 arial;"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - notificationText.getChildren().add(notification); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); - } - } - }); - - //TODO: Wait for a certain time, then clear all again - } - - /** - * Clears all children from notificationText TextFlow - */ - public void clearNotificationText() { - LOGGER.trace("clear notify"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - notificationText.getChildren().remove(0); - } catch (Exception e) { - LOGGER.debug("Not yet initialized"); - } - } - }); - - } - - /** - * Updates the labels of the rooms accordingly to the datastructures in GameStateModel - */ - public void updateRoomLabels() { - LOGGER.debug("roomlables update"); - String[] names = gameStateModel.getPassengerTrainClone()[0]; - String[] roles = gameStateModel.getPassengerTrainClone()[1]; - boolean[] kickedOff = gameStateModel.getKickedOff(); - Text name0 = new Text(names[0]); - name0.setStyle("-fx-font: 25 arial;"); - name0.setFill(Color.WHITE); - Text name1 = new Text(names[1]); - name1.setStyle("-fx-font: 25 arial;"); - name1.setFill(Color.WHITE); - Text name2 = new Text(names[2]); - name2.setStyle("-fx-font: 25 arial;"); - name2.setFill(Color.WHITE); - Text name3 = new Text(names[3]); - name3.setStyle("-fx-font: 25 arial;"); - name3.setFill(Color.WHITE); - Text name4 = new Text(names[4]); - name4.setStyle("-fx-font: 25 arial;"); - name4.setFill(Color.WHITE); - Text name5 = new Text(names[5]); - name5.setStyle("-fx-font: 25 arial;"); - name5.setFill(Color.WHITE); - Text role0; - if(kickedOff[0]) { - role0 = new Text("\nkicked off"); - } else { - role0 = new Text("\n" + roles[0]); + public AnchorPane getChatAreaGame() { + return chatAreaGame; } - role0.setStyle("-fx-font: 25 arial;"); - role0.setFill(Color.WHITE); - Text role1; - if(kickedOff[1]) { - role1 = new Text("\nkicked off"); - } else { - role1 = new Text("\n" + roles[1]); + + /** + * If button 0 is clicked, send the vote message 0 to the server + */ + public void sendVote0() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 0); } - role1.setStyle("-fx-font: 25 arial;"); - role1.setFill(Color.WHITE); - Text role2; - if(kickedOff[2]) { - role2 = new Text("\nkicked off"); - } else { - role2 = new Text("\n" + roles[2]); + + /** + * If button 1 is clicked, send the vote message 0 to the server + */ + public void sendVote1() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1); } - role2.setStyle("-fx-font: 25 arial;"); - role2.setFill(Color.WHITE); - Text role3; - if(kickedOff[3]) { - role3 = new Text("\nkicked off"); - } else { - role3 = new Text("\n" + roles[3]); + + /** + * If button 2 is clicked, send the vote message 0 to the server + */ + public void sendVote2() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2); } - role3.setStyle("-fx-font: 25 arial;"); - role3.setFill(Color.WHITE); - Text role4; - if(kickedOff[4]) { - role4 = new Text("\nkicked off"); - } else { - role4 = new Text("\n" + roles[4]); + + /** + * If button 3 is clicked, send the vote message 0 to the server + */ + public void sendVote3() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3); } - role4.setStyle("-fx-font: 25 arial;"); - role4.setFill(Color.WHITE); - Text role5; - if(kickedOff[5]) { - role5 = new Text("\nkicked off"); - } else { - role5 = new Text("\n" + roles[5]); + + /** + * If button 4 is clicked, send the vote message 0 to the server + */ + public void sendVote4() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4); } - role5.setStyle("-fx-font: 25 arial;"); - role5.setFill(Color.WHITE); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - lableRoom0.getChildren().clear(); - lableRoom0.getChildren().add(name0); - lableRoom0.getChildren().add(role0); - lableRoom1.getChildren().clear(); - lableRoom1.getChildren().add(name1); - lableRoom1.getChildren().add(role1); - lableRoom2.getChildren().clear(); - lableRoom2.getChildren().add(name2); - lableRoom2.getChildren().add(role2); - lableRoom3.getChildren().clear(); - lableRoom3.getChildren().add(name3); - lableRoom3.getChildren().add(role3); - lableRoom4.getChildren().clear(); - lableRoom4.getChildren().add(name4); - lableRoom4.getChildren().add(role4); - lableRoom5.getChildren().clear(); - lableRoom5.getChildren().add(name5); - lableRoom5.getChildren().add(role5); - } catch (Exception e) { - LOGGER.trace("Not yet initialized"); + /** + * If button 5 is clicked, send the vote message 0 to the server + */ + public void sendVote5() { + client.getClient() + .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5); + } + + /** + * Sends a noise message, to the server, should be a gui message? + */ + public void noise() { + LOGGER.info("Do you even get here"); + LOGGER.info(client.getClient()); + LOGGER.info(client.getClient().getPosition()); + if (client.getClient() == null) { + LOGGER.info("But why???"); } - } - }); - } + client.getClient().sendMsgToServer( + Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$" + + GuiParameters.noiseHeardAtPosition + "$" + + client.getClient().getPosition()); //TODO: Test!! + } - public Image loadBellImage(){ - Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png"); - return bell; - } + public void setNoiseButtonInvisible() { + noiseButton.setVisible(false); + } - /** - * Adds an image of a bell on top of button0 - */ - public void noiseDisplay0(){ - LOGGER.debug("noise0 called"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - noiseImage0.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); + public void setNoiseButtonVisible() { + noiseButton.setVisible(true); + } + + /** + * Takes a given message and displays it in the notificationText Flow in the game Scene + * + * @param msg the message to be displayed + */ + public void addMessageToNotificationText(String msg) { + LOGGER.trace("addMessage " + msg); + Text notification = new Text(msg); + notification.setFill(Color.BLACK); + notification.setStyle("-fx-font: 50 arial;"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + notificationText.getChildren().add(notification); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + + //TODO: Wait for a certain time, then clear all again + } + + /** + * Clears all children from notificationText TextFlow + */ + public void clearNotificationText() { + LOGGER.trace("clear notify"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + notificationText.getChildren().remove(0); + } catch (Exception e) { + LOGGER.debug("Not yet initialized"); + } + } + }); + + } + + /** + * Updates the labels of the rooms accordingly to the datastructures in GameStateModel + */ + public void updateRoomLabels() { + LOGGER.debug("roomlables update"); + String[] names = gameStateModel.getPassengerTrainClone()[0]; + String[] roles = gameStateModel.getPassengerTrainClone()[1]; + boolean[] kickedOff = gameStateModel.getKickedOff(); + Text name0 = new Text(names[0]); + name0.setStyle("-fx-font: 25 arial;"); + name0.setFill(Color.WHITE); + Text name1 = new Text(names[1]); + name1.setStyle("-fx-font: 25 arial;"); + name1.setFill(Color.WHITE); + Text name2 = new Text(names[2]); + name2.setStyle("-fx-font: 25 arial;"); + name2.setFill(Color.WHITE); + Text name3 = new Text(names[3]); + name3.setStyle("-fx-font: 25 arial;"); + name3.setFill(Color.WHITE); + Text name4 = new Text(names[4]); + name4.setStyle("-fx-font: 25 arial;"); + name4.setFill(Color.WHITE); + Text name5 = new Text(names[5]); + name5.setStyle("-fx-font: 25 arial;"); + name5.setFill(Color.WHITE); + Text role0; + if (kickedOff[0]) { + role0 = new Text("\nkicked off"); + } else { + role0 = new Text("\n" + roles[0]); } - } - }); - - } - - /** - * Adds an image of a bell on top of button1 - */ - public void noiseDisplay1(){ - LOGGER.debug("noise1 called"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - noiseImage1.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); + role0.setStyle("-fx-font: 25 arial;"); + role0.setFill(Color.WHITE); + Text role1; + if (kickedOff[1]) { + role1 = new Text("\nkicked off"); + } else { + role1 = new Text("\n" + roles[1]); } - } - }); - } - - /** - * Adds an image of a bell on top of button2 - */ - public void noiseDisplay2(){ - LOGGER.debug("noise2 called"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - noiseImage2.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage());; + role1.setStyle("-fx-font: 25 arial;"); + role1.setFill(Color.WHITE); + Text role2; + if (kickedOff[2]) { + role2 = new Text("\nkicked off"); + } else { + role2 = new Text("\n" + roles[2]); } - } - }); - } - - /** - * Adds an image of a bell on top of button3 - */ - public void noiseDisplay3() { - LOGGER.debug("noise3 called"); - Platform.runLater(new Runnable() { - @Override - public void run() { - try { - LOGGER.debug("hello"); - noiseImage3.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); + role2.setStyle("-fx-font: 25 arial;"); + role2.setFill(Color.WHITE); + Text role3; + if (kickedOff[3]) { + role3 = new Text("\nkicked off"); + } else { + role3 = new Text("\n" + roles[3]); } - } - }); - } - - /** - * Adds an image of a bell on top of button4 - */ - public void noiseDisplay4() { - LOGGER.debug("noise4 called"); - Platform.runLater(new Runnable() { - @Override - public void run() { - try { - LOGGER.debug("hello"); - noiseImage4.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); + role3.setStyle("-fx-font: 25 arial;"); + role3.setFill(Color.WHITE); + Text role4; + if (kickedOff[4]) { + role4 = new Text("\nkicked off"); + } else { + role4 = new Text("\n" + roles[4]); } - } - }); - } - - /** - * Adds an image of a bell on top of button5 - */ - public void noiseDisplay5() { - LOGGER.debug("noise5 called"); - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - noiseImage5.setImage(loadBellImage()); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); + role4.setStyle("-fx-font: 25 arial;"); + role4.setFill(Color.WHITE); + Text role5; + if (kickedOff[5]) { + role5 = new Text("\nkicked off"); + } else { + role5 = new Text("\n" + roles[5]); } - } - }); - } + role5.setStyle("-fx-font: 25 arial;"); + role5.setFill(Color.WHITE); - /** - * Clears all bells from the view - */ - public void clearAllNoiseDisplay() { - Platform.runLater(new Runnable(){ - @Override - public void run() { - try { - noiseImage0.setImage(null); - noiseImage1.setImage(null); - noiseImage2.setImage(null); - noiseImage3.setImage(null); - noiseImage4.setImage(null); - noiseImage5.setImage(null); - } catch (Exception e) { - LOGGER.debug(e.getMessage()); - } - } - }); - } + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + lableRoom0.getChildren().clear(); + lableRoom0.getChildren().add(name0); + lableRoom0.getChildren().add(role0); + lableRoom1.getChildren().clear(); + lableRoom1.getChildren().add(name1); + lableRoom1.getChildren().add(role1); + lableRoom2.getChildren().clear(); + lableRoom2.getChildren().add(name2); + lableRoom2.getChildren().add(role2); + lableRoom3.getChildren().clear(); + lableRoom3.getChildren().add(name3); + lableRoom3.getChildren().add(role3); + lableRoom4.getChildren().clear(); + lableRoom4.getChildren().add(name4); + lableRoom4.getChildren().add(role4); + lableRoom5.getChildren().clear(); + lableRoom5.getChildren().add(name5); + lableRoom5.getChildren().add(role5); + } catch (Exception e) { + LOGGER.trace("Not yet initialized"); + } + } + }); + } - public void setGameStateModel( - GameStateModel gameStateModel) { - GameController.gameStateModel = gameStateModel; - } + public Image loadBellImage() { + Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png"); + return bell; + } - @Override - public void initialize(URL location, ResourceBundle resources) { - ChatApp.setGameController(this); - } + /** + * Adds an image of a bell on top of button0 + */ + public void noiseDisplay0() { + LOGGER.debug("noise0 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + noiseImage0.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + + } + + /** + * Adds an image of a bell on top of button1 + */ + public void noiseDisplay1() { + LOGGER.debug("noise1 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + noiseImage1.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + + /** + * Adds an image of a bell on top of button2 + */ + public void noiseDisplay2() { + LOGGER.debug("noise2 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + noiseImage2.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + ; + } + } + }); + } + + /** + * Adds an image of a bell on top of button3 + */ + public void noiseDisplay3() { + LOGGER.debug("noise3 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + LOGGER.debug("hello"); + noiseImage3.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + + /** + * Adds an image of a bell on top of button4 + */ + public void noiseDisplay4() { + LOGGER.debug("noise4 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + LOGGER.debug("hello"); + noiseImage4.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + + /** + * Adds an image of a bell on top of button5 + */ + public void noiseDisplay5() { + LOGGER.debug("noise5 called"); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + noiseImage5.setImage(loadBellImage()); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + + /** + * Clears all bells from the view + */ + public void clearAllNoiseDisplay() { + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + noiseImage0.setImage(null); + noiseImage1.setImage(null); + noiseImage2.setImage(null); + noiseImage3.setImage(null); + noiseImage4.setImage(null); + noiseImage5.setImage(null); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + } + }); + } + + public void setGameStateModel( + GameStateModel gameStateModel) { + GameController.gameStateModel = gameStateModel; + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + ChatApp.setGameController(this); + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java index 7a8c598..a05ba41 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/ClientListItem.java @@ -9,6 +9,7 @@ public class ClientListItem { private final int id; private static int uid = 0; + public ClientListItem(String name, int id) { this.name = new SimpleStringProperty(name); this.id = id; @@ -19,7 +20,7 @@ public class ClientListItem { } @Override - public String toString(){ + public String toString() { return name + " ID: " + id; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index 2b3bdd6..75b2299 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -26,8 +26,7 @@ public class LobbyListItem { private final int MAX_CAPACITY = 6; private SimpleIntegerProperty noOfPlayersInLobby; - public LobbyListItem(SimpleStringProperty lobbyID, - SimpleStringProperty adminName, + public LobbyListItem(SimpleStringProperty lobbyID, SimpleStringProperty adminName, SimpleBooleanProperty ownedByClient, SimpleBooleanProperty isOpen, SimpleIntegerProperty noOfPlayersInLobby) { this.lobbyID = lobbyID; @@ -66,8 +65,7 @@ public class LobbyListItem { return clientsInLobby; } - public void setClientsInLobby( - ObservableList clientsInLobby) { + public void setClientsInLobby(ObservableList clientsInLobby) { this.clientsInLobby = clientsInLobby; } @@ -113,14 +111,9 @@ public class LobbyListItem { @Override public String toString() { - return "LobbyListItem{" + - "lobbyID=" + lobbyID + - ", adminName=" + adminName + - ", clientsInLobby=" + clientsInLobby + - ", ownedByClient=" + ownedByClient + - ", isOpen=" + isOpen + - ", MAX_CAPACITY=" + MAX_CAPACITY + - ", noOfPlayersInLobby=" + noOfPlayersInLobby + - '}'; + return "LobbyListItem{" + "lobbyID=" + lobbyID + ", adminName=" + adminName + + ", clientsInLobby=" + clientsInLobby + ", ownedByClient=" + ownedByClient + ", isOpen=" + + isOpen + ", MAX_CAPACITY=" + MAX_CAPACITY + ", noOfPlayersInLobby=" + noOfPlayersInLobby + + '}'; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index e09ebd9..de9ad34 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -335,15 +335,6 @@ public class LoungeSceneViewController implements Initializable { }); } - public void updateClientListView(ObservableList names) { - ObservableList clientsLeft = ClientListView.getItems(); - clientsLeft.removeAll(names); - this.ClientListView.setItems(names); - for (ClientListItem gone : clientsLeft) { - //TODO - } - } - /** * Adds players to a lobby * "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters} @@ -426,6 +417,20 @@ public class LoungeSceneViewController implements Initializable { } + public void removeClientFromList(String name){ + Iterator it = clients.iterator(); + while (it.hasNext()) { + String uid = it.next().getName(); + if (uid.equals(name)) { + it.remove(); + break; + } + } } + + public void removeClientFromLobby(String s){ + //todo + } + public void newGame() { client.getClient().sendMsgToServer(Protocol.createNewLobby); } @@ -444,17 +449,6 @@ public class LoungeSceneViewController implements Initializable { }); } - public void removePlayer(String id) { - Iterator it = client.getAllClients().iterator(); - while (it.hasNext()) { - String uid = it.next().getValue(); - if (uid.equals(id)) { - it.remove(); - break; - } - } - } - /** * Utility to set the client model for this class * diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java index 449b767..348f77f 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java @@ -79,4 +79,10 @@ public class GuiParameters { * Indicates a player has joined the server. Form: {@code NPLOS$} */ public static final String newPlayerOnServer = "NPLOS"; + + /** + * Tells gui to remove a certain player from the list of clients based on user name. Form: {@code + * RMVLST$} + */ + public static final String removePlayerFromList = "RMVLST"; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java index c928208..acfa8bd 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java @@ -475,8 +475,9 @@ public class ClientHandler implements Runnable { public void createNewLobby() { if (Lobby.clientIsInLobby(this) == -1) { Lobby newGame = new Lobby(this); - guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby() - .getLobbyID() + ":" + getClientUserName()); + guiUpdateAll( + Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby().getLobbyID() + + ":" + getClientUserName()); LOGGER.debug("Lobby: " + getLobby().getLobbyID() + ". In method createNewLobby()"); } else { sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this)); From 2907f95b4e0a354ce35e4f822da152f47f03bee7 Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 15:28:15 +0200 Subject: [PATCH 19/33] Added a s*t tone of Logger statements to find why LobbyListView is null --- .../gui/lounge/LoungeSceneViewController.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index e09ebd9..8224234 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -3,6 +3,7 @@ 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.ChatApp; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.LobbyListView; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser; import java.net.URL; @@ -63,9 +64,9 @@ public class LoungeSceneViewController implements Initializable { @FXML private AnchorPane gameAnchorPane; @FXML - private ListView LobbyListView; + public ListView LobbyListView; @FXML - private ListView ClientListView; + public ListView ClientListView; @FXML private Button ChangeNameButton; @FXML @@ -115,6 +116,7 @@ public class LoungeSceneViewController implements Initializable { LeaveServerButton.setOnAction(event -> leaveServer()); newGameButton.setOnAction(event -> newGame()); LobbyListView.setVisible(true); + LOGGER.debug("Lobby in initialize" + LobbyListView); ClientListView.setVisible(true); ClientListView.setItems(clients); addChatView(); @@ -122,6 +124,7 @@ public class LoungeSceneViewController implements Initializable { ClientListView.setItems(clients); ClientListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { + Label name = new Label(); Label id = new Label(); HBox nameAndId = new HBox(name, id); @@ -196,6 +199,7 @@ public class LoungeSceneViewController implements Initializable { }); LobbyListView.setItems(lobbies); + LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); LobbyListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { @@ -287,7 +291,7 @@ public class LoungeSceneViewController implements Initializable { }; return cell; }); - + LOGGER.debug("In Initialize 3 LobbyListView" + LobbyListView); LobbyListView.setPlaceholder(new Text("No open lobbies!")); LobbyListView.setVisible(true); } @@ -352,8 +356,13 @@ public class LoungeSceneViewController implements Initializable { */ public void addPlayerToLobby(String lobbyID, String player) { LOGGER.debug("Lobby ID: " + lobbyID + " player: " + player); - ObservableList members = lobbyToMemberssMap.get(lobbyID); - members.add(player); + Platform.runLater(new Runnable() { + @Override + public void run() { + ObservableList members = lobbyToMemberssMap.get(lobbyID); + members.add(player); + } + }); } /** @@ -364,10 +373,11 @@ public class LoungeSceneViewController implements Initializable { * @param adminName */ public void newLobby(String lobbyID, String adminName) { + LOGGER.debug("In newLobby()0 LobbyListView" + LobbyListView); LOGGER.debug("New lobby with ID " + lobbyID + " and admin " + adminName); SimpleStringProperty id = new SimpleStringProperty(lobbyID); SimpleStringProperty admin = new SimpleStringProperty((adminName)); - + LOGGER.debug("In newLobby()1 LobbyListView" + LobbyListView); Button startOrJoin; boolean ownedByClient = false; if (adminName.equals(client.getUsername())) { @@ -378,16 +388,19 @@ public class LoungeSceneViewController implements Initializable { } LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient), new SimpleBooleanProperty(true), new SimpleIntegerProperty(0)); + LOGGER.debug("In newLobby()2 LobbyListView" + LobbyListView); Platform.runLater(new Runnable() { @Override public void run() { lobbies.add(item); LOGGER.debug("within newLobby() run() thread"); LOGGER.debug(item.toString()); + LOGGER.debug("In newLobby() run() " + LobbyListView); } }); LOGGER.debug("newLobby() in LoungeSceneViewController seems to have reached end."); LOGGER.debug(lobbies.toString()); + LOGGER.debug("In newLobby()3 LobbyListView" + LobbyListView); } public void joinGame(String lobbyID) { From 5dfa53c001357d8fbb7b0f8aea9c88252c09808c Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:30:30 +0200 Subject: [PATCH 20/33] added RMVLSt command to remove a client from gui --- .../gui/lounge/LoungeSceneViewController.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index de9ad34..7249a5e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -63,9 +63,9 @@ public class LoungeSceneViewController implements Initializable { @FXML private AnchorPane gameAnchorPane; @FXML - private ListView LobbyListView; + public ListView LobbyListView; @FXML - private ListView ClientListView; + public ListView ClientListView; @FXML private Button ChangeNameButton; @FXML @@ -336,8 +336,8 @@ 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 player */ @@ -417,7 +417,7 @@ public class LoungeSceneViewController implements Initializable { } - public void removeClientFromList(String name){ + public void removeClientFromList(String name) { Iterator it = clients.iterator(); while (it.hasNext()) { String uid = it.next().getName(); @@ -425,9 +425,10 @@ public class LoungeSceneViewController implements Initializable { it.remove(); break; } - } } + } + } - public void removeClientFromLobby(String s){ + public void removeClientFromLobby(String s) { //todo } From 115e39c34f715c9a976d730dd0a1bb03197d74fb Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:37:47 +0200 Subject: [PATCH 21/33] .getID() from lobbylistview for debugging --- .../client/gui/lounge/LoungeSceneViewController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 421f259..0f09fc2 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -118,7 +118,6 @@ public class LoungeSceneViewController implements Initializable { LobbyListView.setVisible(true); LOGGER.debug("Lobby in initialize" + LobbyListView); ClientListView.setVisible(true); - ClientListView.setItems(clients); addChatView(); ClientListView.setItems(clients); @@ -200,6 +199,7 @@ public class LoungeSceneViewController implements Initializable { LobbyListView.setItems(lobbies); LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); + LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView.getId()); LobbyListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { From 317968e368576dadcd729fc548c6b7024abbc8b7 Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 15:55:20 +0200 Subject: [PATCH 22/33] Added static field to retain ListView reference --- .../client/gui/lounge/LoungeSceneViewController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 8be52fd..d936a4c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -78,6 +78,9 @@ public class LoungeSceneViewController implements Initializable { @FXML private ToolBar NTtBToolBar; + public static ListView lListView; + public static ListView cListView; + public static ClientModel client; private static ChatApp chatApp; private ChatApp cApp; @@ -116,6 +119,7 @@ public class LoungeSceneViewController implements Initializable { LeaveServerButton.setOnAction(event -> leaveServer()); newGameButton.setOnAction(event -> newGame()); LobbyListView.setVisible(true); + lListView = LobbyListView; LOGGER.debug("Lobby in initialize" + LobbyListView); ClientListView.setVisible(true); ClientListView.setItems(clients); @@ -124,7 +128,6 @@ public class LoungeSceneViewController implements Initializable { ClientListView.setItems(clients); ClientListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { - Label name = new Label(); Label id = new Label(); HBox nameAndId = new HBox(name, id); @@ -202,7 +205,6 @@ public class LoungeSceneViewController implements Initializable { LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); LobbyListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { - Label lobbyID = new Label(); Label adminName = new Label(); Label lobbyIsOpen = new Label(); @@ -364,7 +366,8 @@ public class LoungeSceneViewController implements Initializable { * @param adminName */ public void newLobby(String lobbyID, String adminName) { - LOGGER.debug("In newLobby()0 LobbyListView" + LobbyListView); + LobbyListView = lListView; + LOGGER.debug("In newLobby()0 LobbyListView" + lListView); LOGGER.debug("New lobby with ID " + lobbyID + " and admin " + adminName); SimpleStringProperty id = new SimpleStringProperty(lobbyID); SimpleStringProperty admin = new SimpleStringProperty((adminName)); @@ -384,6 +387,7 @@ public class LoungeSceneViewController implements Initializable { @Override public void run() { lobbies.add(item); + LobbyListView.getItems().add(item); LOGGER.debug("within newLobby() run() thread"); LOGGER.debug(item.toString()); LOGGER.debug("In newLobby() run() " + LobbyListView); From e58f01e4b678daafe5d253c9c235a2a699e4e051 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 15:55:32 +0200 Subject: [PATCH 23/33] .getID() from lobbylistview for debugging --- .../client/gui/lounge/LoungeSceneViewController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 0f09fc2..bd4140c 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -21,6 +21,7 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.collections.ObservableMap; import javafx.event.ActionEvent; +import javafx.event.Event; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -199,7 +200,6 @@ public class LoungeSceneViewController implements Initializable { LobbyListView.setItems(lobbies); LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); - LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView.getId()); LobbyListView.setCellFactory(param -> { ListCell cell = new ListCell<>() { @@ -384,6 +384,7 @@ public class LoungeSceneViewController implements Initializable { @Override public void run() { lobbies.add(item); + LobbyListView.refresh(); LOGGER.debug("within newLobby() run() thread"); LOGGER.debug(item.toString()); LOGGER.debug("In newLobby() run() " + LobbyListView); From a4a12fc9d2d4e6f8feb1cb82156a4c8f48f054ae Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 16:24:53 +0200 Subject: [PATCH 24/33] trying to get the join button to work --- .../multiplayer/client/gui/lounge/LobbyListItem.java | 1 + .../client/gui/lounge/LoungeSceneViewController.java | 4 +++- .../cs108/multiplayer/server/JServerProtocolParser.java | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index 75b2299..5741c4f 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -26,6 +26,7 @@ public class LobbyListItem { private final int MAX_CAPACITY = 6; private SimpleIntegerProperty noOfPlayersInLobby; + public LobbyListItem(SimpleStringProperty lobbyID, SimpleStringProperty adminName, SimpleBooleanProperty ownedByClient, SimpleBooleanProperty isOpen, SimpleIntegerProperty noOfPlayersInLobby) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index d936a4c..cea88c0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -120,6 +120,7 @@ public class LoungeSceneViewController implements Initializable { newGameButton.setOnAction(event -> newGame()); LobbyListView.setVisible(true); lListView = LobbyListView; + cListView = ClientListView; LOGGER.debug("Lobby in initialize" + LobbyListView); ClientListView.setVisible(true); ClientListView.setItems(clients); @@ -216,6 +217,7 @@ public class LoungeSceneViewController implements Initializable { { head.setAlignment(Pos.CENTER_LEFT); + head.setSpacing(5); playerList.setAlignment(Pos.CENTER_LEFT); headParent.setCollapsible(true); } @@ -372,7 +374,6 @@ public class LoungeSceneViewController implements Initializable { SimpleStringProperty id = new SimpleStringProperty(lobbyID); SimpleStringProperty admin = new SimpleStringProperty((adminName)); LOGGER.debug("In newLobby()1 LobbyListView" + LobbyListView); - Button startOrJoin; boolean ownedByClient = false; if (adminName.equals(client.getUsername())) { LOGGER.debug("Client is admin. Name: " + adminName); @@ -423,6 +424,7 @@ public class LoungeSceneViewController implements Initializable { */ public void addClientToList(String s) { ClientListItem cl = new ClientListItem(s); + ClientListView = cListView; Platform.runLater(new Runnable() { @Override public void run() { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index 9749ce3..af4250d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -65,7 +65,8 @@ public class JServerProtocolParser { } catch (Exception e) { h.setUsernameOnLogin("U.N. Owen"); } - h.guiUpdateAll(Protocol.printToGUI+"$"+GuiParameters.newPlayerOnServer+"$"+h.getClientUserName()); + h.guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newPlayerOnServer + "$" + + h.getClientUserName()); break; case Protocol.nameChange: h.changeUsername(msg.substring(6)); @@ -83,6 +84,7 @@ public class JServerProtocolParser { try { int i = Integer.parseInt(msg.substring(6, 7)); h.joinLobby(i); + //h.guiUpdateAll(Protocol.printToGUI+"$"+GuiParameters.addNewMemberToLobby+"$"+i+":"+h.getClientUserName()); handled in joinLobby() } catch (Exception e) { h.sendMsgToClient(Protocol.printToClientConsole + "$Invalid input. Please use JOINL$1 to join Lobby 1, for example."); @@ -90,11 +92,9 @@ public class JServerProtocolParser { break; case Protocol.createNewLobby: h.createNewLobby(); - h.sendMsgToClient( + h.guiUpdateAll( Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby() .getLobbyID() + ":" + h.getClientUserName()); - h.guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby() - .getLobbyID() + ":" + h.getClientUserName()); LOGGER.info("Here"); break; case Protocol.listLobbies: From d6f28a63e86b1a4dd27c3c8547382a97dd505c45 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 1 May 2022 16:53:40 +0200 Subject: [PATCH 25/33] no list of who is in lobby yet but at least functionally one is in a lobby and can play a game --- .../client/gui/lounge/LobbyListItem.java | 7 ++++--- .../gui/lounge/LoungeSceneViewController.java | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java index 5741c4f..19b4cb6 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyListItem.java @@ -18,7 +18,7 @@ public class LobbyListItem { private final SimpleStringProperty lobbyID; private final SimpleStringProperty adminName; - private ObservableList clientsInLobby; + private ObservableList clientsInLobby; private SimpleBooleanProperty ownedByClient; private SimpleBooleanProperty isOpen; @@ -62,11 +62,11 @@ public class LobbyListItem { this.adminName.set(adminName); } - public ObservableList getClientsInLobby() { + public ObservableList getClientsInLobby() { return clientsInLobby; } - public void setClientsInLobby(ObservableList clientsInLobby) { + public void setClientsInLobby(ObservableList clientsInLobby) { this.clientsInLobby = clientsInLobby; } @@ -110,6 +110,7 @@ public class LobbyListItem { this.noOfPlayersInLobby.set(noOfPlayersInLobby); } + @Override public String toString() { return "LobbyListItem{" + "lobbyID=" + lobbyID + ", adminName=" + adminName diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index cea88c0..56d0622 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -90,10 +90,12 @@ public class LoungeSceneViewController implements Initializable { private ObservableMap> lobbyToMemberssMap; private HashMap clientToLobbyMap; + private HashMap lobbyIDtoLobbyMop; public LoungeSceneViewController() { super(); lobbyToMemberssMap = FXCollections.observableHashMap(); + lobbyIDtoLobbyMop = new HashMap<>(); } public void setChatApp(ChatApp chatApp) { @@ -282,7 +284,7 @@ public class LoungeSceneViewController implements Initializable { if (item.isOwnedByClient()) { startGame(); } else { - joinGame(item.lobbyIDProperty().getName()); + joinGame(item.lobbyIDProperty().getValue()); } }); startOrJoin.setText(item.isOwnedByClient() ? "Start" : "Join"); @@ -354,8 +356,15 @@ public class LoungeSceneViewController implements Initializable { Platform.runLater(new Runnable() { @Override public void run() { - ObservableList members = lobbyToMemberssMap.get(lobbyID); - members.add(player); + Iterator itr = clients.iterator(); + while(itr.hasNext()){ + ClientListItem cl = itr.next(); + if(cl.getName().equals(player)){ + LobbyListItem li = lobbyIDtoLobbyMop.get(lobbyID); + li.getClientsInLobby().add(cl); + } + } + } }); } @@ -383,6 +392,7 @@ public class LoungeSceneViewController implements Initializable { } LobbyListItem item = new LobbyListItem(id, admin, new SimpleBooleanProperty(ownedByClient), new SimpleBooleanProperty(true), new SimpleIntegerProperty(0)); + lobbyIDtoLobbyMop.put(lobbyID,item); LOGGER.debug("In newLobby()2 LobbyListView" + LobbyListView); Platform.runLater(new Runnable() { @Override From c9f0654eef569ba9d8a1598a1a7801dc5c32d54d Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 1 May 2022 18:28:12 +0200 Subject: [PATCH 26/33] Implemented highScore functionality into Gui --- .../cs108/highscore/OgGhostHighScore.java | 3 ++- .../dbis/cs108/multiplayer/client/Client.java | 4 +++ .../client/JClientProtocolParser.java | 1 - .../client/gui/game/GameController.java | 2 +- .../gui/lounge/LoungeSceneViewController.java | 27 ++++++++++++++++++- .../multiplayer/helpers/GuiParameters.java | 2 ++ .../multiplayer/server/ClientHandler.java | 7 +++++ .../client/gui/game/GameDayAll.fxml | 6 ++--- .../client/gui/lounge/LoungeSceneView.fxml | 16 ++++++++--- 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/highscore/OgGhostHighScore.java b/src/main/java/ch/unibas/dmi/dbis/cs108/highscore/OgGhostHighScore.java index 9e31856..fd77358 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/highscore/OgGhostHighScore.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/highscore/OgGhostHighScore.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.highscore; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -83,8 +84,8 @@ public class OgGhostHighScore { hm.remove(firstplace); } } - return sb.toString(); + } /** diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index db3bcd2..0ba20c5 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -402,6 +402,10 @@ public class Client { break; case GuiParameters.newPlayerOnServer: addNewPlayerToGui(data); + break; + case GuiParameters.updateHighScore: + chatApp.getLoungeSceneViewController().addHighScore(data); + break; default: notificationTextDisplay(data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController? diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 6ede8e5..050caa0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -29,7 +29,6 @@ public class JClientProtocolParser { header = msg.substring(0, 5); } catch (IndexOutOfBoundsException e) { System.out.println("Received unknown command"); - e.printStackTrace(); } switch (header) { case Protocol.pingFromServer: diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index bf29859..0c26a83 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -199,7 +199,7 @@ public class GameController implements Initializable { */ public void addMessageToNotificationText(String msg) { LOGGER.trace("addMessage " + msg); - Text notification = new Text(msg); + Text notification = new Text("\\R" + msg); notification.setFill(Color.BLACK); notification.setStyle("-fx-font: 50 arial;"); Platform.runLater(new Runnable() { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java index 56d0622..9702821 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneViewController.java @@ -40,6 +40,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,13 +49,16 @@ public class LoungeSceneViewController implements Initializable { public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + @FXML + private TextFlow highScore; @FXML private SplitPane chatSplitPane; @FXML private AnchorPane chatAnchorPane; @FXML private AnchorPane otherNotificationAnchorPane; - + @FXML + public Button highScoreButton; @FXML private Button leaveLobbyButton; @FXML @@ -486,5 +490,26 @@ public class LoungeSceneViewController implements Initializable { public static void setClient(ClientModel client) { LoungeSceneViewController.client = client; } + + public void sendHIghScore() { + client.getClient().sendMsgToServer(Protocol.highScoreList); + } + + public void addHighScore(String data) { + String[] arguments = data.split("/n"); + LOGGER.debug(arguments.length); + Platform.runLater(new Runnable() { + @Override + public void run() { + highScore.getChildren().clear(); + for(String argument : arguments) { + LOGGER.debug("HighScore " + argument); + Text text = new Text(argument + System.lineSeparator()); + text.setFill(Color.BLACK); + highScore.getChildren().add(text); + } + } + }); + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java index 348f77f..19ffd3f 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java @@ -85,4 +85,6 @@ public class GuiParameters { * RMVLST$} */ public static final String removePlayerFromList = "RMVLST"; + + public static final String updateHighScore = "HISCR"; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java index acfa8bd..897792b 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java @@ -652,8 +652,15 @@ public class ClientHandler implements Runnable { public void sendHighScoreList() { String list = OgGhostHighScore.formatGhostHighscoreList(); String[] listarray = list.split("\\R"); + StringBuilder forGui = new StringBuilder(); for (String s : listarray) { sendAnnouncementToClient(s); + forGui.append(s).append("/n"); } + sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.updateHighScore + "$" + forGui.toString()); } + + } + + diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml index 8c6467c..2be235e 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameDayAll.fxml @@ -9,7 +9,7 @@ - + @@ -107,11 +107,11 @@ - - + diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml index 81237cc..1acc649 100644 --- a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml +++ b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LoungeSceneView.fxml @@ -1,11 +1,13 @@ + + @@ -13,6 +15,7 @@ +