Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 116 additions & 135 deletions examples/state/computed_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,19 @@ mod ui {

pub fn setup_menu(mut commands: Commands, tutorial_state: Res<State<TutorialState>>) {
let button_entity = commands
.spawn(Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
..default()
})
.with_children(|parent| {
parent
.spawn((
.spawn((
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
..default()
},
children![
(
Button,
Node {
width: Val::Px(200.),
Expand All @@ -361,20 +361,16 @@ mod ui {
},
BackgroundColor(NORMAL_BUTTON),
MenuButton::Play,
))
.with_children(|parent| {
parent.spawn((
children![(
Text::new("Play"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.9, 0.9, 0.9)),
));
});

parent
.spawn((
)],
),
(
Button,
Node {
width: Val::Px(200.),
Expand All @@ -390,18 +386,17 @@ mod ui {
TutorialState::Inactive => NORMAL_BUTTON,
}),
MenuButton::Tutorial,
))
.with_children(|parent| {
parent.spawn((
children![(
Text::new("Tutorial"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.9, 0.9, 0.9)),
));
});
})
)]
),
],
))
.id();
commands.insert_resource(MenuData {
root_entity: button_entity,
Expand Down Expand Up @@ -453,75 +448,66 @@ mod ui {

pub fn setup_paused_screen(mut commands: Commands) {
info!("Printing Pause");
commands
.spawn((
StateScoped(IsPaused::Paused),
commands.spawn((
StateScoped(IsPaused::Paused),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
children![(
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
width: Val::Px(400.),
height: Val::Px(400.),
// horizontally center child text
justify_content: JustifyContent::Center,
// vertically center child text
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
))
.with_children(|parent| {
parent
.spawn((
Node {
width: Val::Px(400.),
height: Val::Px(400.),
// horizontally center child text
justify_content: JustifyContent::Center,
// vertically center child text
align_items: AlignItems::Center,
..default()
},
BackgroundColor(NORMAL_BUTTON),
MenuButton::Play,
))
.with_children(|parent| {
parent.spawn((
Text::new("Paused"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.9, 0.9, 0.9)),
));
});
});
BackgroundColor(NORMAL_BUTTON),
MenuButton::Play,
children![(
Text::new("Paused"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.9, 0.9, 0.9)),
)],
),],
));
}

pub fn setup_turbo_text(mut commands: Commands) {
commands
.spawn((
StateScoped(TurboMode),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Start,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
commands.spawn((
StateScoped(TurboMode),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Start,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
children![(
Text::new("TURBO MODE"),
TextFont {
font_size: 33.0,
..default()
},
))
.with_children(|parent| {
parent.spawn((
Text::new("TURBO MODE"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.9, 0.3, 0.1)),
));
});
TextColor(Color::srgb(0.9, 0.3, 0.1)),
)],
));
}

pub fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
Expand All @@ -536,93 +522,88 @@ mod ui {
}

pub fn movement_instructions(mut commands: Commands) {
commands
.spawn((
StateScoped(Tutorial::MovementInstructions),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::End,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
))
.with_children(|parent| {
parent.spawn((
commands.spawn((
StateScoped(Tutorial::MovementInstructions),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::End,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
children![
(
Text::new("Move the bevy logo with the arrow keys"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));
parent.spawn((
),
(
Text::new("Press T to enter TURBO MODE"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));

parent.spawn((
),
(
Text::new("Press SPACE to pause"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));

parent.spawn((
),
(
Text::new("Press ESCAPE to return to the menu"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));
});
),
],
));
}

pub fn pause_instructions(mut commands: Commands) {
commands
.spawn((
StateScoped(Tutorial::PauseInstructions),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::End,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
))
.with_children(|parent| {
parent.spawn((
commands.spawn((
StateScoped(Tutorial::PauseInstructions),
Node {
// center button
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::End,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(10.),
position_type: PositionType::Absolute,
..default()
},
children![
(
Text::new("Press SPACE to resume"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));

parent.spawn((
),
(
Text::new("Press ESCAPE to return to the menu"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.3, 0.3, 0.7)),
));
});
),
],
));
}
}