From a10cc0712bccb274334aee979a2a1cacfb78b49c Mon Sep 17 00:00:00 2001 From: nquidox Date: Sat, 18 Apr 2026 20:51:09 +0300 Subject: [PATCH] debug systems toggle --- src/states/linear/components.rs | 16 +++++- src/states/linear/mod.rs | 4 +- .../linear/{systems.rs => systems_debug.rs} | 52 ++++++++++++++---- src/states/linear/ui.rs | 53 ++++++++++++++++--- 4 files changed, 105 insertions(+), 20 deletions(-) rename src/states/linear/{systems.rs => systems_debug.rs} (59%) diff --git a/src/states/linear/components.rs b/src/states/linear/components.rs index 6c0a133..06548c8 100644 --- a/src/states/linear/components.rs +++ b/src/states/linear/components.rs @@ -4,4 +4,18 @@ use bevy::prelude::*; pub struct LinearStateMarker; #[derive(Component, Copy, Clone)] -pub struct LinearRestartMarker; \ No newline at end of file +pub struct LinearRestartMarker; + +#[derive(Resource)] +pub struct LinearDebugConfig { + pub toggle_track: bool, + pub toggle_grid: bool, + pub toggle_laser: bool, +} + +#[derive(Component, Copy, Clone)] +pub enum DebugToggle{ + Track, + Grid, + Laser, +} \ No newline at end of file diff --git a/src/states/linear/mod.rs b/src/states/linear/mod.rs index 1bb90fd..bd0d3da 100644 --- a/src/states/linear/mod.rs +++ b/src/states/linear/mod.rs @@ -3,8 +3,8 @@ pub mod plugin; mod components; pub use components::*; -mod systems; -pub use systems::*; +mod systems_debug; +pub use systems_debug::*; mod components_track; pub use components_track::*; diff --git a/src/states/linear/systems.rs b/src/states/linear/systems_debug.rs similarity index 59% rename from src/states/linear/systems.rs rename to src/states/linear/systems_debug.rs index 16d63b9..bac5622 100644 --- a/src/states/linear/systems.rs +++ b/src/states/linear/systems_debug.rs @@ -1,9 +1,13 @@ -use crate::{HEIGHT, WIDTH, states, FACTOR}; +use crate::{FACTOR, HEIGHT, WIDTH, states}; use bevy::prelude::*; use states::linear::*; use std::f32::consts::FRAC_PI_2; -pub fn draw_track_gizmos(track: Res, mut gizmos: Gizmos) { +pub fn draw_track_gizmos(track: Res, mut gizmos: Gizmos, config: ResMut) { + if !config.toggle_track { + return; + }; + let mut current_pos = track.start_point; let mut current_dir = track.start_direction.normalize(); @@ -53,23 +57,51 @@ pub fn draw_track_gizmos(track: Res, mut gizmos: Gizmos) { gizmos.circle_2d(current_pos, 5.0, Color::WHITE); } -pub fn draw_grid(mut gizmos: Gizmos) { - let half_x = WIDTH as f32 / 2.0 * FACTOR as f32; - let half_y = HEIGHT as f32 / 2.0 * FACTOR as f32; +pub fn draw_grid(mut gizmos: Gizmos, config: ResMut) { + if !config.toggle_grid { + return; + }; + const FF: f32 = FACTOR as f32; + + const HALF_X: f32 = WIDTH as f32 / 2.0; + const HALF_Y: f32 = HEIGHT as f32 / 2.0; + const STEP_X: f32 = HALF_X * FF; + const STEP_Y: f32 = HALF_Y * FF; for i in 0..WIDTH { gizmos.line_2d( - Vec2::new((i as f32 - 8.0) * FACTOR as f32, half_y), - Vec2::new((i as f32 - 8.0) * FACTOR as f32, -half_y), + Vec2::new((i as f32 - HALF_X) * FF, STEP_Y), + Vec2::new((i as f32 - HALF_X) * FF, -STEP_Y), DARK_GREEN, ); } - + for i in 0..HEIGHT { gizmos.line_2d( - Vec2::new(-half_x, (i as f32 - 4.0) * FACTOR as f32), - Vec2::new(half_x, (i as f32 - 4.0) * FACTOR as f32), + Vec2::new(-STEP_X, (i as f32 - HALF_Y) * FF), + Vec2::new(STEP_X, (i as f32 - HALF_Y) * FF), DARK_GREEN, ) } } + +// pub fn draw_cannon_laser(mut gizmos: Gizmos, config: ResMut){ +// if !config.toggle_laser { +// return; +// }; +// } + +pub fn toggle_debug_systems( + buttons: Query<(&Interaction, &DebugToggle), Changed>, + mut config: ResMut, +) { + for (interaction, toggle_type) in &buttons { + if matches!(interaction, Interaction::Pressed) { + match toggle_type { + DebugToggle::Track => config.toggle_track = !config.toggle_track, + DebugToggle::Grid => config.toggle_grid = !config.toggle_grid, + DebugToggle::Laser => config.toggle_laser = !config.toggle_laser, + } + } + } +} diff --git a/src/states/linear/ui.rs b/src/states/linear/ui.rs index 18e4c93..9ceb97c 100644 --- a/src/states/linear/ui.rs +++ b/src/states/linear/ui.rs @@ -1,11 +1,12 @@ use crate::states::AppState; use crate::states::AppState::LinearPlayState; use crate::states::linear::plugin::LinearUpdateSet; -use crate::states::linear::{LinearRestartMarker, LinearStateMarker}; +use crate::states::linear::{DebugToggle, LinearRestartMarker, LinearStateMarker}; use crate::ui::button_click::ButtonClickMessage; use crate::ui::click::handle_click_system; -use crate::ui::{ButtonStyle, spawn_button}; +use crate::ui::{ButtonStyle, spawn_button, spawn_background}; use bevy::prelude::*; +use crate::{FACTOR, HEIGHT, WIDTH}; pub struct LinearUIPlugin; @@ -44,25 +45,63 @@ fn setup_ui(mut commands: Commands, asset_server: Res) { )) .id(); - let restart_button_style = ButtonStyle { + let button_style = ButtonStyle { font: asset_server.load("fonts/QR Ames Beta.otf"), - font_size: 24.0, + font_size: 16.0, text_color: Color::WHITE, normal_bg: Color::linear_rgba(0.15, 0.15, 0.15, 1.0), hovered_bg: Color::linear_rgb(0.25, 0.25, 0.25), pressed_bg: Color::linear_rgb(0.3, 0.3, 0.3), - width: Val::Px(200.0), - height: Val::Px(50.0), + width: Val::Px(100.0), + height: Val::Px(25.0), margin: UiRect::all(Val::Px(10.0)), }; + + let bg_image: Handle = asset_server.load("sprites/bg/linear_bg.png"); + commands.spawn(( + Sprite{ + image: bg_image, + custom_size: Some(Vec2::new((WIDTH*FACTOR) as f32, (HEIGHT*FACTOR) as f32)), + ..default() + }, + Transform::from_xyz(0.0, 0.0, -10.0), + LinearStateMarker, + )); + // spawn_background(&mut commands, bg_image, LinearStateMarker); spawn_button( &mut commands, root, "Restart", - &restart_button_style, + &button_style, LinearRestartMarker, ); + + spawn_button( + &mut commands, + root, + "Track", + &button_style, + DebugToggle::Track, + ); + + spawn_button( + &mut commands, + root, + "Grid", + &button_style, + DebugToggle::Grid, + ); + + spawn_button( + &mut commands, + root, + "Laser", + &button_style, + DebugToggle::Laser, + ); + + } pub fn restart_game_button_system(