diff --git a/assets/weapons/ak105_rifle.glb b/assets/weapons/ak105_rifle.glb index 2266a2f..439e9c9 100644 Binary files a/assets/weapons/ak105_rifle.glb and b/assets/weapons/ak105_rifle.glb differ diff --git a/src/comps/core/events/pickup_item.rs b/src/comps/core/events/pickup_item.rs index 752a000..a32a69b 100644 --- a/src/comps/core/events/pickup_item.rs +++ b/src/comps/core/events/pickup_item.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; use crate::comps::core::{items::item::Item, weapons::firearm_state::FirearmState}; -#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)] +#[derive(Component, Reflect, PartialEq, Debug, Clone)] pub enum ItemState { Weapon(FirearmState), } diff --git a/src/comps/core/markers/inspect_screen.rs b/src/comps/core/markers/inspect_screen.rs index 05cb0b2..72fe4c4 100644 --- a/src/comps/core/markers/inspect_screen.rs +++ b/src/comps/core/markers/inspect_screen.rs @@ -1,9 +1,14 @@ -use bevy::ecs::component::Component; +use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect}; use crate::comps::core::weapons::slot::slot::WeaponSlot; #[derive(Component, PartialEq, Eq, PartialOrd, Ord)] pub struct InspectScreenUiMarker; -#[derive(Component, PartialEq, Eq, PartialOrd, Ord)] -pub struct InspectScreenSlotUiMarker(pub WeaponSlot); \ No newline at end of file +#[derive(Component, PartialEq, Reflect, Default)] +#[reflect(Component)] +pub struct InspectScreenSlotUiMarker { + pub slot: WeaponSlot, + pub active: bool, + pub selected: bool, +} diff --git a/src/comps/core/markers/proxy/plugin.rs b/src/comps/core/markers/proxy/plugin.rs index 3e68354..7efc47d 100644 --- a/src/comps/core/markers/proxy/plugin.rs +++ b/src/comps/core/markers/proxy/plugin.rs @@ -1,8 +1,8 @@ use bevy::app::{Plugin, Update}; -use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, sight_placement_start_slot::SightPlacementStartSlot, sight_placement_end_slot::SightPlacementEndSlot, stock_slot::StockSlot, utility_slot::UtilitySlot, slot::WeaponSlot}}}; +use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, stock_slot::StockSlot, utility_slot::UtilitySlot, slot::WeaponSlot}}}; -use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}, weapons::{firearm::insert_firearm_state_to_firearms, gun_colliders::{GunFirearmCollider, update_gun_collider}}}; +use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}, weapons::{firearm::insert_firearm_state_to_firearms, gun_colliders::{GunFirearmCollider, update_gun_collider}, sight_placement::{SightPlacementStart, SightPlacementEnd}}}; @@ -26,6 +26,9 @@ impl Plugin for ProxyComponentsPlugin { // Attachments app.register_type::(); + app.register_type::(); + app.register_type::(); + app.register_type::(); app.register_type::(); app.register_type::(); @@ -43,8 +46,6 @@ impl Plugin for ProxyComponentsPlugin { app.register_type::(); app.register_type::(); app.register_type::(); - app.register_type::(); - app.register_type::(); app.register_type::(); app.register_type::(); diff --git a/src/comps/core/markers/proxy/weapons/firearm.rs b/src/comps/core/markers/proxy/weapons/firearm.rs index 6acada6..e859a21 100644 --- a/src/comps/core/markers/proxy/weapons/firearm.rs +++ b/src/comps/core/markers/proxy/weapons/firearm.rs @@ -1,8 +1,10 @@ +use std::mem::discriminant; + use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstance}; use crate::{comps::core::{weapons::{firearm::Firearm, firearm_state::FirearmState, slot::slot::WeaponSlot, attachment_slot::AttachmentSlot, attachments::weapon_attachment::WeaponAttachment}, events::pickup_item::ItemState, markers::holdable::InPlayerHands, inventory::player_inventory::PlayerInventory, items::item::ItemId}, setup::assets::{GltfAssets, GltfAssetType}}; -use super::initial_attachments::InitialAttachments; +use super::{initial_attachments::InitialAttachments, sight_placement::{SightPlacementStart, SightPlacementEnd}}; #[derive(SystemParam)] pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { @@ -10,6 +12,8 @@ pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static mut FirearmState>), Or<(Without, Changed)>>, slots_query: Query<'w, 's, (Entity, &'static WeaponSlot, &'static Parent)>, attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>, + //sight_placement_start_query: Query<'w, 's, (&'static Parent, &'static Transform), (With, Without)>, + //sight_placement_end_query: Query<'w, 's, (&'static Parent, &'static Transform), (With, Without)>, in_player_hands_query: Query<'w, 's, &'static ItemId, With>, player_inventories_query: Query<'w, 's, &'static PlayerInventory>, } @@ -72,6 +76,7 @@ pub fn insert_firearm_state_to_firearms( }); } } + if let Some(initial_attachments) = initial_attchments_opt { for initial_attachment in initial_attachments.attachments.iter() { firearm_slots.iter_mut().for_each(|firearm_slot| if initial_attachment.fits_into_slot(&firearm_slot.slot_type) { firearm_slot.attachment = Some(initial_attachment.clone()) }); @@ -103,7 +108,7 @@ fn spawn_attachments_in_firearm( continue; } for attachment_slot in firearm_state.attachment_slots.iter() { - if &attachment_slot.slot_type == weapon_slot { + if discriminant(&attachment_slot.slot_type) == discriminant(weapon_slot) { commands.entity(slot_entity).despawn_descendants(); match &attachment_slot.attachment { Some(attachment) => diff --git a/src/comps/core/markers/proxy/weapons/mod.rs b/src/comps/core/markers/proxy/weapons/mod.rs index 0658ba3..78da5ef 100644 --- a/src/comps/core/markers/proxy/weapons/mod.rs +++ b/src/comps/core/markers/proxy/weapons/mod.rs @@ -1,3 +1,4 @@ pub mod firearm; pub mod initial_attachments; -pub mod gun_colliders; \ No newline at end of file +pub mod gun_colliders; +pub mod sight_placement; \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/sight_placement.rs b/src/comps/core/markers/proxy/weapons/sight_placement.rs new file mode 100644 index 0000000..e5cc8a7 --- /dev/null +++ b/src/comps/core/markers/proxy/weapons/sight_placement.rs @@ -0,0 +1,9 @@ +use bevy::prelude::*; + +#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug, Default)] +#[reflect(Component, Default)] +pub struct SightPlacementStart; + +#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug, Default)] +#[reflect(Component, Default)] +pub struct SightPlacementEnd; \ No newline at end of file diff --git a/src/comps/core/spawners/guns/ak105_spawner.rs b/src/comps/core/spawners/guns/ak105_spawner.rs index e981000..253b6c6 100644 --- a/src/comps/core/spawners/guns/ak105_spawner.rs +++ b/src/comps/core/spawners/guns/ak105_spawner.rs @@ -4,7 +4,7 @@ use uuid::Uuid; use crate::comps::core::{ items::{guns::ak105::Ak105GunItem, item::{Item, ItemId}}, - spawners::item::ItemSpawnPoint, weapons::attachments::{weapon_attachment::WeaponAttachment, compensator::Compensator, foregrip::ForeGrip, magazine::Magazine, stock::Stock}, markers::proxy::weapons::initial_attachments::InitialAttachments, + spawners::item::ItemSpawnPoint, weapons::attachments::{weapon_attachment::WeaponAttachment, compensator::Compensator, foregrip::ForeGrip, magazine::Magazine, stock::Stock, optic::Optic}, markers::proxy::weapons::initial_attachments::InitialAttachments, }; #[derive(Component)] @@ -44,6 +44,7 @@ impl Ak105SpawnPoint { WeaponAttachment::ForeGrip(ForeGrip::Pk5), WeaponAttachment::Magazine(Magazine::Ak105), WeaponAttachment::Stock(Stock::MagpullTan), + WeaponAttachment::Optic(Optic::AimpointT1), ]), } } diff --git a/src/comps/core/weapons/attachment_slot.rs b/src/comps/core/weapons/attachment_slot.rs index b4d30f9..96da357 100644 --- a/src/comps/core/weapons/attachment_slot.rs +++ b/src/comps/core/weapons/attachment_slot.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use super::{attachments::weapon_attachment::WeaponAttachment, slot::slot::WeaponSlot}; -#[derive(Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Default)] +#[derive(Reflect, PartialEq, Debug, Clone, Default)] pub struct AttachmentSlot { pub attachment: Option, pub slot_type: WeaponSlot, diff --git a/src/comps/core/weapons/attachments/weapon_attachment.rs b/src/comps/core/weapons/attachments/weapon_attachment.rs index fbcfacb..66b8dab 100644 --- a/src/comps/core/weapons/attachments/weapon_attachment.rs +++ b/src/comps/core/weapons/attachments/weapon_attachment.rs @@ -64,7 +64,7 @@ impl WeaponAttachment { WeaponAttachment::Magazine(_) => slot == &WeaponSlot::MagazineSlot, WeaponAttachment::Stock(_) => slot == &WeaponSlot::StockSlot, WeaponAttachment::ForeGrip(_) => slot == &WeaponSlot::ForeGripSlot, - WeaponAttachment::Optic(_) => slot == &WeaponSlot::SightPlacementStartSlot || slot == &WeaponSlot::SightPlacementEndSlot, + WeaponAttachment::Optic(_) => slot == &WeaponSlot::SightSlot, } } } \ No newline at end of file diff --git a/src/comps/core/weapons/firearm_state.rs b/src/comps/core/weapons/firearm_state.rs index b6de066..3584c51 100644 --- a/src/comps/core/weapons/firearm_state.rs +++ b/src/comps/core/weapons/firearm_state.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use super::{attachment_slot::AttachmentSlot, slot::slot::WeaponSlot, magazine_data::MagazineData}; -#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)] +#[derive(Component, Reflect, PartialEq, Debug, Clone)] pub struct FirearmState { pub attachment_slots: Vec, pub magazine_data: Option, diff --git a/src/comps/core/weapons/slot/mod.rs b/src/comps/core/weapons/slot/mod.rs index de1a9f9..7c4c49f 100644 --- a/src/comps/core/weapons/slot/mod.rs +++ b/src/comps/core/weapons/slot/mod.rs @@ -3,6 +3,4 @@ pub mod magazine_slot; pub mod stock_slot; pub mod fore_grip_slot; pub mod utility_slot; -pub mod sight_placement_start_slot; -pub mod sight_placement_end_slot; pub mod slot; \ No newline at end of file diff --git a/src/comps/core/weapons/slot/sight_placement_end_slot.rs b/src/comps/core/weapons/slot/sight_placement_end_slot.rs deleted file mode 100644 index c25e75f..0000000 --- a/src/comps/core/weapons/slot/sight_placement_end_slot.rs +++ /dev/null @@ -1,5 +0,0 @@ -use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect}; - -#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)] -#[reflect(Component)] -pub struct SightPlacementEndSlot; \ No newline at end of file diff --git a/src/comps/core/weapons/slot/sight_placement_start_slot.rs b/src/comps/core/weapons/slot/sight_placement_start_slot.rs deleted file mode 100644 index 1fcf69b..0000000 --- a/src/comps/core/weapons/slot/sight_placement_start_slot.rs +++ /dev/null @@ -1,5 +0,0 @@ -use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect}; - -#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)] -#[reflect(Component)] -pub struct SightPlacementStartSlot; \ No newline at end of file diff --git a/src/comps/core/weapons/slot/slot.rs b/src/comps/core/weapons/slot/slot.rs index 8309669..b63ec02 100644 --- a/src/comps/core/weapons/slot/slot.rs +++ b/src/comps/core/weapons/slot/slot.rs @@ -1,14 +1,46 @@ -use bevy::{reflect::Reflect, ecs::{reflect::ReflectComponent, component::Component}}; +use bevy::{reflect::Reflect, ecs::{reflect::ReflectComponent, component::Component}, math::Vec3}; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Reflect, Default, Component)] +#[derive(Clone, Debug, PartialEq, Reflect, Default, Component)] #[reflect(Component)] pub enum WeaponSlot { ForeGripSlot, MagazineSlot, CompensatorSlot, - SightPlacementEndSlot, - SightPlacementStartSlot, + /// Start and End translation Vectors + SightSlot, #[default] StockSlot, UtilitySlot, +} + +impl WeaponSlot { + pub fn get_all_slots() -> Vec { + Vec::from([ + Self::CompensatorSlot, + Self::ForeGripSlot, Self::MagazineSlot, Self::UtilitySlot, Self::SightSlot, Self::StockSlot + ]) + } + pub fn get_index(&self) -> u32 { + match self { + WeaponSlot::ForeGripSlot => 3, + WeaponSlot::MagazineSlot => 4, + WeaponSlot::CompensatorSlot => 1, + WeaponSlot::SightSlot => 5, + WeaponSlot::StockSlot => 6, + WeaponSlot::UtilitySlot => 2, + } + } +} + +impl ToString for WeaponSlot { + fn to_string(&self) -> String { + match self { + WeaponSlot::ForeGripSlot => String::from("Foregrip"), + WeaponSlot::MagazineSlot => String::from("Magazine"), + WeaponSlot::CompensatorSlot => String::from("Muzzle"), + WeaponSlot::SightSlot => String::from("Optic"), + WeaponSlot::StockSlot => String::from("Stock"), + WeaponSlot::UtilitySlot => String::from("Utility"), + } + } } \ No newline at end of file diff --git a/src/logic/core/guns/inspect.rs b/src/logic/core/guns/inspect.rs index b5656ad..66ac0d9 100644 --- a/src/logic/core/guns/inspect.rs +++ b/src/logic/core/guns/inspect.rs @@ -1,20 +1,32 @@ -use bevy::prelude::*; +use bevy::{prelude::*, input::mouse::MouseWheel, ecs::system::SystemParam}; -use crate::comps::core::markers::{proxy::{character::in_player_hands_parent::InPlayerHandsParent, physics::utils::TransformExt}, player::Player}; +use crate::{comps::core::{markers::{proxy::{character::in_player_hands_parent::InPlayerHandsParent, physics::utils::TransformExt, weapons::sight_placement::{SightPlacementStart, SightPlacementEnd}}, player::Player, inspect_screen::InspectScreenSlotUiMarker}, weapons::slot::slot::WeaponSlot}, ui::game::game_ui_state::GameUiState, utils::hierarchy::find_child_in_parent_children}; use super::player_firing::PlayerFiringInfo; - +#[derive(SystemParam)] +pub struct InspectFirearmQueryParams<'w, 's> { + children: Query<'w, 's, &'static Children>, + in_player_hands_parent_query: Query<'w, 's, (&'static mut Transform, Entity, &'static Parent), (With, Without, Without, Without)>, + player_firing_info_query: Query<'w, 's, (&'static mut PlayerFiringInfo, Entity), With>, + inspectable_slot_query: Query<'w, 's, &'static mut InspectScreenSlotUiMarker>, + slot_query: Query<'w, 's, (&'static mut Transform, &'static Parent, &'static Children, &'static WeaponSlot), (Without, Without)>, + sight_placement_query: Query<'w, 's, (&'static Parent, &'static mut Transform), (Or<(With, With)>, Without)>, +} pub fn inspect_firearm( - //mut commands: Commands, - mut in_player_hands_parent_query: Query<&mut Transform, With>, - mut player_firing_info_query: Query<&mut PlayerFiringInfo, With>, + mut commands: Commands, + mut queries: InspectFirearmQueryParams, + game_ui_state: Res, time: Res