prep to draw outline gizmos

main
Elijah Voigt 2 months ago
parent 62d24bec0e
commit 8c892a50aa

@ -22,7 +22,7 @@ pub use bevy::{
}, },
camera::{primitives::*, visibility::*, *}, camera::{primitives::*, visibility::*, *},
color::palettes::css::*, color::palettes::css::*,
feathers::controls::*, feathers::{controls::*, theme::*, dark_theme::*},
feathers::*, feathers::*,
gizmos::{aabb::AabbGizmoPlugin, light::LightGizmoPlugin}, gizmos::{aabb::AabbGizmoPlugin, light::LightGizmoPlugin},
input::{ input::{
@ -40,6 +40,7 @@ pub use bevy::{
render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages}, render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages},
sprite_render::*, sprite_render::*,
time::common_conditions::*, time::common_conditions::*,
ui::*, ui::*,
ui_widgets::{Button, *}, ui_widgets::{Button, *},
window::{WindowResized, WindowResolution}, window::{WindowResized, WindowResolution},

@ -4,11 +4,6 @@ use super::*;
// TODO: // TODO:
// - When shape asset is updated, shape layout update in real time // - When shape asset is updated, shape layout update in real time
// - Rotating shape when arrow up pressed
// - Shape moves left/right/down when respective keys pressed
// - Add Orientation component
// - Add functionality to ShapeLayout
// - Write tests before functionality
// - Debug: gizmo outline entities // - Debug: gizmo outline entities
// - conditional enable/disable // - conditional enable/disable
// - entities without mesh should draw empty cross // - entities without mesh should draw empty cross

@ -1,4 +1,3 @@
use bevy::input_focus::tab_navigation::TabGroup;
use engine::theme::ThemedText; use engine::theme::ThemedText;
use super::*; use super::*;
@ -17,6 +16,7 @@ pub struct DebugPlugin;
impl Plugin for DebugPlugin { impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_state::<DebugState>() app.init_state::<DebugState>()
.init_state::<DebugOutlines>()
.add_systems(Startup, setup_ui) .add_systems(Startup, setup_ui)
.add_systems( .add_systems(
Update, Update,
@ -25,6 +25,7 @@ impl Plugin for DebugPlugin {
log_transition::<DebugState>.run_if(state_changed::<DebugState>), log_transition::<DebugState>.run_if(state_changed::<DebugState>),
log_transition::<Loading>.run_if(state_changed::<Loading>), log_transition::<Loading>.run_if(state_changed::<Loading>),
log_transition::<GameState>.run_if(state_changed::<GameState>), log_transition::<GameState>.run_if(state_changed::<GameState>),
log_transition::<DebugOutlines>.run_if(state_changed::<DebugOutlines>)
), ),
) )
.add_systems( .add_systems(
@ -34,10 +35,21 @@ impl Plugin for DebugPlugin {
.add_systems( .add_systems(
Update, Update,
( (
toggle_state_visibility::<DebugState>, (
sync_state_to_ui::<DebugState>, toggle_state_visibility::<DebugState>,
sync_state_to_ui::<DebugState>,
)
.run_if(state_changed::<DebugState>),
(
toggle_state_visibility::<DebugOutlines>,
sync_state_to_ui::<DebugOutlines>,
)
.run_if(state_changed::<DebugOutlines>),
) )
.run_if(state_changed::<DebugState>), )
.add_systems(
Update,
draw_outline_gizmos.run_if(in_state(DebugOutlines(true)))
); );
} }
} }
@ -79,6 +91,30 @@ fn setup_ui(mut commands: Commands) {
], ],
)); ));
commands.spawn((
Node {
justify_self: JustifySelf::Center,
align_self: AlignSelf::Center,
..default()
},
DebugState(true),
children![
(
Node {
..default()
},
children![
Text::new("Outlines"),
(
toggle_switch((),),
observe(checkbox_self_update),
observe(toggle_outline_state),
),
]
),
]
));
commands.spawn(( commands.spawn((
Node { Node {
bottom: px(0.0), bottom: px(0.0),
@ -93,6 +129,10 @@ fn setup_ui(mut commands: Commands) {
Text::new("DebugState State"), Text::new("DebugState State"),
SyncState::<DebugState>::default() SyncState::<DebugState>::default()
), ),
(
Text::new("DebugOutlines State"),
SyncState::<DebugOutlines>::default()
),
(Text::new("Loading State"), SyncState::<Loading>::default()), (Text::new("Loading State"), SyncState::<Loading>::default()),
(Text::new("Game State"), SyncState::<GameState>::default()), (Text::new("Game State"), SyncState::<GameState>::default()),
], ],
@ -117,3 +157,25 @@ fn debug_toggle(event: On<ValueChange<bool>>, mut next_state: ResMut<NextState<D
info!("Debug State Toggled: {:?}", event.event().value); info!("Debug State Toggled: {:?}", event.event().value);
next_state.set(event.event().value.into()); next_state.set(event.event().value.into());
} }
#[derive(States, Default, Clone, Eq, Debug, PartialEq, Hash, Component)]
struct DebugOutlines(bool);
impl fmt::Display for DebugOutlines {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Debug Outlines {}", self.0)
}
}
fn toggle_outline_state(
event: On<ValueChange<bool>>,
mut next: ResMut<NextState<DebugOutlines>>,
) {
next.set(DebugOutlines(event.event().value));
}
fn draw_debug_outlines(
gizmos: Gizmos
) {
todo!("Draw outlines here")
}

@ -18,6 +18,7 @@ fn main() {
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugins(FeathersPlugins) .add_plugins(FeathersPlugins)
.add_plugins((BlocksPlugin, FighterPlugin, DebugPlugin)) .add_plugins((BlocksPlugin, FighterPlugin, DebugPlugin))
.insert_resource(UiTheme(create_dark_theme()))
.init_state::<Loading>() .init_state::<Loading>()
.init_state::<GameState>() .init_state::<GameState>()
.init_resource::<AllAssets>() .init_resource::<AllAssets>()

Loading…
Cancel
Save