fly_b/ui/
simul_overlay.rs1pub use bundles::lowest_row::LowestRowBundle;
2pub mod bundles;
3
4pub mod compos {
5 pub mod passed_sect_count {
6 use bevy::prelude::*;
7
8 #[derive(Default, Component)]
9 pub struct PassedSectCountDisp {
10 _priv_fields_placeholder: (),
11 }
12 }
13 pub mod motion_scale {
14 use bevy::prelude::*;
15
16 #[derive(Default, Component)]
17 pub struct MotionScaleDisp {
18 _priv_fields_placeholder: (),
19 }
20 }
21}
22pub mod sys {
23 use bevy::prelude::*;
24
25 use crate::ui::{MotionScaleDispBundle, PassedSectCountDispBundle, SimulOverlayBundle};
26
27 use super::LowestRowBundle;
28 pub fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
29 commands
30 .spawn(SimulOverlayBundle::default())
31 .with_children(|child_builder| {
32 child_builder
33 .spawn(LowestRowBundle::default())
34 .with_children(|child_builder| {
35 child_builder.spawn(PassedSectCountDispBundle::new(&asset_server));
36 child_builder.spawn(MotionScaleDispBundle::new(&asset_server));
37 });
38 });
39 }
40
41 pub fn update_passed_sect_count_disp(
42 passed_sect_count: Res<crate::misc::PassedSectCount>,
43 mut query: Query<&mut Text, With<crate::ui::PassedSectCountDisp>>,
44 ) {
45 if passed_sect_count.is_changed() {
46 for mut text in query.iter_mut() {
47 text.sections[1].value = passed_sect_count.to_string();
48 }
49 }
50 }
51 pub fn update_motion_scale_disp(
52 motion_scale: Res<crate::simul::MotionScale>,
53 mut query: Query<&mut Text, With<crate::ui::MotionScaleDisp>>,
54 ) {
55 if motion_scale.is_changed() {
56 for mut text in query.iter_mut() {
57 let ms_val_mut = &mut text.sections[1].value;
58 ms_val_mut.clear();
59 use std::fmt::Write;
60 write!(ms_val_mut, "{:.1}", **motion_scale)
61 .expect("Writing to empty string should not fail on targeted devices.");
62 }
63 }
64 }
65}
66
67use bevy::prelude::*;
68
69#[derive(Default)]
70pub struct SimulOverlayPlugin {
71 _priv_fields_placeholder: (),
72}
73impl Plugin for SimulOverlayPlugin {
74 fn build(&self, app: &mut App) {
75 app.add_systems(Startup, sys::spawn).add_systems(
76 Update,
77 (
78 sys::update_passed_sect_count_disp,
79 sys::update_motion_scale_disp,
80 ),
81 );
82 }
83}