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"
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

View file

@ -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 diagnostics = world.resource::<Diagnostics>();
_ = ui.label("Framerate");
_ = ui.label(
match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) {
None => f64::NAN,
Some(fps) => fps.value.round(),
}
.to_string(),
);
let cursor_position = world.resource::<CursorMapPosition>();
let cursor_y = cursor_position.y;
let cursor_x = cursor_position.x;
_ = ui.label("Coordinates");
_ = ui.label(cursor_position.to_string());
ui.end_row();
}
_ = ui.label("Cursor position");
_ = ui.label(world.resource::<CursorMapPosition>().to_string());
ui.end_row()
let world_manager = world.resource::<WorldManager>();
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 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 {
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,

View file

@ -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::<WorldManager>());
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::<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")
.resizable(false)
.default_height(30.0)