use bevy::prelude::*;
use game_library::font_resource::FontResource;
use game_library::state::Settings;
use crate::{despawn_with_tag, resources::style_prefab};
use super::{
base::SettingsMenuEntity,
button_actions::{ButtonAction, SettingsMenuButton},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Component)]
struct ControlsSettingsMenuEntity;
fn show_controls_settings(mut commands: Commands, fonts: Res<FontResource>) {
commands
.spawn((
style_prefab::settings_menu_full_node_bundle(),
ControlsSettingsMenuEntity,
SettingsMenuEntity,
))
.with_children(|parent| {
parent.spawn(style_prefab::settings_menu_title_bundle(
"Controls",
fonts.display_font.clone(),
));
parent
.spawn(style_prefab::settings_menu_column_node_bundle())
.with_children(|menu_buttons| {
menu_buttons
.spawn((
style_prefab::menu_button_bundle(),
ButtonAction::BackToMenu,
SettingsMenuButton,
))
.with_children(|button| {
button.spawn(style_prefab::menu_button_text(
"Back",
fonts.interface_font.clone(),
));
});
});
});
}
pub(super) struct ControlsSettingsMenuPlugin;
impl Plugin for ControlsSettingsMenuPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(Settings::Controls), show_controls_settings);
app.add_systems(
OnExit(Settings::Controls),
despawn_with_tag::<ControlsSettingsMenuEntity>,
);
}
}