diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/IntroVideoPlayer.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/IntroVideoPlayer.java new file mode 100644 index 0000000..1b84557 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/IntroVideoPlayer.java @@ -0,0 +1,91 @@ +package ch.unibas.dmi.dbis.cs108.casono.client.ui; + +import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui; +import java.net.URL; +import javafx.application.Application; +import javafx.application.Platform; +import javafx.geometry.Rectangle2D; +import javafx.scene.Scene; +import javafx.scene.layout.StackPane; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import javafx.scene.media.MediaView; +import javafx.stage.Screen; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** Plays an intro video in fullscreen and then starts the main UI. */ +public class IntroVideoPlayer extends Application { + + private static final Logger LOGGER = LogManager.getLogger(IntroVideoPlayer.class); + + private Stage videoStage; + + @Override + public void start(Stage stage) { + this.videoStage = stage; + + URL videoUrl = getClass().getResource("/images/placeholder-animation.mp4"); + + if (videoUrl == null) { + LOGGER.error("Video file not found!"); + Platform.exit(); + return; + } + + Media media = new Media(videoUrl.toExternalForm()); + MediaPlayer mediaPlayer = new MediaPlayer(media); + MediaView mediaView = new MediaView(mediaPlayer); + + StackPane root = new StackPane(mediaView); + + Rectangle2D screenBounds = Screen.getPrimary().getBounds(); + + Scene scene = new Scene(root, screenBounds.getWidth(), screenBounds.getHeight()); + + // scale video automatically + mediaView.setPreserveRatio(true); + mediaView.setFitWidth(screenBounds.getWidth()); + mediaView.setFitHeight(screenBounds.getHeight()); + + stage.initStyle(StageStyle.UNDECORATED); + stage.setFullScreen(true); + stage.setScene(scene); + stage.show(); + + mediaPlayer.setOnEndOfMedia(this::onVideoEnd); + mediaPlayer.play(); + } + + private void onVideoEnd() { + videoStage.close(); + setSystemProperties(); + startMainUI(); + } + + private void setSystemProperties() { + var params = getParameters().getRaw(); + if (params == null || params.isEmpty()) { + return; + } + + String arg = params.get(0); + String[] parts = arg.split(":", 2); + if (parts.length == 2) { + System.setProperty("casono.server.host", parts[0]); + System.setProperty("casono.server.port", parts[1]); + } + } + + private void startMainUI() { + Stage mainStage = new Stage(); + try { + new Casinomainui().start(mainStage); + } catch (Exception e) { + e.printStackTrace(); + Platform.exit(); + } + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java index 85d42df..d1b6300 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java @@ -1,13 +1,8 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui; -import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui; import javafx.application.Application; -/** - * Launcher for the Casono main UI. - * - *
Default constructor for the application. - */ +/** Launcher for the Casono intro animation. */ public class Launcher { /** Default constructor. */ @@ -21,6 +16,6 @@ public class Launcher { * @param args Command line arguments */ public static void main(String[] args) { - Application.launch(Casinomainui.class, args); + Application.launch(IntroVideoPlayer.class, args); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java index 742bf3b..0be342d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java @@ -36,15 +36,9 @@ public class Casinomainui extends Application { // If the launcher passed an address argument (ip:port), expose it as // system properties so controllers can read it without embedding defaults. - var raw = getParameters().getRaw(); - if (raw != null && raw.size() > 0) { - String arg = raw.get(0); - String[] parts = arg.split(":", 2); - if (parts.length == 2) { - System.setProperty("casono.server.host", parts[0]); - System.setProperty("casono.server.port", parts[1]); - } - } + var params = getParameters(); + processServerParameters(params); + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ui-structure/Casinomainui.fxml")); Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT); @@ -58,6 +52,24 @@ public class Casinomainui extends Application { stage.show(); } + private void processServerParameters(Application.Parameters params) { + if (params == null) { + return; + } + + var raw = params.getRaw(); + if (raw == null || raw.isEmpty()) { + return; + } + + String arg = raw.get(0); + String[] parts = arg.split(":", 2); + if (parts.length == 2) { + System.setProperty("casono.server.host", parts[0]); + System.setProperty("casono.server.port", parts[1]); + } + } + /** * Main entry point for launching the application. *