Invalidated player controls when settings screen is up

This commit is contained in:
Franklin 2023-11-07 13:10:45 -04:00
parent 45639fd0f3
commit 331fb31c40
4 changed files with 35 additions and 24 deletions

View File

@ -1,9 +1,9 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use crate::logic::core::player::player_movement::{
use crate::{logic::core::player::player_movement::{
move_player, PlayerLinearXZState, PlayerLinearYState, PlayerMovementInput,
};
}, ui::game::settings::SettingsScreenUIConfiguration};
use super::markers::player::Player;
@ -22,6 +22,7 @@ pub fn capture_input(
With<Player>,
>,
time: Res<Time>,
settings_screen_config: Res<SettingsScreenUIConfiguration>,
) {
// Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate.
if keyboard_input.any_pressed([
@ -48,6 +49,10 @@ pub fn capture_input(
back: keyboard_input.pressed(KeyCode::S),
sprint: keyboard_input.pressed(KeyCode::ShiftLeft),
};
if settings_screen_config.settings_menu_shown {
move_player(PlayerMovementInput::default(), player_query, time);
} else {
move_player(player_movement_input, player_query, time);
}
}
}

View File

@ -74,21 +74,9 @@ pub fn follow_cursor_with_camera(
keyboard_input: Res<Input<KeyCode>>,
btn: Res<Input<MouseButton>>,
time: Res<Time>,
mut settings_screen_config: ResMut<SettingsScreenUIConfiguration>
mut settings_screen_config: ResMut<SettingsScreenUIConfiguration>,
) {
if let Ok(mut window) = primary_window.get_single_mut() {
if btn.just_pressed(MouseButton::Left) {
// if you want to use the cursor, but not let it leave the window,
// use `Confined` mode:
// window.cursor.grab_mode = CursorGrabMode::Confined;
// for a game that doesn't use the cursor (like a shooter):
// use `Locked` mode to keep the cursor in one place
window.cursor.grab_mode = CursorGrabMode::Locked;
// also hide the cursor
window.cursor.visible = false;
}
if keyboard_input.just_pressed(KeyCode::Escape) {
if settings_screen_config.settings_menu_shown { // Hide settings screen & Capture Cursor
settings_screen_config.settings_menu_shown = false;
@ -100,6 +88,21 @@ pub fn follow_cursor_with_camera(
window.cursor.visible = true; // Show cursor
}
}
if settings_screen_config.settings_menu_shown {
return;
}
if btn.just_pressed(MouseButton::Left) {
// if you want to use the cursor, but not let it leave the window,
// use `Confined` mode:
// window.cursor.grab_mode = CursorGrabMode::Confined;
// for a game that doesn't use the cursor (like a shooter):
// use `Locked` mode to keep the cursor in one place
window.cursor.grab_mode = CursorGrabMode::Locked;
// also hide the cursor
window.cursor.visible = false;
}
if window.cursor.grab_mode != CursorGrabMode::None {
for mut player_transform in player_query.iter_mut() {

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
use crate::{
comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::InPlayerHands, player::{PlayerHand, Player}},
logic::core::guns::{player_firing::PlayerFiringInfo, firearm::Firearm}, utils::rad_deg::radians_from_degrees, setup::{animations::AllFirearmAnimations, load_state::GameLoadState, equipment::{EquipmentChangeEvent, Equipment}},
logic::core::guns::{player_firing::PlayerFiringInfo, firearm::Firearm}, utils::rad_deg::radians_from_degrees, setup::{animations::AllFirearmAnimations, load_state::GameLoadState, equipment::{EquipmentChangeEvent, Equipment}}, ui::game::settings::SettingsScreenUIConfiguration,
};
pub fn capture_hand_usage(
@ -24,6 +24,7 @@ pub fn capture_hand_usage(
game_load_state: Res<GameLoadState>,
mut equipment_change_event_writer: EventWriter<EquipmentChangeEvent>,
settings_screen_config: Res<SettingsScreenUIConfiguration>,
) {
if !game_load_state.player_loaded {
return;
@ -50,7 +51,7 @@ pub fn capture_hand_usage(
}
}
} else { // Player is not in a reload animation
if keyboard_input.just_pressed(KeyCode::R) {
if keyboard_input.just_pressed(KeyCode::R) && !settings_screen_config.settings_menu_shown{
// Start reload animation
for mut animation_player in &mut animation_players {
if let Some(firearm_animations) = all_firearm_animations.animations.iter().find(|animation| &animation.firearm == &player_firearm) {
@ -62,7 +63,7 @@ pub fn capture_hand_usage(
// At the end of reload animation, set magazine data to capacity = 0
}
// AIMING IN/OUT
if mouse_buttons.pressed(MouseButton::Right) {
if mouse_buttons.pressed(MouseButton::Right) && !settings_screen_config.settings_menu_shown {
let rotation_lerp_quat = hand_transform.rotation.lerp(
firearm_data.final_aimed_rotation,
(time.delta_seconds() / firearm_data.rebound_time_seconds).clamp(0.0, 1.0),
@ -82,13 +83,14 @@ pub fn capture_hand_usage(
(time.delta_seconds() / firearm_data.rebound_time_seconds).clamp(0.0, 1.0),
);
}
if keyboard_input.just_pressed(KeyCode::Key1) {
// Equipping gun
if keyboard_input.just_pressed(KeyCode::Key1) && !settings_screen_config.settings_menu_shown {
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment{ primary_firearm: Some(Firearm::M4A1) }));
} else if keyboard_input.just_pressed(KeyCode::Key2) {
} else if keyboard_input.just_pressed(KeyCode::Key2) && !settings_screen_config.settings_menu_shown {
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment{ primary_firearm: Some(Firearm::Glock17) }));
}
// SHOOTING & RECOIL
if mouse_buttons.pressed(MouseButton::Left) {
if mouse_buttons.pressed(MouseButton::Left) && !settings_screen_config.settings_menu_shown {
if player_firing_info.full_auto_timer.finished() {
if magazine_data.rounds_shot < magazine_data.max_capacity {
// Get recoil numbers from patterns

View File

@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, ui::FocusPolicy};
use super::settings::SettingsScreenUIConfiguration;
@ -17,7 +17,8 @@ pub fn setup_settings_screen(mut commands: Commands) {
..Default::default()
},
visibility: Visibility::Hidden,
background_color: BackgroundColor(Color::BLACK),
background_color: BackgroundColor(Color::rgba(0.0, 0.0, 0.0, 0.9)),
focus_policy: FocusPolicy::Block,
..Default::default()
}
).insert(SettingsScreenMarker);