From 0419a69e7e10e1365dcd6051ed5bed8c789808f7 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sat, 5 Jul 2025 20:59:03 -0500 Subject: [PATCH] merge zoom --- crates/unified/assets/config/planets.pc.toml | 4 +- crates/unified/src/client/mod.rs | 5 +- crates/unified/src/client/starfield.rs | 25 ++++--- crates/unified/src/client/zoom.rs | 74 ++++++++++++++++++++ 4 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 crates/unified/src/client/zoom.rs diff --git a/crates/unified/assets/config/planets.pc.toml b/crates/unified/assets/config/planets.pc.toml index a974824217387dd7151bc4f6bae9fa0e77768799..9a39aa5bf0e247131cd30d073f77640e9429f418 100644 --- a/crates/unified/assets/config/planets.pc.toml +++ b/crates/unified/assets/config/planets.pc.toml @@ -4,7 +4,7 @@ sprite = "textures/sun.png" radius = 20_000.0 # m mass = 16_000_000.0 # kg default_transform = [0.0, 0.0, 0.0] -special_sprite_properties = { DrawAsCircle = { Oklcha = { lightness = 10.0, chroma = 0.058, hue = 104.26, alpha = 1.0 } } } +special_sprite_properties = { ForceColor = { Oklcha = { lightness = 10.0, chroma = 0.058, hue = 104.26, alpha = 1.0 } } } [[planets]] name = "Mercury" @@ -77,4 +77,4 @@ name = "Pluto" sprite = "textures/pluto.png" radius = 186.8 # m mass = 22.075_947_755_1 # kg -default_transform = [11_844_600.0, 0.0, 0.0] \ No newline at end of file +default_transform = [11_844_600.0, 0.0, 0.0] diff --git a/crates/unified/src/client/mod.rs b/crates/unified/src/client/mod.rs index 8051bba09982b10be122ab7dd0e5a39265bd938e..1cadf0a625818772558d301b76d69555d17a8be3 100644 --- a/crates/unified/src/client/mod.rs +++ b/crates/unified/src/client/mod.rs @@ -6,6 +6,7 @@ mod net; mod starfield; mod ui; mod planet; +mod zoom; use crate::client::incoming_particles::replicated_particles_plugin; use crate::client::incoming_parts::incoming_parts_plugin; @@ -13,6 +14,7 @@ use planet::incoming_planets::incoming_planets_plugin; use crate::client::key_input::key_input_plugin; use crate::client::starfield::starfield_plugin; use crate::client::ui::ui_plugin; +use crate::client::zoom::zoom_plugin; use crate::ecs::{CursorWorldCoordinates, MainCamera, Part, Player}; use aeronet_websocket::client::WebSocketClient; use bevy::core_pipeline::bloom::Bloom; @@ -49,7 +51,8 @@ impl Plugin for ClientPlugin { .add_plugins(key_input_plugin) .add_plugins(starfield_plugin) .add_plugins(ui_plugin) - .add_plugins(replicated_particles_plugin); + .add_plugins(replicated_particles_plugin) + .add_plugins(zoom_plugin); } } diff --git a/crates/unified/src/client/starfield.rs b/crates/unified/src/client/starfield.rs index f51f5cad56f26df8c5f4208f17725cb718659499..b533bcf2369e5de28c46e86353050c9cec8d4c16 100644 --- a/crates/unified/src/client/starfield.rs +++ b/crates/unified/src/client/starfield.rs @@ -4,7 +4,7 @@ use bevy::{ ecs::{ event::EventReader, query::{With, Without}, - system::{Commands, Query, Res}, + system::{Commands, Query, Res, Single}, }, image::Image, math::{Vec2, Vec3}, @@ -15,12 +15,12 @@ use bevy::{ use crate::{ client::Me, - ecs::{StarfieldBack, StarfieldFront, StarfieldMid}, + ecs::{MainCamera, StarfieldBack, StarfieldFront, StarfieldMid}, }; -const BACK_STARFIELD_SIZE: f32 = 256.0; -const MID_STARFIELD_SIZE: f32 = 384.0; -const FRONT_STARFIELD_SIZE: f32 = 512.0; +pub const BACK_STARFIELD_SIZE: f32 = 256.0; +pub const MID_STARFIELD_SIZE: f32 = 384.0; +pub const FRONT_STARFIELD_SIZE: f32 = 512.0; pub fn starfield_plugin(app: &mut App) { app.add_systems(Startup, setup_starfield) @@ -165,14 +165,15 @@ pub fn resize_starfield( ), >, mut resize_event: EventReader, + camera: Single<&Transform, With>, ) { for event in resize_event.read() { starfield_back.single_mut().unwrap().custom_size = - Some(Vec2::new(event.width, event.height) + Vec2::splat(BACK_STARFIELD_SIZE * 2.0)); + Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(BACK_STARFIELD_SIZE * 2.0)); starfield_mid.single_mut().unwrap().custom_size = - Some(Vec2::new(event.width, event.height) + Vec2::splat(MID_STARFIELD_SIZE * 2.0)); + Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(MID_STARFIELD_SIZE * 2.0)); starfield_front.single_mut().unwrap().custom_size = - Some(Vec2::new(event.width, event.height) + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0)); + Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0)); } } @@ -204,6 +205,8 @@ pub fn update_starfield( Without, ), >, + window: Single<&Window>, + camera: Single<&Transform, (With, Without, Without, Without, Without)>, player: Query<&Transform, (With, Without)>, ) { let Some(player) = player.iter().next() else { @@ -215,11 +218,17 @@ pub fn update_starfield( //starfield_pos.translation = (player.translation / STARFIELD_SIZE).round() * STARFIELD_SIZE; starfield_back_pos.translation = player.translation + (-player.translation / 3.0) % BACK_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % BACK_STARFIELD_SIZE + + Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0) - Vec3::new(0.0, 0.0, 5.0); starfield_mid_pos.translation = player.translation + (-player.translation / 2.5) % MID_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % MID_STARFIELD_SIZE + + Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0) - Vec3::new(0.0, 0.0, 4.5); starfield_front_pos.translation = player.translation + (-player.translation / 2.0) % FRONT_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % FRONT_STARFIELD_SIZE + + Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0) - Vec3::new(0.0, 0.0, 4.0); } diff --git a/crates/unified/src/client/zoom.rs b/crates/unified/src/client/zoom.rs new file mode 100644 index 0000000000000000000000000000000000000000..4d39931d4e3943950e86a550dcdb6f25125eade3 --- /dev/null +++ b/crates/unified/src/client/zoom.rs @@ -0,0 +1,74 @@ +use bevy::{input::mouse::{MouseScrollUnit, MouseWheel}, prelude::*}; + +use crate::{client::{starfield::{BACK_STARFIELD_SIZE, FRONT_STARFIELD_SIZE, MID_STARFIELD_SIZE}, Me}, ecs::{MainCamera, StarfieldBack, StarfieldFront, StarfieldMid}}; + +pub fn zoom_plugin(app: &mut App) { + app.add_systems(Update, on_scroll); +} + +fn on_scroll( + mut scroll_events: EventReader, + window: Single<&Window>, + starfield_back: Single< + (&mut Sprite, &mut Transform), + ( + With, + Without, + Without, + ), + >, + starfield_mid: Single< + (&mut Sprite, &mut Transform), + ( + With, + Without, + Without, + ), + >, + starfield_front: Single< + (&mut Sprite, &mut Transform), + ( + With, + Without, + Without, + ), + >, + mut camera: Single<&mut Transform, (With, Without, Without, Without, Without)>, + player: Single<&Transform, (With, Without, Without, Without, Without)>, +) { + let (mut starfield_back, mut starfield_back_pos) = starfield_back.into_inner(); + let (mut starfield_mid, mut starfield_mid_pos) = starfield_mid.into_inner(); + let (mut starfield_front, mut starfield_front_pos) = starfield_front.into_inner(); + for event in scroll_events.read() { + match event.unit { + MouseScrollUnit::Line | MouseScrollUnit::Pixel => { + if event.y > 0.0 { + camera.scale *= 0.97; + } else { + camera.scale *= 1.03; + } + starfield_back.custom_size = + Some(window.size() * camera.scale.z + Vec2::splat(BACK_STARFIELD_SIZE * 2.0)); + starfield_mid.custom_size = + Some(window.size() * camera.scale.z + Vec2::splat(MID_STARFIELD_SIZE * 2.0)); + starfield_front.custom_size = + Some(window.size() * camera.scale.z + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0)); + starfield_back_pos.translation = player.translation + + (-player.translation / 3.0) % BACK_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % BACK_STARFIELD_SIZE + + Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0) + - Vec3::new(0.0, 0.0, 5.0); + starfield_mid_pos.translation = player.translation + + (-player.translation / 2.5) % MID_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % MID_STARFIELD_SIZE + + Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0) + - Vec3::new(0.0, 0.0, 4.5); + starfield_front_pos.translation = player.translation + + (-player.translation / 2.0) % FRONT_STARFIELD_SIZE + + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % FRONT_STARFIELD_SIZE + + Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0) + - Vec3::new(0.0, 0.0, 4.0); + } + } + } +}