Skip to content

Commit

Permalink
Improve pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 27, 2024
1 parent 220d665 commit a5b68e0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/screen/playing/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn lower_hud(player: Entity) -> impl EntityCommand<World> {
justify_content: JustifyContent::Center,
..default()
},
z_index: ZIndex::Global(2),
..default()
},
))
Expand Down
5 changes: 3 additions & 2 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ fn open_level_up_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
}

fn level_up_overlay(mut entity: EntityWorldMut) {
entity.add(widget::overlay).insert((
entity.add(widget::blocking_overlay).insert((
Name::new("LevelUpOverlay"),
ZIndex::Global(1),
ThemeColor::Overlay.target::<BackgroundColor>(),
StateScope::<PlayingMenu>::default(),
));
}
Expand Down Expand Up @@ -109,7 +110,7 @@ fn button_container(mut entity: EntityWorldMut) {

fn ready_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Ready?"))
.add(widget::menu_button("Ready?", Vw(9.0)))
.insert(On::<Pointer<Click>>::run(PlayingMenu::disable));
}

Expand Down
15 changes: 7 additions & 8 deletions src/screen/playing/pause_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn open_pause_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
}

fn pause_overlay(mut entity: EntityWorldMut) {
entity.add(widget::overlay).insert((
entity.add(widget::blocking_overlay).insert((
Name::new("PauseOverlay"),
ZIndex::Global(1),
ThemeColor::Overlay.target::<BackgroundColor>(),
Expand All @@ -36,7 +36,7 @@ fn pause_menu(mut entity: EntityWorldMut) {
.insert((
Name::new("PauseMenu"),
NodeBundle {
style: Style::ABS_COLUMN_CENTER,
style: Style::ABS_COLUMN_MID,
z_index: ZIndex::Global(2),
..default()
},
Expand All @@ -61,7 +61,7 @@ fn header(mut entity: EntityWorldMut) {
},
)
.with_style(Style {
margin: UiRect::new(Val::ZERO, Val::ZERO, Vw(3.5), Vw(0.5)),
margin: UiRect::top(Vw(4.5)),
..default()
}),
DynamicFontSize::new(Vw(5.0)).with_step(8.0),
Expand All @@ -75,10 +75,9 @@ fn button_container(mut entity: EntityWorldMut) {
Name::new("ButtonContainer"),
NodeBundle {
style: Style {
width: Percent(100.0),
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
margin: UiRect::vertical(VMin(9.0)),
margin: UiRect::vertical(VMin(7.0)),
row_gap: Vw(2.5),
..default()
},
Expand All @@ -94,20 +93,20 @@ fn button_container(mut entity: EntityWorldMut) {

fn continue_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Continue"))
.add(widget::menu_button("Continue", Vw(9.0)))
.insert(On::<Pointer<Click>>::run(PlayingMenu::disable));
}

fn restart_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Restart"))
.add(widget::menu_button("Restart", Vw(9.0)))
.insert(On::<Pointer<Click>>::run(|mut commands: Commands| {
commands.spawn_with(fade_out(Screen::Playing));
}));
}

fn quit_to_title_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Quit to title"))
.add(widget::menu_button("Quit to title", Vw(9.0)))
.insert(On::<Pointer<Click>>::run(Screen::Title.enter()));
}
4 changes: 2 additions & 2 deletions src/screen/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn button_container(mut entity: EntityWorldMut) {

fn play_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Play"))
.add(widget::menu_button("Play", Vw(11.0)))
.insert(On::<Pointer<Click>>::run(
|mut commands: Commands, progress: Res<ProgressCounter>| {
let Progress { done, total } = progress.progress_complete();
Expand All @@ -126,7 +126,7 @@ fn play_button(mut entity: EntityWorldMut) {
}

fn quit_button(mut entity: EntityWorldMut) {
entity.add(widget::menu_button("Quit")).insert((
entity.add(widget::menu_button("Quit", Vw(11.0))).insert((
#[cfg(feature = "web")]
IsDisabled(true),
#[cfg(not(feature = "web"))]
Expand Down
4 changes: 2 additions & 2 deletions src/ui/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ pub fn blocking_overlay(mut entity: EntityWorldMut) {
});
}

pub fn menu_button(text: impl Into<String>) -> impl EntityCommand<World> {
pub fn menu_button(text: impl Into<String>, height: Val) -> impl EntityCommand<World> {
let text = text.into();
move |mut entity: EntityWorldMut| {
entity
.insert((
Name::new(format!("Button(\"{}\")", text)),
ButtonBundle {
style: Style {
height: Vw(11.0),
height,
width: Vw(38.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
Expand Down

0 comments on commit a5b68e0

Please sign in to comment.