use crate::{settings, actor}; use bevy::prelude::*; use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}; const HUD_REFRESH_TIME: f32 = 0.5; const FONT: &str = "tmp/fonts/NotoSansSC-Thin.ttf"; pub struct HudPlugin; impl Plugin for HudPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); app.add_systems(Update, (update, handle_input)); app.insert_resource(FPSUpdateTimer( Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating))); } } #[derive(Component)] struct GaugesText; #[derive(Resource)] struct FPSUpdateTimer(Timer); fn setup( mut commands: Commands, settings: Res, asset_server: Res, ) { let visibility = if settings.hud_active { Visibility::Inherited } else { Visibility::Hidden }; 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( "\n 电量 ", 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::GRAY, ..default() } ), TextSection::new( "\n Adren水平 ", 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() } ), ]); bundle_fps.visibility = visibility; commands.spawn(( bundle_fps, GaugesText, )); } fn update( diagnostics: Res, time: Res