tutorial menu works

main
Elijah C. Voigt 2 years ago
parent 3091a15dea
commit aef8c719f2

@ -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()
});
});
});
}

@ -46,6 +46,7 @@ impl Plugin for GamePlugin {
PostUpdate,
(debug_board.run_if(resource_exists::<debug::DebugEnabled>()),),
)
.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<AppExit>,
) {
fn handle_quit(mut app_exit_events: EventWriter<AppExit>) {
app_exit_events.send(AppExit);
}
fn handle_restart() {
todo!("Restart is not implemented yet!");
}

@ -17,11 +17,15 @@ impl Plugin for MenuPlugin {
Update,
manage_state_entities::<MenuState>().run_if(state_changed::<MenuState>()),
)
.add_systems(Update, (
handle_button_press::<GameState>,
handle_button_press::<MenuState>,
handle_button_press::<TutorialState>,
).run_if(any_component_changed::<Interaction>()))
.add_systems(
Update,
(
handle_button_press::<GameState>,
handle_button_press::<MenuState>,
handle_button_press::<TutorialState>,
)
.run_if(any_component_changed::<Interaction>()),
)
.add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape)));
}
}
@ -347,7 +351,5 @@ fn handle_button_press<S: States + Clone + Component>(
.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()));
}

@ -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!"),
}
}

Loading…
Cancel
Save