refactor: Combine two UiStatusText components into one enum

This commit is contained in:
demenik
2025-11-26 20:08:55 +01:00
parent 3b7bfb17e1
commit b63b2d060d
2 changed files with 14 additions and 17 deletions

View File

@@ -1,3 +1,5 @@
use std::thread::current;
use crate::features::savegame::messages::SavegameDumpMessage; use crate::features::savegame::messages::SavegameDumpMessage;
use crate::prelude::*; use crate::prelude::*;
@@ -34,13 +36,13 @@ fn setup(mut commands: Commands) {
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)),
children![ children![
( (
UiPhaseText, UiStatusText::Phase,
Text::new("..."), Text::new("..."),
TextFont::from_font_size(16.0), TextFont::from_font_size(16.0),
TextColor(Color::WHITE) TextColor(Color::WHITE)
), ),
( (
UiTimerText, UiStatusText::Timer,
Text::new("--:--"), Text::new("--:--"),
TextFont::from_font_size(16.0), TextFont::from_font_size(16.0),
TextColor(Color::WHITE) TextColor(Color::WHITE)
@@ -59,22 +61,17 @@ fn setup(mut commands: Commands) {
)); ));
} }
fn update_status( fn update_status(phase_res: Res<CurrentPhase>, mut text_query: Query<(&mut Text, &UiStatusText)>) {
phase_res: Res<CurrentPhase>,
mut phase_query: Query<&mut Text, (With<UiPhaseText>, Without<UiTimerText>)>,
mut timer_query: Query<&mut Text, (With<UiTimerText>, Without<UiPhaseText>)>,
) {
if !phase_res.is_changed() { if !phase_res.is_changed() {
return; return;
} }
let current_phase = &phase_res.0; let current_phase = &phase_res.0;
if let Ok(mut phase_text) = phase_query.single_mut() { for (mut text, status_type) in text_query.iter_mut() {
phase_text.0 = current_phase.display_name().to_string(); text.0 = match status_type {
} UiStatusText::Phase => current_phase.display_name().into(),
UiStatusText::Timer => current_phase.format_duration(),
if let Ok(mut timer_text) = timer_query.single_mut() { };
timer_text.0 = current_phase.format_duration();
} }
} }

View File

@@ -4,10 +4,10 @@ use crate::prelude::*;
pub struct UiStatusRootContainer; pub struct UiStatusRootContainer;
#[derive(Component)] #[derive(Component)]
pub struct UiPhaseText; pub enum UiStatusText {
Phase,
#[derive(Component)] Timer,
pub struct UiTimerText; }
#[derive(Component)] #[derive(Component)]
pub enum UiStatusButton { pub enum UiStatusButton {