From 9472ec29eb7c58d89d00b28ab8bfed495af92b07 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Fri, 26 Jul 2024 03:17:48 -0700 Subject: [PATCH] Add arrows around deck display --- src/game/card/deck.rs | 23 +------ src/screen/playing.rs | 16 ++--- src/screen/playing/hud.rs | 39 +++++++++++- src/screen/playing/level_up_menu.rs | 93 ++++++++++++++++++++++++++--- src/screen/playing/pause_menu.rs | 5 +- 5 files changed, 132 insertions(+), 44 deletions(-) diff --git a/src/game/card/deck.rs b/src/game/card/deck.rs index 8dc7403..b65769f 100644 --- a/src/game/card/deck.rs +++ b/src/game/card/deck.rs @@ -1,4 +1,3 @@ -use bevy::ecs::system::EntityCommand; use bevy::prelude::*; use serde::Deserialize; use serde::Serialize; @@ -9,7 +8,6 @@ use crate::game::actor::player::IsPlayer; use crate::game::card::card; use crate::game::card::AddCardEvent; use crate::game::music::beat::on_beat; -use crate::ui::prelude::*; use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { @@ -95,7 +93,7 @@ fn advance_deck( #[derive(Component, Reflect)] #[reflect(Component)] -struct IsDeckDisplay; +pub struct IsDeckDisplay; impl Configure for IsDeckDisplay { fn configure(app: &mut App) { @@ -147,22 +145,3 @@ fn populate_deck_display( }); } } - -pub fn deck_display(player: Entity) -> impl EntityCommand { - move |entity: Entity, world: &mut World| { - world.entity_mut(entity).insert(( - Name::new("DeckDisplay"), - NodeBundle { - style: Style { - width: Percent(100.0), - justify_content: JustifyContent::Center, - column_gap: Px(-4.0), - ..default() - }, - ..default() - }, - IsDeckDisplay, - Selection(player), - )); - } -} diff --git a/src/screen/playing.rs b/src/screen/playing.rs index 2604f5e..8c78e8f 100644 --- a/src/screen/playing.rs +++ b/src/screen/playing.rs @@ -138,18 +138,10 @@ fn restart(mut commands: Commands) { commands.spawn_with(fade_out(Screen::Playing)); } -// TODO: Where can we define the in-game pause menu? -// In playing screen, we can say "on TogglePause action, toggle the Pause state AND toggle the in-game pause menu" -// In-game pause menu should be defined by the playing screen itself. Think of it like an extension of the HUD, but usually hidden. -// It _could_ be in a submodule as well. -// Then what about the level-up menu? Is that also defined by the playing screen? -// What happens if you try to pause while in the level-up menu? - -// TODO: This state is usually disabled. Disable it when you exit `Screen::Playing`. Also make sure `PlayingAction` is enabled / disabled based on `Screen::Playing`. -// on `PlayingAction::Pause`, enter `PlayingMenu::Pause` which will enable `Pause`. Exiting `PlayingMenu::Pause` will disable `Pause`. -// Same pausing behavior for `PlayingMenu::LevelUp`. -// Use state-scoping for any `PlayingMenu` spawned UI, while also being a child of the UI root (not the playing screen). Compare this to how the playing screen root UI node is set up. -// Both playing menus will be defined in `src/screen/playing/`, not in `src/game/actor/level/up` or whatever. +// TODO: Deck actions in deck.rs, but disabled by default. Enable the actions within PlayingMenu::LevelUp (and disable PlayingAction maybe?). + +// TODO: What happens if you try to pause while in the level-up menu? +// TODO: Make sure `PlayingAction` is enabled / disabled based on `Screen::Playing`. #[derive(State, Eq, PartialEq, Clone, Debug, Reflect)] #[state(after(Screen), before(Pause), entity_scope, log_flush)] #[reflect(Resource)] diff --git a/src/screen/playing/hud.rs b/src/screen/playing/hud.rs index 70a4fc9..33c9117 100644 --- a/src/screen/playing/hud.rs +++ b/src/screen/playing/hud.rs @@ -3,7 +3,7 @@ use bevy::prelude::*; use crate::game::actor::level::xp::IsXpBarFill; use crate::game::actor::level::IsLevelIndicator; -use crate::game::card::deck::deck_display; +use crate::game::card::deck::IsDeckDisplay; use crate::screen::playing::PlayingAssets; use crate::ui::prelude::*; use crate::util::prelude::*; @@ -170,7 +170,44 @@ fn lower_hud(player: Entity) -> impl EntityCommand { }, )) .with_children(|children| { + children.spawn_with(arrow); children.spawn_with(deck_display(player)); + children.spawn_with(arrow); }); } } + +fn deck_display(player: Entity) -> impl EntityCommand { + move |entity: Entity, world: &mut World| { + world.entity_mut(entity).insert(( + Name::new("DeckDisplay"), + NodeBundle { + style: Style { + column_gap: Px(-4.0), + ..default() + }, + ..default() + }, + IsDeckDisplay, + Selection(player), + )); + } +} + +fn arrow(mut entity: EntityWorldMut) { + let texture = entity.world().resource::().arrow.clone(); + + entity.insert(( + Name::new("Arrow"), + ImageBundle { + style: Style { + height: Px(20.0), + margin: UiRect::horizontal(Px(8.0)), + ..default() + }, + image: UiImage::new(texture), + ..default() + }, + ThemeColor::Indicator.target::(), + )); +} diff --git a/src/screen/playing/level_up_menu.rs b/src/screen/playing/level_up_menu.rs index a17059a..d49860e 100644 --- a/src/screen/playing/level_up_menu.rs +++ b/src/screen/playing/level_up_menu.rs @@ -1,10 +1,10 @@ -// TODO -#![allow(unused)] - use bevy::prelude::*; +use bevy_mod_picking::prelude::*; use pyri_state::prelude::*; use crate::core::pause::Pause; +use crate::core::UpdateSet; +use crate::game::actor::level::up::LevelUp; use crate::screen::playing::PlayingMenu; use crate::ui::prelude::*; use crate::util::prelude::*; @@ -14,12 +14,91 @@ pub(super) fn plugin(app: &mut App) { StateFlush, PlayingMenu::LevelUp.on_edge(Pause::disable, (Pause::enable_default, open_level_up_menu)), ); + app.add_systems( + Update, + PlayingMenu::LevelUp + .enter() + .in_set(UpdateSet::SyncLate) + .run_if(on_event::()), + ); +} + +fn open_level_up_menu(mut commands: Commands, ui_root: Res) { + commands + .spawn_with(level_up_overlay) + .set_parent(ui_root.body); + commands.spawn_with(level_up_menu).set_parent(ui_root.body); +} + +fn level_up_overlay(mut entity: EntityWorldMut) { + entity.add(widget::blocking_overlay).insert(( + Name::new("LevelUpOverlay"), + ZIndex::Global(1), + StateScope::::default(), + )); +} + +fn level_up_menu(mut entity: EntityWorldMut) { + entity + .insert(( + Name::new("LevelUpMenu"), + NodeBundle { + style: Style::ABS_COLUMN_CENTER, + z_index: ZIndex::Global(2), + ..default() + }, + StateScope::::default(), + )) + .with_children(|children| { + children.spawn_with(header); + children.spawn_with(button_container); + }); +} + +const HEADER: &str = "Level up!"; + +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::new(Val::ZERO, Val::ZERO, Vw(3.5), Vw(0.5)), + ..default() + }), + DynamicFontSize::new(Vw(5.0)).with_step(8.0), + ThemeColorForText(vec![ThemeColor::BodyText]), + )); } -fn open_level_up_menu(mut commands: Commands) { - commands.spawn_with(level_up_menu); +fn button_container(mut entity: EntityWorldMut) { + entity + .insert(( + Name::new("ButtonContainer"), + NodeBundle { + style: Style { + width: Percent(100.0), + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + margin: UiRect::vertical(VMin(9.0)), + row_gap: Vw(2.5), + ..default() + }, + ..default() + }, + )) + .with_children(|children| { + children.spawn_with(ready_button); + }); } -fn level_up_menu(entity: Entity, world: &mut World) { - // TODO +fn ready_button(mut entity: EntityWorldMut) { + entity + .add(widget::menu_button("Ready?")) + .insert(On::>::run(PlayingMenu::disable)); } diff --git a/src/screen/playing/pause_menu.rs b/src/screen/playing/pause_menu.rs index 47cd55a..a9ffa35 100644 --- a/src/screen/playing/pause_menu.rs +++ b/src/screen/playing/pause_menu.rs @@ -24,6 +24,7 @@ fn open_pause_menu(mut commands: Commands, ui_root: Res) { fn pause_overlay(mut entity: EntityWorldMut) { entity.add(widget::blocking_overlay).insert(( Name::new("PauseOverlay"), + ZIndex::Global(1), ThemeColor::Overlay.target::(), StateScope::::default(), )); @@ -34,8 +35,8 @@ fn pause_menu(mut entity: EntityWorldMut) { .insert(( Name::new("PauseMenu"), NodeBundle { - style: Style::ABS_COLUMN_MID, - z_index: ZIndex::Global(5000), + style: Style::ABS_COLUMN_CENTER, + z_index: ZIndex::Global(2), ..default() }, StateScope::::default(),