|
|
|
|
@ -3,7 +3,9 @@
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
|
audio::Volume, input::mouse::{AccumulatedMouseMotion, MouseMotion}, picking::hover::Hovered,
|
|
|
|
|
audio::Volume,
|
|
|
|
|
input::mouse::{AccumulatedMouseMotion, MouseMotion},
|
|
|
|
|
picking::hover::Hovered,
|
|
|
|
|
platform::collections::HashMap,
|
|
|
|
|
};
|
|
|
|
|
use engine::*;
|
|
|
|
|
@ -19,6 +21,7 @@ fn main() {
|
|
|
|
|
}))
|
|
|
|
|
.init_resource::<Coordinates>()
|
|
|
|
|
.init_resource::<CellAssets>()
|
|
|
|
|
.init_resource::<Panning>()
|
|
|
|
|
.init_state::<SimulationState>()
|
|
|
|
|
.insert_resource(GlobalVolume::new(Volume::Linear(1.0)))
|
|
|
|
|
.add_message::<Lifecycle>()
|
|
|
|
|
@ -40,6 +43,7 @@ fn main() {
|
|
|
|
|
Update,
|
|
|
|
|
de_spawn_cells
|
|
|
|
|
.run_if(not(is_ui_hovered))
|
|
|
|
|
.run_if(not(is_panning))
|
|
|
|
|
.run_if(input_just_released(MouseButton::Left)),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -66,6 +70,7 @@ fn main() {
|
|
|
|
|
)
|
|
|
|
|
.add_systems(Update, cell_lifecycle.run_if(on_message::<Lifecycle>))
|
|
|
|
|
.add_systems(Update, mouse_pan.run_if(on_message::<MouseMotion>))
|
|
|
|
|
.add_systems(Update, set_pan_state)
|
|
|
|
|
.add_observer(on_add_ui_button)
|
|
|
|
|
.add_observer(on_add_coordinates)
|
|
|
|
|
.run();
|
|
|
|
|
@ -685,3 +690,23 @@ fn mouse_pan(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
|
struct Panning(bool);
|
|
|
|
|
|
|
|
|
|
fn set_pan_state(
|
|
|
|
|
mut panning: ResMut<Panning>,
|
|
|
|
|
mouse_motion: Res<AccumulatedMouseMotion>,
|
|
|
|
|
button: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
) {
|
|
|
|
|
// Set to panning if clicked and delta > 0
|
|
|
|
|
if button.pressed(MouseButton::Left) && mouse_motion.delta.abs().length() > 0.0 {
|
|
|
|
|
panning.0 = true
|
|
|
|
|
} else if button.just_released(MouseButton::Left) {
|
|
|
|
|
panning.0 = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_panning(panning: Res<Panning>) -> bool {
|
|
|
|
|
panning.0
|
|
|
|
|
}
|
|
|
|
|
|