Feat: Add F11 fullscreen toggle
This commit is contained in:
@@ -6,6 +6,7 @@ import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
@@ -54,6 +55,16 @@ public class IntroVideoPlayer extends Application {
|
||||
stage.setFullScreen(true);
|
||||
stage.setFullScreenExitHint("");
|
||||
stage.setScene(scene);
|
||||
|
||||
// Add F11 fullscreen toggle
|
||||
scene.setOnKeyPressed(
|
||||
event -> {
|
||||
if (event.getCode() == KeyCode.F11) {
|
||||
stage.setFullScreen(!stage.isFullScreen());
|
||||
event.consume();
|
||||
}
|
||||
});
|
||||
|
||||
stage.show();
|
||||
|
||||
mediaPlayer.setOnEndOfMedia(this::onVideoEnd);
|
||||
|
||||
@@ -14,6 +14,7 @@ import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
@@ -83,7 +84,22 @@ public class CasinoGameUI extends Application {
|
||||
*/
|
||||
@Override
|
||||
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) {
|
||||
clientService = ClientApp.getSharedClientService();
|
||||
}
|
||||
@@ -93,18 +109,21 @@ public class CasinoGameUI extends Application {
|
||||
+ "Call CasinoGameUI.setClientService(...)"
|
||||
+ " or start via ClientApp with a shared connection.");
|
||||
}
|
||||
}
|
||||
|
||||
private String determineEffectiveUsername() {
|
||||
String effectiveUsername = normalize(username);
|
||||
|
||||
if (effectiveUsername == null) {
|
||||
effectiveUsername = normalize(ClientApp.getSharedUsername());
|
||||
}
|
||||
|
||||
if (effectiveUsername == null) {
|
||||
effectiveUsername =
|
||||
"Guest-" + UUID.randomUUID().toString().substring(0, GUEST_ID_LENGTH);
|
||||
}
|
||||
return effectiveUsername;
|
||||
}
|
||||
|
||||
private void logStartInfo(String effectiveUsername) {
|
||||
LOG.info(
|
||||
"CasinoGameUI starting: effectiveUsername='"
|
||||
+ effectiveUsername
|
||||
@@ -114,12 +133,10 @@ public class CasinoGameUI extends Application {
|
||||
+ ClientApp.getSharedUsername()
|
||||
+ "', hasClientService="
|
||||
+ (clientService != null));
|
||||
}
|
||||
|
||||
FXMLLoader fxmlLoader =
|
||||
new FXMLLoader(CasinoGameUI.class.getResource("/ui-structure/Casinogameui.fxml"));
|
||||
Parent root = fxmlLoader.load();
|
||||
CasinoGameController controller = fxmlLoader.getController();
|
||||
|
||||
private void configureController(CasinoGameController controller, String effectiveUsername)
|
||||
throws IOException {
|
||||
if (lobbyId <= 0) {
|
||||
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);
|
||||
GameService gameService = new GameService(gameClient);
|
||||
controller.setGameService(gameService);
|
||||
|
||||
controller.setMyPlayerId(PlayerId.of(effectiveUsername));
|
||||
controller.setChatContext(effectiveUsername, clientService, lobbyId);
|
||||
|
||||
@@ -139,20 +155,24 @@ public class CasinoGameUI extends Application {
|
||||
}
|
||||
|
||||
controller.startChat(chatController);
|
||||
}
|
||||
|
||||
Scene scene = new Scene(root, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
private void configureStage(Stage stage, Scene scene, CasinoGameController controller) {
|
||||
stage.setTitle("Casono");
|
||||
|
||||
String iconPath = getClass().getResource("/images/logoinverted.png").toExternalForm();
|
||||
stage.getIcons().add(new javafx.scene.image.Image(iconPath));
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setFullScreen(true);
|
||||
stage.setFullScreenExitHint("");
|
||||
stage.setOnHidden(e -> controller.stop());
|
||||
scene.setOnKeyPressed(
|
||||
event -> {
|
||||
if (event.getCode() == KeyCode.F11) {
|
||||
stage.setFullScreen(!stage.isFullScreen());
|
||||
event.consume();
|
||||
}
|
||||
});
|
||||
stage.show();
|
||||
|
||||
controller.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
@@ -1663,6 +1663,17 @@ public class TaskbarController {
|
||||
newStage.getIcons().add(icon);
|
||||
newStage.setScene(scene);
|
||||
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();
|
||||
} catch (Exception 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.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,16 @@ public class Casinomainui extends Application {
|
||||
stage.setScene(scene);
|
||||
stage.setFullScreen(true);
|
||||
stage.setFullScreenExitHint("");
|
||||
|
||||
// Add F11 fullscreen toggle
|
||||
scene.setOnKeyPressed(
|
||||
event -> {
|
||||
if (event.getCode() == KeyCode.F11) {
|
||||
stage.setFullScreen(!stage.isFullScreen());
|
||||
event.consume();
|
||||
}
|
||||
});
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user