Skip to content

Commit

Permalink
feat: showed stat of selected unit
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Oct 28, 2023
1 parent 3a05ce5 commit 406b307
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions game/src/in_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ fn setup(
},
PickableBundle::default(),
RaycastPickTarget::default(),
Health {
max: 5.0,
current: (i + 2) as f32,
},
));
}
}
Expand All @@ -90,19 +94,40 @@ fn draw_hud(mut commands: Commands, asset_server: Res<AssetServer>) {
should_emit_events: false,
},
),
|_| {},
|p| {
texti("", (), (), HealthVis, p);
},
);
}

#[derive(Component)]
struct Hud;

fn apply_seelected(q: Query<(Entity, &PickingInteraction)>) {
for (ent, p) in &q {
match p {
PickingInteraction::Pressed => println!("{ent:?}"),
PickingInteraction::Hovered => {}
PickingInteraction::None => {}
#[derive(Component)]
struct HealthVis;

#[derive(Component)]
struct Health {
max: f32,
current: f32,
}

fn apply_seelected(
q: Query<(&Health, &PickingInteraction), Changed<PickingInteraction>>,
mut texts: Query<&mut Text, With<HealthVis>>,
) {
for (health, interaction) in &q {
for mut text in &mut texts {
match interaction {
PickingInteraction::Pressed => {
text.sections = vec![TextSection {
value: format!("{} of {}", health.current, health.max),
style: TextStyle::default(),
}]
}
PickingInteraction::Hovered => {}
PickingInteraction::None => text.sections = vec![],
}
}
}
}

0 comments on commit 406b307

Please sign in to comment.