From 31fd4b64953cd902125c05af43927e0cb751be12 Mon Sep 17 00:00:00 2001 From: Paulo Bressan Date: Tue, 23 Apr 2024 05:50:29 -0300 Subject: [PATCH] Dynamic hud (#43) * feat: added dynamic ship hud * chore: added new pixel font with dynamic size * feat: added position and fuel available * chore: refactor folders * chore: asteroid hud and folder refactor --- Cargo.lock | 203 ++++++++++++++++++ visualizer/Cargo.toml | 9 +- visualizer/assets/fonts/pixel.otf | Bin 0 -> 37268 bytes visualizer/src/asteroid/hud.rs | 148 +++++++++++++ .../src/{asteroid.rs => asteroid/mod.rs} | 12 +- visualizer/src/main.rs | 12 +- visualizer/src/{map.rs => map/mod.rs} | 4 + visualizer/src/ships/hud.rs | 174 +++++++++++++++ visualizer/src/{ships.rs => ships/mod.rs} | 24 ++- 9 files changed, 572 insertions(+), 14 deletions(-) create mode 100644 visualizer/assets/fonts/pixel.otf create mode 100644 visualizer/src/asteroid/hud.rs rename visualizer/src/{asteroid.rs => asteroid/mod.rs} (85%) rename visualizer/src/{map.rs => map/mod.rs} (97%) create mode 100644 visualizer/src/ships/hud.rs rename visualizer/src/{ships.rs => ships/mod.rs} (86%) diff --git a/Cargo.lock b/Cargo.lock index d605bcf..9745706 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -496,6 +496,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65b9eadaacf8fe971331bc3f250f35c18bc9dace3f96b483062f38ac07e3a1b4" dependencies = [ + "bevy_dylib", "bevy_internal", ] @@ -672,6 +673,15 @@ dependencies = [ "sysinfo", ] +[[package]] +name = "bevy_dylib" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "922826e3b8f37c19836b49e18ceca662260cce87ab8faa4db6df8433903660cc" +dependencies = [ + "bevy_internal", +] + [[package]] name = "bevy_ecs" version = "0.13.2" @@ -714,6 +724,30 @@ dependencies = [ "encase_derive_impl", ] +[[package]] +name = "bevy_eventlistener" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9d65c75b4f81818cacdc8a4302c5413910c5fb7727564deaf95e56e0dea4bd0" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_eventlistener_derive", + "bevy_hierarchy", + "bevy_utils", +] + +[[package]] +name = "bevy_eventlistener_derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa29be733a02a5d7ca4507ef15f294711c1a0884b9a9a2730640ff4e7d0200ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "bevy_gilrs" version = "0.13.2" @@ -910,6 +944,54 @@ dependencies = [ "glam", ] +[[package]] +name = "bevy_mod_picking" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d79f17a34025d95e2e3525207ec73090647c6f40c3136fc674f87e167a9ae6be" +dependencies = [ + "bevy_app", + "bevy_core", + "bevy_core_pipeline", + "bevy_ecs", + "bevy_eventlistener", + "bevy_math", + "bevy_picking_core", + "bevy_picking_highlight", + "bevy_picking_input", + "bevy_picking_raycast", + "bevy_picking_selection", + "bevy_picking_sprite", + "bevy_picking_ui", + "bevy_reflect", + "bevy_render", + "bevy_text", + "bevy_ui", + "bevy_utils", + "bevy_window", +] + +[[package]] +name = "bevy_mod_raycast" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca646aeaab4a170e1f3e8284b925e2f990eb18616e95d7826c873c8e26ee945" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_derive", + "bevy_ecs", + "bevy_gizmos", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_sprite", + "bevy_transform", + "bevy_utils", + "bevy_window", + "crossbeam-channel", +] + [[package]] name = "bevy_pancam" version = "0.11.1" @@ -953,6 +1035,126 @@ dependencies = [ "thread_local", ] +[[package]] +name = "bevy_picking_core" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c8cdca408508a7d006bf077c6cbb6660a65895323333f206b7cce7b801a8e2" +dependencies = [ + "bevy_app", + "bevy_derive", + "bevy_ecs", + "bevy_eventlistener", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_transform", + "bevy_utils", + "bevy_window", +] + +[[package]] +name = "bevy_picking_highlight" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e684569b5f7dae06d1ff66e2287cee808b3862d9ae0d01dbe114d7d199d40cfd" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_ecs", + "bevy_pbr", + "bevy_picking_core", + "bevy_picking_selection", + "bevy_reflect", + "bevy_render", + "bevy_sprite", +] + +[[package]] +name = "bevy_picking_input" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60182209f48943de6c8bc3305a70f52012a18ef26f92f460f9436441b8badf0b" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_hierarchy", + "bevy_input", + "bevy_math", + "bevy_picking_core", + "bevy_picking_selection", + "bevy_reflect", + "bevy_render", + "bevy_utils", + "bevy_window", +] + +[[package]] +name = "bevy_picking_raycast" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2677d0a3402fea3327a216649c104f969685a5c01d969d274c89facba86c164d" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_mod_raycast", + "bevy_picking_core", + "bevy_reflect", + "bevy_render", + "bevy_transform", + "bevy_window", +] + +[[package]] +name = "bevy_picking_selection" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc986eefd38058918322418d1e6ae398e74d48730e623a55dc20be78d5ee24b" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_eventlistener", + "bevy_input", + "bevy_picking_core", + "bevy_reflect", + "bevy_utils", +] + +[[package]] +name = "bevy_picking_sprite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ac5309026e8c7f5aed2afec3aa2f21fb0a0487e9bb3d851860377891459df75" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_ecs", + "bevy_math", + "bevy_picking_core", + "bevy_render", + "bevy_sprite", + "bevy_transform", + "bevy_window", +] + +[[package]] +name = "bevy_picking_ui" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ad6d40e33203115af38adc984341cf5637911baa940028b6a43a9917d64e79" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_hierarchy", + "bevy_math", + "bevy_picking_core", + "bevy_render", + "bevy_transform", + "bevy_ui", + "bevy_utils", + "bevy_window", +] + [[package]] name = "bevy_prng" version = "0.5.2" @@ -5239,6 +5441,7 @@ name = "visualizer" version = "0.1.0" dependencies = [ "bevy", + "bevy_mod_picking", "bevy_pancam", "bevy_panorbit_camera", "bevy_rand", diff --git a/visualizer/Cargo.toml b/visualizer/Cargo.toml index d875dc3..ceb3546 100644 --- a/visualizer/Cargo.toml +++ b/visualizer/Cargo.toml @@ -6,12 +6,19 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = "0.13.2" +bevy = { version = "0.13.2", features = ["dynamic_linking"] } bevy_pancam = "0.11.1" bevy_panorbit_camera = "0.17.0" rand = "0.8.5" rand_core = "0.6" bevy_rand = { version = "0.5", features = ["rand_chacha", "wyrand"] } +bevy_mod_picking = "0.18.2" [target.wasm32-unknown-unknown] runner = "wasm-server-runner" + +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 3 diff --git a/visualizer/assets/fonts/pixel.otf b/visualizer/assets/fonts/pixel.otf new file mode 100644 index 0000000000000000000000000000000000000000..20a3100fb5a778e03bf130027ce1b1c01444e24b GIT binary patch literal 37268 zcmchA31C#!)&G5Owj@AU6ZSX>Ap>E{PFO_9#v)6E0J3UG0tQ2ZAt+cs>ssQ5*0vTE zcUx^;t7xlriPlzHEw$QO6r27zzP9x*#wAJ(`!?`z+*H18vzcBBP-6@Z?%MKA zReOC&dAPqrDd+i{>$Wt2ZUgWQ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g$z^H8V4Ba$^l0!hKZnM z0)Ube8bqKxP&FcXNv2SjXK_>6S|vV$0dJtpA1Y&$^mLGD1wDdFMbJh9m>7XhZBb|n zF2Fy*Cz{s+M1yFR;95YeBPpD2lSFF@g-i%URASpG5JLsRp_rrq$-xR0xCYmV15~74 z%d%|Ru4K=$^CjXfe8*w}^x6rRB?C=>ki-K5S>SQx2#5WX{GrD~O^1DlL#uJ{O~Uu@ zem*|z4?PxGjk7QC7~Y{x2cNow7a@4yHuN|^54&4_n#iYi$ELTlJF(!uiqk&$ok{p7 zzNedVN++|B%<1;UaQh4u4haL4w!`GVhs`3(;F|3<&U|x5=XP{=EOADB1?Eb#Lu{f| zi`O$Yq((J(7TaB6wGotJdl2W>#I}3h`>M4Y7D~4(CFtj{hyaq2lQGiribfsL=-E&U zg=x=03L(Zv^P?$9EQGmAk3#Jr4zt^2?2O!?6#n_}S!@KuU*xpRM8>IfM6m^QSd7si z0bg-U1R@DOOtsiByAhrlsK7Rte%bZ46WsNt0?zm{22jzW5Zmg`%o+l#APpT}5aiET zrOfHO60Y8WL44MboCZiy!*&=dz#pg-HZ{fU5crEN%>n{+r^PvJN6sa#yBv=EfJ`-%Sd~;xi9INP!~hK8skwc^{F~S=13rifRv;hIV#H1RpA#`-B)o zDVTPb52T+w7)|RLo5G_VjbHZhGhYyGz!OQ59B7M-8#*E})X3~dSGoyi>3GbYLsA7e z@DpQyV3mbeQZub(?i$k5UaR~!0~`?Kk$^A)X&nR*3)6EeU5}6V#@}*F^98rKo8KGs KWdi<#z5fSo7^(aK literal 0 HcmV?d00001 diff --git a/visualizer/src/asteroid/hud.rs b/visualizer/src/asteroid/hud.rs new file mode 100644 index 0000000..8e10442 --- /dev/null +++ b/visualizer/src/asteroid/hud.rs @@ -0,0 +1,148 @@ +use bevy::prelude::*; +use bevy_mod_picking::prelude::*; + +use crate::map::{AsteroidIdentity, Fuel, Position}; + +#[derive(States, Debug, Clone, Eq, PartialEq, Hash)] +pub struct HudState(pub Option); + +pub fn render_hud( + mut commands: Commands, + query: Query<(Option<&PickingInteraction>, &Position, &Fuel), With>, + asset_server: Res, + mut state: ResMut>, +) { + let text_style = TextStyle { + font: asset_server.load("fonts/pixel.otf"), + font_size: 32.0, + color: Color::GOLD, + }; + + for (i, p, f) in &query { + if let Some(PickingInteraction::Pressed) = i { + state.set(HudState(Some( + commands + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(50.), + height: Val::Percent(30.), + border: UiRect::all(Val::Px(2.)), + flex_wrap: FlexWrap::Wrap, + padding: UiRect::all(Val::Px(12.)), + ..default() + }, + background_color: Color::rgba(0., 0., 0., 0.8).into(), + border_color: Color::GOLD.into(), + ..default() + }) + .with_children(|parent| { + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(2.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + ..default() + }, + border_color: Color::GOLD.into(), + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Asteroid Detail", + text_style.clone(), + )); + + parent + .spawn(( + ButtonBundle { + style: Style { + width: Val::Px(30.), + height: Val::Px(30.), + ..default() + }, + background_color: Color::rgba(0., 0., 0., 1.) + .into(), + ..default() + }, + On::>::run(move |mut commands: Commands, state: Res>,| { + commands.entity(state.get().0.unwrap()).despawn_recursive(); + }), + )) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "X", + text_style.clone(), + )); + }); + }); + + + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + margin: UiRect::all(Val::Px(4.)), + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Position", + text_style.clone(), + )); + parent.spawn(TextBundle::from_section( + format!("({},{})", p.x, p.y), + text_style.clone(), + )); + }); + + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + margin: UiRect::all(Val::Px(4.)), + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Fuel", + text_style.clone(), + )); + parent.spawn(TextBundle::from_section( + f.available.to_string(), + text_style.clone(), + )); + }); + }); + }) + .id(), + ))); + } + } +} diff --git a/visualizer/src/asteroid.rs b/visualizer/src/asteroid/mod.rs similarity index 85% rename from visualizer/src/asteroid.rs rename to visualizer/src/asteroid/mod.rs index 663c39b..9d46b84 100644 --- a/visualizer/src/asteroid.rs +++ b/visualizer/src/asteroid/mod.rs @@ -1,6 +1,10 @@ use bevy::prelude::*; -use crate::map::{Fuel, Position}; +use crate::map::{AsteroidIdentity, Fuel, Position}; + +use self::hud::{render_hud, HudState}; + +mod hud; const TILE_SIZE: u32 = 64; @@ -35,6 +39,7 @@ impl FromWorld for Material { #[derive(Bundle)] pub struct Asteroid { sprite_sheet: SpriteSheetBundle, + identity: AsteroidIdentity, position: Position, fuel: Fuel, } @@ -56,6 +61,7 @@ impl Asteroid { }, position, fuel, + identity: AsteroidIdentity, } } } @@ -74,6 +80,8 @@ pub struct AsteroidPlugin; impl Plugin for AsteroidPlugin { fn build(&self, app: &mut App) { - app.init_resource::().add_systems(Update, render); + app.init_resource::() + .add_systems(Update, (render, render_hud)) + .insert_state(HudState(None)); } } diff --git a/visualizer/src/main.rs b/visualizer/src/main.rs index 9593467..cc96020 100644 --- a/visualizer/src/main.rs +++ b/visualizer/src/main.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_mod_picking::prelude::*; use bevy_pancam::{PanCam, PanCamPlugin}; use bevy_rand::{plugin::EntropyPlugin, prelude::WyRand}; @@ -22,13 +23,22 @@ fn setup_ui(mut commands: Commands) { }); } +// fn setup_environment(mut commands: Commands, asset_server: Res) { +// commands.spawn(SpriteBundle { +// texture: asset_server.load("background.gif"), +// ..default() +// }); +// } + fn main() { App::new() .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) - .add_plugins(PanCamPlugin::default()) + .add_plugins(PanCamPlugin) .add_plugins(EntropyPlugin::::default()) + .add_plugins(DefaultPickingPlugins) .add_systems(Startup, setup_camera) .add_systems(Startup, setup_ui) + // .add_systems(Startup, setup_environment) .add_plugins((map::MapPlugin, ships::ShipsPlugin, asteroid::AsteroidPlugin)) .run(); } diff --git a/visualizer/src/map.rs b/visualizer/src/map/mod.rs similarity index 97% rename from visualizer/src/map.rs rename to visualizer/src/map/mod.rs index c649c81..7fc0f1b 100644 --- a/visualizer/src/map.rs +++ b/visualizer/src/map/mod.rs @@ -58,6 +58,10 @@ where } } +#[derive(Component)] +pub struct AsteroidIdentity; + + const RANDOM_SHIP_COUNT: usize = 50; const RANDOM_ASTEROID_COUNT: usize = 100; diff --git a/visualizer/src/ships/hud.rs b/visualizer/src/ships/hud.rs new file mode 100644 index 0000000..2c9b71f --- /dev/null +++ b/visualizer/src/ships/hud.rs @@ -0,0 +1,174 @@ +use bevy::prelude::*; +use bevy_mod_picking::prelude::*; + +use crate::map::{Fuel, Position, ShipIdentity}; + +#[derive(States, Debug, Clone, Eq, PartialEq, Hash)] +pub struct HudState(pub Option); + +pub fn render_hud( + mut commands: Commands, + query: Query< + (Option<&PickingInteraction>, &ShipIdentity, &Position, &Fuel), + With, + >, + asset_server: Res, + mut state: ResMut>, +) { + let text_style = TextStyle { + font: asset_server.load("fonts/pixel.otf"), + font_size: 32.0, + color: Color::GOLD, + }; + + for (i, s, p, f) in &query { + if let Some(PickingInteraction::Pressed) = i { + state.set(HudState(Some( + commands + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(50.), + height: Val::Percent(40.), + border: UiRect::all(Val::Px(2.)), + flex_wrap: FlexWrap::Wrap, + padding: UiRect::all(Val::Px(12.)), + ..default() + }, + background_color: Color::rgba(0., 0., 0., 0.8).into(), + border_color: Color::GOLD.into(), + ..default() + }) + .with_children(|parent| { + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(2.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + ..default() + }, + border_color: Color::GOLD.into(), + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Ship Detail", + text_style.clone(), + )); + + parent + .spawn(( + ButtonBundle { + style: Style { + width: Val::Px(30.), + height: Val::Px(30.), + ..default() + }, + background_color: Color::rgba(0., 0., 0., 1.) + .into(), + ..default() + }, + On::>::run(move |mut commands: Commands, state: Res>,| { + commands.entity(state.get().0.unwrap()).despawn_recursive(); + }), + )) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "X", + text_style.clone(), + )); + }); + }); + + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + margin: UiRect::all(Val::Px(4.)), + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Name", + text_style.clone(), + )); + parent.spawn(TextBundle::from_section( + &s.name, + text_style.clone(), + )); + }); + + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + margin: UiRect::all(Val::Px(4.)), + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Position", + text_style.clone(), + )); + parent.spawn(TextBundle::from_section( + format!("({},{})", p.x, p.y), + text_style.clone(), + )); + }); + + parent + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Px(60.), + border: UiRect::bottom(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceBetween, + margin: UiRect::all(Val::Px(4.)), + ..default() + }, + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Fuel Available", + text_style.clone(), + )); + parent.spawn(TextBundle::from_section( + f.available.to_string(), + text_style.clone(), + )); + }); + }); + }) + .id(), + ))); + } + } +} diff --git a/visualizer/src/ships.rs b/visualizer/src/ships/mod.rs similarity index 86% rename from visualizer/src/ships.rs rename to visualizer/src/ships/mod.rs index 7ee2c00..b75ee77 100644 --- a/visualizer/src/ships.rs +++ b/visualizer/src/ships/mod.rs @@ -1,13 +1,12 @@ -use std::time::Duration; - use bevy::{prelude::*, time::common_conditions::on_timer}; -use bevy_rand::{ - prelude::{ChaCha8Rng, WyRand}, - resource::GlobalEntropy, -}; +use bevy_rand::{prelude::WyRand, resource::GlobalEntropy}; use rand::Rng; +use std::time::Duration; use crate::map::{Fuel, Position, ShipIdentity}; +use hud::{HudState, render_hud}; + +mod hud; const TILE_SIZE: u32 = 64; @@ -86,7 +85,6 @@ fn render(mut query: Query<(&mut Transform, &Position)>) { fn random_move( mut query: Query<(&mut Position, &Fuel), With>, - time: Res