handle emitter property changed
-use crate::inspector::handlers::node::base::handle_base_property_changed;
-use crate::{do_command, inspector::SenderHelper, scene::commands::particle_system::*};
+use crate::{
+ do_command, inspector::handlers::node::base::handle_base_property_changed,
+ inspector::SenderHelper, scene::commands::particle_system::*,
+};
use rg3d::{
core::pool::Handle,
gui::{
@@ -15,9 +17,13 @@ use rg3d::{
},
scene::{
node::Node,
- particle_system::{emitter::Emitter, ParticleSystem},
+ particle_system::{
+ emitter::{base::BaseEmitter, sphere::SphereEmitter, Emitter},
+ ParticleSystem,
+ },
},
};
+use std::any::TypeId;
pub struct ParticleSystemHandler {
selector_window: Handle<UiNode>,
@@ -108,6 +114,7 @@ impl ParticleSystemHandler {
helper: &SenderHelper,
ui: &UserInterface,
) -> Option<()> {
+ if let Node::ParticleSystem(particle_system) = node {
match args.value {
FieldKind::Object(ref value) => match args.name.as_ref() {
ParticleSystem::TEXTURE => {
@@ -137,17 +144,75 @@ impl ParticleSystemHandler {
CollectionChanged::Remove(index) => {
helper.do_scene_command(DeleteEmitterCommand::new(handle, *index))
}
- CollectionChanged::ItemChanged { .. } => {
- // TODO
+ CollectionChanged::ItemChanged { index, property } => {
+ let emitter = particle_system.emitters.get(*index)?;
+ if property.owner_type_id == TypeId::of::<SphereEmitter>() {
+ handle_sphere_emitter_property_changed(
+ handle, emitter, property, helper, *index,
+ )
+ } else {
None
}
+ }
},
_ => None,
},
FieldKind::Inspectable(ref inner) => match args.name.as_ref() {
- ParticleSystem::BASE => handle_base_property_changed(&inner, handle, node, helper),
+ ParticleSystem::BASE => {
+ handle_base_property_changed(&inner, handle, node, helper)
+ }
_ => None,
},
}
+ } else {
+ None
+ }
+ }
+}
+
+fn handle_base_emitter_property_changed(
+ handle: Handle<Node>,
+ property_changed: &PropertyChanged,
+ helper: &SenderHelper,
+ index: usize,
+) -> Option<()> {
+ match property_changed.value {
+ FieldKind::Object(ref value) => match property_changed.name.as_ref() {
+ BaseEmitter::POSITION => helper.do_scene_command(SetEmitterPositionCommand::new(
+ handle,
+ index,
+ value.cast_value().cloned()?,
+ )),
+ _ => None,
+ },
+ _ => None,
+ }
+}
+
+fn handle_sphere_emitter_property_changed(
+ handle: Handle<Node>,
+ emitter: &Emitter,
+ property_changed: &PropertyChanged,
+ helper: &SenderHelper,
+ index: usize,
+) -> Option<()> {
+ if let Emitter::Sphere(_) = emitter {
+ match property_changed.value {
+ FieldKind::Object(ref value) => match property_changed.name.as_ref() {
+ SphereEmitter::RADIUS => helper.do_scene_command(
+ SetSphereEmitterRadiusCommand::new(handle, index, value.cast_value().cloned()?),
+ ),
+ _ => None,
+ },
+ FieldKind::Inspectable(ref inner) => match property_changed.name.as_ref() {
+ SphereEmitter::EMITTER => {
+ handle_base_emitter_property_changed(handle, inner, helper, index)
+ }
+ _ => None,
+ },
+ _ => None,
+ }
+ } else {
+ None
}
}
