Feat: Add F11 fullscreen toggle #335

Merged
jona.walpert merged 1 commits from feat/f11-fullscreen-toggle into main 2026-05-14 13:48:02 +02:00
4 changed files with 66 additions and 13 deletions
@@ -6,6 +6,7 @@ import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Rectangle2D; import javafx.geometry.Rectangle2D;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.media.Media; import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaPlayer;
@@ -54,6 +55,16 @@ public class IntroVideoPlayer extends Application {
stage.setFullScreen(true); stage.setFullScreen(true);
stage.setFullScreenExitHint(""); stage.setFullScreenExitHint("");
stage.setScene(scene); stage.setScene(scene);
// Add F11 fullscreen toggle
scene.setOnKeyPressed(
event -> {
if (event.getCode() == KeyCode.F11) {
stage.setFullScreen(!stage.isFullScreen());
event.consume();
}
});
stage.show(); stage.show();
mediaPlayer.setOnEndOfMedia(this::onVideoEnd); mediaPlayer.setOnEndOfMedia(this::onVideoEnd);
@@ -14,6 +14,7 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage; import javafx.stage.Stage;
/** /**
@@ -83,7 +84,22 @@ public class CasinoGameUI extends Application {
*/ */
@Override @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
ensureClientService();
String effectiveUsername = determineEffectiveUsername();
logStartInfo(effectiveUsername);
FXMLLoader fxmlLoader =
new FXMLLoader(CasinoGameUI.class.getResource("/ui-structure/Casinogameui.fxml"));
Parent root = fxmlLoader.load();
CasinoGameController controller = fxmlLoader.getController();
configureController(controller, effectiveUsername);
Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT);
configureStage(stage, scene, controller);
controller.start();
}
private void ensureClientService() {
if (clientService == null) { if (clientService == null) {
clientService = ClientApp.getSharedClientService(); clientService = ClientApp.getSharedClientService();
} }
@@ -93,18 +109,21 @@ public class CasinoGameUI extends Application {
+ "Call CasinoGameUI.setClientService(...)" + "Call CasinoGameUI.setClientService(...)"
+ " or start via ClientApp with a shared connection."); + " or start via ClientApp with a shared connection.");
} }
}
private String determineEffectiveUsername() {
String effectiveUsername = normalize(username); String effectiveUsername = normalize(username);
if (effectiveUsername == null) { if (effectiveUsername == null) {
effectiveUsername = normalize(ClientApp.getSharedUsername()); effectiveUsername = normalize(ClientApp.getSharedUsername());
} }
if (effectiveUsername == null) { if (effectiveUsername == null) {
effectiveUsername = effectiveUsername =
"Guest-" + UUID.randomUUID().toString().substring(0, GUEST_ID_LENGTH); "Guest-" + UUID.randomUUID().toString().substring(0, GUEST_ID_LENGTH);
} }
return effectiveUsername;
}
private void logStartInfo(String effectiveUsername) {
LOG.info( LOG.info(
"CasinoGameUI starting: effectiveUsername='" "CasinoGameUI starting: effectiveUsername='"
+ effectiveUsername + effectiveUsername
@@ -114,12 +133,10 @@ public class CasinoGameUI extends Application {
+ ClientApp.getSharedUsername() + ClientApp.getSharedUsername()
+ "', hasClientService=" + "', hasClientService="
+ (clientService != null)); + (clientService != null));
}
FXMLLoader fxmlLoader = private void configureController(CasinoGameController controller, String effectiveUsername)
new FXMLLoader(CasinoGameUI.class.getResource("/ui-structure/Casinogameui.fxml")); throws IOException {
Parent root = fxmlLoader.load();
CasinoGameController controller = fxmlLoader.getController();
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()");
} }
@@ -127,7 +144,6 @@ public class CasinoGameUI extends Application {
GameClient gameClient = new GameClient(clientService, lobbyId); GameClient gameClient = new GameClient(clientService, lobbyId);
GameService gameService = new GameService(gameClient); GameService gameService = new GameService(gameClient);
controller.setGameService(gameService); controller.setGameService(gameService);
controller.setMyPlayerId(PlayerId.of(effectiveUsername)); controller.setMyPlayerId(PlayerId.of(effectiveUsername));
controller.setChatContext(effectiveUsername, clientService, lobbyId); controller.setChatContext(effectiveUsername, clientService, lobbyId);
@@ -139,20 +155,24 @@ public class CasinoGameUI extends Application {
} }
controller.startChat(chatController); controller.startChat(chatController);
}
Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT); private void configureStage(Stage stage, Scene scene, CasinoGameController controller) {
stage.setTitle("Casono"); stage.setTitle("Casono");
String iconPath = getClass().getResource("/images/logoinverted.png").toExternalForm(); String iconPath = getClass().getResource("/images/logoinverted.png").toExternalForm();
stage.getIcons().add(new javafx.scene.image.Image(iconPath)); stage.getIcons().add(new javafx.scene.image.Image(iconPath));
stage.setScene(scene); stage.setScene(scene);
stage.setFullScreen(true); stage.setFullScreen(true);
stage.setFullScreenExitHint(""); stage.setFullScreenExitHint("");
stage.setOnHidden(e -> controller.stop()); stage.setOnHidden(e -> controller.stop());
scene.setOnKeyPressed(
event -> {
if (event.getCode() == KeyCode.F11) {
stage.setFullScreen(!stage.isFullScreen());
event.consume();
}
});
stage.show(); stage.show();
controller.start();
} }
/** /**
@@ -1663,6 +1663,17 @@ public class TaskbarController {
newStage.getIcons().add(icon); newStage.getIcons().add(icon);
newStage.setScene(scene); newStage.setScene(scene);
newStage.setFullScreen(true); newStage.setFullScreen(true);
newStage.setFullScreenExitHint("");
// Add F11 fullscreen toggle
scene.setOnKeyPressed(
event -> {
if (event.getCode() == KeyCode.F11) {
newStage.setFullScreen(!newStage.isFullScreen());
event.consume();
}
});
newStage.show(); newStage.show();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error: starting the lobby UI: {}", e.getMessage(), e); LOGGER.error("Error: starting the lobby UI: {}", e.getMessage(), e);
@@ -6,6 +6,7 @@ import java.io.IOException;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage; import javafx.stage.Stage;
/** /**
@@ -50,6 +51,16 @@ public class Casinomainui extends Application {
stage.setScene(scene); stage.setScene(scene);
stage.setFullScreen(true); stage.setFullScreen(true);
stage.setFullScreenExitHint(""); stage.setFullScreenExitHint("");
// Add F11 fullscreen toggle
scene.setOnKeyPressed(
event -> {
if (event.getCode() == KeyCode.F11) {
stage.setFullScreen(!stage.isFullScreen());
event.consume();
}
});
stage.show(); stage.show();
} }