refactor: Move status to hud

This commit is contained in:
demenik
2025-11-27 17:33:37 +01:00
parent 3e04c71e9d
commit 2a17d161f3
8 changed files with 48 additions and 45 deletions

View File

@@ -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,
}

View File

@@ -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<CurrentPhase>, mut text_query: Query<(&mut Text, &UiStatusText)>) {
fn update_status(phase_res: Res<CurrentPhase>, mut text_query: Query<(&mut Text, &TextType)>) {
if !phase_res.is_changed() {
return;
}
@@ -67,32 +68,27 @@ fn update_status(phase_res: Res<CurrentPhase>, 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<Interaction>, With<Button>),
>,
mut savegamedump_messages: MessageWriter<SavegameDumpMessage>,
fn buttons(
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
) {
for (interaction, button_type) in &mut interaction_query {
match *interaction {
Interaction::Pressed => match button_type {
UiStatusButton::SavegameDump => {
savegamedump_messages.write(SavegameDumpMessage);
}
ButtonType::SettingsOpen => {}
_ => {}
},
_ => {}
}
}
}
fn cleanup(mut commands: Commands, query: Query<Entity, With<UiStatusRootContainer>>) {
fn cleanup(mut commands: Commands, query: Query<Entity, With<RootMarker>>) {
for entity in query.iter() {
commands.entity(entity).despawn();
}

View File

@@ -0,0 +1 @@
pub mod settings;

View File

@@ -0,0 +1,3 @@
use crate::prelude::*;
pub fn open_settings(commands: &mut Commands) {}

View File

@@ -2,21 +2,21 @@ pub mod config;
pub mod core;
pub mod game_screen;
pub mod grid;
pub mod hud;
pub mod input;
pub mod phase;
pub mod pom;
pub mod savegame;
pub mod start_screen;
pub mod status;
pub mod ui;
pub use core::CorePlugin;
pub use game_screen::GameScreenPlugin;
pub use grid::GridPlugin;
pub use hud::HudPlugin;
pub use input::InputPlugin;
pub use phase::PhasePlugin;
pub use pom::PomPlugin;
pub use savegame::SavegamePlugin;
pub use start_screen::StartScreenPlugin;
pub use status::StatusPlugin;
pub use ui::UiPlugin;

View File

@@ -6,17 +6,3 @@ pub struct Scroll {
pub entity: Entity,
pub delta: Vec2,
}
#[derive(Component)]
pub struct UiStatusRootContainer;
#[derive(Component)]
pub enum UiStatusText {
Phase,
Timer,
}
#[derive(Component)]
pub enum UiStatusButton {
SavegameDump,
}

View File

@@ -29,7 +29,7 @@ fn main() {
features::PomPlugin,
features::InputPlugin,
features::PhasePlugin,
features::StatusPlugin,
features::HudPlugin,
features::SavegamePlugin,
features::UiPlugin,
))

View File

@@ -13,10 +13,7 @@ pub use crate::features::{
messages::{InteractStartMessage, MoveMessage},
},
savegame::components::SavegamePath,
ui::{
components::{UiStatusButton, UiStatusRootContainer, UiStatusText},
consts::*,
},
ui::consts::*,
};
pub use crate::utils::path::get_internal_path;
pub use bevy::prelude::*;