diff --git a/src/features/hud/components.rs b/src/features/hud/components.rs new file mode 100644 index 0000000..ea70282 --- /dev/null +++ b/src/features/hud/components.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; + +#[derive(Component)] +pub enum RootMarker { + Status, + Settings, +} + +#[derive(Component)] +pub enum TextType { + Phase, + Timer, +} + +#[derive(Component)] +pub enum ButtonType { + SavegameDump, + SettingsOpen, + SettingsClose, +} diff --git a/src/features/status/mod.rs b/src/features/hud/mod.rs similarity index 66% rename from src/features/status/mod.rs rename to src/features/hud/mod.rs index 79e123c..663158c 100644 --- a/src/features/status/mod.rs +++ b/src/features/hud/mod.rs @@ -1,23 +1,24 @@ use crate::features::savegame::messages::SavegameDumpMessage; use crate::prelude::*; +use components::*; -pub struct StatusPlugin; +pub mod components; +pub mod ui; -impl Plugin for StatusPlugin { +pub struct HudPlugin; + +impl Plugin for HudPlugin { fn build(&self, app: &mut App) { app.add_systems(OnEnter(AppState::GameScreen), setup); app.add_systems(OnExit(AppState::GameScreen), cleanup); app.add_systems(Update, update_status.run_if(in_state(AppState::GameScreen))); - app.add_systems( - Update, - status_buttons.run_if(in_state(AppState::GameScreen)), - ); + app.add_systems(Update, buttons.run_if(in_state(AppState::GameScreen))); } } fn setup(mut commands: Commands) { commands.spawn(( - UiStatusRootContainer, + RootMarker::Status, Node { position_type: PositionType::Absolute, bottom: px(0), @@ -34,23 +35,23 @@ fn setup(mut commands: Commands) { BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), children![ ( - UiStatusText::Phase, + TextType::Phase, Text::new("..."), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ), ( - UiStatusText::Timer, + TextType::Timer, Text::new("--:--"), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ), ( Button, - UiStatusButton::SavegameDump, + ButtonType::SettingsOpen, Node::default(), children![ - Text::new("Save"), + Text::new("Einstellungen"), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ] @@ -59,7 +60,7 @@ fn setup(mut commands: Commands) { )); } -fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &UiStatusText)>) { +fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &TextType)>) { if !phase_res.is_changed() { return; } @@ -67,32 +68,27 @@ fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, for (mut text, status_type) in text_query.iter_mut() { text.0 = match status_type { - UiStatusText::Phase => current_phase.display_name().into(), - UiStatusText::Timer => current_phase.format_duration(), + TextType::Phase => current_phase.display_name().into(), + TextType::Timer => current_phase.format_duration(), }; } } -fn status_buttons( - mut interaction_query: Query< - (&Interaction, &UiStatusButton), - (Changed, With