From 13dd0e27330ba195cd41fd34af8e7a389d9242ef Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 24 Nov 2023 12:59:34 -0400 Subject: [PATCH] Finished persisting optic pos data --- Design.md | 2 +- .../core/markers/proxy/weapons/firearm.rs | 25 ++++++++++++--- src/ui/game/inspect/mapper.rs | 6 ---- src/ui/game/inspect/menu.rs | 32 +++++++------------ src/ui/game/inspect/mod.rs | 1 - 5 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 src/ui/game/inspect/mapper.rs diff --git a/Design.md b/Design.md index c1219e8..b7db72e 100644 --- a/Design.md +++ b/Design.md @@ -26,7 +26,7 @@ Multiplayer - [x] Inspect animation & state (procedural) - [x] Attachment editor system when in inspect mode - [x] remove Start and End optic from Slots, instead make one slot, and have code that checks for the starter slot and the end slot - - [ ] SightSlot not retaining position when dropped or switched. + - [x] SightSlot not retaining position when dropped or switched. - [x] High Ready & Low Ready system with state - [x] High ready animation (procedural) - [x] Low ready animation (procedural) diff --git a/src/comps/core/markers/proxy/weapons/firearm.rs b/src/comps/core/markers/proxy/weapons/firearm.rs index e859a21..a55a478 100644 --- a/src/comps/core/markers/proxy/weapons/firearm.rs +++ b/src/comps/core/markers/proxy/weapons/firearm.rs @@ -4,13 +4,13 @@ use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstanc 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, sight_placement::{SightPlacementStart, SightPlacementEnd}}; +use super::initial_attachments::InitialAttachments; #[derive(SystemParam)] pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, Option<&'static InitialAttachments>, &'static Children), With>, 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)>, + slots_query: Query<'w, 's, (Entity, &'static WeaponSlot, &'static Parent, &'static mut Transform)>, 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)>, @@ -37,6 +37,7 @@ pub fn insert_firearm_state_to_firearms( if let ItemState::Weapon(mut firearm_state) = item_state.clone() { commands.entity(firearm_scene_entity).remove::(); spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets); + adjust_sight_slot_position(&mut queries.slots_query, firearm_state.optic_pos); commands .entity(firearm_entity) .insert(firearm_state); @@ -48,6 +49,7 @@ pub fn insert_firearm_state_to_firearms( Some(mut firearm_state) => { // Change the Slots spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets); + adjust_sight_slot_position(&mut queries.slots_query, firearm_state.optic_pos); for in_player_hands_item_id in queries.in_player_hands_query.iter() { for player_inventory in queries.player_inventories_query.iter() { if let Some(current_item) = player_inventory.get_current_slot_item() { @@ -62,7 +64,7 @@ pub fn insert_firearm_state_to_firearms( // Create the firearm_state let mut firearm_slots = Vec::new(); let magazine_data = None; - for (slot_entity, slot, parent_entity) in queries.slots_query.iter() { + for (slot_entity, slot, parent_entity, _) in queries.slots_query.iter() { if firearm_entity == parent_entity.get() { let mut attachment = None; for (_, weapon_attachment, attachment_parent) in queries.attachments_query.iter() { @@ -99,11 +101,11 @@ fn spawn_attachments_in_firearm( commands: &mut Commands, firearm_entity: Entity, firearm_state: &mut FirearmState, - slots_query: &Query<(Entity, &WeaponSlot, &Parent)>, + slots_query: &Query<(Entity, &WeaponSlot, &Parent, &mut Transform)>, assets_gltf: &GltfAssets, loaded_gltf_assets: &Assets, ) { - for (slot_entity, weapon_slot, slot_parent) in slots_query.iter() { + for (slot_entity, weapon_slot, slot_parent, _) in slots_query.iter() { if slot_parent.get() != firearm_entity { continue; } @@ -136,4 +138,17 @@ fn spawn_attachments_in_firearm( } } } +} + +fn adjust_sight_slot_position( + slots_query: &mut Query<(Entity, &'static WeaponSlot, &'static Parent, &'static mut Transform)>, + optic_pos_opt: Option, +) { + if let Some(optic_pos) = optic_pos_opt { + for (_, slot, _, mut slot_transform) in slots_query.iter_mut() { + if slot == &WeaponSlot::SightSlot { + slot_transform.translation = optic_pos; + } + } + } } \ No newline at end of file diff --git a/src/ui/game/inspect/mapper.rs b/src/ui/game/inspect/mapper.rs deleted file mode 100644 index 1d74c9e..0000000 --- a/src/ui/game/inspect/mapper.rs +++ /dev/null @@ -1,6 +0,0 @@ -use bevy::prelude::*; - -/// This function takes currently equipped gun real world coordinates and converts them to UI coordinates that match the real world position in the screen. -pub fn map_gun_slots_to_ui_slots() { - -} \ No newline at end of file diff --git a/src/ui/game/inspect/menu.rs b/src/ui/game/inspect/menu.rs index a0826e4..4e3eba7 100644 --- a/src/ui/game/inspect/menu.rs +++ b/src/ui/game/inspect/menu.rs @@ -1,6 +1,6 @@ use bevy::{prelude::*, ui::FocusPolicy}; -use crate::{comps::core::{markers::{inspect_screen::{InspectScreenUiMarker, InspectScreenSlotUiMarker}, player::Player, holdable::InPlayerHands, camera::MainCamera}, weapons::{firearm_state::FirearmState, slot::slot::WeaponSlot}}, logic::core::guns::player_firing::PlayerFiringInfo}; +use crate::{comps::core::{markers::{inspect_screen::{InspectScreenUiMarker, InspectScreenSlotUiMarker}, camera::MainCamera}, weapons::slot::slot::WeaponSlot}, logic::core::guns::player_firing::PlayerFiringInfo}; pub fn setup_inspect_screen(mut commands: Commands) { // Background @@ -17,7 +17,7 @@ pub fn setup_inspect_screen(mut commands: Commands) { flex_direction: FlexDirection::Row, ..Default::default() }, - visibility: Visibility::Visible, //TODO: switch off + visibility: Visibility::Hidden, background_color: BackgroundColor(Color::NONE), focus_policy: FocusPolicy::Block, ..Default::default() @@ -60,32 +60,24 @@ pub fn setup_inspect_screen(mut commands: Commands) { )).set_parent(node_bg); } -// TODO: Create every single slot to be used here (1 per weapon slot) } -// TODO: put all queries in one params -// TODO: Add state of this screen to GameUiState -// TODO: Create slots if they aren't there for a specific weapon slot -// TODO: Hide and show slots depending on the weapon. -// TODO: Modify their contents to show what they have pub fn update_inspect_screen( - mut commands: Commands, - player_firing_info_query: Query<(&Player, &PlayerFiringInfo)>, - in_player_hands_query: Query<(Entity, &InPlayerHands, &Children), Without>, - mut firearm_query: Query<(Entity, &mut FirearmState), Without>, - slots_query: Query<(Entity, &WeaponSlot, &GlobalTransform)>, - mut inspect_screen_query: Query<(Entity, &mut Visibility), With>, - mut inspect_slots_query: Query<(Entity, &mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without>, + //commands: Commands, + player_firing_info_query: Query<&PlayerFiringInfo>, + slots_query: Query<(&WeaponSlot, &GlobalTransform)>, + mut inspect_screen_query: Query<&mut Visibility, With>, + mut inspect_slots_query: Query<(&mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without>, camera_query: Query<(&Camera, &GlobalTransform), With>, ) { - for (inspect_screen_entity, mut inspect_screen_visibility) in inspect_screen_query.iter_mut() { - for (player, player_firing_info) in player_firing_info_query.iter() { + for mut inspect_screen_visibility in inspect_screen_query.iter_mut() { + for player_firing_info in player_firing_info_query.iter() { if player_firing_info.is_inspecting { *inspect_screen_visibility = Visibility::Visible; // TODO: Build for (camera, camera_transform) in camera_query.iter() { - for (inspect_slot_entity, mut inspect_slot_visibility, mut inspect_slot, mut inspect_slot_style, mut inspect_slot_border_color) in inspect_slots_query.iter_mut() { - for (slot_entity, slot, slot_transform) in slots_query.iter() { + for (mut inspect_slot_visibility, mut inspect_slot, mut inspect_slot_style, mut inspect_slot_border_color) in inspect_slots_query.iter_mut() { + for (slot, slot_transform) in slots_query.iter() { if &inspect_slot.slot == slot { //inspect_slot_text.sections.first_mut().expect("No section in an already created text...").value = format!("{}", slot.get_index()); match camera.world_to_viewport(camera_transform, slot_transform.translation()) { @@ -111,7 +103,7 @@ pub fn update_inspect_screen( } } else { *inspect_screen_visibility = Visibility::Hidden; - for (_, mut inspect_slot_visibility, _, _, _) in inspect_slots_query.iter_mut() { + for (mut inspect_slot_visibility, _, _, _) in inspect_slots_query.iter_mut() { *inspect_slot_visibility = Visibility::Hidden; } } diff --git a/src/ui/game/inspect/mod.rs b/src/ui/game/inspect/mod.rs index 838d162..8875e5f 100644 --- a/src/ui/game/inspect/mod.rs +++ b/src/ui/game/inspect/mod.rs @@ -1,3 +1,2 @@ pub mod plugin; -pub mod mapper; pub mod menu; \ No newline at end of file