From 8c892a50aa04206e1c8df74913e4f24cf1c2e300 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Wed, 17 Dec 2025 22:40:54 -0800 Subject: [PATCH] prep to draw outline gizmos --- engine/src/lib.rs | 3 +- tetris/src/blocks.rs | 5 ---- tetris/src/debug.rs | 70 +++++++++++++++++++++++++++++++++++++++++--- tetris/src/main.rs | 1 + 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/engine/src/lib.rs b/engine/src/lib.rs index fb7334f..335d5b9 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -22,7 +22,7 @@ pub use bevy::{ }, camera::{primitives::*, visibility::*, *}, color::palettes::css::*, - feathers::controls::*, + feathers::{controls::*, theme::*, dark_theme::*}, feathers::*, gizmos::{aabb::AabbGizmoPlugin, light::LightGizmoPlugin}, input::{ @@ -40,6 +40,7 @@ pub use bevy::{ render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages}, sprite_render::*, time::common_conditions::*, + ui::*, ui_widgets::{Button, *}, window::{WindowResized, WindowResolution}, diff --git a/tetris/src/blocks.rs b/tetris/src/blocks.rs index e4725b9..c605464 100644 --- a/tetris/src/blocks.rs +++ b/tetris/src/blocks.rs @@ -4,11 +4,6 @@ use super::*; // TODO: // - 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 // - conditional enable/disable // - entities without mesh should draw empty cross diff --git a/tetris/src/debug.rs b/tetris/src/debug.rs index afe90ee..25668f8 100644 --- a/tetris/src/debug.rs +++ b/tetris/src/debug.rs @@ -1,4 +1,3 @@ -use bevy::input_focus::tab_navigation::TabGroup; use engine::theme::ThemedText; use super::*; @@ -17,6 +16,7 @@ pub struct DebugPlugin; impl Plugin for DebugPlugin { fn build(&self, app: &mut App) { app.init_state::() + .init_state::() .add_systems(Startup, setup_ui) .add_systems( Update, @@ -25,6 +25,7 @@ impl Plugin for DebugPlugin { log_transition::.run_if(state_changed::), log_transition::.run_if(state_changed::), log_transition::.run_if(state_changed::), + log_transition::.run_if(state_changed::) ), ) .add_systems( @@ -34,10 +35,21 @@ impl Plugin for DebugPlugin { .add_systems( Update, ( - toggle_state_visibility::, - sync_state_to_ui::, + ( + toggle_state_visibility::, + sync_state_to_ui::, + ) + .run_if(state_changed::), + ( + toggle_state_visibility::, + sync_state_to_ui::, + ) + .run_if(state_changed::), ) - .run_if(state_changed::), + ) + .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(( Node { bottom: px(0.0), @@ -93,6 +129,10 @@ fn setup_ui(mut commands: Commands) { Text::new("DebugState State"), SyncState::::default() ), + ( + Text::new("DebugOutlines State"), + SyncState::::default() + ), (Text::new("Loading State"), SyncState::::default()), (Text::new("Game State"), SyncState::::default()), ], @@ -117,3 +157,25 @@ fn debug_toggle(event: On>, mut next_state: ResMut) -> fmt::Result { + write!(f, "Debug Outlines {}", self.0) + } +} + +fn toggle_outline_state( + event: On>, + mut next: ResMut>, +) { + next.set(DebugOutlines(event.event().value)); +} + +fn draw_debug_outlines( + gizmos: Gizmos +) { + todo!("Draw outlines here") +} diff --git a/tetris/src/main.rs b/tetris/src/main.rs index 0d788cd..b656387 100644 --- a/tetris/src/main.rs +++ b/tetris/src/main.rs @@ -18,6 +18,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugins(FeathersPlugins) .add_plugins((BlocksPlugin, FighterPlugin, DebugPlugin)) + .insert_resource(UiTheme(create_dark_theme())) .init_state::() .init_state::() .init_resource::()