From e9ba4a3e0a039715fdf1c169edd7f56faa8570b1 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 3 Dec 2026 13:19:38 +0400 Subject: feat(ui): play the installed startup movies before the menu --- apps/fparkan-game/src/startup_intro.rs | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 apps/fparkan-game/src/startup_intro.rs (limited to 'apps/fparkan-game/src/startup_intro.rs') diff --git a/apps/fparkan-game/src/startup_intro.rs b/apps/fparkan-game/src/startup_intro.rs new file mode 100644 index 00000000..d5fa80ef --- /dev/null +++ b/apps/fparkan-game/src/startup_intro.rs @@ -0,0 +1,67 @@ +//! Startup movie sequence shown before the mission menu. + +use fparkan_assets::startup_movies::movie_paths; +use fparkan_platform_winit::{intro_video::IntroVideo, startup_window}; +use fparkan_vfs::DirectoryVfs; +use std::{ + collections::VecDeque, + path::{Path, PathBuf}, +}; +use winit::window::Window; + +pub(super) struct StartupIntro { + waiting: VecDeque, + playing: Option, +} + +impl StartupIntro { + pub(super) fn open(root: &Path) -> Option { + let paths = match movie_paths(&DirectoryVfs::new(root)) { + Ok(paths) => paths, + Err(error) => { + eprintln!("startup movies: {error}"); + return None; + } + }; + if paths.is_empty() { + return None; + } + Some(Self { + waiting: paths.iter().map(|path| root.join(path.as_str())).collect(), + playing: None, + }) + } + + /// Returns whether a movie is still playing. + pub(super) fn update(&mut self, window: &Window) -> bool { + if let Some(movie) = &self.playing { + match movie.finished() { + Ok(false) => return true, + Ok(true) => {} + Err(error) => eprintln!("startup playback: {error}"), + } + } + self.playing = None; + while let Some(path) = self.waiting.pop_front() { + if let Err(error) = startup_window::paint(window, [1, 1], &[0]) { + eprintln!("startup movie background: {error}"); + } + match IntroVideo::play(window, &path) { + Ok(movie) => { + self.playing = Some(movie); + return true; + } + Err(error) => eprintln!("startup movie {}: {error}", path.display()), + } + } + false + } + + pub(super) fn resize(&self, window: &Window) { + if let Some(movie) = &self.playing { + if let Err(error) = movie.resize(window) { + eprintln!("startup movie resize: {error}"); + } + } + } +} -- cgit v1.2.3