use bevy::window::PrimaryWindow; use crate::prelude::*; pub(crate) struct UiPlugin; impl Plugin for UiPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, initialize); app.add_systems(OnEnter(GameState::Menu), sync_display_mode); app.add_systems( Update, ( toggle_display_mode.run_if(any_component_changed::), sync_display_mode .run_if(state_changed::()) .run_if(in_state(GameState::Menu)), sync_display_mode .run_if(state_changed::()) .run_if(in_state(GameState::Play)), manage_cursor.run_if(any_component_changed::), interactive_button.run_if(any_component_changed::), ), ); } } #[derive(Debug, Component)] struct UiRoot; fn initialize(mut commands: Commands) { commands .spawn(( NodeBundle { style: Style { position_type: PositionType::Absolute, right: Val::Px(5.0), bottom: Val::Px(5.0), ..default() }, background_color: Color::WHITE.into(), visibility: Visibility::Hidden, ..default() }, UiRoot, )) .with_children(|parent| { parent.spawn(( ButtonBundle { style: Style { width: Val::Px(25.0), height: Val::Px(25.0), ..default() }, background_color: Color::WHITE.into(), ..default() }, DisplayState::Display2d, )); }); } /// When button is clicked, switch display state to that state and hide the other option. /// Display2d -> Click -> Display2d mode & Display3d butto fn toggle_display_mode( events: Query<(&Interaction, &DisplayState), (Changed, With