diff --git a/src/game/mod.rs b/src/game/mod.rs index 02dda3b..e4efe5d 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -6,6 +6,7 @@ mod runtime; mod seed; mod setup; pub mod state; +mod ui; #[allow(unused_imports)] pub mod prelude { diff --git a/src/game/plugin.rs b/src/game/plugin.rs index 27242d6..8929879 100644 --- a/src/game/plugin.rs +++ b/src/game/plugin.rs @@ -9,8 +9,11 @@ use super::{ net::{handle_deleted_peer, handle_incoming_packets, handle_new_peer}, runtime::{move_camera, move_player, quit, zoom_camera}, seed::Seed, - setup::{check_for_seed, setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls}, + setup::{ + check_for_seed, setup_balls, setup_camera, setup_from_seed, setup_player, setup_walls, + }, state::AppState, + ui::{setup_seed_display, update_seed_display}, }; #[derive(Debug, Clone, Copy)] @@ -56,7 +59,7 @@ impl Plugin for GamePlugin { PhysicsPlugins::default().with_length_unit(50.0), )) .init_state::() - .add_systems(Startup, setup_ui) + .add_systems(Startup, (setup_camera, setup_seed_display)) .add_systems( OnEnter(AppState::InGame), ( @@ -81,6 +84,7 @@ impl Plugin for GamePlugin { ( ((move_player, move_camera).chain(), zoom_camera) .run_if(in_state(AppState::InGame)), + update_seed_display, quit.run_if(input_pressed(KeyCode::KeyQ)), ), ); diff --git a/src/game/setup.rs b/src/game/setup.rs index 0a2f15b..eb4585c 100644 --- a/src/game/setup.rs +++ b/src/game/setup.rs @@ -43,7 +43,7 @@ pub fn setup_from_seed(mut commands: Commands, seed: Res) { } /// I mean, a camera is technically a user interface, I guess -pub fn setup_ui(mut commands: Commands) { +pub fn setup_camera(mut commands: Commands) { commands.spawn((Name::new("Camera"), Camera2d, IsDefaultUiCamera)); } diff --git a/src/game/ui.rs b/src/game/ui.rs new file mode 100644 index 0000000..ad05109 --- /dev/null +++ b/src/game/ui.rs @@ -0,0 +1,31 @@ +use bevy::prelude::*; + +use super::seed::Seed; + +#[derive(Component, Debug)] +pub struct SeedUI; + +pub fn setup_seed_display(mut commands: Commands) { + commands + .spawn(( + Text::new("Seed: "), + Node { + position_type: PositionType::Absolute, + bottom: Val::Px(5.0), + left: Val::Px(5.0), + ..Default::default() + }, + )) + .with_child((TextSpan::new(""), SeedUI)); +} + +pub fn update_seed_display(seed: Option>, text: Query<&mut TextSpan, With>) { + if let Some(value) = seed { + if value.is_changed() { + for mut span in text { + let number: u64 = (*value).into(); + **span = format!("{}", number); + } + } + } +}