From aef8c719f24e3bb9e9449e63c3fd20d4831fd81b Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Wed, 28 Feb 2024 22:08:30 -0800 Subject: [PATCH] tutorial menu works --- src/credits.rs | 39 +++++++++++++++-------------- src/game.rs | 12 +++++---- src/menu.rs | 18 ++++++++------ src/tutorial.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 33 deletions(-) diff --git a/src/credits.rs b/src/credits.rs index 531d24f..87168aa 100644 --- a/src/credits.rs +++ b/src/credits.rs @@ -31,29 +31,31 @@ fn init_credits_ui(mut commands: Commands) { }, )) .with_children(|parent| { - parent.spawn(( - Credits, - NodeBundle { - style: Style { - padding: UiRect::all(Val::Px(25.0)), - ..default() - }, - background_color: Color::BLACK.with_a(0.5).into(), - ..default() - } - )).with_children(|parent| { - parent.spawn(( + parent + .spawn(( Credits, - TextBundle { - text: Text { - alignment: TextAlignment::Center, - sections: vec![], + NodeBundle { + style: Style { + padding: UiRect::all(Val::Px(25.0)), ..default() }, + background_color: Color::BLACK.with_a(0.5).into(), ..default() }, - )); - }); + )) + .with_children(|parent| { + parent.spawn(( + Credits, + TextBundle { + text: Text { + alignment: TextAlignment::Center, + sections: vec![], + ..default() + }, + ..default() + }, + )); + }); parent .spawn(( @@ -85,7 +87,6 @@ fn init_credits_ui(mut commands: Commands) { ..default() }); }); - }); } diff --git a/src/game.rs b/src/game.rs index ee0448f..afbe5c5 100644 --- a/src/game.rs +++ b/src/game.rs @@ -46,6 +46,7 @@ impl Plugin for GamePlugin { PostUpdate, (debug_board.run_if(resource_exists::()),), ) + .add_systems(OnEnter(GameState::Restart), handle_restart) .add_systems(OnEnter(GameState::Quit), handle_quit); } } @@ -845,10 +846,11 @@ fn reset_game( }); } - /// Very simple system to handle the "Quit" state (shutdown the game) -fn handle_quit( - mut app_exit_events: EventWriter, -) { +fn handle_quit(mut app_exit_events: EventWriter) { app_exit_events.send(AppExit); -} \ No newline at end of file +} + +fn handle_restart() { + todo!("Restart is not implemented yet!"); +} diff --git a/src/menu.rs b/src/menu.rs index bf9b691..8d581a8 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -17,11 +17,15 @@ impl Plugin for MenuPlugin { Update, manage_state_entities::().run_if(state_changed::()), ) - .add_systems(Update, ( - handle_button_press::, - handle_button_press::, - handle_button_press::, - ).run_if(any_component_changed::())) + .add_systems( + Update, + ( + handle_button_press::, + handle_button_press::, + handle_button_press::, + ) + .run_if(any_component_changed::()), + ) .add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape))); } } @@ -347,7 +351,5 @@ fn handle_button_press( .filter_map(|(interaction, button_action)| { (*interaction == Interaction::Pressed).then_some(button_action) }) - .for_each(|ButtonAction(ba)| { - next_state.set(ba.clone()) - }); + .for_each(|ButtonAction(ba)| next_state.set(ba.clone())); } diff --git a/src/tutorial.rs b/src/tutorial.rs index 7369089..eb45fb2 100644 --- a/src/tutorial.rs +++ b/src/tutorial.rs @@ -182,6 +182,7 @@ fn initialize_tutorial( width: Val::Percent(33.0), max_height: Val::Percent(100.0), padding: UiRect::all(Val::Px(25.0)), + flex_direction: FlexDirection::Column, ..default() }, background_color: Color::hex(&background_hex).unwrap().into(), @@ -210,6 +211,69 @@ fn initialize_tutorial( ..default() }, )); + if *step == TutorialState::Outro { + parent + .spawn(NodeBundle { + style: Style { + flex_direction: FlexDirection::Row, + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent + .spawn(( + menu::ButtonAction(tutorial::TutorialState::None), + menu::ButtonAction(GameState::Restart), + menu::ButtonAction(menu::MenuState::None), + 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((TextBundle::from_section( + "Start Over", + TextStyle { + color: Color::BLACK, + font_size: 16.0, + ..default() + }, + ),)); + }); + + parent + .spawn(( + menu::ButtonAction(tutorial::TutorialState::None), + menu::ButtonAction(GameState::Play), + menu::ButtonAction(menu::MenuState::None), + 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((TextBundle::from_section( + "Continue Game", + TextStyle { + color: Color::BLACK, + font_size: 16.0, + ..default() + }, + ),)); + }); + }); + } }); }); }) @@ -305,7 +369,7 @@ fn step( next_state.set(next); } // After the outro, we exit the tutorial - TutorialState::Outro => next_state.set(TutorialState::None), + TutorialState::Outro => error!("Press a button!"), TutorialState::_Promotions => todo!("Not implemented yet!"), } }