feat: Add HUD text for shovel mode

This commit is contained in:
demenik
2025-12-09 18:33:48 +01:00
parent eb0b8ca91a
commit 50314e6c4e
2 changed files with 84 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ use crate::{features::phase::components::TimerSettings, prelude::*};
pub enum RootMarker {
Status,
Settings,
ShovelOverlay,
}
#[derive(Component)]

View File

@@ -16,12 +16,18 @@ impl Plugin for HudPlugin {
app.add_systems(OnExit(AppState::GameScreen), cleanup);
app.add_systems(
Update,
(update_status, buttons, update_timer_settings).run_if(in_state(AppState::GameScreen)),
(
update_status,
buttons,
update_timer_settings,
update_shovel_overlay_visibility,
)
.run_if(in_state(AppState::GameScreen)),
);
}
}
fn setup(mut commands: Commands) {
fn setup(mut commands: Commands, game_config: Res<GameConfig>, asset_server: Res<AssetServer>) {
commands.spawn((
RootMarker::Status,
Node {
@@ -61,6 +67,63 @@ fn setup(mut commands: Commands) {
)
],
));
// Shovel Overlay
commands.spawn((
RootMarker::ShovelOverlay,
Node {
position_type: PositionType::Absolute,
top: px(20),
left: px(0),
right: px(0),
width: percent(100),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: px(5),
..default()
},
Visibility::Hidden,
children![(
Node {
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
padding: UiRect::all(px(10)),
row_gap: px(5),
..default()
},
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.7)),
BorderRadius::all(px(10)),
children![
(
Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
column_gap: px(10),
..default()
},
children![
(
Node {
width: px(32),
height: px(32),
..default()
},
inventory::components::ItemType::Shovel
.get_sprite(&asset_server, &game_config),
ImageNode::default()
),
text("Schaufel-Modus", 20.0, Color::WHITE)
]
),
text(
"Klicke auf ein freies Feld, um es freizuschalten.",
14.0,
Color::WHITE
)
]
)],
));
}
fn update_status(phase_res: Res<CurrentPhase>, mut text_query: Query<(&mut Text, &TextType)>) {
@@ -151,3 +214,21 @@ fn update_timer_settings(
}
}
}
fn update_shovel_overlay_visibility(
inventory: Res<inventory::components::Inventory>,
item_stacks: Query<&inventory::components::ItemStack>,
mut overlay_query: Query<(&RootMarker, &mut Visibility)>,
) {
let has_shovel = inventory.has_item_type(&item_stacks, inventory::components::ItemType::Shovel);
for (marker, mut vis) in overlay_query.iter_mut() {
if let RootMarker::ShovelOverlay = marker {
*vis = if has_shovel {
Visibility::Inherited
} else {
Visibility::Hidden
};
}
}
}