Skip to content

Commit

Permalink
Add arrows around deck display
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 26, 2024
1 parent ce6f33a commit 9472ec2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 44 deletions.
23 changes: 1 addition & 22 deletions src/game/card/deck.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::ecs::system::EntityCommand;
use bevy::prelude::*;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
));
}
}
16 changes: 4 additions & 12 deletions src/screen/playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
39 changes: 38 additions & 1 deletion src/screen/playing/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -170,7 +170,44 @@ fn lower_hud(player: Entity) -> impl EntityCommand<World> {
},
))
.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::<PlayingAssets>().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::<UiImage>(),
));
}
93 changes: 86 additions & 7 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand All @@ -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::<LevelUp>()),
);
}

fn open_level_up_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
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::<PlayingMenu>::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::<PlayingMenu>::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::<Pointer<Click>>::run(PlayingMenu::disable));
}
5 changes: 3 additions & 2 deletions src/screen/playing/pause_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn open_pause_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
fn pause_overlay(mut entity: EntityWorldMut) {
entity.add(widget::blocking_overlay).insert((
Name::new("PauseOverlay"),
ZIndex::Global(1),
ThemeColor::Overlay.target::<BackgroundColor>(),
StateScope::<PlayingMenu>::default(),
));
Expand All @@ -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::<PlayingMenu>::default(),
Expand Down

0 comments on commit 9472ec2

Please sign in to comment.