Add input visualizer

This commit is contained in:
2026-08-27 16:35:10 +02:00
parent 00d47e9c9b
commit 348b1c172b
2 changed files with 29 additions and 0 deletions
+27
View File
@@ -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::<f32>());
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(())
}
+2
View File
@@ -3,6 +3,7 @@
use bevy::platform::collections::HashMap; use bevy::platform::collections::HashMap;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_egui::EguiPrimaryContextPass;
use bevy_ggrs::prelude::*; use bevy_ggrs::prelude::*;
use bevy_ggrs::{LocalInputs, LocalPlayers}; use bevy_ggrs::{LocalInputs, LocalPlayers};
@@ -13,6 +14,7 @@ pub mod gamecube;
pub mod gamepad; pub mod gamepad;
pub mod keyboard; pub mod keyboard;
pub mod map; pub mod map;
pub mod debug;
pub use buffer::{FighterCommands, FighterInput}; pub use buffer::{FighterCommands, FighterInput};
pub use frame::FighterInputFrame; pub use frame::FighterInputFrame;