diff --git a/progress-pile-app/src/main.rs b/progress-pile-app/src/main.rs index 477619e..05aedca 100644 --- a/progress-pile-app/src/main.rs +++ b/progress-pile-app/src/main.rs @@ -5,8 +5,9 @@ use bevy::prelude::*; #[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)] enum AppState { - MainView, #[default] + Loading, + MainView, Menu, List, Graph @@ -36,11 +37,15 @@ fn main() { .insert_resource(ViewerMode::PokerTip2D) .init_state::() .add_systems(Startup, setup) - .add_plugins(((plugins::main_menu::menu_plugin, plugins::main_view::main_view_plugin))) + .add_plugins((plugins::loading::loading_plugin, plugins::main_menu::menu_plugin, plugins::main_view::main_view_plugin)) .run(); } +fn setup(mut commands: Commands) { + commands.spawn(Camera2d); +} + // Generic system that takes a component as a parameter, and will despawn all entities with that component diff --git a/progress-pile-app/src/plugins/loading.rs b/progress-pile-app/src/plugins/loading.rs new file mode 100644 index 0000000..071cd7c --- /dev/null +++ b/progress-pile-app/src/plugins/loading.rs @@ -0,0 +1,59 @@ +use bevy::prelude::*; + +use crate::{despawn_screen, AppState}; + +// This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu +pub fn loading_plugin(app: &mut App) { + // As this plugin is managing the splash screen, it will focus on the state `GameState::Splash` + app + // When entering the state, spawn everything needed for this screen + .add_systems(OnEnter(AppState::Loading), loading_setup) + // While in this state, run the `countdown` system + .add_systems(Update, countdown.run_if(in_state(AppState::Loading))) + // When exiting the state, despawn everything that was spawned for this screen + .add_systems(OnExit(AppState::Loading), despawn_screen::); +} + +// Tag component used to tag entities added on the splash screen +#[derive(Component)] +struct OnLoadingScreen; + +// Newtype to use a `Timer` for this screen as a resource +#[derive(Resource, Deref, DerefMut)] +struct LoadingTimer(Timer); + +fn loading_setup(mut commands: Commands, asset_server: Res) { + let icon = asset_server.load("textures/Game Icons/wrench.png"); + // Display the logo + commands.spawn(( + Node { + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + width: Val::Percent(100.0), + height: Val::Percent(100.0), + ..default() + }, + OnLoadingScreen, + children![( + ImageNode::new(icon), + Node { + // This will set the logo to be 200px wide, and auto adjust its height + width: Val::Px(200.0), + ..default() + }, + )], + )); + // Insert the timer as a resource + commands.insert_resource(LoadingTimer(Timer::from_seconds(1.0, TimerMode::Once))); +} + +// Tick the timer, and change state when finished +fn countdown( + mut game_state: ResMut>, + time: Res