diff --git a/src/input/debug.rs b/src/input/debug.rs new file mode 100644 index 0000000..1bd8843 --- /dev/null +++ b/src/input/debug.rs @@ -0,0 +1,27 @@ +use bevy_egui::{egui::Color32, prelude::*}; + +use crate::input::FighterInput; +use bevy::prelude::*; + +pub fn input_debug(mut contexts: EguiContexts, query: Query<(&FighterInput)>) -> Result { + for (i, input) in query.iter().enumerate() { + const STICK_SIZE: f32 = 50.0; + const STICK_SIZE_FRACTION: f32 = 0.75; + let last_frame = input.get_last_frame(); + let movement = egui::Vec2::new(last_frame.movement.x.to_num(), -last_frame.movement.y.to_num::()); + egui::Window::new(format!("Input {}", i)).show(contexts.ctx_mut()?, |ui| { + let (_, rect) = ui.allocate_space(egui::Vec2::new(STICK_SIZE*(1.0 + STICK_SIZE_FRACTION), STICK_SIZE*(1.0 + STICK_SIZE_FRACTION))); + let painter = ui.painter(); + let button_bg = egui::Rgba::WHITE * egui::Rgba::from_white_alpha(0.25); + painter.circle_filled(rect.center(), STICK_SIZE * 0.5, button_bg); + painter.circle_filled( + rect.center() + STICK_SIZE * 0.5 * movement, + STICK_SIZE * STICK_SIZE_FRACTION * 0.5, + button_bg, + ); + ui.label(format!("X: {:.2}\nY:{:.2}", last_frame.movement.x, last_frame.movement.y)); + }); + } + + Ok(()) +} diff --git a/src/input/mod.rs b/src/input/mod.rs index 57cc57a..3928a84 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -3,6 +3,7 @@ use bevy::platform::collections::HashMap; use bevy::prelude::*; +use bevy_egui::EguiPrimaryContextPass; use bevy_ggrs::prelude::*; use bevy_ggrs::{LocalInputs, LocalPlayers}; @@ -13,6 +14,7 @@ pub mod gamecube; pub mod gamepad; pub mod keyboard; pub mod map; +pub mod debug; pub use buffer::{FighterCommands, FighterInput}; pub use frame::FighterInputFrame;