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
This commit is contained in:
+27
-1
@@ -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 ch.unibas.dmi.dbis.cs108.casono.ui.sound.SoundManager;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import javafx.animation.PauseTransition;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
@@ -26,6 +27,7 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
|
import javafx.util.Duration;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -50,6 +52,11 @@ public class CasinomainuiController {
|
|||||||
private int nextButtonId = 1;
|
private int nextButtonId = 1;
|
||||||
private LobbyClient lobbyClient;
|
private LobbyClient lobbyClient;
|
||||||
private ChatController chatController;
|
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. */
|
/** Default constructor used by FXMLLoader. */
|
||||||
public CasinomainuiController() {
|
public CasinomainuiController() {
|
||||||
@@ -63,7 +70,7 @@ public class CasinomainuiController {
|
|||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
titleLabel.setText("Casono");
|
titleLabel.setText(DEFAULT_TITLE);
|
||||||
subtitleLabel.setText("Texas Hold'em Poker");
|
subtitleLabel.setText("Texas Hold'em Poker");
|
||||||
logoView.setImage(new Image(getClass().getResource("/images/logo.png").toExternalForm()));
|
logoView.setImage(new Image(getClass().getResource("/images/logo.png").toExternalForm()));
|
||||||
|
|
||||||
@@ -221,6 +228,11 @@ public class CasinomainuiController {
|
|||||||
loginButton.setText("Change Name");
|
loginButton.setText("Change Name");
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} 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());
|
LOGGER.error("Change username failed: {}", e.getMessage());
|
||||||
showAlert("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. */
|
/** Shows an alert dialog with the given message. */
|
||||||
private void showAlert(String message) {
|
private void showAlert(String message) {
|
||||||
Alert alert = new Alert(AlertType.INFORMATION);
|
Alert alert = new Alert(AlertType.INFORMATION);
|
||||||
|
|||||||
+1
-2
@@ -134,8 +134,7 @@ public class ChangeUsernameHandler extends CommandHandler<ChangeUsernameRequest>
|
|||||||
dispatchError(
|
dispatchError(
|
||||||
context,
|
context,
|
||||||
"CANNOT_CHANGE_USERNAME_DURING_LOBBY",
|
"CANNOT_CHANGE_USERNAME_DURING_LOBBY",
|
||||||
"Cannot change username while actively playing in a lobby. "
|
"Name change blocked while lobby is active.");
|
||||||
+ "Wait until the game ends.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user