diff --git a/src/debug.rs b/src/debug.rs index 3161b6b..a438e01 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -13,6 +13,7 @@ use crate::{ player::{FallStarted, MoveSettings, Player, Velocity, spawn_player}, score::Depth, }, + screen::DisplayImage, states::GameState, world::{Chunk, RunSeed}, }; @@ -33,6 +34,7 @@ fn spawn_debug_camera(mut commands: Commands) { Camera2d, Camera { is_active: false, + order: 2, ..default() }, )); @@ -45,13 +47,17 @@ fn setup_debug_camera(mut camera: Single<&mut Projection, With>) { } fn toggle_debug_camera( - input: Res>, mut main_camera: Single<&mut Camera, (With, Without)>, mut debug_camera: Single<&mut Camera, (With, Without)>, + mut display_image: Single<&mut Visibility, With>, ) { - if input.just_pressed(KeyCode::Tab) { - main_camera.is_active = !main_camera.is_active; - debug_camera.is_active = !debug_camera.is_active; + main_camera.is_active = !main_camera.is_active; + debug_camera.is_active = !debug_camera.is_active; + + if debug_camera.is_active { + **display_image = Visibility::Hidden; + } else { + **display_image = Visibility::Visible; } } @@ -209,83 +215,6 @@ fn update_view_debug_text(mut text: Single<&mut Text, With>) { text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"); } -fn debug_panel( - mut contexts: EguiContexts, - store: Res, - mut run_seed: ResMut, - player: Single<(Entity, &Transform, &Velocity), With>, - chunk: Query>, - mut main_camera: Single<&mut Camera, (With, Without)>, - mut debug_camera: Single<&mut Camera, (With, Without)>, - mut commands: Commands, - mut fall_started: ResMut, - mut depth: ResMut, -) { - egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| { - // Fps - let fps = store - .get(&FrameTimeDiagnosticsPlugin::FPS) - .and_then(|diagnostic| diagnostic.smoothed()); - - match fps { - Some(fps) => ui.label(format!("FPS: {fps:.0}")), - None => ui.label("FPS: -"), - }; - - // Frame time in ms - match store - .get(&FrameTimeDiagnosticsPlugin::FRAME_TIME) - .and_then(|d| d.smoothed()) - { - Some(ms) => ui.label(format!("Frame: {ms:.2} ms")), - None => ui.label("Frame : - ms"), - }; - - // Run seed - ui.label(format!("Seed: {}", run_seed.0)); - - let (player_entity, transform, velocity) = *player; - ui.label(format!( - "Position: ({:.0}, {:.0})", - transform.translation.x, transform.translation.y - )); - ui.label(format!( - "Velocity: ({:.0},{:.0})", - velocity.0.x, velocity.0.y - )); - - // Resolution - ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}")); - - ui.separator(); - - let state = if debug_camera.is_active { "ON" } else { "OFF" }; - if ui.button(format!("Debug camera: {state}")).clicked() { - main_camera.is_active = !main_camera.is_active; - debug_camera.is_active = !debug_camera.is_active; - } - - ui.separator(); - - let restart = ui.button("Restart (same seed)").clicked(); - let new_map = ui.button("Restart (new map)").clicked(); - if restart || new_map { - for entity in chunk.iter() { - commands.entity(entity).despawn(); - } - if new_map { - run_seed.0 = rand::random::(); - } - fall_started.0 = false; - depth.0 = 0.0; - - commands.entity(player_entity).despawn(); - - spawn_player(commands); - } - }); -} - // Real time tuning movement & inertia sliders fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut) { egui::Window::new("Movement / Inertia ").show( @@ -333,6 +262,84 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut, + mut run_seed: ResMut, + player: Single<(Entity, &Transform, &Velocity), With>, + chunk: Query>, + mut main_camera: Single<&mut Camera, (With, Without)>, + mut debug_camera: Single<&mut Camera, (With, Without)>, + mut commands: Commands, + mut fall_started: ResMut, + mut depth: ResMut, + mut display_image: Single<&mut Visibility, With>, +) { + egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| { + // Fps + let fps = store + .get(&FrameTimeDiagnosticsPlugin::FPS) + .and_then(|diagnostic| diagnostic.smoothed()); + + match fps { + Some(fps) => ui.label(format!("FPS: {fps:.0}")), + None => ui.label("FPS: -"), + }; + + // Frame time in ms + match store + .get(&FrameTimeDiagnosticsPlugin::FRAME_TIME) + .and_then(|d| d.smoothed()) + { + Some(ms) => ui.label(format!("Frame: {ms:.2} ms")), + None => ui.label("Frame : - ms"), + }; + + // Run seed + ui.label(format!("Seed: {}", run_seed.0)); + + let (player_entity, transform, velocity) = *player; + ui.label(format!( + "Position: ({:.0}, {:.0})", + transform.translation.x, transform.translation.y + )); + ui.label(format!( + "Velocity: ({:.0},{:.0})", + velocity.0.x, velocity.0.y + )); + + // Resolution + ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}")); + + ui.separator(); + + let state = if debug_camera.is_active { "ON" } else { "OFF" }; + if ui.button(format!("Debug camera: {state}")).clicked() { + toggle_debug_camera(main_camera, debug_camera, display_image); + } + + ui.separator(); + + let restart = ui.button("Restart (same seed)").clicked(); + let new_map = ui.button("Restart (new map)").clicked(); + if restart || new_map { + for entity in chunk.iter() { + commands.entity(entity).despawn(); + } + if new_map { + run_seed.0 = rand::random::(); + } + fall_started.0 = false; + depth.0 = 0.0; + + commands.entity(player_entity).despawn(); + + spawn_player(commands); + } + // TODO: Add colidbox On/Off button + }); +} + pub struct DebugPlugin; impl Plugin for DebugPlugin { @@ -351,7 +358,6 @@ impl Plugin for DebugPlugin { ( draw_view_frame, follow_player_debug, - toggle_debug_camera, // update_seed_debug_text, // update_fps_debug_text, // update_view_debug_text, diff --git a/src/screen.rs b/src/screen.rs index ef80e7f..3add648 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -49,6 +49,7 @@ fn spawn_virtual_screen(mut commands: Commands, mut images: ResMut DisplayImage, Sprite::from_image(game_image), Transform::default(), + Visibility::Visible, RenderLayers::layer(1), )); }