From ab230a95f165754c9be3ba9af886921d6af9909a Mon Sep 17 00:00:00 2001 From: Franklin Blanco Date: Wed, 8 Nov 2023 12:29:07 -0800 Subject: [PATCH] Added resources to reflect derive macro --- src/logic/core/guns/firearm.rs | 1 - src/logic/core/player/camera_player_sync.rs | 17 +++++++++-------- src/scenes/scene1/skybox.rs | 3 ++- src/setup/animations.rs | 1 + src/setup/assets.rs | 3 ++- src/setup/load_state.rs | 1 + src/ui/editor/inspector.rs | 16 ++++++++++++++++ src/ui/editor/plugin.rs | 6 +++++- src/ui/game/settings.rs | 6 ++++-- 9 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index d29209c..4b8f4a6 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -3,7 +3,6 @@ use bevy::prelude::*; use super::{caliber::Caliber, spray_pattern::FirearmSprayPattern}; -#[allow(unused)] #[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect)] pub enum Firearm { M4A1, diff --git a/src/logic/core/player/camera_player_sync.rs b/src/logic/core/player/camera_player_sync.rs index fd8f48f..720e729 100644 --- a/src/logic/core/player/camera_player_sync.rs +++ b/src/logic/core/player/camera_player_sync.rs @@ -10,16 +10,17 @@ use super::{player_movement::PlayerLinearXZState, player_values_state::PlayerVal /// Mouse sensitivity and movement speed #[derive(Resource, Reflect)] +#[reflect(Resource)] pub struct MouseMovementSettings { - pub sensitivity: f32, - pub speed: f32, - pub aimed_sensitivity: f32, + pub sensitivity: f64, + pub speed: f64, + pub aimed_sensitivity: f64, } impl Default for MouseMovementSettings { fn default() -> Self { Self { - sensitivity: 0.0003, + sensitivity: 0.0001, speed: 3.0, aimed_sensitivity: 0.00005, } @@ -111,14 +112,14 @@ pub fn follow_cursor_with_camera( for motion in motions.iter() { let window_scale = window.height().min(window.width()); if btn.pressed(MouseButton::Right) { - pitch -= (settings.aimed_sensitivity * motion.delta.y * window_scale) + pitch -= ((settings.aimed_sensitivity * motion.delta.y as f64 * window_scale as f64) as f32) .to_radians(); - yaw -= (settings.aimed_sensitivity * motion.delta.x * window_scale) + yaw -= ((settings.aimed_sensitivity * motion.delta.x as f64 * window_scale as f64) as f32) .to_radians(); } else { pitch -= - (settings.sensitivity * motion.delta.y * window_scale).to_radians(); - yaw -= (settings.sensitivity * motion.delta.x * window_scale).to_radians(); + ((settings.sensitivity * motion.delta.y as f64 * window_scale as f64) as f32).to_radians(); + yaw -= ((settings.sensitivity * motion.delta.x as f64 * window_scale as f64) as f32).to_radians(); } } pitch = pitch.clamp(-1.54, 1.54); diff --git a/src/scenes/scene1/skybox.rs b/src/scenes/scene1/skybox.rs index 52ccd95..85c3971 100644 --- a/src/scenes/scene1/skybox.rs +++ b/src/scenes/scene1/skybox.rs @@ -13,7 +13,8 @@ use crate::comps::core::markers::camera::MainCamera; pub const CUBEMAPS: &[(&str, CompressedImageFormats)] = &[("skybox/skybox.png", CompressedImageFormats::NONE)]; -#[derive(Resource, Reflect)] +#[derive(Resource, Reflect, Default)] +#[reflect(Resource)] pub struct Cubemap { pub is_loaded: bool, pub image_handle: Handle, diff --git a/src/setup/animations.rs b/src/setup/animations.rs index b1f1a01..14f5a67 100644 --- a/src/setup/animations.rs +++ b/src/setup/animations.rs @@ -5,6 +5,7 @@ use crate::logic::core::guns::firearm::Firearm; use super::{assets::GltfAssets, load_state::GameLoadState}; #[derive(Resource, Default, Reflect)] +#[reflect(Resource)] pub struct AllFirearmAnimations { pub animations: Vec, } diff --git a/src/setup/assets.rs b/src/setup/assets.rs index cc0724e..4df9ade 100644 --- a/src/setup/assets.rs +++ b/src/setup/assets.rs @@ -10,7 +10,8 @@ pub enum GltfAssetType { #[allow(unused)] Enemy, } -#[derive(Resource, Reflect)] +#[derive(Resource, Reflect, Default)] +#[reflect(Resource)] pub struct GltfAssets { pub assets: Vec } diff --git a/src/setup/load_state.rs b/src/setup/load_state.rs index 9f2fec1..12750af 100644 --- a/src/setup/load_state.rs +++ b/src/setup/load_state.rs @@ -1,6 +1,7 @@ use bevy::prelude::*; #[derive(Resource, Default, Reflect)] +#[reflect(Resource)] pub struct GameLoadState { pub assets_loaded: bool, pub animations_loaded: bool, diff --git a/src/ui/editor/inspector.rs b/src/ui/editor/inspector.rs index 93805d2..cba097b 100644 --- a/src/ui/editor/inspector.rs +++ b/src/ui/editor/inspector.rs @@ -1,4 +1,5 @@ use bevy::{prelude::*, window::PrimaryWindow}; +use bevy_editor_pls::controls::{self, EditorControls}; use bevy_inspector_egui::{egui, bevy_egui::EguiContext, bevy_inspector}; #[allow(unused)] @@ -15,4 +16,19 @@ pub fn inspector_ui(world: &mut World) { bevy_inspector::ui_for_world(world, ui); }); }); +} + +pub fn editor_controls() -> EditorControls { + let mut editor_controls = EditorControls::default_bindings(); + editor_controls.unbind(controls::Action::PlayPauseEditor); + + editor_controls.insert( + controls::Action::PlayPauseEditor, + controls::Binding { + input: controls::UserInput::Single(controls::Button::Keyboard(KeyCode::Back)), + conditions: vec![controls::BindingCondition::ListeningForText(false)], + }, + ); + + editor_controls } \ No newline at end of file diff --git a/src/ui/editor/plugin.rs b/src/ui/editor/plugin.rs index dfcdd40..fd40d1d 100644 --- a/src/ui/editor/plugin.rs +++ b/src/ui/editor/plugin.rs @@ -4,6 +4,8 @@ use bevy_inspector_egui::bevy_egui::EguiPlugin; use crate::{logic::core::{guns::{player_firing::PlayerFiringInfo, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}, player::{player_values_state::PlayerValuesState, camera_player_sync::MouseMovementSettings, player_movement::{PlayerLinearYState, PlayerLinearXZState, PlayerMovementInput}}}, comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::{HoldableObjectData, InPlayerHands}, player::{PlayerData, Player, PlayerHand}}, scenes::scene1::skybox::Cubemap, setup::{animations::{AllFirearmAnimations, FirearmAnimations}, assets::{GltfAssetType, GltfAssets}, equipment::Equipment, load_state::GameLoadState}}; +use super::inspector::editor_controls; + //use super::inspector::inspector_ui; //use super::{panels::editor_ui, state::EditorUiState, camera::set_camera_viewport}; @@ -37,7 +39,9 @@ impl Plugin for MainEditorUiPlugin { .register_type::() .register_type::() .add_plugins(EguiPlugin) - .add_plugins(EditorPlugin::default()); + .add_plugins(EditorPlugin::default()) + .insert_resource(editor_controls()); + //.add_plugins(ResourceInspectorPlugin::::default()); //.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s //.add_systems(Update, inspector_ui); //app.insert_resource(EditorUiState::new()); diff --git a/src/ui/game/settings.rs b/src/ui/game/settings.rs index 7f7a037..693deaa 100644 --- a/src/ui/game/settings.rs +++ b/src/ui/game/settings.rs @@ -1,6 +1,7 @@ use bevy::prelude::*; -#[derive(Resource)] +#[derive(Resource, Reflect)] +#[reflect(Resource)] pub struct SettingsScreenUIConfiguration { pub settings_menu_shown: bool, } @@ -11,7 +12,8 @@ impl Default for SettingsScreenUIConfiguration { } } -#[derive(Resource)] +#[derive(Resource, Reflect)] +#[reflect(Resource)] pub struct GameConfiguration { pub fps_counter_enabled: bool,