From b857d46119999dfa7b08d3ef7a1db39759c7dedc Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 15 Apr 2024 02:27:11 +0200 Subject: [PATCH] clean up HUD creation --- src/hud.rs | 194 +++++++++-------------------------------------------- 1 file changed, 32 insertions(+), 162 deletions(-) diff --git a/src/hud.rs b/src/hud.rs index 600ed25..367c63a 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -163,142 +163,34 @@ fn setup( } else { Visibility::Hidden }; + let style = TextStyle { + font: asset_server.load(FONT), + font_size: settings.font_size_hud, + color: Color::GRAY, + ..default() + }; + let style_choices = TextStyle { + font: asset_server.load(FONT), + font_size: settings.font_size_hud, + color: Color::WHITE, + ..default() + }; let mut bundle_fps = TextBundle::from_sections([ - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - " ⚡ ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - " ☣ ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - "\n氧 OXYGEN ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::MAROON, - ..default() - } - ), - TextSection::new( - "\nProximity 警告 ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - "\nSuit Integrity ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( - "\nVitals ", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - }, - ), - TextSection::new( - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), - TextSection::new( // Target - "", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::GRAY, - ..default() - } - ), + TextSection::new("", style.clone()), + TextSection::new(" ⚡ ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new(" ☣ ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("\n氧 OXYGEN ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("\nProximity 警告 ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("\nSuit Integrity ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("\nVitals ", style.clone()), + TextSection::new("", style.clone()), + TextSection::new("", style.clone()), // Target ]).with_style(Style { top: Val::VMin(2.0), left: Val::VMin(3.0), @@ -313,33 +205,9 @@ fn setup( // Add Chat Box let bundle_chatbox = TextBundle::from_sections([ - TextSection::new( - "Warning: System Log Uninitialized", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::rgb(0.7, 0.7, 0.7), - ..default() - } - ), - TextSection::new( - "\n", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::WHITE, - ..default() - } - ), - TextSection::new( - "\n\n\n", - TextStyle { - font: asset_server.load(FONT), - font_size: settings.font_size_hud, - color: Color::WHITE, - ..default() - } - ), + TextSection::new("\n\n\n", style_choices), + TextSection::new("\n", style.clone()), + TextSection::new("Warning: System Log Uninitialized", style.clone()), ]).with_style(Style { position_type: PositionType::Absolute, bottom: Val::VMin(0.0), @@ -440,9 +308,11 @@ fn update_hud( if suit.oxygen > nature::OXY_H { let oxy_hour = suit.oxygen / nature::OXY_H; text.sections[7].value = format!("{oxy_percent:.1}% [lasts {oxy_hour:.1} hours]"); + text.sections[7].style.color = Color::GRAY; } else { let oxy_min = suit.oxygen / nature::OXY_M; text.sections[7].value = format!("{oxy_percent:.1}% [lasts {oxy_min:.1} min]"); + text.sections[7].style.color = Color::MAROON; } //let adrenaline = lifeform.adrenaline * 990.0 + 10.0; //text.sections[11].value = format!("{adrenaline:.0}pg/mL");