diff --git a/examples/ecs/computed_states.rs b/examples/ecs/computed_states.rs index 888d8de79e..04d8428151 100644 --- a/examples/ecs/computed_states.rs +++ b/examples/ecs/computed_states.rs @@ -18,6 +18,8 @@ use bevy::prelude::*; +use ui::*; + // To begin, we want to define our state objects. #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] enum AppState { @@ -221,110 +223,6 @@ fn main() { .run(); } -#[derive(Resource)] -struct MenuData { - root_entity: Entity, -} - -#[derive(Component, PartialEq, Eq)] -enum MenuButton { - Play, - Tutorial, -} - -const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15); -const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25); -const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35); - -const ACTIVE_BUTTON: Color = Color::srgb(0.15, 0.85, 0.15); -const HOVERED_ACTIVE_BUTTON: Color = Color::srgb(0.25, 0.55, 0.25); -const PRESSED_ACTIVE_BUTTON: Color = Color::srgb(0.35, 0.95, 0.35); - -fn setup(mut commands: Commands) { - commands.spawn(Camera2dBundle::default()); -} - -fn setup_menu(mut commands: Commands, tutorial_state: Res>) { - let button_entity = commands - .spawn(NodeBundle { - style: Style { - // 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() - }, - ..default() - }) - .with_children(|parent| { - parent - .spawn(( - ButtonBundle { - style: Style { - width: Val::Px(200.), - height: Val::Px(65.), - // horizontally center child text - justify_content: JustifyContent::Center, - // vertically center child text - align_items: AlignItems::Center, - ..default() - }, - image: UiImage::default().with_color(NORMAL_BUTTON), - ..default() - }, - MenuButton::Play, - )) - .with_children(|parent| { - parent.spawn(TextBundle::from_section( - "Play", - TextStyle { - font_size: 40.0, - color: Color::srgb(0.9, 0.9, 0.9), - ..default() - }, - )); - }); - - parent - .spawn(( - ButtonBundle { - style: Style { - width: Val::Px(200.), - height: Val::Px(65.), - // horizontally center child text - justify_content: JustifyContent::Center, - // vertically center child text - align_items: AlignItems::Center, - ..default() - }, - image: UiImage::default().with_color(match tutorial_state.get() { - TutorialState::Active => ACTIVE_BUTTON, - TutorialState::Inactive => NORMAL_BUTTON, - }), - ..default() - }, - MenuButton::Tutorial, - )) - .with_children(|parent| { - parent.spawn(TextBundle::from_section( - "Tutorial", - TextStyle { - font_size: 40.0, - color: Color::srgb(0.9, 0.9, 0.9), - ..default() - }, - )); - }); - }) - .id(); - commands.insert_resource(MenuData { - root_entity: button_entity, - }); -} - fn menu( mut next_state: ResMut>, tutorial_state: Res>, @@ -379,23 +277,9 @@ fn menu( } } -fn cleanup_menu(mut commands: Commands, menu_data: Res) { - commands.entity(menu_data.root_entity).despawn_recursive(); -} - #[derive(Component)] struct StateBound(S); -fn setup_game(mut commands: Commands, asset_server: Res) { - commands.spawn(( - StateBound(InGame), - SpriteBundle { - texture: asset_server.load("branding/icon.png"), - ..default() - }, - )); -} - fn clear_state_bound_entities( state: S, ) -> impl Fn(Commands, Query<(Entity, &StateBound)>) { @@ -409,37 +293,6 @@ fn clear_state_bound_entities( } } -const SPEED: f32 = 100.0; -const TURBO_SPEED: f32 = 300.0; -fn movement( - time: Res