From 4760b55673e0d3d1f29070101616be1b86f4b5a1 Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Sat, 16 May 2026 22:31:03 +0200 Subject: [PATCH] Feat: Instead of a popup saying you are not allowed to change username while the lobyb is still active, this commit changes the "Casono" Title to more or less the same message for 2 seconds and then switches back. This improves the quality of the UI drastically --- .../ui/lobbyui/CasinomainuiController.java | 28 ++++++++++++++++++- .../ChangeUsernameHandler.java | 3 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java index c51722a..87555fc 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java @@ -8,6 +8,7 @@ import ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents.Highsco import ch.unibas.dmi.dbis.cs108.casono.ui.sound.SoundManager; import java.io.IOException; import java.net.URL; +import javafx.animation.PauseTransition; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -26,6 +27,7 @@ import javafx.scene.layout.VBox; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.stage.StageStyle; +import javafx.util.Duration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -50,6 +52,11 @@ public class CasinomainuiController { private int nextButtonId = 1; private LobbyClient lobbyClient; private ChatController chatController; + private PauseTransition titleResetTransition; + + private static final String DEFAULT_TITLE = "Casono"; + private static final String BLOCKED_USERNAME_TITLE = + "Name change blocked while lobby is active"; /** Default constructor used by FXMLLoader. */ public CasinomainuiController() { @@ -63,7 +70,7 @@ public class CasinomainuiController { */ @FXML public void initialize() { - titleLabel.setText("Casono"); + titleLabel.setText(DEFAULT_TITLE); subtitleLabel.setText("Texas Hold'em Poker"); logoView.setImage(new Image(getClass().getResource("/images/logo.png").toExternalForm())); @@ -221,6 +228,11 @@ public class CasinomainuiController { loginButton.setText("Change Name"); } } catch (RuntimeException e) { + if (containsProtocolError(e, "CANNOT_CHANGE_USERNAME_DURING_LOBBY") + || containsProtocolError(e, "RENAME_CONFLICT")) { + showTemporaryTitleMessage(BLOCKED_USERNAME_TITLE); + return; + } LOGGER.error("Change username failed: {}", e.getMessage()); showAlert("Change username failed: " + e.getMessage()); } @@ -246,6 +258,20 @@ public class CasinomainuiController { } } + private void showTemporaryTitleMessage(String message) { + if (titleLabel == null) { + return; + } + + titleLabel.setText(message); + if (titleResetTransition != null) { + titleResetTransition.stop(); + } + titleResetTransition = new PauseTransition(Duration.seconds(2)); + titleResetTransition.setOnFinished(event -> titleLabel.setText(DEFAULT_TITLE)); + titleResetTransition.playFromStart(); + } + /** Shows an alert dialog with the given message. */ private void showAlert(String message) { Alert alert = new Alert(AlertType.INFORMATION); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/change_username/ChangeUsernameHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/change_username/ChangeUsernameHandler.java index 86057b0..a37f5d3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/change_username/ChangeUsernameHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/change_username/ChangeUsernameHandler.java @@ -134,8 +134,7 @@ public class ChangeUsernameHandler extends CommandHandler dispatchError( context, "CANNOT_CHANGE_USERNAME_DURING_LOBBY", - "Cannot change username while actively playing in a lobby. " - + "Wait until the game ends."); + "Name change blocked while lobby is active."); return true; } return false;