Feat: Add chat box into the game screen #303

Merged
m.ginkel merged 28 commits from feat/chat-integration into main 2026-04-24 14:14:17 +02:00
2 changed files with 22 additions and 19 deletions
Showing only changes of commit 36348d0d93 - Show all commits
@@ -69,6 +69,7 @@ public class CasinoGameController {
private java.util.List<String> lastCommunityKeys = java.util.List.of(); private java.util.List<String> lastCommunityKeys = java.util.List.of();
private java.util.List<String> lastMyCardKeys = java.util.List.of(); private java.util.List<String> lastMyCardKeys = java.util.List.of();
private int lastPot = Integer.MIN_VALUE; private int lastPot = Integer.MIN_VALUE;
private ChatController chatController;
private static final int TOTAL_SLOTS = 5; private static final int TOTAL_SLOTS = 5;
private static final int PLAYER_SLOTS = 2; 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_WIDTH = 400;
private static final double CHAT_HEIGHT = 600; private static final double CHAT_HEIGHT = 600;
private ChatController chatController;
private String chatUsername; private String chatUsername;
private ClientService chatClientService; private ClientService chatClientService;
private int chatLobbyId = -1; 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. */ /** Set the PlayerId of the current player. */
@FXML @FXML
public void initialize() { public void initialize() {
@@ -241,6 +246,8 @@ public class CasinoGameController {
// empty display only (optional) // empty display only (optional)
renderCommunityCards(List.of()); renderCommunityCards(List.of());
renderPlayerCards(List.of()); renderPlayerCards(List.of());
chatContainer.toFront();
} }
/** /**
@@ -258,7 +265,7 @@ public class CasinoGameController {
this.chatUsername = username; this.chatUsername = username;
this.chatClientService = clientService; this.chatClientService = clientService;
this.chatLobbyId = lobbyId; this.chatLobbyId = lobbyId;
//initializeChatIfPossible(); //startChat(chatController);
} }
/** /**
@@ -272,18 +279,19 @@ public class CasinoGameController {
try { try {
ChatBoxController chatBoxController = new ChatBoxController(chatUsername, chatController); ChatBoxController chatBoxController = new ChatBoxController(chatUsername, chatController);
chatController.setChatBoxController(chatBoxController);
URL resource = getClass().getResource("/ui-structure/components/chatui/chatbox.fxml"); URL resource = getClass().getResource("/ui-structure/components/chatui/chatbox.fxml");
FXMLLoader loader = new FXMLLoader(resource); FXMLLoader loader = new FXMLLoader(resource);
loader.setController(chatBoxController); 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); Scene scene = new Scene(root);
chatStage.setScene(scene); chatStage.setScene(scene);
@@ -293,7 +301,8 @@ public class CasinoGameController {
chatStage.setOnCloseRequest(event -> chatInitialized = false); chatStage.setOnCloseRequest(event -> chatInitialized = false);
chatStage.show(); chatStage.show();
*/ */
if (chatLobbyId >= 0) { if (chatLobbyId >= 0) {
chatController.setLobbyChat(chatLobbyId); chatController.setLobbyChat(chatLobbyId);
} }
@@ -1340,8 +1349,4 @@ public class CasinoGameController {
return null; return null;
} }
public void startChat(ChatController chatController) {
this.chatController = chatController;
initializeChatIfPossible();
}
} }
@@ -58,6 +58,8 @@ public class CasinoGameUI extends Application {
CasinoGameUI.username = username; CasinoGameUI.username = username;
} }
public static void setChatController(ChatController chatController) {CasinoGameUI.chatController = chatController;}
/** /**
* Sets the lobby ID to be used by the application. * Sets the lobby ID to be used by the application.
* *
@@ -67,10 +69,6 @@ public class CasinoGameUI extends Application {
CasinoGameUI.lobbyId = lobbyId; 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 * The main entry point for the JavaFX application. This method is called after the application
* is * is
@@ -119,8 +117,6 @@ public class CasinoGameUI extends Application {
Parent root = fxmlLoader.load(); Parent root = fxmlLoader.load();
CasinoGameController controller = fxmlLoader.getController(); CasinoGameController controller = fxmlLoader.getController();
controller.startChat(chatController);
if (lobbyId <= 0) { if (lobbyId <= 0) {
throw new IllegalStateException("CasinoGameUI: lobbyId must be set before start()"); 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.setMyPlayerId(PlayerId.of(effectiveUsername));
controller.setChatContext(effectiveUsername, clientService, lobbyId); controller.setChatContext(effectiveUsername, clientService, lobbyId);
controller.startChat(chatController);
Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT); Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT);
stage.setTitle("Casono"); stage.setTitle("Casono");