Fill info panel

This commit is contained in:
Tobias Berger 2022-10-23 22:09:38 +02:00
parent 2130de17fe
commit 752d1e819c
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
5 changed files with 93 additions and 37 deletions

View file

@ -1,5 +0,0 @@
[profile.dev.package."*"]
opt-level = 3
[profile.release]
lto = "thin"

View file

@ -4,8 +4,13 @@ version = "0.1.1"
edition = "2021" edition = "2021"
resolver = "2" resolver = "2"
[profile] [profile.release]
release = { strip = "symbols", lto = "thin", opt-level = "z" } strip = "symbols"
lto = "thin"
opt-level = 3
[profile.dev.package."*"]
opt-level = 3
[features] [features]
# bevy/trace_chrome for tracing by function # bevy/trace_chrome for tracing by function

View file

@ -1,5 +1,3 @@
#[cfg(feature = "logging")]
use bevy::diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin};
use { use {
crate::{ crate::{
gui::{WidgetId, WidgetSystem}, gui::{WidgetId, WidgetSystem},
@ -10,6 +8,7 @@ use {
world::World, world::World,
}, },
bevy_egui::egui::{Grid, Ui}, bevy_egui::egui::{Grid, Ui},
planet::{BiomeStats, TerrainCell, WorldManager},
std::marker::PhantomData, std::marker::PhantomData,
}; };
@ -25,26 +24,48 @@ impl WidgetSystem for InfoPanel<'_, '_> {
_ = Grid::new("info_panel") _ = Grid::new("info_panel")
.num_columns(2) .num_columns(2)
.striped(true) .striped(false)
.show(ui, |ui| { .show(ui, |ui| {
#[cfg(feature = "logging")] let cursor_position = world.resource::<CursorMapPosition>();
{ let cursor_y = cursor_position.y;
let diagnostics = world.resource::<Diagnostics>(); let cursor_x = cursor_position.x;
_ = ui.label("Coordinates");
_ = ui.label("Framerate"); _ = ui.label(cursor_position.to_string());
_ = ui.label(
match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) {
None => f64::NAN,
Some(fps) => fps.value.round(),
}
.to_string(),
);
ui.end_row(); ui.end_row();
}
_ = ui.label("Cursor position"); let world_manager = world.resource::<WorldManager>();
_ = ui.label(world.resource::<CursorMapPosition>().to_string()); if cursor_x >= 0
ui.end_row() && cursor_x <= world_manager.world().width.try_into().unwrap()
&& cursor_y >= 0
&& cursor_y < world_manager.world().height.try_into().unwrap()
{
let TerrainCell {
altitude,
rainfall,
temperature,
biome_presences,
} = &world_manager.world().terrain[cursor_y as usize][cursor_x as usize];
_ = 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.end_row();
ui.end_row();
_ = ui.label("Biome presences");
for (biome_type, presence) in biome_presences {
ui.end_row();
_ = ui.label(<BiomeStats>::from(biome_type).name);
_ = ui.label(format!("{:.2}%", presence * 100.0));
}
} else {
_ = ui.label("No tile at this position");
}
}); });
} }
} }

View file

@ -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 { use {
crate::{ crate::{
components::panning::Pan2d,
gui::{WidgetId, WidgetSystem}, gui::{WidgetId, WidgetSystem},
macros::iterable_enum, macros::iterable_enum,
}, },
bevy::{ bevy::{
asset::Assets,
ecs::{ ecs::{
change_detection::Mut,
component::Component, component::Component,
system::{SystemParam, SystemState}, system::{SystemParam, SystemState},
world::World, world::World,
}, },
log::debug, log::debug,
prelude::{Assets, Camera, Camera2d, Camera3d, Image, Mut, With, Without}, render::{render_resource::Extent3d, texture::Image},
render::render_resource::Extent3d,
}, },
bevy_egui::egui::{Layout, Ui}, bevy_egui::egui::{Layout, Ui},
planet::WorldManager, planet::WorldManager,

View file

@ -1,5 +1,3 @@
use gui::widgets::{InfoPanel, ToolbarWidget};
pub(crate) mod components; pub(crate) mod components;
#[cfg(feature = "render")] #[cfg(feature = "render")]
pub(crate) mod gui; pub(crate) mod gui;
@ -7,14 +5,17 @@ pub(crate) mod macros;
pub(crate) mod plugins; pub(crate) mod plugins;
pub(crate) mod resources; pub(crate) mod resources;
#[cfg(all(feature = "render", feature = "logging"))]
use {
bevy::diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
bevy_egui::egui::Frame,
};
use { use {
bevy::{ bevy::{
app::App, app::App,
log::LogSettings, log::LogSettings,
prelude::{IntoExclusiveSystem, World},
utils::{default, tracing::Level}, utils::{default, tracing::Level},
}, },
bevy_egui::egui::{FontData, FontDefinitions, FontFamily},
planet::WorldManager, planet::WorldManager,
plugins::WorldPlugins, plugins::WorldPlugins,
}; };
@ -26,7 +27,8 @@ use {
ecs::{ ecs::{
change_detection::{Mut, ResMut}, change_detection::{Mut, ResMut},
query::With, query::With,
system::{Commands, Query, Res}, system::{Commands, IntoExclusiveSystem, Query, Res},
world::World,
}, },
prelude::Vec2, prelude::Vec2,
render::{ render::{
@ -45,9 +47,15 @@ use {
window::{WindowDescriptor, Windows}, window::{WindowDescriptor, Windows},
winit::WinitSettings, winit::WinitSettings,
}, },
bevy_egui::EguiContext, bevy_egui::{
egui::{FontData, FontDefinitions, FontFamily},
EguiContext,
},
components::panning::Pan2d, components::panning::Pan2d,
gui::widget, gui::{
widget,
widgets::{InfoPanel, ToolbarWidget},
},
resources::CursorMapPosition, resources::CursorMapPosition,
}; };
#[cfg(all(feature = "render", feature = "globe_view"))] #[cfg(all(feature = "render", feature = "globe_view"))]
@ -239,16 +247,34 @@ fn generate_graphics(
} }
} }
#[cfg(feature = "render")]
fn update_gui(world: &mut World) { fn update_gui(world: &mut World) {
debug_assert!(world.contains_resource::<WorldManager>());
world.resource_scope(|world, mut ctx: Mut<'_, EguiContext>| { world.resource_scope(|world, mut ctx: Mut<'_, EguiContext>| {
let ctx = ctx.ctx_mut(); let ctx = ctx.ctx_mut();
_ = bevy_egui::egui::Window::new("Info panel") _ = bevy_egui::egui::Window::new("Tile Info")
.resizable(false) .resizable(false)
.show(ctx, |ui| { .show(ctx, |ui| {
widget::<InfoPanel<'_, '_>>(world, ui, "Map Info Panel".into()); widget::<InfoPanel<'_, '_>>(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::<Diagnostics>()
.get_measurement(FrameTimeDiagnosticsPlugin::FPS)
{
None => f64::NAN,
Some(fps) => fps.value,
}
));
});
}
_ = bevy_egui::egui::TopBottomPanel::bottom("Toolbar") _ = bevy_egui::egui::TopBottomPanel::bottom("Toolbar")
.resizable(false) .resizable(false)
.default_height(30.0) .default_height(30.0)