diff --git a/Design.md b/Design.md index 678cdba..5ccdec7 100644 --- a/Design.md +++ b/Design.md @@ -39,7 +39,7 @@ Multiplayer - [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly - [x] Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) - [x] Optic glass material - - [ ] TODO: Reticle render + - [x] Reticle render - [ ] Parallax effect on reticle - [ ] Weapon Clipping - [x] Make the player's collider bigger towards the front diff --git a/assets/attachments/aimpoint_t1.glb b/assets/attachments/aimpoint_t1.glb index d03deff..c2b62d1 100644 Binary files a/assets/attachments/aimpoint_t1.glb and b/assets/attachments/aimpoint_t1.glb differ diff --git a/src/comps/core/markers/proxy/character/player_eye.rs b/src/comps/core/markers/proxy/character/player_eye.rs index a707869..b8e9d3f 100644 --- a/src/comps/core/markers/proxy/character/player_eye.rs +++ b/src/comps/core/markers/proxy/character/player_eye.rs @@ -1,4 +1,4 @@ -use bevy::{prelude::*, core_pipeline::{tonemapping::Tonemapping, bloom::{BloomSettings, BloomCompositeMode}}}; +use bevy::{prelude::*, core_pipeline::{tonemapping::Tonemapping, bloom::BloomSettings}}; use bevy_rapier3d::prelude::*; use crate::{comps::core::markers::{proxy::physics::rapier::LinkToPlayer, camera::MainCamera}, logic::core::player::player_values_state::PlayerValuesState}; diff --git a/src/comps/core/markers/proxy/weapons/mod.rs b/src/comps/core/markers/proxy/weapons/mod.rs index 696b9ad..db75712 100644 --- a/src/comps/core/markers/proxy/weapons/mod.rs +++ b/src/comps/core/markers/proxy/weapons/mod.rs @@ -2,4 +2,5 @@ pub mod firearm; pub mod initial_attachments; pub mod gun_colliders; pub mod sight_placement; -pub mod optic_sight_glass; \ No newline at end of file +pub mod optic_sight_glass; +pub mod reticle; \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/reticle.rs b/src/comps/core/markers/proxy/weapons/reticle.rs new file mode 100644 index 0000000..87323fb --- /dev/null +++ b/src/comps/core/markers/proxy/weapons/reticle.rs @@ -0,0 +1,5 @@ +use bevy::{ecs::component::Component, reflect::Reflect}; + + +#[derive(Component, Reflect, Clone, Debug, Default)] +pub struct DrawnReticle; \ No newline at end of file diff --git a/src/comps/core/weapons/attachments/optic.rs b/src/comps/core/weapons/attachments/optic.rs index 201c738..6f4dd35 100644 --- a/src/comps/core/weapons/attachments/optic.rs +++ b/src/comps/core/weapons/attachments/optic.rs @@ -20,13 +20,14 @@ impl Optic { } } + /// Goes from 1-300 pub fn default_reticle_brightness(&self) -> f32 { - 1.0 + 200.0 } pub fn reticle(&self) -> SightReticle { match self { - Optic::AimpointT1 => SightReticle::Dot(0.1, Color::rgb_linear(100.0, 0.0, 0.0)), + Optic::AimpointT1 => SightReticle::Dot(0.05, Color::rgb_linear(1.0, 0.0, 0.0)), } } diff --git a/src/comps/core/weapons/reticle.rs b/src/comps/core/weapons/reticle.rs index 751eba1..3267abc 100644 --- a/src/comps/core/weapons/reticle.rs +++ b/src/comps/core/weapons/reticle.rs @@ -1,5 +1,7 @@ use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; +use crate::comps::core::markers::proxy::weapons::reticle::DrawnReticle; + #[derive(Reflect, PartialEq, Clone, Debug)] pub enum SightReticle { /// Reticle Radius & Reticle Color @@ -8,7 +10,7 @@ pub enum SightReticle { impl Default for SightReticle { fn default() -> Self { - Self::Dot(0.05, Color::rgb_linear(100.0, 0.0, 0.0)) + Self::Dot(0.05, Color::rgb_linear(1.0, 0.0, 0.0)) } } @@ -16,7 +18,7 @@ impl SightReticle { pub fn spawn(self, commands: &mut Commands, parent: Entity, meshes: &mut ResMut>, materials: &mut ResMut>) { match self { SightReticle::Dot(radius, color) => { - commands.spawn( + commands.spawn(( MaterialMeshBundle { mesh: meshes.add(shape::Circle::new(radius).into()).into(), material: materials.add(StandardMaterial { @@ -30,8 +32,17 @@ impl SightReticle { }, ..default() } - ).set_parent(parent); + , + Name::new("Reticle"), + DrawnReticle, + )).set_parent(parent); }, } } + + pub fn get_color(&self) -> Color { + match self { + SightReticle::Dot(_, color) => color.clone(), + } + } } \ No newline at end of file diff --git a/src/logic/core/guns/reticle.rs b/src/logic/core/guns/reticle.rs index d37c0c4..df1a591 100644 --- a/src/logic/core/guns/reticle.rs +++ b/src/logic/core/guns/reticle.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use crate::comps::core::markers::proxy::weapons::optic_sight_glass::OpticSightGlass; +use crate::comps::core::{markers::proxy::weapons::{optic_sight_glass::OpticSightGlass, reticle::DrawnReticle}, weapons::firearm_state::FirearmState}; /// How? /// Achieve parallax on all reticles by drawing a line straight out of the barrel and a straight line from the sight that intersected at the specified zeroed range for the optic. @@ -8,13 +8,32 @@ use crate::comps::core::markers::proxy::weapons::optic_sight_glass::OpticSightGl pub fn update_reticle( mut commands: Commands, // TODO: make this identify which optic is on the gun, but meanwhile just start doing it to all the optics in - sight_query: Query<(Entity, &OpticSightGlass), Added>, + sight_query_added: Query<(Entity, &OpticSightGlass), Added>, + sight_query: Query<(Entity, &OpticSightGlass)>, + reticle_query: Query<(&Parent, &Handle, &DrawnReticle),>, + firearm_state: Query<&FirearmState, Changed>, mut meshes: ResMut>, mut materials: ResMut>, ) { - for (entity, sight) in sight_query.iter() { + + // Spawn reticles + for (entity, sight) in sight_query_added.iter() { let reticle = sight.0.reticle(); reticle.spawn(&mut commands, entity, &mut meshes, &mut materials); println!("Added reticle"); } + // Modify reticle brightness + + for (optic_entity, optic_sight_glass) in sight_query.iter() { + for (reticle_parent, reticle_material, _) in reticle_query.iter() { + if optic_entity != reticle_parent.get() { continue; } + for firearm_state in firearm_state.iter() { + if let Some(ref optic_data) = firearm_state.optic_data { + if let Some(mat) = materials.get_mut(reticle_material) { + mat.emissive = optic_sight_glass.0.reticle().get_color() * optic_data.reticle_brightness.clamp(1.0, 500.0); + } + } + } + } + } } \ No newline at end of file diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index fecf192..9deb40d 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -50,7 +50,6 @@ pub struct CaptureHandUsageQueryParams<'w, 's> { children: Query<'w, 's, &'static Children>, } -#[allow(unused)] #[allow(irrefutable_let_patterns)] pub fn capture_hand_usage( mut resources: CaptureHandUsageResourcesParams, @@ -92,7 +91,7 @@ pub fn capture_hand_usage( }; *hand_transform = hand_transform.lerp(default_hand_transform, resources.time.delta_seconds() / 0.25); } - + let scroll_events: Vec<&MouseWheel> = mouse_wheel_events.read().collect(); if !resources.game_ui_state.any_window() && !player_firing_info.is_reloading { if resources.keyboard_input.just_pressed(resources.player_controls.primary_weapon) { if let Some(primary_item) = player_inventory.get_primary() { @@ -142,9 +141,9 @@ pub fn capture_hand_usage( if player.0.equipment.is_firearm() { player_firing_info.is_inspecting = true; } - } else if !mouse_wheel_events.is_empty() { + } else if !scroll_events.is_empty() { if player.0.equipment.is_firearm() { - for mouse_wheel_event in mouse_wheel_events.read() { + for mouse_wheel_event in scroll_events.iter() { if player_firing_info.gun_colliding_with_object { continue; } if mouse_wheel_event.y >= 0.0 { player_firing_info.gun_ready_pose = GunReadyPose::HighReady; @@ -216,6 +215,18 @@ pub fn capture_hand_usage( ); in_hand_transform.rotation = rotation_lerp_quat; in_hand_transform.translation = position_lerp_vec3; + + if resources.keyboard_input.pressed(resources.player_controls.reticle_adjustment_requisite) { + if let Some(ref mut optic_data) = firearm_state.optic_data { + for mouse_wheel_event in scroll_events.iter() { + let add_to_brightness = mouse_wheel_event.y * resources.time.delta_seconds() * 200.0; + println!("Changed reticle bright by {}", add_to_brightness); + // TODO: Clamp values correctly + optic_data.reticle_brightness = (optic_data.reticle_brightness + add_to_brightness).clamp(1.0, 500.0); + //println!("Changed reticle bright by {}", add_to_brightness); + } + } + } } else { in_hand_transform.rotation = in_hand_transform.rotation.lerp( firearm_data.rotation_offset + resources.player_settings.rot_offset, diff --git a/src/ui/game/settings/player_controls.rs b/src/ui/game/settings/player_controls.rs index 4375f16..1d36b68 100644 --- a/src/ui/game/settings/player_controls.rs +++ b/src/ui/game/settings/player_controls.rs @@ -57,6 +57,9 @@ pub struct PlayerControls { pub inventory: KeyCode, + /// Press this key and then adjust with another key + pub reticle_adjustment_requisite: KeyCode, + } impl Default for PlayerControls { @@ -100,6 +103,8 @@ impl Default for PlayerControls { low_ready: ControlsInput::ScrollWheel(ScrollWheelInput::Down), inventory: KeyCode::Tab, + + reticle_adjustment_requisite: KeyCode::ShiftLeft, } } } \ No newline at end of file