void ParticlesEditorController::AddParticleEmitterNodeToScene(Entity* emitterSceneNode) { // We are adding new Emitter to the Particle Effect node just selected. Entity* effectNode = NULL; BaseParticleEditorNode* selectedNode = GetSelectedNode(); if (selectedNode) { effectNode = selectedNode->GetRootNode(); } EffectParticleEditorNode* effectEditorNode = GetRootForParticleEffectNode(effectNode); if (effectNode && effectEditorNode) { EmitterParticleEditorNode* emitterEditorNode = new EmitterParticleEditorNode(effectNode, emitterSceneNode, QString::fromStdString(emitterSceneNode->GetName())); ParticleEmitter * emitter = GetEmitter(emitterSceneNode); if (!emitter) { return; } emitter->SetLifeTime(LIFETIME_FOR_NEW_PARTICLE_EMITTER); effectNode->AddNode(emitterSceneNode); effectEditorNode->AddChildNode(emitterEditorNode); } }
void CommandRestartParticleEffect::Execute() { BaseParticleEditorNode* selectedNode = ParticlesEditorController::Instance()->GetSelectedNode(); EffectParticleEditorNode* effectNode = dynamic_cast<EffectParticleEditorNode*>(selectedNode); if (!effectNode || !effectNode->GetRootNode() || !effectNode->GetRootNode()) { return; } ParticleEffectComponent * effectComponent = effectNode->GetParticleEffectComponent(); DVASSERT(effectComponent); effectComponent->Restart(); }
void ParticlesEditorController::RemoveParticleEmitterNode(Entity* emitterSceneNode) { // Lookup for such node. EffectParticleEditorNode* effectEditorNode = NULL; EmitterParticleEditorNode* emitterEditorNode = NULL; FindEmitterEditorNode(emitterSceneNode, &effectEditorNode, &emitterEditorNode); if (effectEditorNode && emitterEditorNode) { CleanupSelectedNodeIfDeleting(emitterEditorNode); effectEditorNode->RemoveChildNode(emitterEditorNode); } }
void CommandStartStopParticleEffect::Execute() { BaseParticleEditorNode* selectedNode = ParticlesEditorController::Instance()->GetSelectedNode(); EffectParticleEditorNode* effectNode = dynamic_cast<EffectParticleEditorNode*>(selectedNode); if (!effectNode || !effectNode->GetRootNode()) { return; } ParticleEffectComponent* effectComponent = effectNode->GetParticleEffectComponent(); if (this->isStart) { effectComponent->Start(); } else { effectComponent->Stop(); } }
void ParticlesEditorController::EmitSelectedNodeChanged(bool forceRefresh) { if (this->selectedNode == NULL) { emit EmitterSelected(NULL, this->selectedNode); return; } // Determine the exact node type and emit the event needed. EffectParticleEditorNode* effectEditorNode = dynamic_cast<EffectParticleEditorNode*>(this->selectedNode); if (effectEditorNode) { emit EmitterSelected(NULL, this->selectedNode); emit EffectSelected(effectEditorNode->GetRootNode()); return; } EmitterParticleEditorNode* emitterEditorNode = dynamic_cast<EmitterParticleEditorNode*>(this->selectedNode); if (emitterEditorNode) { emit EmitterSelected(emitterEditorNode->GetEmitterNode(), this->selectedNode); return; } LayerParticleEditorNode* layerEditorNode = dynamic_cast<LayerParticleEditorNode*>(this->selectedNode); if (layerEditorNode) { emit LayerSelected(layerEditorNode->GetEmitterNode(), layerEditorNode->GetLayer(), this->selectedNode, forceRefresh); return; } ForceParticleEditorNode* forceEditorNode = dynamic_cast<ForceParticleEditorNode*>(this->selectedNode); if (forceEditorNode) { emit ForceSelected(forceEditorNode->GetEmitterNode(), forceEditorNode->GetLayer(), forceEditorNode->GetForceIndex(), this->selectedNode); return; } // Cleanip the selection in case we don't know what to do. Logger::Warning("ParticlesEditorController::EmitSelectedNodeChanged() - unknown selected node type!"); EmitterSelected(NULL, this->selectedNode); }
Entity* ParticlesEditorSceneModelHelper::PreprocessSceneNode(Entity* rawNode) { // There is one and only preprocessing case - if the "raw" node is "orphaned" Particles Emitter // (without the ParticlesEffectNode parent), we'll create the new Particles Effect node and // move the raw Emitter node to it. ParticleEmitter * emitter = GetEmitter(rawNode); if (!emitter) { return rawNode; } //ParticleEmitterNode* emitterNode = static_cast<ParticleEmitterNode*>(rawNode); //emitterNode->SetEmitter(emitterComponent->GetParticleEmitter()); Entity* curParentNode = rawNode->GetParent(); ParticleEffectComponent * effectComponent = cast_if_equal<ParticleEffectComponent*>(curParentNode->GetComponent(Component::PARTICLE_EFFECT_COMPONENT)); // If the Emitter Node has parent, but its parent is not ParticleEffectNode, we need to // "adopt" this node by creating ParticleEffect node and attaching. if (curParentNode && (effectComponent == NULL)) { Entity* newParentNodeParticleEffect = CreateParticleEffectNode(); curParentNode->AddNode(newParentNodeParticleEffect); // Add the emitter node to the new Effect (this will also remove it from the scene). newParentNodeParticleEffect->AddNode(rawNode); // Register the Particle Editor structure for the new node. EffectParticleEditorNode* effectEditorNode = ParticlesEditorController::Instance()->RegisterParticleEffectNode(newParentNodeParticleEffect); EmitterParticleEditorNode* emitterEditorNode = new EmitterParticleEditorNode(newParentNodeParticleEffect, rawNode, QString::fromStdString(rawNode->GetName())); effectEditorNode->AddNode(emitterEditorNode); return newParentNodeParticleEffect; } // No preprocessing needed. return rawNode; }