Finished persisting optic pos data
This commit is contained in:
parent
223d81d8f7
commit
13dd0e2733
|
@ -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)
|
||||
|
|
|
@ -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<SceneInstance>>,
|
||||
firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static mut FirearmState>), Or<(Without<FirearmState>, Changed<FirearmState>)>>,
|
||||
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<SightPlacementStart>, Without<SightPlacementEnd>)>,
|
||||
//sight_placement_end_query: Query<'w, 's, (&'static Parent, &'static Transform), (With<SightPlacementEnd>, Without<SightPlacementStart>)>,
|
||||
|
@ -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::<ItemState>();
|
||||
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<Gltf>,
|
||||
) {
|
||||
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<Vec3>,
|
||||
) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
||||
}
|
|
@ -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<Player>>,
|
||||
mut firearm_query: Query<(Entity, &mut FirearmState), Without<InPlayerHands>>,
|
||||
slots_query: Query<(Entity, &WeaponSlot, &GlobalTransform)>,
|
||||
mut inspect_screen_query: Query<(Entity, &mut Visibility), With<InspectScreenUiMarker>>,
|
||||
mut inspect_slots_query: Query<(Entity, &mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without<InspectScreenUiMarker>>,
|
||||
//commands: Commands,
|
||||
player_firing_info_query: Query<&PlayerFiringInfo>,
|
||||
slots_query: Query<(&WeaponSlot, &GlobalTransform)>,
|
||||
mut inspect_screen_query: Query<&mut Visibility, With<InspectScreenUiMarker>>,
|
||||
mut inspect_slots_query: Query<(&mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without<InspectScreenUiMarker>>,
|
||||
camera_query: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
|
||||
) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
pub mod plugin;
|
||||
pub mod mapper;
|
||||
pub mod menu;
|
Loading…
Reference in New Issue