Replace bevy_pancam with custom Plugin
This commit is contained in:
parent
162850e263
commit
ca230f6a9b
8 changed files with 77 additions and 36 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -427,15 +427,6 @@ dependencies = [
|
||||||
"glam",
|
"glam",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_pancam"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ebc698de3f4e824a67f517fe9cca35f08d5fdaab99ed8e141102c582768fc62"
|
|
||||||
dependencies = [
|
|
||||||
"bevy",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_pbr"
|
name = "bevy_pbr"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
|
@ -2771,7 +2762,6 @@ name = "worlds-sim-rust"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy_pancam",
|
|
||||||
"planet",
|
"planet",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ resolver = "2"
|
||||||
[features]
|
[features]
|
||||||
logging = ["planet/logging"]
|
logging = ["planet/logging"]
|
||||||
globe_view = ["planet/globe_view", "render"]
|
globe_view = ["planet/globe_view", "render"]
|
||||||
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:bevy_pancam"]
|
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render"]
|
||||||
default = ["render", "logging"]
|
default = ["render", "logging"]
|
||||||
|
|
||||||
[dependencies.planet]
|
[dependencies.planet]
|
||||||
|
@ -17,7 +17,3 @@ default-features = false
|
||||||
[dependencies.bevy]
|
[dependencies.bevy]
|
||||||
version = "0.8"
|
version = "0.8"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.bevy_pancam]
|
|
||||||
version = "0.6.1"
|
|
||||||
optional = true
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
pub(crate) mod markers;
|
pub(crate) mod markers;
|
||||||
|
|
||||||
pub(crate) mod third_party {
|
|
||||||
#[cfg(feature = "render")]
|
#[cfg(feature = "render")]
|
||||||
pub(crate) use bevy_pancam::PanCam;
|
pub(crate) mod panning;
|
||||||
}
|
|
||||||
|
|
12
src/components/panning/mod.rs
Normal file
12
src/components/panning/mod.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use bevy::ecs::component::Component;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub(crate) struct Pan2d {
|
||||||
|
pub(crate) enabled: bool,
|
||||||
|
}
|
||||||
|
impl Pan2d {
|
||||||
|
#[must_use]
|
||||||
|
pub(crate) const fn new() -> Pan2d {
|
||||||
|
Pan2d { enabled: true }
|
||||||
|
}
|
||||||
|
}
|
15
src/main.rs
15
src/main.rs
|
@ -89,7 +89,7 @@ use {
|
||||||
},
|
},
|
||||||
components::{
|
components::{
|
||||||
markers::{InfoPanel, ToolbarButton},
|
markers::{InfoPanel, ToolbarButton},
|
||||||
third_party::PanCam,
|
panning::Pan2d,
|
||||||
},
|
},
|
||||||
planet::BiomeStats,
|
planet::BiomeStats,
|
||||||
resources::CursorMapPosition,
|
resources::CursorMapPosition,
|
||||||
|
@ -198,7 +198,7 @@ fn handle_toolbar_button(
|
||||||
#[cfg(feature = "globe_view")] mut camera_2d_query: Query<
|
#[cfg(feature = "globe_view")] mut camera_2d_query: Query<
|
||||||
'_,
|
'_,
|
||||||
'_,
|
'_,
|
||||||
(&mut Camera, &mut PanCam),
|
(&mut Camera, &mut Pan2d),
|
||||||
(With<Camera2d>, Without<Camera3d>),
|
(With<Camera2d>, Without<Camera3d>),
|
||||||
>,
|
>,
|
||||||
#[cfg(feature = "globe_view")] mut materials: ResMut<'_, Assets<StandardMaterial>>,
|
#[cfg(feature = "globe_view")] mut materials: ResMut<'_, Assets<StandardMaterial>>,
|
||||||
|
@ -529,20 +529,17 @@ fn generate_graphics(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = commands.spawn_bundle(Camera2dBundle::default());
|
||||||
_ = commands
|
_ = commands
|
||||||
.spawn_bundle(Camera2dBundle { ..default() })
|
.spawn_bundle(SpriteBundle {
|
||||||
.insert(PanCam {
|
|
||||||
max_scale: Some(80.0),
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
_ = commands.spawn_bundle(SpriteBundle {
|
|
||||||
texture: images.get_handle(world_manager.map_image_handle_id.unwrap()),
|
texture: images.get_handle(world_manager.map_image_handle_id.unwrap()),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
custom_size: Some(custom_sprite_size),
|
custom_size: Some(custom_sprite_size),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
});
|
})
|
||||||
|
.insert(Pan2d::new());
|
||||||
|
|
||||||
_ = commands
|
_ = commands
|
||||||
.spawn_bundle(NodeBundle {
|
.spawn_bundle(NodeBundle {
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
#[cfg(feature = "render")]
|
||||||
|
pub(crate) mod panning_plugin;
|
||||||
pub(crate) mod world_plugins;
|
pub(crate) mod world_plugins;
|
||||||
pub(crate) use world_plugins::WorldPlugins;
|
pub(crate) use world_plugins::WorldPlugins;
|
||||||
|
|
47
src/plugins/panning_plugin.rs
Normal file
47
src/plugins/panning_plugin.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
use {
|
||||||
|
crate::components::panning::Pan2d,
|
||||||
|
bevy::{
|
||||||
|
app::{App, Plugin},
|
||||||
|
ecs::{
|
||||||
|
event::EventReader,
|
||||||
|
query::With,
|
||||||
|
system::{Query, Res},
|
||||||
|
},
|
||||||
|
input::{
|
||||||
|
mouse::{MouseButton, MouseMotion},
|
||||||
|
Input,
|
||||||
|
},
|
||||||
|
sprite::Sprite,
|
||||||
|
transform::components::Transform,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub(crate) struct PanningPlugin;
|
||||||
|
|
||||||
|
impl Plugin for PanningPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
_ = app.add_system(panning_system_2d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn panning_system_2d(
|
||||||
|
mut query: Query<'_, '_, (&mut Transform, &Pan2d), With<Sprite>>,
|
||||||
|
mut mouse_motion_events: EventReader<'_, '_, MouseMotion>,
|
||||||
|
input_mouse: Res<'_, Input<MouseButton>>,
|
||||||
|
) {
|
||||||
|
if !input_mouse.pressed(MouseButton::Left) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut horizontal = 0.0;
|
||||||
|
for movement in mouse_motion_events.iter() {
|
||||||
|
horizontal += movement.delta.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
query.for_each_mut(|(mut transform, pan)| {
|
||||||
|
if pan.enabled {
|
||||||
|
transform.translation.x += horizontal;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ impl PluginGroup for WorldPlugins {
|
||||||
#[cfg(feature = "render")]
|
#[cfg(feature = "render")]
|
||||||
{
|
{
|
||||||
use {
|
use {
|
||||||
|
crate::plugins::panning_plugin::PanningPlugin,
|
||||||
bevy::{
|
bevy::{
|
||||||
asset::AssetPlugin,
|
asset::AssetPlugin,
|
||||||
core_pipeline::CorePipelinePlugin,
|
core_pipeline::CorePipelinePlugin,
|
||||||
|
@ -31,7 +32,6 @@ impl PluginGroup for WorldPlugins {
|
||||||
window::WindowPlugin,
|
window::WindowPlugin,
|
||||||
winit::WinitPlugin,
|
winit::WinitPlugin,
|
||||||
},
|
},
|
||||||
bevy_pancam::PanCamPlugin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = group
|
_ = group
|
||||||
|
@ -47,7 +47,7 @@ impl PluginGroup for WorldPlugins {
|
||||||
.add(SpritePlugin::default())
|
.add(SpritePlugin::default())
|
||||||
.add(TextPlugin::default())
|
.add(TextPlugin::default())
|
||||||
.add(UiPlugin::default())
|
.add(UiPlugin::default())
|
||||||
.add(PanCamPlugin::default());
|
.add(PanningPlugin::default());
|
||||||
#[cfg(feature = "globe_view")]
|
#[cfg(feature = "globe_view")]
|
||||||
{
|
{
|
||||||
use bevy::pbr::PbrPlugin;
|
use bevy::pbr::PbrPlugin;
|
||||||
|
|
Loading…
Reference in a new issue