Hacking in tutorial button.

Need to toggle it on/off, but this is a good step.
main
Elijah C. Voigt 2 years ago
parent ad7090aa47
commit 0a37814aeb

@ -14,7 +14,10 @@ impl Plugin for IntroPlugin {
.run_if(run_once()), .run_if(run_once()),
) )
.add_systems(OnEnter(GameState::Intro), manage_intro) .add_systems(OnEnter(GameState::Intro), manage_intro)
.add_systems(OnExit(GameState::Intro), (deactivate::<Intro>, cleanup_intro)) .add_systems(
OnExit(GameState::Intro),
(deactivate::<Intro>, cleanup_intro),
)
// All of these run during GameState::Intro // All of these run during GameState::Intro
.add_systems( .add_systems(
Update, Update,
@ -23,15 +26,18 @@ impl Plugin for IntroPlugin {
manage_intro.run_if(any_component_removed::<ui::TextScrollAnimation>()), manage_intro.run_if(any_component_removed::<ui::TextScrollAnimation>()),
// Started when the TextScrollAnimation component is added to the parent entity // Started when the TextScrollAnimation component is added to the parent entity
// Updated for as long as there is scrolling text // Updated for as long as there is scrolling text
manage_scroll_text_animation manage_scroll_text_animation.run_if(
.run_if(any_component_added::<ui::TextScrollAnimation>.or_else( any_component_added::<ui::TextScrollAnimation>.or_else(
|keys: Res<Input<KeyCode>>| -> bool { keys.just_pressed(KeyCode::Return) }, |keys: Res<Input<KeyCode>>| -> bool {
)), keys.just_pressed(KeyCode::Return)
},
),
),
// Play intro manages playing the intro of each individual paragraph // Play intro manages playing the intro of each individual paragraph
// Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated
scroll_text scroll_text.run_if(any_with_component::<ui::TextScroll>()),
.run_if(any_with_component::<ui::TextScroll>()), )
).run_if(in_state(GameState::Intro)) .run_if(in_state(GameState::Intro)),
); );
} }
} }
@ -144,7 +150,11 @@ fn cleanup_intro(
info!("Cleaning up intro"); info!("Cleaning up intro");
query.iter().for_each(|e| { query.iter().for_each(|e| {
commands.entity(e).remove::<ui::TextScrollAnimation>().remove::<ui::TextScroll>().insert(Visibility::Hidden); commands
.entity(e)
.remove::<ui::TextScrollAnimation>()
.remove::<ui::TextScroll>()
.insert(Visibility::Hidden);
}); });
{ {
@ -166,7 +176,13 @@ fn cleanup_intro(
struct CurrentIntroParagraph(Option<Entity>); struct CurrentIntroParagraph(Option<Entity>);
fn manage_scroll_text_animation( fn manage_scroll_text_animation(
roots: Query<Entity, Or<(With<ui::TextScrollAnimation>, Added<ui::TextScrollAnimation>)>>, roots: Query<
Entity,
Or<(
With<ui::TextScrollAnimation>,
Added<ui::TextScrollAnimation>,
)>,
>,
texts: Query<Entity, (With<Text>, With<Intro>)>, texts: Query<Entity, (With<Text>, With<Intro>)>,
animated_texts: Query<&ui::TextScroll>, animated_texts: Query<&ui::TextScroll>,
parents: Query<&Parent>, parents: Query<&Parent>,

@ -97,6 +97,7 @@ fn activate<Marker: Component>(
), ),
>, >,
) { ) {
info!("Activating state");
entities.iter_mut().for_each(|mut visibility| { entities.iter_mut().for_each(|mut visibility| {
*visibility = Visibility::Visible; *visibility = Visibility::Visible;
}); });

@ -13,11 +13,10 @@ impl Plugin for MenuPlugin {
.add_systems( .add_systems(
Update, Update,
( (
handle_menu_button::<GameState>, handle_menu_button::<GameState>, // Run in all states
handle_menu_quit, handle_menu_quit.run_if(in_state(GameState::Menu)),
bevy::window::close_on_esc, bevy::window::close_on_esc.run_if(in_state(GameState::Menu)),
) ),
.run_if(in_state(GameState::Menu)),
) )
.add_systems( .add_systems(
OnEnter(GameState::Menu), OnEnter(GameState::Menu),
@ -88,35 +87,6 @@ fn init_menu_ui(mut commands: Commands) {
)); ));
}); });
parent
.spawn((
GameState::Play,
tutorial::TutorialState::Intro,
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((
GameState::Play,
tutorial::TutorialState::Intro,
TextBundle::from_section(
"Tutorial",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),
));
});
parent parent
.spawn(( .spawn((
GameState::Credits, GameState::Credits,

@ -16,7 +16,7 @@ impl Plugin for TutorialPlugin {
) )
.add_systems( .add_systems(
Update, Update,
menu::handle_menu_button::<TutorialState>.run_if(in_state(GameState::Menu)), menu::handle_menu_button::<TutorialState>.run_if(in_state(GameState::Play)),
) )
.add_systems( .add_systems(
Update, Update,
@ -39,10 +39,7 @@ impl Plugin for TutorialPlugin {
), ),
) )
.add_systems(OnExit(GameState::Play), deactivate::<TutorialState>) .add_systems(OnExit(GameState::Play), deactivate::<TutorialState>)
.add_systems( .add_systems(OnEnter(GameState::Play), activate::<Tutorial>)
OnEnter(GameState::Play),
activate_tutorial_step.run_if(state_exists::<TutorialState>()),
)
.add_systems( .add_systems(
Update, Update,
activate_tutorial_step.run_if(state_changed::<TutorialState>()), activate_tutorial_step.run_if(state_changed::<TutorialState>()),
@ -50,6 +47,9 @@ impl Plugin for TutorialPlugin {
} }
} }
#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)]
pub(crate) struct Tutorial;
#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)] #[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)]
pub(crate) enum TutorialState { pub(crate) enum TutorialState {
#[default] #[default]
@ -84,6 +84,39 @@ fn initialize_tutorial(
info!("Initializing tutorial entities"); info!("Initializing tutorial entities");
// Tutorial button used for toggling on/off during gameplay
{
commands
.spawn((
TutorialState::Intro, // Marks the button to start the tutorial
Tutorial, // Marks the button for activate::<Tutorial>
GameState::Play, // Marks the button to be ignored during tutorial step cleanup
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
position_type: PositionType::Absolute,
top: Val::Px(0.0),
right: Val::Px(0.0),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
visibility: Visibility::Hidden,
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Tutorial",
TextStyle {
color: Color::BLACK,
font_size: 16.0,
..default()
},
),));
});
}
let background_hex = tweak.get::<String>("tutorial_rgba_background").unwrap(); let background_hex = tweak.get::<String>("tutorial_rgba_background").unwrap();
let text_visible_hex = tweak.get::<String>("tutorial_rgba_visible").unwrap(); let text_visible_hex = tweak.get::<String>("tutorial_rgba_visible").unwrap();

Loading…
Cancel
Save