use bevy::prelude::*;
use crate::despawn_with_tag;
use game_library::state::{Overlay, Settings};
use super::{
accessibility::AccessibilitySettingsMenuPlugin,
audio::AudioSettingsMenuPlugin,
base::{clear_background, transition_to_base_menu, SettingsMenuBackground, SettingsMenuEntity},
button_actions::menu_actions,
controls::ControlsSettingsMenuPlugin,
display::DisplaySettingsMenuPlugin,
events::ChangeSetting,
gameplay::GameplaySettingsMenuPlugin,
main::{show_main_menu, BaseSettingsMenuEntity},
};
pub struct SettingsMenuPlugin;
impl Plugin for SettingsMenuPlugin {
fn build(&self, app: &mut App) {
app.add_state::<Settings>();
app.add_event::<ChangeSetting>();
app.add_systems(
OnEnter(Settings::Main),
(clear_background, show_main_menu).chain(),
);
app.add_systems(
OnExit(Settings::Main),
(despawn_with_tag::<BaseSettingsMenuEntity>,),
);
app.add_systems(
OnEnter(Settings::Disabled),
(
despawn_with_tag::<SettingsMenuEntity>,
despawn_with_tag::<SettingsMenuBackground>,
),
);
app.add_plugins((
AccessibilitySettingsMenuPlugin,
AudioSettingsMenuPlugin,
ControlsSettingsMenuPlugin,
DisplaySettingsMenuPlugin,
GameplaySettingsMenuPlugin,
));
app.add_systems(Update, menu_actions.run_if(in_state(Overlay::Settings)));
app.add_systems(OnEnter(Overlay::Settings), transition_to_base_menu);
app.add_systems(OnExit(Overlay::Settings), exit_settings_menu);
}
}
fn exit_settings_menu(mut next_settings_state: ResMut<NextState<Settings>>) {
next_settings_state.set(Settings::Disabled);
}