use bevy::{ app::AppExit, color::palettes::css::CRIMSON, ecs::spawn::{SpawnIter, SpawnWith}, prelude::*, }; use crate::{ despawn_screen, themes::dark::{self, NORMAL_BUTTON}, DisplayQuality, AppState, Volume, }; #[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)] enum MenuState { Main, Settings, SettingsDisplay, SettingsVolume, #[default] Disabled, } pub fn menu_plugin(app: &mut App) { app .init_state::() .add_systems(OnEnter(AppState::Menu), menu_setup) .add_systems(OnEnter(MenuState::Main), main_menu_setup) .add_systems(OnExit(MenuState::Main), crate::despawn_screen::) .add_systems(OnEnter(MenuState::Settings), settings_menu_setup) .add_systems( OnExit(MenuState::Settings), crate::despawn_screen:: ) .add_systems(OnEnter(MenuState::SettingsDisplay), display_settings_menu_setup) .add_systems( Update, (setting_button::.run_if(in_state(MenuState::SettingsDisplay))) ) .add_systems( OnExit(MenuState::SettingsDisplay), despawn_screen:: ) .add_systems(OnEnter(MenuState::SettingsVolume), sound_settings_menu_setup) .add_systems( Update, (setting_button::.run_if(in_state(MenuState::SettingsVolume))) ) .add_systems( OnExit(MenuState::SettingsVolume), despawn_screen:: ) .add_systems( Update, (menu_action, button_system).run_if(in_state(AppState::Menu)) ) ; } #[derive(Component)] struct OnMainMenuScreen; #[derive(Component)] struct OnSettingsMenuScreen; #[derive(Component)] struct OnDisplaySettingsMenuScreen; #[derive(Component)] struct OnSoundSettingsMenuScreen; #[derive(Component)] struct SelectedOption; #[derive(Component)] enum MenuButtonAction { BackToMainView, BackToMainMenu, BackToSettings, Settings, SettingsDisplay, SettingsSound, Quit, } fn button_system( mut interaction_query: Query<(&Interaction, &mut BackgroundColor, Option<&SelectedOption>),(Changed, With