debug systems toggle
This commit is contained in:
parent
eb4e1a1e6c
commit
a10cc0712b
4 changed files with 105 additions and 20 deletions
|
|
@ -5,3 +5,17 @@ pub struct LinearStateMarker;
|
||||||
|
|
||||||
#[derive(Component, Copy, Clone)]
|
#[derive(Component, Copy, Clone)]
|
||||||
pub struct LinearRestartMarker;
|
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,
|
||||||
|
}
|
||||||
|
|
@ -3,8 +3,8 @@ pub mod plugin;
|
||||||
mod components;
|
mod components;
|
||||||
pub use components::*;
|
pub use components::*;
|
||||||
|
|
||||||
mod systems;
|
mod systems_debug;
|
||||||
pub use systems::*;
|
pub use systems_debug::*;
|
||||||
|
|
||||||
mod components_track;
|
mod components_track;
|
||||||
pub use components_track::*;
|
pub use components_track::*;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
use crate::{HEIGHT, WIDTH, states, FACTOR};
|
use crate::{FACTOR, HEIGHT, WIDTH, states};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use states::linear::*;
|
use states::linear::*;
|
||||||
use std::f32::consts::FRAC_PI_2;
|
use std::f32::consts::FRAC_PI_2;
|
||||||
|
|
||||||
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
|
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>) {
|
||||||
|
if !config.toggle_track {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let mut current_pos = track.start_point;
|
let mut current_pos = track.start_point;
|
||||||
let mut current_dir = track.start_direction.normalize();
|
let mut current_dir = track.start_direction.normalize();
|
||||||
|
|
||||||
|
|
@ -53,23 +57,51 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
|
||||||
gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
|
gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_grid(mut gizmos: Gizmos) {
|
pub fn draw_grid(mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>) {
|
||||||
let half_x = WIDTH as f32 / 2.0 * FACTOR as f32;
|
if !config.toggle_grid {
|
||||||
let half_y = HEIGHT as f32 / 2.0 * FACTOR as f32;
|
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 {
|
for i in 0..WIDTH {
|
||||||
gizmos.line_2d(
|
gizmos.line_2d(
|
||||||
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 - 8.0) * FACTOR as f32, -half_y),
|
Vec2::new((i as f32 - HALF_X) * FF, -STEP_Y),
|
||||||
DARK_GREEN,
|
DARK_GREEN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..HEIGHT {
|
for i in 0..HEIGHT {
|
||||||
gizmos.line_2d(
|
gizmos.line_2d(
|
||||||
Vec2::new(-half_x, (i as f32 - 4.0) * FACTOR as f32),
|
Vec2::new(-STEP_X, (i as f32 - HALF_Y) * FF),
|
||||||
Vec2::new(half_x, (i as f32 - 4.0) * FACTOR as f32),
|
Vec2::new(STEP_X, (i as f32 - HALF_Y) * FF),
|
||||||
DARK_GREEN,
|
DARK_GREEN,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub fn draw_cannon_laser(mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>){
|
||||||
|
// if !config.toggle_laser {
|
||||||
|
// return;
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn toggle_debug_systems(
|
||||||
|
buttons: Query<(&Interaction, &DebugToggle), Changed<Interaction>>,
|
||||||
|
mut config: ResMut<LinearDebugConfig>,
|
||||||
|
) {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
use crate::states::AppState;
|
use crate::states::AppState;
|
||||||
use crate::states::AppState::LinearPlayState;
|
use crate::states::AppState::LinearPlayState;
|
||||||
use crate::states::linear::plugin::LinearUpdateSet;
|
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::button_click::ButtonClickMessage;
|
||||||
use crate::ui::click::handle_click_system;
|
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 bevy::prelude::*;
|
||||||
|
use crate::{FACTOR, HEIGHT, WIDTH};
|
||||||
|
|
||||||
pub struct LinearUIPlugin;
|
pub struct LinearUIPlugin;
|
||||||
|
|
||||||
|
|
@ -44,25 +45,63 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let restart_button_style = ButtonStyle {
|
let button_style = ButtonStyle {
|
||||||
font: asset_server.load("fonts/QR Ames Beta.otf"),
|
font: asset_server.load("fonts/QR Ames Beta.otf"),
|
||||||
font_size: 24.0,
|
font_size: 16.0,
|
||||||
text_color: Color::WHITE,
|
text_color: Color::WHITE,
|
||||||
normal_bg: Color::linear_rgba(0.15, 0.15, 0.15, 1.0),
|
normal_bg: Color::linear_rgba(0.15, 0.15, 0.15, 1.0),
|
||||||
hovered_bg: Color::linear_rgb(0.25, 0.25, 0.25),
|
hovered_bg: Color::linear_rgb(0.25, 0.25, 0.25),
|
||||||
pressed_bg: Color::linear_rgb(0.3, 0.3, 0.3),
|
pressed_bg: Color::linear_rgb(0.3, 0.3, 0.3),
|
||||||
width: Val::Px(200.0),
|
width: Val::Px(100.0),
|
||||||
height: Val::Px(50.0),
|
height: Val::Px(25.0),
|
||||||
margin: UiRect::all(Val::Px(10.0)),
|
margin: UiRect::all(Val::Px(10.0)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let bg_image: Handle<Image> = 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(
|
spawn_button(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
root,
|
root,
|
||||||
"Restart",
|
"Restart",
|
||||||
&restart_button_style,
|
&button_style,
|
||||||
LinearRestartMarker,
|
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(
|
pub fn restart_game_button_system(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue