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/mission_loading.rs | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'apps/fparkan-game/src/mission_loading.rs') diff --git a/apps/fparkan-game/src/mission_loading.rs b/apps/fparkan-game/src/mission_loading.rs index 7410aec4..823c6b35 100644 --- a/apps/fparkan-game/src/mission_loading.rs +++ b/apps/fparkan-game/src/mission_loading.rs @@ -22,9 +22,12 @@ use winit::{ #[cfg(windows)] use { + super::startup_intro::StartupIntro, fparkan_assets::mission_loader::MissionLoader, fparkan_platform_winit::{startup_window, text::StringResources}, fparkan_vfs::DirectoryVfs, + std::time::{Duration, Instant}, + winit::event::{ElementState, MouseButton}, }; #[derive(Clone, Copy)] @@ -58,6 +61,8 @@ pub(super) fn run( let event_loop = new_game_event_loop().map_err(|error| format!("winit event loop: {error}"))?; event_loop.set_control_flow(ControlFlow::Wait); let mut startup = WindowedMission { + #[cfg(windows)] + intro: menu.as_ref().and_then(|_| StartupIntro::open(&args.root)), args, extent, resizable: capture.is_none(), @@ -107,6 +112,9 @@ struct WindowedMission { extent: [u32; 2], resizable: bool, menu: Option, + // The DirectShow child and its graph must release before the window. + #[cfg(windows)] + intro: Option, loading: MissionLoading, load_request: Option>, receive: Option>, @@ -229,6 +237,28 @@ impl ApplicationHandler for WindowedMission { event_loop.exit(); return; } + #[cfg(windows)] + if let Some(intro) = &self.intro { + match event { + WindowEvent::KeyboardInput { event, .. } + if event.state == ElementState::Pressed && !event.repeat => + { + self.intro = None; + window.request_redraw(); + } + WindowEvent::MouseInput { + state: ElementState::Pressed, + button: MouseButton::Left, + .. + } => { + self.intro = None; + window.request_redraw(); + } + WindowEvent::Resized(_) => intro.resize(window), + _ => {} + } + return; + } if let Some(menu) = &mut self.menu { if matches!(event, WindowEvent::RedrawRequested) { if let Err(error) = menu.paint(window) { @@ -279,8 +309,26 @@ impl ApplicationHandler for WindowedMission { } fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { + if event_loop.exiting() { + return; + } if let Some(game) = &mut self.game { game.about_to_wait(event_loop); + return; + } + #[cfg(windows)] + if let Some((intro, window)) = self.intro.as_mut().zip(self.window.as_ref()) { + if intro.update(window) { + event_loop.set_control_flow(ControlFlow::WaitUntil( + Instant::now() + Duration::from_millis(50), + )); + } else { + self.intro = None; + event_loop.set_control_flow(ControlFlow::Wait); + window.request_redraw(); + } + } else if self.menu.is_some() { + event_loop.set_control_flow(ControlFlow::Wait); } } } -- cgit v1.2.3