Optic movement Done, inspect ui improvements, and selection

This commit is contained in:
Franklin 2023-11-24 10:21:03 -04:00
parent 66c651cb93
commit fa481130b0
19 changed files with 227 additions and 49 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@ use bevy::prelude::*;
use crate::comps::core::{items::item::Item, weapons::firearm_state::FirearmState}; 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 { pub enum ItemState {
Weapon(FirearmState), Weapon(FirearmState),
} }

View File

@ -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; use crate::comps::core::weapons::slot::slot::WeaponSlot;
#[derive(Component, PartialEq, Eq, PartialOrd, Ord)] #[derive(Component, PartialEq, Eq, PartialOrd, Ord)]
pub struct InspectScreenUiMarker; pub struct InspectScreenUiMarker;
#[derive(Component, PartialEq, Eq, PartialOrd, Ord)] #[derive(Component, PartialEq, Reflect, Default)]
pub struct InspectScreenSlotUiMarker(pub WeaponSlot); #[reflect(Component)]
pub struct InspectScreenSlotUiMarker {
pub slot: WeaponSlot,
pub active: bool,
pub selected: bool,
}

View File

@ -1,8 +1,8 @@
use bevy::app::{Plugin, Update}; 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 // Attachments
app.register_type::<WeaponAttachment>(); app.register_type::<WeaponAttachment>();
app.register_type::<SightPlacementStart>();
app.register_type::<SightPlacementEnd>();
app.register_type::<WeaponSlot>(); app.register_type::<WeaponSlot>();
app.register_type::<Optic>(); app.register_type::<Optic>();
app.register_type::<Stock>(); app.register_type::<Stock>();
@ -43,8 +46,6 @@ impl Plugin for ProxyComponentsPlugin {
app.register_type::<CompensatorSlot>(); app.register_type::<CompensatorSlot>();
app.register_type::<ForeGripSlot>(); app.register_type::<ForeGripSlot>();
app.register_type::<MagazineSlot>(); app.register_type::<MagazineSlot>();
app.register_type::<SightPlacementStartSlot>();
app.register_type::<SightPlacementEndSlot>();
app.register_type::<StockSlot>(); app.register_type::<StockSlot>();
app.register_type::<UtilitySlot>(); app.register_type::<UtilitySlot>();

View File

@ -1,8 +1,10 @@
use std::mem::discriminant;
use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstance}; 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 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)] #[derive(SystemParam)]
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { 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<FirearmState>, Changed<FirearmState>)>>, 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)>,
attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>, 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>)>,
in_player_hands_query: Query<'w, 's, &'static ItemId, With<InPlayerHands>>, in_player_hands_query: Query<'w, 's, &'static ItemId, With<InPlayerHands>>,
player_inventories_query: Query<'w, 's, &'static PlayerInventory>, 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 { if let Some(initial_attachments) = initial_attchments_opt {
for initial_attachment in initial_attachments.attachments.iter() { 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()) }); 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; continue;
} }
for attachment_slot in firearm_state.attachment_slots.iter() { 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(); commands.entity(slot_entity).despawn_descendants();
match &attachment_slot.attachment { match &attachment_slot.attachment {
Some(attachment) => Some(attachment) =>

View File

@ -1,3 +1,4 @@
pub mod firearm; pub mod firearm;
pub mod initial_attachments; pub mod initial_attachments;
pub mod gun_colliders; pub mod gun_colliders;
pub mod sight_placement;

View File

@ -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;

View File

@ -4,7 +4,7 @@ use uuid::Uuid;
use crate::comps::core::{ use crate::comps::core::{
items::{guns::ak105::Ak105GunItem, item::{Item, ItemId}}, 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)] #[derive(Component)]
@ -44,6 +44,7 @@ impl Ak105SpawnPoint {
WeaponAttachment::ForeGrip(ForeGrip::Pk5), WeaponAttachment::ForeGrip(ForeGrip::Pk5),
WeaponAttachment::Magazine(Magazine::Ak105), WeaponAttachment::Magazine(Magazine::Ak105),
WeaponAttachment::Stock(Stock::MagpullTan), WeaponAttachment::Stock(Stock::MagpullTan),
WeaponAttachment::Optic(Optic::AimpointT1),
]), ]),
} }
} }

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
use super::{attachments::weapon_attachment::WeaponAttachment, slot::slot::WeaponSlot}; 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 struct AttachmentSlot {
pub attachment: Option<WeaponAttachment>, pub attachment: Option<WeaponAttachment>,
pub slot_type: WeaponSlot, pub slot_type: WeaponSlot,

View File

@ -64,7 +64,7 @@ impl WeaponAttachment {
WeaponAttachment::Magazine(_) => slot == &WeaponSlot::MagazineSlot, WeaponAttachment::Magazine(_) => slot == &WeaponSlot::MagazineSlot,
WeaponAttachment::Stock(_) => slot == &WeaponSlot::StockSlot, WeaponAttachment::Stock(_) => slot == &WeaponSlot::StockSlot,
WeaponAttachment::ForeGrip(_) => slot == &WeaponSlot::ForeGripSlot, WeaponAttachment::ForeGrip(_) => slot == &WeaponSlot::ForeGripSlot,
WeaponAttachment::Optic(_) => slot == &WeaponSlot::SightPlacementStartSlot || slot == &WeaponSlot::SightPlacementEndSlot, WeaponAttachment::Optic(_) => slot == &WeaponSlot::SightSlot,
} }
} }
} }

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
use super::{attachment_slot::AttachmentSlot, slot::slot::WeaponSlot, magazine_data::MagazineData}; 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 struct FirearmState {
pub attachment_slots: Vec<AttachmentSlot>, pub attachment_slots: Vec<AttachmentSlot>,
pub magazine_data: Option<MagazineData>, pub magazine_data: Option<MagazineData>,

View File

@ -3,6 +3,4 @@ pub mod magazine_slot;
pub mod stock_slot; pub mod stock_slot;
pub mod fore_grip_slot; pub mod fore_grip_slot;
pub mod utility_slot; pub mod utility_slot;
pub mod sight_placement_start_slot;
pub mod sight_placement_end_slot;
pub mod slot; pub mod slot;

View File

@ -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;

View File

@ -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;

View File

@ -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)] #[reflect(Component)]
pub enum WeaponSlot { pub enum WeaponSlot {
ForeGripSlot, ForeGripSlot,
MagazineSlot, MagazineSlot,
CompensatorSlot, CompensatorSlot,
SightPlacementEndSlot, /// Start and End translation Vectors
SightPlacementStartSlot, SightSlot,
#[default] #[default]
StockSlot, StockSlot,
UtilitySlot, UtilitySlot,
} }
impl WeaponSlot {
pub fn get_all_slots() -> Vec<Self> {
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"),
}
}
}

View File

@ -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; 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<InPlayerHandsParent>, Without<WeaponSlot>, Without<SightPlacementEnd>, Without<SightPlacementStart>)>,
player_firing_info_query: Query<'w, 's, (&'static mut PlayerFiringInfo, Entity), With<Player>>,
inspectable_slot_query: Query<'w, 's, &'static mut InspectScreenSlotUiMarker>,
slot_query: Query<'w, 's, (&'static mut Transform, &'static Parent, &'static Children, &'static WeaponSlot), (Without<SightPlacementEnd>, Without<SightPlacementStart>)>,
sight_placement_query: Query<'w, 's, (&'static Parent, &'static mut Transform), (Or<(With<SightPlacementStart>, With<SightPlacementEnd>)>, Without<WeaponSlot>)>,
}
pub fn inspect_firearm( pub fn inspect_firearm(
//mut commands: Commands, mut commands: Commands,
mut in_player_hands_parent_query: Query<&mut Transform, With<InPlayerHandsParent>>, mut queries: InspectFirearmQueryParams,
mut player_firing_info_query: Query<&mut PlayerFiringInfo, With<Player>>, game_ui_state: Res<GameUiState>,
time: Res<Time>, time: Res<Time>,
keyboard_input: Res<Input<KeyCode>>, keyboard_input: Res<Input<KeyCode>>,
mut mouse_wheel_events: EventReader<MouseWheel>,
) { ) {
for mut player_firing_info in player_firing_info_query.iter_mut() { for (mut player_firing_info, player_entity) in queries.player_firing_info_query.iter_mut() {
for mut in_player_hands_parent_transform in in_player_hands_parent_query.iter_mut() { for (mut in_player_hands_parent_transform, in_player_hands_entity, in_player_hands_parent) in queries.in_player_hands_parent_query.iter_mut() {
//if !find_child_in_parent_children(&mut commands, player_entity, in_player_hands_parent.get(), &queries.children) {
// continue;
//}
if player_firing_info.is_inspecting { if player_firing_info.is_inspecting {
let inspect_hand_transform: Transform = Transform { let inspect_hand_transform: Transform = Transform {
translation: Vec3 { x: 0.0, y: -0.1, z: -0.8 }, translation: Vec3 { x: 0.0, y: -0.1, z: -0.8 },
@ -22,9 +34,77 @@ pub fn inspect_firearm(
..Default::default() ..Default::default()
}; };
*in_player_hands_parent_transform = in_player_hands_parent_transform.lerp(inspect_hand_transform, time.delta_seconds() / 0.5); *in_player_hands_parent_transform = in_player_hands_parent_transform.lerp(inspect_hand_transform, time.delta_seconds() / 0.5);
if game_ui_state.any_window() { return; }
if keyboard_input.just_pressed(KeyCode::Return) { if keyboard_input.just_pressed(KeyCode::Return) {
for mut inspectable_slot in queries.inspectable_slot_query.iter_mut() {
inspectable_slot.selected = false;
}
player_firing_info.is_inspecting = false; player_firing_info.is_inspecting = false;
} return;
}
let mut selected: Option<u32> = None;
for (index, input) in [KeyCode::Key1, KeyCode::Key2, KeyCode::Key3, KeyCode::Key4, KeyCode::Key5, KeyCode::Key6].into_iter().enumerate() {
if keyboard_input.just_pressed(input) {
selected = Some(index as u32 + 1);
break;
}
}
for mut inspectable_slot in queries.inspectable_slot_query.iter_mut() {
if let Some(selected) = selected { // If user selects a slot
if inspectable_slot.slot.get_index() == selected && inspectable_slot.active {
inspectable_slot.selected = true;
} else {
inspectable_slot.selected = false;
}
}
for (mut slot_transform, slot_parent, slot_children, slot) in queries.slot_query.iter_mut() {
if slot != &inspectable_slot.slot { continue; }
if !find_child_in_parent_children(&mut commands, in_player_hands_entity, slot_parent.get(), &queries.children) {
continue;
}
if keyboard_input.just_pressed(KeyCode::A) || keyboard_input.just_pressed(KeyCode::Left) {
} else if keyboard_input.just_pressed(KeyCode::D) || keyboard_input.just_pressed(KeyCode::Right) {
}
if inspectable_slot.slot == WeaponSlot::SightSlot && inspectable_slot.selected {
println!("sightslot");
// The optic should sit in between these two transforms
let mut pos_1 = None;
let mut pos_2 = None;
for (sight_placement_parent, sight_placement_transform) in queries.sight_placement_query.iter() {
if slot_parent != sight_placement_parent { continue; }
if pos_1.is_none() {
pos_1 = Some(sight_placement_transform.translation)
} else {
pos_2 = Some(sight_placement_transform.translation)
}
}
for mouse_wheel_event in mouse_wheel_events.read() { // TODO: Specifically for optic, scroll wheel == position change
println!("mouse");
match (pos_1, pos_2) {
(None, None) => break,
(None, Some(pos_2)) => { slot_transform.translation = pos_2 },
(Some(pos_1), None) => { slot_transform.translation = pos_1 },
(Some(pos_1), Some(pos_2)) => {
let move_sight_by_y = mouse_wheel_event.y * time.delta_seconds() * 1.0;
slot_transform.translation.y = (move_sight_by_y + slot_transform.translation.y).clamp(pos_1.y.min(pos_2.y), pos_1.y.max(pos_2.y));
println!("moved");
},
};
// TODO: Translate SightSlot transform by mouse_wheel_event.y * time.delta_time_seconds() * sens_multiplier
}
}
}
}
} }
} }
} }

View File

@ -16,7 +16,7 @@ use super::assets::{GltfAssetType, GltfAssets};
#[derive(Event)] #[derive(Event)]
pub struct EquipmentChangeEvent(pub Equipment, pub Option<ItemId>); pub struct EquipmentChangeEvent(pub Equipment, pub Option<ItemId>);
/// Foundation for inventory System. /// Foundation for inventory System.
#[derive(Component, Clone, Default, Reflect, PartialEq, PartialOrd)] #[derive(Component, Clone, Default, Reflect, PartialEq)]
pub enum Equipment { pub enum Equipment {
Firearm(Firearm, FirearmState), Firearm(Firearm, FirearmState),
#[default] #[default]

View File

@ -5,7 +5,7 @@ use bevy_inspector_egui::bevy_egui::EguiPlugin;
use crate::{ use crate::{
comps::core::{markers::{ comps::core::{markers::{
holdable::{HoldableObjectData, InPlayerHands}, holdable::{HoldableObjectData, InPlayerHands},
player::{Player, PlayerData, PlayerHand}, player::{Player, PlayerData, PlayerHand}, inspect_screen::InspectScreenSlotUiMarker,
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern, firearm_state::FirearmState}}, }, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern, firearm_state::FirearmState}},
logic::core::{ logic::core::{
guns::player_firing::PlayerFiringInfo, guns::player_firing::PlayerFiringInfo,
@ -54,6 +54,7 @@ impl Plugin for MainEditorUiPlugin {
.register_type::<Cubemap>() .register_type::<Cubemap>()
.register_type::<FirearmState>() .register_type::<FirearmState>()
.register_type::<PlayerSettings>() .register_type::<PlayerSettings>()
.register_type::<InspectScreenSlotUiMarker>()
//.register_type::<AllAnimations>() //.register_type::<AllAnimations>()
//.register_type::<FirearmAnimations>() //.register_type::<FirearmAnimations>()
.register_type::<GltfAssetType>() .register_type::<GltfAssetType>()

View File

@ -4,7 +4,7 @@ use crate::{comps::core::{markers::{inspect_screen::{InspectScreenUiMarker, Insp
pub fn setup_inspect_screen(mut commands: Commands) { pub fn setup_inspect_screen(mut commands: Commands) {
// Background // Background
commands let background = commands
.spawn(( .spawn((
NodeBundle { NodeBundle {
style: Style { style: Style {
@ -24,7 +24,42 @@ pub fn setup_inspect_screen(mut commands: Commands) {
}, },
Name::new("Inspect Screen"), Name::new("Inspect Screen"),
)) ))
.insert(InspectScreenUiMarker); .insert(InspectScreenUiMarker).id();
for slot in WeaponSlot::get_all_slots().into_iter() {
let node_bg = commands.spawn((
Name::new(format!("{:?} UI Node", slot)),
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
display: Display::Flex,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
padding: UiRect::all(Val::Percent(1.0)),
border: UiRect::all(Val::Px(0.5)),
..Default::default()
},
background_color: BackgroundColor(Color::Rgba { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.96 }),
border_color: BorderColor(Color::WHITE),
..Default::default()
},
InspectScreenSlotUiMarker {
slot: slot.clone(),
active: false,
selected: false,
},
)).set_parent(background).id();
commands.spawn((
Name::new(format!("{:?} Text Node", slot)),
TextBundle {
text: Text::from_sections([
TextSection { value: format!("{} ", slot.get_index()), style: TextStyle { font_size: 20.0, color: Color::WHITE, ..Default::default() }},
TextSection { value: format!("{}", slot.to_string()), style: TextStyle { font_size: 14.0, color: Color::WHITE, ..Default::default() }},
]),
..Default::default()
}.with_text_alignment(TextAlignment::Center),
)).set_parent(node_bg);
}
// TODO: Create every single slot to be used here (1 per weapon slot) // TODO: Create every single slot to be used here (1 per weapon slot)
} }
@ -40,7 +75,7 @@ pub fn update_inspect_screen(
mut firearm_query: Query<(Entity, &mut FirearmState), Without<InPlayerHands>>, mut firearm_query: Query<(Entity, &mut FirearmState), Without<InPlayerHands>>,
slots_query: Query<(Entity, &WeaponSlot, &GlobalTransform)>, slots_query: Query<(Entity, &WeaponSlot, &GlobalTransform)>,
mut inspect_screen_query: Query<(Entity, &mut Visibility), With<InspectScreenUiMarker>>, mut inspect_screen_query: Query<(Entity, &mut Visibility), With<InspectScreenUiMarker>>,
mut inspect_slots_query: Query<(Entity, &mut Visibility, &mut InspectScreenSlotUiMarker)>, mut inspect_slots_query: Query<(Entity, &mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without<InspectScreenUiMarker>>,
camera_query: Query<(&Camera, &GlobalTransform), With<MainCamera>>, camera_query: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
) { ) {
for (inspect_screen_entity, mut inspect_screen_visibility) in inspect_screen_query.iter_mut() { for (inspect_screen_entity, mut inspect_screen_visibility) in inspect_screen_query.iter_mut() {
@ -49,16 +84,36 @@ pub fn update_inspect_screen(
*inspect_screen_visibility = Visibility::Visible; *inspect_screen_visibility = Visibility::Visible;
// TODO: Build // TODO: Build
for (camera, camera_transform) in camera_query.iter() { 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 (slot_entity, slot, slot_transform) in slots_query.iter() {
for (inspect_slot_entity, mut inspect_slot_visibility, mut inspect_slot) in inspect_slots_query.iter_mut() { if &inspect_slot.slot == slot {
// Create slot if not there, number them, etc... //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()) {
Some(pos_vec) => {
*inspect_slot_visibility = Visibility::Visible;
inspect_slot.active = true;
inspect_slot_style.top = Val::Px(pos_vec.y);
inspect_slot_style.left = Val::Px(pos_vec.x);
if inspect_slot.selected {
*inspect_slot_border_color = BorderColor(Color::GREEN);
} else {
*inspect_slot_border_color = BorderColor(Color::WHITE);
}
},
None => {
*inspect_slot_visibility = Visibility::Hidden;
inspect_slot.active = false;
},
};
}
} }
camera.world_to_viewport(camera_transform, slot_transform.translation());
} }
} }
} else { } else {
*inspect_screen_visibility = Visibility::Hidden; *inspect_screen_visibility = Visibility::Hidden;
for (_, mut inspect_slot_visibility, _, _, _) in inspect_slots_query.iter_mut() {
*inspect_slot_visibility = Visibility::Hidden;
}
} }
} }
} }