fix: add client leave-lobby rejoin flow

This commit is contained in:
Jona Walpert
2026-05-13 23:25:57 +02:00
parent 0097da6bdc
commit b58eb656b3
3 changed files with 110 additions and 79 deletions
@@ -127,6 +127,15 @@ public class LobbyClient {
client.processCommand("JOIN_LOBBY ID=" + lobbyId);
}
/**
* Request the server to mark the current user as absent from the given lobby.
*
* @param lobbyId the lobby to leave
*/
public void leaveLobby(int lobbyId) {
client.processCommand("LEAVE_LOBBY ID=" + lobbyId);
}
/**
* Logs in to the server with the given username by sending a "LOGIN" command.
*
@@ -393,91 +393,92 @@ public class CasinoGameController {
// Test method to demonstrate the UI functionality with sample data.
// @FXML
// public void uiTest() {
// if (communityCardsBox == null) {
// LOGGER.info("communityCardsBox is NULL");
// return;
// }
// if (communityCardsBox == null) {
// LOGGER.info("communityCardsBox is NULL");
// return;
// }
//
// try {
// renderCommunityCards(
// List.of(
// new Card("ace", "hearts"),
// new Card("king", "spades"),
// new Card("10", "diamonds")));
// try {
// renderCommunityCards(
// List.of(
// new Card("ace", "hearts"),
// new Card("king", "spades"),
// new Card("10", "diamonds")));
//
// renderPlayerCards(List.of(new Card("10", "spades"), new Card("king", "spades")));
// } catch (Exception e) {
// e.printStackTrace();
// }
// renderPlayerCards(List.of(new Card("10", "spades"), new Card("king",
// "spades")));
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// Player mathis = new Player(PlayerId.of("Mathis"), 20000);
// mathis.setState(PlayerState.ACTIVE);
// Player mathis = new Player(PlayerId.of("Mathis"), 20000);
// mathis.setState(PlayerState.ACTIVE);
//
// Player jona = new Player(PlayerId.of("Jona"), 20000);
// jona.setState(PlayerState.FOLDED);
// Player jona = new Player(PlayerId.of("Jona"), 20000);
// jona.setState(PlayerState.FOLDED);
//
// Player lars = new Player(PlayerId.of("Lars"), 20000);
// lars.setState(PlayerState.ACTIVE);
// Player lars = new Player(PlayerId.of("Lars"), 20000);
// lars.setState(PlayerState.ACTIVE);
//
// player1Controller.setPlayer(mathis);
// player2Controller.setPlayer(jona);
// player3Controller.setPlayer(lars);
// player1Controller.setPlayer(mathis);
// player2Controller.setPlayer(jona);
// player3Controller.setPlayer(lars);
//
// LOGGER.info(
// "Player 1: "
// + mathis.getName()
// + " | $"
// + mathis.getChips()
// + " | "
// + mathis.getState());
// LOGGER.info(
// "Player 2: "
// + jona.getName()
// + " | $"
// + jona.getChips()
// + " | "
// + jona.getState());
// LOGGER.info(
// "Player 3: "
// + lars.getName()
// + " | $"
// + lars.getChips()
// + " | "
// + lars.getState());
// LOGGER.info(
// "Player 1: "
// + mathis.getName()
// + " | $"
// + mathis.getChips()
// + " | "
// + mathis.getState());
// LOGGER.info(
// "Player 2: "
// + jona.getName()
// + " | $"
// + jona.getChips()
// + " | "
// + jona.getState());
// LOGGER.info(
// "Player 3: "
// + lars.getName()
// + " | $"
// + lars.getChips()
// + " | "
// + lars.getState());
//
// if (playerStatusController != null) {
// playerStatusController.setPlayer(mathis);
// } else {
// LOGGER.warning("PlayerStatusController is NULL");
// }
// if (playerStatusController != null) {
// playerStatusController.setPlayer(mathis);
// } else {
// LOGGER.warning("PlayerStatusController is NULL");
// }
//
// javafx.stage.Screen screen = javafx.stage.Screen.getPrimary();
// double screenHeight = screen.getBounds().getHeight();
// javafx.stage.Screen screen = javafx.stage.Screen.getPrimary();
// double screenHeight = screen.getBounds().getHeight();
//
// casinoTableInnerBox.setTranslateY(-screenHeight * 0.08);
// playerCardsBox.setTranslateY(screenHeight * 0.35);
// casinoTableInnerBox.setTranslateY(-screenHeight * 0.08);
// playerCardsBox.setTranslateY(screenHeight * 0.35);
//
// renderPot(500);
// renderPot(500);
//
// lars.removeChips(500);
// LOGGER.info("Lars: $" + lars.getChips());
// lars.removeChips(500);
// LOGGER.info("Lars: $" + lars.getChips());
//
// player3Controller.refresh();
// player3Controller.refresh();
//
// mathis.fall();
// player1Controller.refresh();
// mathis.fall();
// player1Controller.refresh();
//
// GameState s = new GameState();
// s.dealer = 3;
// highlightDealer(s);
// GameState s = new GameState();
// s.dealer = 3;
// highlightDealer(s);
//
// s.phase = "FLOP";
// s.phase = "FLOP";
//
// updateGameInfo(s);
// updateGameInfo(s);
//
// s.winnerIndex = 1;
// s.winnerIndex = 1;
//
// updateGameInfo(s);
// updateGameInfo(s);
// }
/** Start the UI update loop. */
@@ -1747,22 +1748,22 @@ public class CasinoGameController {
*/
// private void animateCardHover(ImageView view, boolean hover) {
//
// double scale = hover ? HOVER_SCALE_ON : HOVER_SCALE_OFF;
// double lift = hover ? HOVER_LIFT_ON : HOVER_LIFT_OFF;
// double scale = hover ? HOVER_SCALE_ON : HOVER_SCALE_OFF;
// double lift = hover ? HOVER_LIFT_ON : HOVER_LIFT_OFF;
//
// javafx.animation.ScaleTransition st =
// new javafx.animation.ScaleTransition(
// javafx.util.Duration.millis(HOVER_DURATION_MS), view);
// st.setToX(scale);
// st.setToY(scale);
// javafx.animation.ScaleTransition st =
// new javafx.animation.ScaleTransition(
// javafx.util.Duration.millis(HOVER_DURATION_MS), view);
// st.setToX(scale);
// st.setToY(scale);
//
// javafx.animation.TranslateTransition tt =
// new javafx.animation.TranslateTransition(
// javafx.util.Duration.millis(HOVER_DURATION_MS), view);
// tt.setToY(lift);
// javafx.animation.TranslateTransition tt =
// new javafx.animation.TranslateTransition(
// javafx.util.Duration.millis(HOVER_DURATION_MS), view);
// tt.setToY(lift);
//
// st.play();
// tt.play();
// st.play();
// tt.play();
// }
/**
@@ -2156,6 +2157,9 @@ public class CasinoGameController {
if (controller == null) {
return;
}
if (chatClientService != null && chatLobbyId >= 0) {
controller.setLobbyContext(new LobbyClient(chatClientService), chatLobbyId);
}
controller.setLobbyActionAnnouncer(this::sendLobbyActionMessage);
}
@@ -52,6 +52,8 @@ public class TaskbarController {
@FXML private Label moneyLabel;
private GameService gameService;
private LobbyClient lobbyClient;
private int lobbyId = -1;
private PlayerId myPlayerId;
private String myPlayerName;
private GameState lastState;
@@ -242,6 +244,12 @@ public class TaskbarController {
this.myPlayerName = myPlayerId != null ? normalizeIdentifier(myPlayerId.value()) : null;
}
/** Sets the lobby context so Exit can notify the server before closing. */
public void setLobbyContext(LobbyClient lobbyClient, int lobbyId) {
this.lobbyClient = lobbyClient;
this.lobbyId = lobbyId;
}
/** Sets the NotebookController reference for showing/hiding tips. */
public void setNotebookController(NotebookController notebookController) {
this.notebookController = notebookController;
@@ -1622,6 +1630,16 @@ public class TaskbarController {
SoundManager.getInstance().playButtonClick();
javafx.application.Platform.runLater(
() -> {
if (lobbyClient != null && lobbyId > 0) {
try {
lobbyClient.leaveLobby(lobbyId);
} catch (RuntimeException e) {
LOGGER.warn(
"Could not notify server about lobby leave: {}",
e.getMessage());
}
}
// Close game stage
javafx.stage.Stage currentStage =
(javafx.stage.Stage) taskbar.getScene().getWindow();