From 752d1e819cc677d1a54748a252c646fc978a7a48 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 23 Oct 2022 22:09:38 +0200 Subject: [PATCH] Fill info panel --- .cargo/config.toml | 5 ---- Cargo.toml | 9 ++++-- src/gui/widgets/info_panel.rs | 55 ++++++++++++++++++++++++----------- src/gui/widgets/toolbar.rs | 15 ++++++++-- src/main.rs | 46 ++++++++++++++++++++++------- 5 files changed, 93 insertions(+), 37 deletions(-) delete mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 8bf89ab..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,5 +0,0 @@ -[profile.dev.package."*"] -opt-level = 3 - -[profile.release] -lto = "thin" diff --git a/Cargo.toml b/Cargo.toml index 5e370d7..35651ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,13 @@ version = "0.1.1" edition = "2021" resolver = "2" -[profile] -release = { strip = "symbols", lto = "thin", opt-level = "z" } +[profile.release] +strip = "symbols" +lto = "thin" +opt-level = 3 + +[profile.dev.package."*"] +opt-level = 3 [features] # bevy/trace_chrome for tracing by function diff --git a/src/gui/widgets/info_panel.rs b/src/gui/widgets/info_panel.rs index 9ebf7ef..ad3ea86 100644 --- a/src/gui/widgets/info_panel.rs +++ b/src/gui/widgets/info_panel.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "logging")] -use bevy::diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin}; use { crate::{ gui::{WidgetId, WidgetSystem}, @@ -10,6 +8,7 @@ use { world::World, }, bevy_egui::egui::{Grid, Ui}, + planet::{BiomeStats, TerrainCell, WorldManager}, std::marker::PhantomData, }; @@ -25,26 +24,48 @@ impl WidgetSystem for InfoPanel<'_, '_> { _ = Grid::new("info_panel") .num_columns(2) - .striped(true) + .striped(false) .show(ui, |ui| { - #[cfg(feature = "logging")] + let cursor_position = world.resource::(); + let cursor_y = cursor_position.y; + let cursor_x = cursor_position.x; + _ = ui.label("Coordinates"); + _ = ui.label(cursor_position.to_string()); + ui.end_row(); + + let world_manager = world.resource::(); + if cursor_x >= 0 + && cursor_x <= world_manager.world().width.try_into().unwrap() + && cursor_y >= 0 + && cursor_y < world_manager.world().height.try_into().unwrap() { - let diagnostics = world.resource::(); + let TerrainCell { + altitude, + rainfall, + temperature, + biome_presences, + } = &world_manager.world().terrain[cursor_y as usize][cursor_x as usize]; - _ = ui.label("Framerate"); - _ = ui.label( - match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) { - None => f64::NAN, - Some(fps) => fps.value.round(), - } - .to_string(), - ); + _ = ui.label("Altitude"); + _ = ui.label(format!("{:.2}", altitude)); ui.end_row(); - } + _ = ui.label("Rainfall"); + _ = ui.label(format!("{:.2}", rainfall)); + ui.end_row(); + _ = ui.label("Temperature"); + _ = ui.label(format!("{:.2}", temperature)); - _ = ui.label("Cursor position"); - _ = ui.label(world.resource::().to_string()); - ui.end_row() + ui.end_row(); + ui.end_row(); + _ = ui.label("Biome presences"); + for (biome_type, presence) in biome_presences { + ui.end_row(); + _ = ui.label(::from(biome_type).name); + _ = ui.label(format!("{:.2}%", presence * 100.0)); + } + } else { + _ = ui.label("No tile at this position"); + } }); } } diff --git a/src/gui/widgets/toolbar.rs b/src/gui/widgets/toolbar.rs index b84cce1..60a9400 100644 --- a/src/gui/widgets/toolbar.rs +++ b/src/gui/widgets/toolbar.rs @@ -1,18 +1,27 @@ +#[cfg(feature = "globe_view")] +use { + crate::components::panning::Pan2d, + bevy::{ + core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}, + ecs::query::{With, Without}, + render::camera::Camera, + }, +}; use { crate::{ - components::panning::Pan2d, gui::{WidgetId, WidgetSystem}, macros::iterable_enum, }, bevy::{ + asset::Assets, ecs::{ + change_detection::Mut, component::Component, system::{SystemParam, SystemState}, world::World, }, log::debug, - prelude::{Assets, Camera, Camera2d, Camera3d, Image, Mut, With, Without}, - render::render_resource::Extent3d, + render::{render_resource::Extent3d, texture::Image}, }, bevy_egui::egui::{Layout, Ui}, planet::WorldManager, diff --git a/src/main.rs b/src/main.rs index d02229b..417596c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -use gui::widgets::{InfoPanel, ToolbarWidget}; - pub(crate) mod components; #[cfg(feature = "render")] pub(crate) mod gui; @@ -7,14 +5,17 @@ pub(crate) mod macros; pub(crate) mod plugins; pub(crate) mod resources; +#[cfg(all(feature = "render", feature = "logging"))] +use { + bevy::diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin}, + bevy_egui::egui::Frame, +}; use { bevy::{ app::App, log::LogSettings, - prelude::{IntoExclusiveSystem, World}, utils::{default, tracing::Level}, }, - bevy_egui::egui::{FontData, FontDefinitions, FontFamily}, planet::WorldManager, plugins::WorldPlugins, }; @@ -26,7 +27,8 @@ use { ecs::{ change_detection::{Mut, ResMut}, query::With, - system::{Commands, Query, Res}, + system::{Commands, IntoExclusiveSystem, Query, Res}, + world::World, }, prelude::Vec2, render::{ @@ -45,9 +47,15 @@ use { window::{WindowDescriptor, Windows}, winit::WinitSettings, }, - bevy_egui::EguiContext, + bevy_egui::{ + egui::{FontData, FontDefinitions, FontFamily}, + EguiContext, + }, components::panning::Pan2d, - gui::widget, + gui::{ + widget, + widgets::{InfoPanel, ToolbarWidget}, + }, resources::CursorMapPosition, }; #[cfg(all(feature = "render", feature = "globe_view"))] @@ -239,16 +247,34 @@ fn generate_graphics( } } +#[cfg(feature = "render")] fn update_gui(world: &mut World) { - debug_assert!(world.contains_resource::()); world.resource_scope(|world, mut ctx: Mut<'_, EguiContext>| { let ctx = ctx.ctx_mut(); - _ = bevy_egui::egui::Window::new("Info panel") + _ = bevy_egui::egui::Window::new("Tile Info") .resizable(false) .show(ctx, |ui| { - widget::>(world, ui, "Map Info Panel".into()); + widget::>(world, ui, "Tile Info Panel".into()); }); + #[cfg(feature = "logging")] + { + bevy_egui::egui::CentralPanel::default() + .frame(Frame::none()) + .show(ctx, |ui| { + _ = ui.label(format!( + "{:.0}", + match world + .resource::() + .get_measurement(FrameTimeDiagnosticsPlugin::FPS) + { + None => f64::NAN, + Some(fps) => fps.value, + } + )); + }); + } + _ = bevy_egui::egui::TopBottomPanel::bottom("Toolbar") .resizable(false) .default_height(30.0)