From 2a03571cd1d8357fa2721ec2511e085a6b797d71 Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Thu, 23 Apr 2026 11:57:48 +0200 Subject: [PATCH] Feat: Add chat box into the game screen Refs #107 --- .../ui/gameui/CasinoGameController.java | 31 +++++++++++-------- .../casono/client/ui/gameui/CasinoGameUI.java | 10 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameController.java index 5ef57da..fe0f782 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameController.java @@ -69,6 +69,7 @@ public class CasinoGameController { private java.util.List lastCommunityKeys = java.util.List.of(); private java.util.List lastMyCardKeys = java.util.List.of(); private int lastPot = Integer.MIN_VALUE; + private ChatController chatController; private static final int TOTAL_SLOTS = 5; private static final int PLAYER_SLOTS = 2; @@ -141,7 +142,6 @@ public class CasinoGameController { private static final double CHAT_WIDTH = 400; private static final double CHAT_HEIGHT = 600; - private ChatController chatController; private String chatUsername; private ClientService chatClientService; private int chatLobbyId = -1; @@ -199,6 +199,11 @@ public class CasinoGameController { } } + public void startChat(ChatController chatController) { + this.chatController = chatController; + initializeChatIfPossible(); + } + /** Set the PlayerId of the current player. */ @FXML public void initialize() { @@ -241,6 +246,8 @@ public class CasinoGameController { // empty display only (optional) renderCommunityCards(List.of()); renderPlayerCards(List.of()); + + chatContainer.toFront(); } /** @@ -258,7 +265,7 @@ public class CasinoGameController { this.chatUsername = username; this.chatClientService = clientService; this.chatLobbyId = lobbyId; - //initializeChatIfPossible(); + //startChat(chatController); } /** @@ -272,18 +279,19 @@ public class CasinoGameController { try { ChatBoxController chatBoxController = new ChatBoxController(chatUsername, chatController); + + chatController.setChatBoxController(chatBoxController); + URL resource = getClass().getResource("/ui-structure/components/chatui/chatbox.fxml"); FXMLLoader loader = new FXMLLoader(resource); loader.setController(chatBoxController); - chatContainer.getChildren().add(loader.load()); + chatBoxController.loadChats(); + Node chatBox = loader.load(); + + chatContainer.getChildren().add(chatBox); /* - chatStage.setTitle("Casono"); - - String iconPath = getClass().getResource("/images/logoinverted.png").toExternalForm(); - chatStage.getIcons().add(new Image(iconPath)); - Scene scene = new Scene(root); chatStage.setScene(scene); @@ -293,7 +301,8 @@ public class CasinoGameController { chatStage.setOnCloseRequest(event -> chatInitialized = false); chatStage.show(); - */ + */ + if (chatLobbyId >= 0) { chatController.setLobbyChat(chatLobbyId); } @@ -1340,8 +1349,4 @@ public class CasinoGameController { return null; } - public void startChat(ChatController chatController) { - this.chatController = chatController; - initializeChatIfPossible(); - } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameUI.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameUI.java index 15f7d27..76f55db 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameUI.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameUI.java @@ -58,6 +58,8 @@ public class CasinoGameUI extends Application { CasinoGameUI.username = username; } + public static void setChatController(ChatController chatController) {CasinoGameUI.chatController = chatController;} + /** * Sets the lobby ID to be used by the application. * @@ -67,10 +69,6 @@ public class CasinoGameUI extends Application { CasinoGameUI.lobbyId = lobbyId; } - public static void setChatController(ChatController chatController) { - CasinoGameUI.chatController = chatController; - } - /** * The main entry point for the JavaFX application. This method is called after the application * is @@ -119,8 +117,6 @@ public class CasinoGameUI extends Application { Parent root = fxmlLoader.load(); CasinoGameController controller = fxmlLoader.getController(); - controller.startChat(chatController); - if (lobbyId <= 0) { throw new IllegalStateException("CasinoGameUI: lobbyId must be set before start()"); } @@ -132,6 +128,8 @@ public class CasinoGameUI extends Application { controller.setMyPlayerId(PlayerId.of(effectiveUsername)); controller.setChatContext(effectiveUsername, clientService, lobbyId); + controller.startChat(chatController); + Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT); stage.setTitle("Casono");