diff --git a/src/tutorial.rs b/src/tutorial.rs index 2d9b026..f2f83a2 100644 --- a/src/tutorial.rs +++ b/src/tutorial.rs @@ -15,17 +15,35 @@ const INGREDIENTS_TEXT_POS: Vec2 = Vec2::new(615., 60.); const SUMMONING_TEXT_POS: Vec2 = Vec2::new(0., 210.); const MINIONS_TEXT_POS: Vec2 = Vec2::new(0., -440.); +const ENEMY_CARDS_TEXT_POS: Vec2 = Vec2::ZERO; + pub struct TutorialPlugin; impl Plugin for TutorialPlugin { fn build(&self, app: &mut App) { app.init_state::() + .init_resource::() .add_systems( Update, handle_tutorial_control.run_if(in_state(GameState::Playing)), ) .add_systems(OnEnter(TutorialState::None), clean_up_tutorial) - .add_systems(OnEnter(TutorialState::Summoning), show_summoning_tutorial); + .add_systems( + OnEnter(TutorialState::Summoning), + show_summoning_tutorial.run_if(resource_equals(FirstTutorial(false))), + ) + .add_systems( + OnEnter(GameScreen::Summoning), + show_summoning_tutorial.run_if(resource_equals(FirstTutorial(true))), + ) + .add_systems( + OnEnter(TutorialState::Planning), + show_planning_tutorial.run_if(resource_equals(FirstTutorial(false))), + ) + .add_systems( + OnEnter(GameScreen::Planning), + show_planning_tutorial.run_if(resource_equals(FirstTutorial(true))), + ); } } @@ -40,11 +58,21 @@ pub enum TutorialState { #[derive(Component)] struct TutorialEntity; +#[derive(Resource, PartialEq, Eq)] +struct FirstTutorial(bool); + +impl Default for FirstTutorial { + fn default() -> Self { + Self(true) + } +} + fn handle_tutorial_control( keyboard_input: Res>, mouse_input: Res>, game_screen: Res>, mut next_tutorial_state: ResMut>, + mut first_tutorial: ResMut, ) { if keyboard_input.just_pressed(KeyCode::F1) { match game_screen.get() { @@ -55,6 +83,10 @@ fn handle_tutorial_control( } if mouse_input.just_pressed(MouseButton::Left) { + if *game_screen.get() == GameScreen::Planning { + first_tutorial.0 = false; + } + next_tutorial_state.set(TutorialState::None); } } @@ -69,7 +101,10 @@ fn show_summoning_tutorial( mut commands: Commands, textures: Res, fonts: Res, + mut next_tutorial_state: ResMut>, ) { + next_tutorial_state.set(TutorialState::Summoning); + // highlight commands.spawn(( SpriteBundle { @@ -212,3 +247,91 @@ fn show_summoning_tutorial( TutorialEntity, )); } + +fn show_planning_tutorial( + mut commands: Commands, + textures: Res, + fonts: Res, + mut next_tutorial_state: ResMut>, +) { + next_tutorial_state.set(TutorialState::Planning); + + // highlight + commands.spawn(( + SpriteBundle { + texture: textures.tutorial_highlight_planning.clone(), + sprite: Sprite { + color: Color::WHITE.with_a(HIGHLIGHT_TRANSPARENCY), + ..Default::default() + }, + transform: Transform::from_xyz(0., 0., HIGHLIGHT_Z), + ..Default::default() + }, + TutorialEntity, + )); + + // minions text + commands.spawn(( + Text2dBundle { + text: Text { + sections: vec![TextSection::new( + "ENEMY CARDS\nEACH SHOW ENEMY STATS AND REWARDS\nLMB - SELECT ENEMY", + TextStyle { + font: fonts.texts.clone(), + color: Color::BLACK, + font_size: TEXT_SIZE, + }, + )], + justify: JustifyText::Center, + ..Default::default() + }, + transform: Transform::from_translation(ENEMY_CARDS_TEXT_POS.extend(TEXT_Z)), + ..Default::default() + }, + TutorialEntity, + )); + + // show help text + commands.spawn(( + Text2dBundle { + text: Text { + sections: vec![TextSection::new( + "F1 - SHOW THIS HELP", + TextStyle { + font: fonts.texts.clone(), + color: Color::WHITE, + font_size: TEXT_SIZE, + }, + )], + justify: JustifyText::Center, + ..Default::default() + }, + text_anchor: bevy::sprite::Anchor::TopLeft, + transform: Transform::from_xyz(-950., 530., TEXT_Z), + ..Default::default() + }, + TutorialEntity, + )); + + // continue text + commands.spawn(( + Text2dBundle { + text: Text { + sections: vec![TextSection::new( + "(CLICK ANYWHERE TO CONTINUE)", + TextStyle { + font: fonts.texts.clone(), + color: Color::WHITE, + font_size: TEXT_SIZE * 0.7, + }, + )], + justify: JustifyText::Center, + ..Default::default() + }, + text_anchor: bevy::sprite::Anchor::TopCenter, + transform: Transform::from_translation(Vec2::new(0., 530.).extend(TEXT_Z)), + ..Default::default() + }, + TutorialEntity, + )); +}