Skip to content

Commit 9472ec2

Browse files
committed
Add arrows around deck display
1 parent ce6f33a commit 9472ec2

File tree

5 files changed

+132
-44
lines changed

5 files changed

+132
-44
lines changed

src/game/card/deck.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bevy::ecs::system::EntityCommand;
21
use bevy::prelude::*;
32
use serde::Deserialize;
43
use serde::Serialize;
@@ -9,7 +8,6 @@ use crate::game::actor::player::IsPlayer;
98
use crate::game::card::card;
109
use crate::game::card::AddCardEvent;
1110
use crate::game::music::beat::on_beat;
12-
use crate::ui::prelude::*;
1311
use crate::util::prelude::*;
1412

1513
pub(super) fn plugin(app: &mut App) {
@@ -95,7 +93,7 @@ fn advance_deck(
9593

9694
#[derive(Component, Reflect)]
9795
#[reflect(Component)]
98-
struct IsDeckDisplay;
96+
pub struct IsDeckDisplay;
9997

10098
impl Configure for IsDeckDisplay {
10199
fn configure(app: &mut App) {
@@ -147,22 +145,3 @@ fn populate_deck_display(
147145
});
148146
}
149147
}
150-
151-
pub fn deck_display(player: Entity) -> impl EntityCommand {
152-
move |entity: Entity, world: &mut World| {
153-
world.entity_mut(entity).insert((
154-
Name::new("DeckDisplay"),
155-
NodeBundle {
156-
style: Style {
157-
width: Percent(100.0),
158-
justify_content: JustifyContent::Center,
159-
column_gap: Px(-4.0),
160-
..default()
161-
},
162-
..default()
163-
},
164-
IsDeckDisplay,
165-
Selection(player),
166-
));
167-
}
168-
}

src/screen/playing.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,10 @@ fn restart(mut commands: Commands) {
138138
commands.spawn_with(fade_out(Screen::Playing));
139139
}
140140

141-
// TODO: Where can we define the in-game pause menu?
142-
// In playing screen, we can say "on TogglePause action, toggle the Pause state AND toggle the in-game pause menu"
143-
// In-game pause menu should be defined by the playing screen itself. Think of it like an extension of the HUD, but usually hidden.
144-
// It _could_ be in a submodule as well.
145-
// Then what about the level-up menu? Is that also defined by the playing screen?
146-
// What happens if you try to pause while in the level-up menu?
147-
148-
// TODO: This state is usually disabled. Disable it when you exit `Screen::Playing`. Also make sure `PlayingAction` is enabled / disabled based on `Screen::Playing`.
149-
// on `PlayingAction::Pause`, enter `PlayingMenu::Pause` which will enable `Pause`. Exiting `PlayingMenu::Pause` will disable `Pause`.
150-
// Same pausing behavior for `PlayingMenu::LevelUp`.
151-
// 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.
152-
// Both playing menus will be defined in `src/screen/playing/`, not in `src/game/actor/level/up` or whatever.
141+
// TODO: Deck actions in deck.rs, but disabled by default. Enable the actions within PlayingMenu::LevelUp (and disable PlayingAction maybe?).
142+
143+
// TODO: What happens if you try to pause while in the level-up menu?
144+
// TODO: Make sure `PlayingAction` is enabled / disabled based on `Screen::Playing`.
153145
#[derive(State, Eq, PartialEq, Clone, Debug, Reflect)]
154146
#[state(after(Screen), before(Pause), entity_scope, log_flush)]
155147
#[reflect(Resource)]

src/screen/playing/hud.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bevy::prelude::*;
33

44
use crate::game::actor::level::xp::IsXpBarFill;
55
use crate::game::actor::level::IsLevelIndicator;
6-
use crate::game::card::deck::deck_display;
6+
use crate::game::card::deck::IsDeckDisplay;
77
use crate::screen::playing::PlayingAssets;
88
use crate::ui::prelude::*;
99
use crate::util::prelude::*;
@@ -170,7 +170,44 @@ fn lower_hud(player: Entity) -> impl EntityCommand<World> {
170170
},
171171
))
172172
.with_children(|children| {
173+
children.spawn_with(arrow);
173174
children.spawn_with(deck_display(player));
175+
children.spawn_with(arrow);
174176
});
175177
}
176178
}
179+
180+
fn deck_display(player: Entity) -> impl EntityCommand {
181+
move |entity: Entity, world: &mut World| {
182+
world.entity_mut(entity).insert((
183+
Name::new("DeckDisplay"),
184+
NodeBundle {
185+
style: Style {
186+
column_gap: Px(-4.0),
187+
..default()
188+
},
189+
..default()
190+
},
191+
IsDeckDisplay,
192+
Selection(player),
193+
));
194+
}
195+
}
196+
197+
fn arrow(mut entity: EntityWorldMut) {
198+
let texture = entity.world().resource::<PlayingAssets>().arrow.clone();
199+
200+
entity.insert((
201+
Name::new("Arrow"),
202+
ImageBundle {
203+
style: Style {
204+
height: Px(20.0),
205+
margin: UiRect::horizontal(Px(8.0)),
206+
..default()
207+
},
208+
image: UiImage::new(texture),
209+
..default()
210+
},
211+
ThemeColor::Indicator.target::<UiImage>(),
212+
));
213+
}

src/screen/playing/level_up_menu.rs

+86-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// TODO
2-
#![allow(unused)]
3-
41
use bevy::prelude::*;
2+
use bevy_mod_picking::prelude::*;
53
use pyri_state::prelude::*;
64

75
use crate::core::pause::Pause;
6+
use crate::core::UpdateSet;
7+
use crate::game::actor::level::up::LevelUp;
88
use crate::screen::playing::PlayingMenu;
99
use crate::ui::prelude::*;
1010
use crate::util::prelude::*;
@@ -14,12 +14,91 @@ pub(super) fn plugin(app: &mut App) {
1414
StateFlush,
1515
PlayingMenu::LevelUp.on_edge(Pause::disable, (Pause::enable_default, open_level_up_menu)),
1616
);
17+
app.add_systems(
18+
Update,
19+
PlayingMenu::LevelUp
20+
.enter()
21+
.in_set(UpdateSet::SyncLate)
22+
.run_if(on_event::<LevelUp>()),
23+
);
24+
}
25+
26+
fn open_level_up_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
27+
commands
28+
.spawn_with(level_up_overlay)
29+
.set_parent(ui_root.body);
30+
commands.spawn_with(level_up_menu).set_parent(ui_root.body);
31+
}
32+
33+
fn level_up_overlay(mut entity: EntityWorldMut) {
34+
entity.add(widget::blocking_overlay).insert((
35+
Name::new("LevelUpOverlay"),
36+
ZIndex::Global(1),
37+
StateScope::<PlayingMenu>::default(),
38+
));
39+
}
40+
41+
fn level_up_menu(mut entity: EntityWorldMut) {
42+
entity
43+
.insert((
44+
Name::new("LevelUpMenu"),
45+
NodeBundle {
46+
style: Style::ABS_COLUMN_CENTER,
47+
z_index: ZIndex::Global(2),
48+
..default()
49+
},
50+
StateScope::<PlayingMenu>::default(),
51+
))
52+
.with_children(|children| {
53+
children.spawn_with(header);
54+
children.spawn_with(button_container);
55+
});
56+
}
57+
58+
const HEADER: &str = "Level up!";
59+
60+
fn header(mut entity: EntityWorldMut) {
61+
entity.insert((
62+
Name::new("Header"),
63+
TextBundle::from_section(
64+
HEADER,
65+
TextStyle {
66+
font: BOLD_FONT_HANDLE,
67+
..default()
68+
},
69+
)
70+
.with_style(Style {
71+
margin: UiRect::new(Val::ZERO, Val::ZERO, Vw(3.5), Vw(0.5)),
72+
..default()
73+
}),
74+
DynamicFontSize::new(Vw(5.0)).with_step(8.0),
75+
ThemeColorForText(vec![ThemeColor::BodyText]),
76+
));
1777
}
1878

19-
fn open_level_up_menu(mut commands: Commands) {
20-
commands.spawn_with(level_up_menu);
79+
fn button_container(mut entity: EntityWorldMut) {
80+
entity
81+
.insert((
82+
Name::new("ButtonContainer"),
83+
NodeBundle {
84+
style: Style {
85+
width: Percent(100.0),
86+
align_items: AlignItems::Center,
87+
flex_direction: FlexDirection::Column,
88+
margin: UiRect::vertical(VMin(9.0)),
89+
row_gap: Vw(2.5),
90+
..default()
91+
},
92+
..default()
93+
},
94+
))
95+
.with_children(|children| {
96+
children.spawn_with(ready_button);
97+
});
2198
}
2299

23-
fn level_up_menu(entity: Entity, world: &mut World) {
24-
// TODO
100+
fn ready_button(mut entity: EntityWorldMut) {
101+
entity
102+
.add(widget::menu_button("Ready?"))
103+
.insert(On::<Pointer<Click>>::run(PlayingMenu::disable));
25104
}

src/screen/playing/pause_menu.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn open_pause_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
2424
fn pause_overlay(mut entity: EntityWorldMut) {
2525
entity.add(widget::blocking_overlay).insert((
2626
Name::new("PauseOverlay"),
27+
ZIndex::Global(1),
2728
ThemeColor::Overlay.target::<BackgroundColor>(),
2829
StateScope::<PlayingMenu>::default(),
2930
));
@@ -34,8 +35,8 @@ fn pause_menu(mut entity: EntityWorldMut) {
3435
.insert((
3536
Name::new("PauseMenu"),
3637
NodeBundle {
37-
style: Style::ABS_COLUMN_MID,
38-
z_index: ZIndex::Global(5000),
38+
style: Style::ABS_COLUMN_CENTER,
39+
z_index: ZIndex::Global(2),
3940
..default()
4041
},
4142
StateScope::<PlayingMenu>::default(),

0 commit comments

Comments
 (0)