use bevy::{color::palettes, diagnostic::DiagnosticsStore, prelude::*}; use vleue_navigator::prelude::*; #[derive(Component)] pub enum UiSettings { Simplify, MergeSteps, AgentRadius, AgentRadiusOuter, Cache, } #[derive(Component)] pub enum UiSettingsButtons { SimplifyInc, SimplifyDec, MergeStepsInc, MergeStepsDec, AgentRadiusInc, AgentRadiusDec, AgentRadiusOuterToggle, ToggleCache, } #[derive(Resource, Default)] pub struct ExampleSettings { pub cache_enabled: bool, } fn button(text: &str, action: UiSettingsButtons, parent: &mut ChildBuilder) { parent .spawn(( ButtonBundle { style: Style { margin: UiRect::all(Val::Px(5.0)), border: UiRect::all(Val::Px(1.0)), justify_content: JustifyContent::Center, height: Val::Px(30.0), align_items: AlignItems::Center, ..default() }, border_color: BorderColor(palettes::tailwind::GRAY_500.into()), border_radius: BorderRadius::MAX, background_color: palettes::tailwind::GRAY_700.into(), ..default() }, action, )) .with_children(|parent| { parent.spawn(TextBundle::from_section( text, TextStyle { font_size: 20.0, ..default() }, )); }); } pub fn setup_settings(mut commands: Commands) { commands.init_resource::(); commands .spawn(( NodeBundle { style: Style { position_type: PositionType::Absolute, right: Val::Px(0.0), flex_direction: FlexDirection::Column, ..default() }, border_radius: BorderRadius { top_left: Val::Px(0.), top_right: Val::Px(0.), bottom_left: Val::Px(20.0), bottom_right: Val::Px(0.), }, background_color: BackgroundColor( palettes::tailwind::GRAY_900.with_alpha(0.8).into(), ), ..default() }, Ui, )) .with_children(|parent| { parent .spawn(NodeBundle { ..default() }) .with_children(|parent| { parent.spawn(( TextBundle { text: Text::from_sections( [("Simplify: ", 30.0), ("{}", 30.0)].into_iter().map( |(text, font_size): (&str, f32)| { TextSection::new( text, TextStyle { font_size, ..default() }, ) }, ), ), style: Style { margin: UiRect::all(Val::Px(12.0)), ..default() }, ..default() } .with_text_justify(JustifyText::Right), UiSettings::Simplify, )); button(" - ", UiSettingsButtons::SimplifyDec, parent); button(" + ", UiSettingsButtons::SimplifyInc, parent); }); parent .spawn(NodeBundle { ..default() }) .with_children(|parent| { parent.spawn(( TextBundle { text: Text::from_sections( [("Merge Steps: ", 30.0), ("{}", 30.0)].into_iter().map( |(text, font_size): (&str, f32)| { TextSection::new( text, TextStyle { font_size, ..default() }, ) }, ), ), style: Style { margin: UiRect::all(Val::Px(12.0)), ..default() }, ..default() } .with_text_justify(JustifyText::Right), UiSettings::MergeSteps, )); button(" - ", UiSettingsButtons::MergeStepsDec, parent); button(" + ", UiSettingsButtons::MergeStepsInc, parent); }); parent .spawn(NodeBundle { ..default() }) .with_children(|parent| { parent.spawn(( TextBundle { text: Text::from_sections( [("Agent Radius: ", 30.0), ("{}", 30.0)].into_iter().map( |(text, font_size): (&str, f32)| { TextSection::new( text, TextStyle { font_size, ..default() }, ) }, ), ), style: Style { margin: UiRect::all(Val::Px(12.0)), ..default() }, ..default() } .with_text_justify(JustifyText::Right), UiSettings::AgentRadius, )); button(" - ", UiSettingsButtons::AgentRadiusDec, parent); button(" + ", UiSettingsButtons::AgentRadiusInc, parent); }); parent .spawn(( ButtonBundle { style: Style { margin: UiRect::px(30.0, 30.0, 10.0, 30.0), border: UiRect::all(Val::Px(1.0)), justify_content: JustifyContent::Center, height: Val::Px(30.0), align_items: AlignItems::Center, ..default() }, border_color: BorderColor(palettes::tailwind::GRAY_500.into()), border_radius: BorderRadius::all(Val::Px(10.0)), image: UiImage::default().with_color(palettes::tailwind::GRAY_700.into()), ..default() }, UiSettingsButtons::AgentRadiusOuterToggle, UiSettings::AgentRadiusOuter, )) .with_children(|parent| { parent.spawn(TextBundle::from_section( "Agent Radius on Outer Edges", TextStyle { font_size: 20.0, ..default() }, )); }); if WITH_CACHE { parent .spawn(( ButtonBundle { style: Style { margin: UiRect::px(30.0, 30.0, 10.0, 30.0), border: UiRect::all(Val::Px(1.0)), justify_content: JustifyContent::Center, height: Val::Px(30.0), align_items: AlignItems::Center, ..default() }, border_color: BorderColor(palettes::tailwind::GRAY_500.into()), border_radius: BorderRadius::all(Val::Px(10.0)), image: UiImage::default() .with_color(palettes::tailwind::GRAY_700.into()), ..default() }, UiSettingsButtons::ToggleCache, UiSettings::Cache, )) .with_children(|parent| { parent.spawn(TextBundle::from_section( "Cache", TextStyle { font_size: 20.0, ..default() }, )); }); } }); } pub fn display_settings( settings: Query>, example_settings: Res, mut texts: Query<(&mut Text, &UiSettings)>, mut buttons: Query<(&mut BackgroundColor, &UiSettings), With