diff --git a/src/game.rs b/src/game.rs index 16fc96d..5107247 100644 --- a/src/game.rs +++ b/src/game.rs @@ -747,9 +747,15 @@ fn handle_race( mut ew_sfx: EventWriter, mut ew_achievement: EventWriter, q_player: Query<(&Position, &LinearVelocity, &Transform), With>, + mut q_scoredisplay: Query<&mut Text, With>, + mut q_scorewrapper: Query<&mut Visibility, With>, mut q_racetarget: Query< (Entity, &mut Position, &mut LinearVelocity, &mut Visibility), - (With, Without), + ( + With, + Without, + Without, + ), >, ) { let mut deinitialize = false; @@ -785,10 +791,19 @@ fn handle_race( race.score = 0.0; race.initialized = true; spawn_target = true; + if let Ok(mut text) = q_scoredisplay.get_single_mut() { + text.sections[0].value = race.score.to_string(); + } + if let Ok(mut vis) = q_scorewrapper.get_single_mut() { + *vis = Visibility::Inherited; + } } if player_pos.distance(target_pos.0) < RACE_TARGET_RADIUS { race.score += 1.0; + if let Ok(mut text) = q_scoredisplay.get_single_mut() { + text.sections[0].value = race.score.to_string(); + } spawn_target = true; } @@ -823,5 +838,8 @@ fn handle_race( settings.race_active = false; *target_vis = Visibility::Hidden; commands.entity(target_entity).remove::(); + if let Ok(mut vis) = q_scorewrapper.get_single_mut() { + *vis = Visibility::Hidden; + } } } diff --git a/src/hud.rs b/src/hud.rs index 157da1b..a430c12 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -147,6 +147,10 @@ struct Speedometer2; #[derive(Component)] struct GaugeLength(f32); #[derive(Component)] +pub struct SkyRaceScoreWrapper; +#[derive(Component)] +pub struct SkyRaceScoreDisplay; +#[derive(Component)] pub struct ToggleableHudElement; #[derive(Component)] pub struct ToggleableHudMapElement; @@ -389,6 +393,12 @@ pub fn setup( color: settings.hud_color_speedometer, ..default() }; + let style_skyrace = TextStyle { + font: font_handle.clone(), + font_size: settings.font_size_skyrace_score, + color: settings.hud_color_skyrace_score, + ..default() + }; let style = TextStyle { font: font_handle, font_size: settings.font_size_hud, @@ -742,6 +752,47 @@ pub fn setup( )); }); + // SkyRace score display + commands + .spawn(( + NodeBundle { + style: Style { + width: Val::Vw(100.0), + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + position_type: PositionType::Absolute, + top: Val::Vh(10.0), + left: Val::Px(0.0), + ..default() + }, + visibility: Visibility::Hidden, + ..default() + }, + SkyRaceScoreWrapper, + )) + .with_children(|builder| { + builder.spawn(( + TextBundle { + text: Text { + sections: vec![TextSection::new("skyrace-score", style_skyrace)], + justify: JustifyText::Center, + ..default() + }, + style: Style { + max_width: Val::Percent(50.0), + margin: UiRect { + top: Val::Vh(1.0), + ..default() + }, + ..default() + }, + ..default() + }, + SkyRaceScoreDisplay, + ToggleableHudElement, + )); + }); + // Selectagon let mut entitycmd = commands.spawn(( Selectagon, diff --git a/src/var.rs b/src/var.rs index 07cf0b0..978e0bc 100644 --- a/src/var.rs +++ b/src/var.rs @@ -58,6 +58,7 @@ pub struct Settings { pub font_size_choices: f32, pub font_size_console: f32, pub font_size_speedometer: f32, + pub font_size_skyrace_score: f32, pub font_size_deathtext: f32, pub font_size_deathsubtext: f32, pub font_size_deathpoem: f32, @@ -77,6 +78,7 @@ pub struct Settings { pub hud_color_subtitles: Color, pub hud_color_choices: Color, pub hud_color_speedometer: Color, + pub hud_color_skyrace_score: Color, pub hud_color_deathpoem: Color, pub hud_color_achievement: Color, pub hud_color_achievement_header: Color, @@ -206,6 +208,7 @@ impl Default for Settings { font_size_choices: 28.0, font_size_console: 20.0, font_size_speedometer: 34.0, + font_size_skyrace_score: 64.0, font_size_deathtext: 64.0, font_size_deathsubtext: 32.0, font_size_deathpoem: 18.0, @@ -225,6 +228,7 @@ impl Default for Settings { hud_color_subtitles: Srgba::hex(COLOR_SECONDARY).unwrap().into(), hud_color_choices: Srgba::hex(COLOR_BODY).unwrap().into(), hud_color_speedometer: Srgba::hex(COLOR_PRIMARY).unwrap().into(), + hud_color_skyrace_score: Srgba::hex(COLOR_PRIMARY).unwrap().into(), hud_color_deathpoem: Srgba::hex("#CC2200").unwrap().into(), hud_color_achievement: Srgba::hex(COLOR_DIM).unwrap().into(), hud_color_achievement_accomplished: Srgba::hex(COLOR_SUCCESS).unwrap().into(),