enable scrolling the map with the mouse wheel
This commit is contained in:
parent
ed1ef1bb1f
commit
42a3577c57
|
@ -1,5 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::input::mouse::MouseMotion;
|
||||
use bevy::input::mouse::{MouseMotion, MouseWheel};
|
||||
use bevy::window::PrimaryWindow;
|
||||
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
|
@ -119,6 +119,7 @@ pub fn update_map_camera(
|
|||
q_playercam: Query<&Transform, (With<actor::PlayerCamera>, Without<Camera>)>,
|
||||
q_target: Query<&Transform, (With<hud::IsTargeted>, Without<Camera>, Without<actor::PlayerCamera>)>,
|
||||
mut mouse_events: EventReader<MouseMotion>,
|
||||
mut er_mousewheel: EventReader<MouseWheel>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if !settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {
|
||||
|
@ -151,12 +152,17 @@ pub fn update_map_camera(
|
|||
mapcam.zoom_level *= target.scale.x * factor;
|
||||
mapcam.initialized = true;
|
||||
}
|
||||
let mut change_zoom = 0.0;
|
||||
if keyboard_input.pressed(settings.key_map_zoom_out) {
|
||||
mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1).min(17e18);
|
||||
change_zoom += 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(settings.key_map_zoom_in) {
|
||||
mapcam.target_zoom_level = (mapcam.target_zoom_level / 1.1).max(target.scale.x);
|
||||
change_zoom -= 1.0;
|
||||
}
|
||||
for wheel_event in er_mousewheel.read() {
|
||||
change_zoom -= wheel_event.y * 3.0;
|
||||
}
|
||||
mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1f32.powf(change_zoom)).clamp(target.scale.x, 17e18);
|
||||
let zoom_speed = 0.05; // should be between 0.0001 (slow) and 1.0 (instant)
|
||||
mapcam.zoom_level = zoom_speed * mapcam.target_zoom_level + (1.0 - zoom_speed) * mapcam.zoom_level;
|
||||
|
||||
|
|
Loading…
Reference in a new issue