Skip to content

Commit

Permalink
Set up victory/defeat menu layouting
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 28, 2024
1 parent 8fa3ab1 commit 3ab0dea
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 99 deletions.
Binary file modified assets/mockup/pyrious.aseprite
Binary file not shown.
183 changes: 143 additions & 40 deletions src/screen/playing/defeat_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use pyri_state::extra::entity_scope::StateScope;
use pyri_state::prelude::*;

use crate::core::pause::Pause;
use crate::game::actor::health::Health;
use crate::game::actor::player::IsPlayer;
use crate::game::combat::death::IsDead;
use crate::game::combat::death::OnDeath;
use crate::screen::fade_out;
use crate::screen::playing::PlayingAssets;
Expand Down Expand Up @@ -52,22 +54,37 @@ fn defeat_overlay(mut entity: EntityWorldMut) {

fn defeat_menu(mut entity: EntityWorldMut) {
entity
.add(Style::ABS_COLUMN_CENTER.div())
.insert((
Name::new("DefeatMenu"),
NodeBundle {
style: Style::ABS_COLUMN_MID,
z_index: ZIndex::Global(2),
..default()
},
Name::new("DefeatMenuContainer"),
StateScope::<PlayingMenu>::default(),
))
.with_children(|children| {
children.spawn_with(header);
children.spawn_with(button_container);
children
.spawn((
Name::new("DefeatMenu"),
NodeBundle {
style: Style {
height: VMin(75.0),
top: Vw(-5.2),
align_items: AlignItems::Center,
justify_content: JustifyContent::SpaceBetween,
flex_direction: FlexDirection::Column,
..default()
},
z_index: ZIndex::Global(2),
..default()
},
))
.with_children(|children| {
children.spawn_with(header);
children.spawn_with(body);
children.spawn_with(button_container);
});
});
}

const HEADER: &str = "Defeat :(";
const HEADER: &str = "Party over :(";

fn header(mut entity: EntityWorldMut) {
entity.insert((
Expand All @@ -88,56 +105,142 @@ fn header(mut entity: EntityWorldMut) {
));
}

fn body(mut entity: EntityWorldMut) {
entity
.insert((
Name::new("Body"),
NodeBundle {
style: Style {
display: Display::Grid,
grid_template_columns: RepeatedGridTrack::auto(2),
row_gap: Vw(1.2),
column_gap: Vw(2.5),
..default()
},
..default()
},
))
.with_children(|children| {
// TODO: Real stats.
for (i, text) in [
"[b]125",
"seconds partied",
"[b]23",
"blobos impressed",
"[b]125",
"dances performed",
"[b]241",
"notes played",
"[b]45",
"rests taken",
]
.into_iter()
.enumerate()
{
children.spawn((
Name::new("BodySpan"),
TextBundle::from_sections(parse_rich(text)).with_style(Style {
justify_self: if i % 2 == 0 {
JustifySelf::End
} else {
JustifySelf::Start
},
..default()
}),
DynamicFontSize::new(Vw(3.0)).with_step(8.0),
ThemeColorForText(vec![if i % 2 == 0 {
ThemeColor::Indicator
} else {
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),
column_gap: Vw(3.8),
..default()
},
..default()
},
))
.with_children(|children| {
children.spawn_with(dance_on_button);
children.spawn_with(restart_button);
children.spawn_with(quit_to_title_button);
children.spawn_with(quit_button);
});
}

fn dance_on_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button_with_font_size("Dance on", Vw(3.5)))
.insert((
On::<Pointer<Click>>::run(
|mut commands: Commands,
mut player_query: Query<(Entity, &mut Health), (With<IsPlayer>, With<IsDead>)>,
audio: Res<Audio>,
assets: Res<PlayingAssets>,
mut playing_menu: NextMut<PlayingMenu>| {
for (player, mut health) in &mut player_query {
health.current = health.max;
commands.entity(player).remove::<IsDead>();
}

audio.play(assets.sfx_restart.clone()).with_volume(0.7);

playing_menu.disable();
},
),
Style {
height: Vw(9.0),
width: Vw(28.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
));
}

fn restart_button(mut entity: EntityWorldMut) {
entity.add(widget::menu_button("Restart")).insert((
On::<Pointer<Click>>::run(
|mut commands: Commands, audio: Res<Audio>, assets: Res<PlayingAssets>| {
audio.play(assets.sfx_restart.clone()).with_volume(0.7);
commands.spawn_with(fade_out(Screen::Playing));
entity
.add(widget::menu_button_with_font_size("Restart", Vw(3.5)))
.insert((
On::<Pointer<Click>>::run(
|mut commands: Commands, audio: Res<Audio>, assets: Res<PlayingAssets>| {
audio.play(assets.sfx_restart.clone()).with_volume(0.7);
commands.spawn_with(fade_out(Screen::Playing));
},
),
Style {
height: Vw(9.0),
width: Vw(28.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
),
Style {
height: Vw(9.0),
width: Vw(38.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
));
));
}

fn quit_to_title_button(mut entity: EntityWorldMut) {
entity.add(widget::menu_button("Quit to title")).insert((
On::<Pointer<Click>>::run(|mut commands: Commands| {
commands.spawn_with(fade_out(Screen::Title));
}),
Style {
height: Vw(9.0),
width: Vw(38.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
));
fn quit_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button_with_font_size("Quit", Vw(3.5)))
.insert((
On::<Pointer<Click>>::run(|mut commands: Commands| {
commands.spawn_with(fade_out(Screen::Title));
}),
Style {
height: Vw(9.0),
width: Vw(28.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
));
}
6 changes: 4 additions & 2 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ fn level_up_overlay(mut entity: EntityWorldMut) {
fn level_up_menu(mut entity: EntityWorldMut) {
entity
.add(Style::ABS_COLUMN_CENTER.div())
.insert(Name::new("LevelUpMenuContainer"))
.insert((
Name::new("LevelUpMenuContainer"),
StateScope::<PlayingMenu>::default(),
))
.with_children(|children| {
children
.spawn((
Expand All @@ -75,7 +78,6 @@ fn level_up_menu(mut entity: EntityWorldMut) {
z_index: ZIndex::Global(2),
..default()
},
StateScope::<PlayingMenu>::default(),
))
.with_children(|children| {
children.spawn_with(header);
Expand Down
Loading

0 comments on commit 3ab0dea

Please sign in to comment.