Feat: Add chat box into the game screen

Refs #107
This commit is contained in:
Mathis Ginkel
2026-04-23 11:57:48 +02:00
parent 7eafaba65a
commit 2a03571cd1
2 changed files with 22 additions and 19 deletions
@@ -69,6 +69,7 @@ public class CasinoGameController {
private java.util.List<String> lastCommunityKeys = java.util.List.of();
private java.util.List<String> 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();
}
}
@@ -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");