From cd5cc93f8aa30fe846b3daaac0981c4f32bfb852 Mon Sep 17 00:00:00 2001 From: mramirez Date: Sun, 28 Jul 2024 02:16:31 -0400 Subject: [PATCH] added victory and defeat screens --- src/screen/playing.rs | 14 ++- src/screen/playing/defeat_menu.rs | 138 ++++++++++++++++++++++ src/screen/playing/level_up_menu.rs | 3 +- src/screen/playing/victory_menu.rs | 177 ++++++++++++++++++++++++++++ 4 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 src/screen/playing/defeat_menu.rs create mode 100644 src/screen/playing/victory_menu.rs diff --git a/src/screen/playing.rs b/src/screen/playing.rs index 5e4d665..fdd09d0 100644 --- a/src/screen/playing.rs +++ b/src/screen/playing.rs @@ -1,6 +1,8 @@ +pub mod defeat_menu; pub mod hud; pub mod level_up_menu; pub mod pause_menu; +pub mod victory_menu; use bevy::prelude::*; use bevy_asset_loader::prelude::*; @@ -20,6 +22,7 @@ use crate::game::wave::wave; use crate::game::GameRoot; use crate::screen::fade_in; use crate::screen::playing::hud::playing_hud; +use crate::screen::playing::victory_menu::reset_endless_mode; use crate::screen::Screen; use crate::ui::prelude::*; use crate::util::prelude::*; @@ -27,12 +30,17 @@ use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { app.add_systems( StateFlush, - Screen::Playing.on_edge(stop_music, (enter_playing, start_music)), + Screen::Playing.on_edge(stop_music, (enter_playing, start_music, reset_endless_mode)), ); app.configure::<(PlayingAssets, PlayingAction, PlayingMenu)>(); - app.add_plugins((level_up_menu::plugin, pause_menu::plugin)); + app.add_plugins(( + level_up_menu::plugin, + pause_menu::plugin, + victory_menu::plugin, + defeat_menu::plugin, + )); } fn enter_playing(mut commands: Commands, game_root: Res, ui_root: Res) { @@ -138,6 +146,8 @@ impl Configure for PlayingAction { enum PlayingMenu { Pause, LevelUp, + Victory, + Defeat, } impl Configure for PlayingMenu { diff --git a/src/screen/playing/defeat_menu.rs b/src/screen/playing/defeat_menu.rs new file mode 100644 index 0000000..1014112 --- /dev/null +++ b/src/screen/playing/defeat_menu.rs @@ -0,0 +1,138 @@ +use bevy::prelude::*; +use bevy_kira_audio::prelude::*; +use bevy_mod_picking::prelude::*; +use pyri_state::extra::entity_scope::StateScope; +use pyri_state::prelude::*; + +use crate::core::pause::Pause; +use crate::core::UpdateSet; +use crate::game::actor::player::IsPlayer; +use crate::screen::fade_out; +use crate::screen::playing::PlayingAssets; +use crate::screen::playing::PlayingMenu; +use crate::screen::Screen; +use crate::ui::prelude::*; +use crate::util::prelude::*; + +pub(super) fn plugin(app: &mut App) { + app.add_systems( + StateFlush, + PlayingMenu::Defeat.on_edge(Pause::disable, (Pause::enable_default, open_defeat_menu)), + ); + + app.add_systems( + Update, + PlayingMenu::Defeat + .enter() + .in_set(UpdateSet::SyncLate) + .run_if(detect_defeat), + ); +} + +fn open_defeat_menu(mut commands: Commands, ui_root: Res) { + commands.spawn_with(defeat_overlay).set_parent(ui_root.body); + commands.spawn_with(defeat_menu).set_parent(ui_root.body); +} + +pub fn detect_defeat(player_query: Query>) -> bool { + player_query.is_empty() +} + +fn defeat_overlay(mut entity: EntityWorldMut) { + entity.add(widget::blocking_overlay).insert(( + Name::new("DefeatOverlay"), + ZIndex::Global(1), + ThemeColor::Overlay.target::(), + StateScope::::default(), + )); +} + +fn defeat_menu(mut entity: EntityWorldMut) { + entity + .insert(( + Name::new("DefeatMenu"), + NodeBundle { + style: Style::ABS_COLUMN_MID, + z_index: ZIndex::Global(2), + ..default() + }, + StateScope::::default(), + )) + .with_children(|children| { + children.spawn_with(header); + children.spawn_with(button_container); + }); +} + +const HEADER: &str = "Defeat :("; + +fn header(mut entity: EntityWorldMut) { + entity.insert(( + Name::new("Header"), + TextBundle::from_section( + HEADER, + TextStyle { + font: BOLD_FONT_HANDLE, + ..default() + }, + ) + .with_style(Style { + margin: UiRect::top(Vw(4.5)), + ..default() + }), + DynamicFontSize::new(Vw(5.0)).with_step(8.0), + ThemeColorForText(vec![ThemeColor::BodyText]), + )); +} + +fn button_container(mut entity: EntityWorldMut) { + entity + .insert(( + Name::new("ButtonContainer"), + NodeBundle { + style: Style { + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + margin: UiRect::top(VMin(6.0)), + row_gap: Vw(2.5), + ..default() + }, + ..default() + }, + )) + .with_children(|children| { + children.spawn_with(restart_button); + children.spawn_with(quit_to_title_button); + }); +} + +fn restart_button(mut entity: EntityWorldMut) { + entity.add(widget::menu_button("Restart")).insert(( + On::>::run( + |mut commands: Commands, audio: Res