/* * This file is part of laurelin_client * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ use bevy::{ prelude::*, ui::{JustifyContent, Size, Style, Val}, }; use crate::{despawn_screen, GameState}; /// This plugin will display a splsh logo on startup pub struct SplashPlugin; impl Plugin for SplashPlugin { fn build(&self, app: &mut App) { app // Load the splash when we enter the Splash state .add_system(splash_setup.in_schedule(OnEnter(GameState::Splash))) // Run a timer for a few seconds .add_system(splash_timer.run_if(in_state(GameState::Splash))) // Despawn when we exit the Splash state .add_system(despawn_screen::.in_schedule(OnExit(GameState::Splash))); } } /// Tag component for tagging entities on the splash screen #[derive(Component)] struct OnSplashScreen; /// Timer resource #[derive(Resource, Deref, DerefMut)] struct SplashTimer(Timer); fn splash_setup(mut commands: Commands, asset_server: Res) { let logo = asset_server.load("branding/logo.png"); commands .spawn(( NodeBundle { style: Style { align_items: AlignItems::Center, justify_content: JustifyContent::Center, size: Size::new(Val::Percent(100.), Val::Percent(100.)), ..Default::default() }, ..Default::default() }, OnSplashScreen, )) .with_children(|parent| { parent.spawn(ImageBundle { style: Style { size: Size::new(Val::Px(1000.), Val::Auto), ..Default::default() }, image: UiImage { texture: logo, flip_x: false, flip_y: false, }, ..Default::default() }); }); // Insert the timer resource commands.insert_resource(SplashTimer(Timer::from_seconds(2., TimerMode::Once))); } fn splash_timer(mut commands: Commands, time: Res