Mouse lock toggle (#13)

* dbg feature, update inspector

* Ability to toggle cursor
This commit is contained in:
GitGhillie
2025-03-22 10:29:46 +01:00
committed by GitHub
parent f0d3303b86
commit cf30288c4e

View File

@@ -13,6 +13,7 @@ use avian3d::{
prelude::*,
};
use bevy::{
input::common_conditions::input_just_pressed,
prelude::*,
window::{CursorGrabMode, PrimaryWindow},
};
@@ -38,7 +39,7 @@ struct PlayerSpawned {
pub fn plugin(app: &mut App) {
app.init_resource::<PlayerSpawned>();
app.add_systems(Startup, (initial_grab_cursor, cursor_recenter));
app.add_systems(Startup, (toggle_cursor_system, cursor_recenter));
app.add_systems(
Update,
(
@@ -46,6 +47,7 @@ pub fn plugin(app: &mut App) {
collect_cash,
toggle_animation,
setup_animations_marker_for_player,
toggle_cursor_system.run_if(input_just_pressed(KeyCode::Escape)),
),
);
@@ -128,7 +130,6 @@ fn spawn(
fn rotate_view_gamepad(
controls: Res<Controls>,
// todo: Put the player head as a child of the rig to avoid this mess:
mut player: Query<&mut Transform, With<PlayerRig>>,
) {
let Some(gamepad) = controls.gamepad_state else {
@@ -146,7 +147,6 @@ fn rotate_view_gamepad(
fn rotate_view_keyboard(
mut controls: ResMut<Controls>,
// todo: Put the player head as a child of the rig to avoid this mess:
mut player: Query<&mut Transform, With<PlayerRig>>,
) {
if controls.keyboard_state.view_mode {
@@ -179,11 +179,11 @@ fn toggle_grab_cursor(window: &mut Window) {
}
}
fn initial_grab_cursor(mut primary_window: Query<&mut Window, With<PrimaryWindow>>) {
fn toggle_cursor_system(mut primary_window: Query<&mut Window, With<PrimaryWindow>>) {
if let Ok(mut window) = primary_window.get_single_mut() {
toggle_grab_cursor(&mut window);
} else {
warn!("Primary window not found for `initial_grab_cursor`!");
warn!("Primary window not found for `toggle_cursor_system`!");
}
}