1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EditorDefs.h"
- #include "Entity/EditorEntityHelpers.h"
- #include "TrackViewSequence.h"
- // Qt
- #include <QMessageBox>
- // AzCore
- #include <AzCore/std/algorithm.h>
- #include <AzCore/std/containers/set.h>
- #include <AzCore/std/sort.h>
- // AzToolsFramework
- #include <AzToolsFramework/API/ComponentEntityObjectBus.h>
- // CryCommon
- #include <CryCommon/Maestro/Types/AnimValueType.h>
- #include <CryCommon/Maestro/Types/AnimNodeType.h>
- #include <CryCommon/Maestro/Bus/EditorSequenceComponentBus.h>
- #include <CryCommon/MathConversion.h>
- // Editor
- #include "AnimationContext.h"
- #include "Clipboard.h"
- #include "TrackViewSequenceManager.h"
- #include "TrackViewNodeFactories.h"
- CTrackViewSequence::CTrackViewSequence(IAnimSequence* pSequence)
- : CTrackViewAnimNode(pSequence, nullptr, nullptr)
- , m_pAnimSequence(pSequence)
- {
- AZ_Assert(m_pAnimSequence, "Expected valid m_pAnimSequence");
- }
- CTrackViewSequence::CTrackViewSequence(AZStd::intrusive_ptr<IAnimSequence>& sequence)
- : CTrackViewAnimNode(sequence.get(), nullptr, nullptr)
- , m_pAnimSequence(sequence)
- {
- }
- CTrackViewSequence::~CTrackViewSequence()
- {
- GetIEditor()->GetSequenceManager()->RemoveListener(this);
- GetIEditor()->GetUndoManager()->RemoveListener(this); // For safety. Should be done by OnRemoveSequence callback
- // For safety, disconnect to any buses we may have been listening on for record mode
- if (m_pAnimSequence)
- {
- // disconnect from all EBuses for notification of changes for all AZ::Entities in our sequence
- for (int i = m_pAnimSequence->GetNodeCount(); --i >= 0;)
- {
- IAnimNode* animNode = m_pAnimSequence->GetNode(i);
- if (animNode->GetType() == AnimNodeType::AzEntity)
- {
- Maestro::EditorSequenceComponentRequestBus::Event(m_pAnimSequence->GetSequenceEntityId(), &Maestro::EditorSequenceComponentRequestBus::Events::RemoveEntityToAnimate, animNode->GetAzEntityId());
- ConnectToBusesForRecording(animNode->GetAzEntityId(), false);
- }
- }
- }
- }
- void CTrackViewSequence::Load()
- {
- m_childNodes.clear();
- const int nodeCount = m_pAnimSequence->GetNodeCount();
- for (int i = 0; i < nodeCount; ++i)
- {
- IAnimNode* node = m_pAnimSequence->GetNode(i);
- // Only add top level nodes to sequence
- if (!node->GetParent())
- {
- CTrackViewAnimNodeFactory animNodeFactory;
- CTrackViewAnimNode* pNewTVAnimNode = animNodeFactory.BuildAnimNode(m_pAnimSequence.get(), node, this);
- m_childNodes.push_back(AZStd::unique_ptr<CTrackViewNode>(pNewTVAnimNode));
- }
- }
- SortNodes();
- }
- void CTrackViewSequence::BindToEditorObjects()
- {
- m_bBoundToEditorObjects = true;
- CTrackViewAnimNode::BindToEditorObjects();
- }
- void CTrackViewSequence::UnBindFromEditorObjects()
- {
- m_bBoundToEditorObjects = false;
- CTrackViewAnimNode::UnBindFromEditorObjects();
- }
- bool CTrackViewSequence::IsBoundToEditorObjects() const
- {
- return m_bBoundToEditorObjects;
- }
- CTrackViewKeyHandle CTrackViewSequence::FindSingleSelectedKey()
- {
- CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
- if (!pSequence)
- {
- return CTrackViewKeyHandle();
- }
- CTrackViewKeyBundle selectedKeys = pSequence->GetSelectedKeys();
- if (selectedKeys.GetKeyCount() != 1)
- {
- return CTrackViewKeyHandle();
- }
- return selectedKeys.GetKey(0);
- }
- void CTrackViewSequence::OnEntityComponentPropertyChanged(AZ::ComponentId changedComponentId)
- {
- // find the component node for this changeComponentId if it exists
- for (int i = m_pAnimSequence->GetNodeCount(); --i >= 0;)
- {
- IAnimNode* animNode = m_pAnimSequence->GetNode(i);
- if (animNode && animNode->GetComponentId() == changedComponentId)
- {
- // we have a component animNode for this changedComponentId. Process the component change
- RecordTrackChangesForNode(static_cast<CTrackViewAnimNode*>(animNode->GetNodeOwner()));
- }
- }
- }
- CTrackViewTrack* CTrackViewSequence::FindTrackById(unsigned int trackId)
- {
- CTrackViewTrack* result = nullptr;
- CTrackViewTrackBundle allTracks = GetAllTracks();
- int allTracksCount = allTracks.GetCount();
- for (int trackIndex = 0; trackIndex < allTracksCount; trackIndex++)
- {
- CTrackViewTrack* track = allTracks.GetTrack(trackIndex);
- AZ_Assert(track, "Expected valid track.");
- if (track->GetId() == trackId)
- {
- result = track;
- break;
- }
- }
- return result;
- }
- AZStd::vector<bool> CTrackViewSequence::SaveKeyStates() const
- {
- // const hack because GetAllKeys();
- CTrackViewSequence* nonConstSequence = const_cast<CTrackViewSequence*>(this);
- CTrackViewKeyBundle keys = nonConstSequence->GetAllKeys();
- const unsigned int numkeys = keys.GetKeyCount();
- AZStd::vector<bool> selectionState;
- selectionState.reserve(numkeys);
- for (unsigned int i = 0; i < numkeys; ++i)
- {
- const CTrackViewKeyHandle& keyHandle = keys.GetKey(i);
- selectionState.push_back(keyHandle.IsSelected());
- }
- return selectionState;
- }
- void CTrackViewSequence::RestoreKeyStates(const AZStd::vector<bool>& keyStates)
- {
- CTrackViewKeyBundle keys = GetAllKeys();
- const unsigned int numkeys = keys.GetKeyCount();
- if (keyStates.size() >= numkeys)
- {
- CTrackViewSequenceNotificationContext context(this);
- for (unsigned int i = 0; i < numkeys; ++i)
- {
- CTrackViewKeyHandle keyHandle = keys.GetKey(i);
- keyHandle.Select(keyStates[i]);
- }
- }
- }
- void CTrackViewSequence::ConnectToBusesForRecording(const AZ::EntityId& entityId, bool enableConnection)
- {
- // we connect to PropertyEditorEntityChangeNotificationBus for all other changes
- if (enableConnection)
- {
- AzToolsFramework::PropertyEditorEntityChangeNotificationBus::MultiHandler::BusConnect(entityId);
- }
- else
- {
- AzToolsFramework::PropertyEditorEntityChangeNotificationBus::MultiHandler::BusDisconnect(entityId);
- }
- }
- int CTrackViewSequence::RecordTrackChangesForNode(CTrackViewAnimNode* componentNode)
- {
- int retNumKeysSet = 0;
- if (componentNode)
- {
- retNumKeysSet = componentNode->SetKeysForChangedTrackValues(GetIEditor()->GetAnimation()->GetTime());
- if (retNumKeysSet)
- {
- OnKeysChanged(); // change notification for updating TrackView UI
- }
- }
- return retNumKeysSet;
- }
- void CTrackViewSequence::SetRecording(bool enableRecording)
- {
- if (m_pAnimSequence)
- {
- // connect (or disconnect) to EBuses for notification of changes for all AZ::Entities in our sequence
- for (int i = m_pAnimSequence->GetNodeCount(); --i >= 0;)
- {
- IAnimNode* animNode = m_pAnimSequence->GetNode(i);
- if (animNode->GetType() == AnimNodeType::AzEntity)
- {
- ConnectToBusesForRecording(animNode->GetAzEntityId(), enableRecording);
- }
- }
- }
- }
- bool CTrackViewSequence::IsAncestorOf(CTrackViewSequence* pSequence) const
- {
- return m_pAnimSequence->IsAncestorOf(pSequence->m_pAnimSequence.get());
- }
- void CTrackViewSequence::BeginCutScene(const bool bResetFx) const
- {
- IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
- IMovieUser* pMovieUser = movieSystem ? movieSystem->GetUser() : nullptr;
- if (pMovieUser)
- {
- pMovieUser->BeginCutScene(m_pAnimSequence.get(), m_pAnimSequence->GetCutSceneFlags(false), bResetFx);
- }
- }
- void CTrackViewSequence::EndCutScene() const
- {
- IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
- IMovieUser* pMovieUser = movieSystem ? movieSystem->GetUser() : nullptr;
- if (pMovieUser)
- {
- pMovieUser->EndCutScene(m_pAnimSequence.get(), m_pAnimSequence->GetCutSceneFlags(true));
- }
- }
- void CTrackViewSequence::Render(const SAnimContext& animContext)
- {
- for (auto iter = m_childNodes.begin(); iter != m_childNodes.end(); ++iter)
- {
- CTrackViewNode* pChildNode = (*iter).get();
- if (pChildNode->GetNodeType() == eTVNT_AnimNode)
- {
- CTrackViewAnimNode* pChildAnimNode = (CTrackViewAnimNode*)pChildNode;
- pChildAnimNode->Render(animContext);
- }
- }
- m_pAnimSequence->Render();
- }
- void CTrackViewSequence::Animate(const SAnimContext& animContext)
- {
- if (!m_pAnimSequence->IsActivated())
- {
- return;
- }
- m_time = animContext.time;
- m_pAnimSequence->Animate(animContext);
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_childNodes.begin(); iter != m_childNodes.end(); ++iter)
- {
- CTrackViewNode* pChildNode = (*iter).get();
- if (pChildNode->GetNodeType() == eTVNT_AnimNode)
- {
- CTrackViewAnimNode* pChildAnimNode = (CTrackViewAnimNode*)pChildNode;
- pChildAnimNode->Animate(animContext);
- }
- }
- }
- void CTrackViewSequence::AddListener(ITrackViewSequenceListener* pListener)
- {
- stl::push_back_unique(m_sequenceListeners, pListener);
- }
- void CTrackViewSequence::RemoveListener(ITrackViewSequenceListener* pListener)
- {
- stl::find_and_erase(m_sequenceListeners, pListener);
- }
- void CTrackViewSequence::OnNodeSelectionChanged()
- {
- if (m_bNoNotifications)
- {
- return;
- }
- if (m_bQueueNotifications)
- {
- m_bNodeSelectionChanged = true;
- }
- else
- {
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnNodeSelectionChanged(this);
- }
- }
- }
- void CTrackViewSequence::ForceAnimation()
- {
- if (m_bNoNotifications)
- {
- return;
- }
- if (m_bQueueNotifications)
- {
- m_bForceAnimation = true;
- }
- else
- {
- if (IsActive())
- {
- GetIEditor()->GetAnimation()->ForceAnimation();
- }
- }
- }
- void CTrackViewSequence::OnKeySelectionChanged()
- {
- if (m_bNoNotifications)
- {
- return;
- }
- if (m_bQueueNotifications)
- {
- m_bKeySelectionChanged = true;
- }
- else
- {
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnKeySelectionChanged(this);
- }
- }
- }
- void CTrackViewSequence::OnKeysChanged()
- {
- if (m_bNoNotifications)
- {
- return;
- }
- if (m_bQueueNotifications)
- {
- m_bKeysChanged = true;
- }
- else
- {
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnKeysChanged(this);
- }
- if (IsActive())
- {
- GetIEditor()->GetAnimation()->ForceAnimation();
- }
- }
- }
- void CTrackViewSequence::OnKeyAdded(CTrackViewKeyHandle& addedKeyHandle)
- {
- if (m_bNoNotifications)
- {
- return;
- }
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnKeyAdded(addedKeyHandle);
- }
- }
- void CTrackViewSequence::OnNodeChanged(CTrackViewNode* node, ITrackViewSequenceListener::ENodeChangeType type)
- {
- if (node && node->GetNodeType() == eTVNT_AnimNode)
- {
- // Deselect the node before deleting to give listeners a chance to update things like UI state.
- if (type == ITrackViewSequenceListener::eNodeChangeType_Removed)
- {
- CTrackViewSequenceNotificationContext context(this);
- // Make sure to deselect any keys
- CTrackViewKeyBundle keys = node->GetAllKeys();
- for (unsigned int key = 0; key < keys.GetKeyCount(); key++)
- {
- CTrackViewKeyHandle keyHandle = keys.GetKey(key);
- if (keyHandle.IsSelected())
- {
- keyHandle.Select(false);
- m_bKeySelectionChanged = true;
- }
- }
- // Cancel notification if nothing changed.
- if (!m_bKeySelectionChanged)
- {
- context.Cancel();
- }
- // deselect the node
- if (node->IsSelected())
- {
- node->SetSelected(false);
- }
- }
- CTrackViewAnimNode* pAnimNode = static_cast<CTrackViewAnimNode*>(node);
- if (pAnimNode->IsActive())
- {
- switch (type)
- {
- case ITrackViewSequenceListener::eNodeChangeType_Added:
- {
- ForceAnimation();
- // if we're in record mode and this is an AzEntity node, add the node to the buses we listen to for notification of changes
- if (pAnimNode->GetType() == AnimNodeType::AzEntity && GetIEditor()->GetAnimation()->IsRecordMode())
- {
- ConnectToBusesForRecording(pAnimNode->GetAzEntityId(), true);
- }
- }
- break;
- case ITrackViewSequenceListener::eNodeChangeType_Removed:
- {
- ForceAnimation();
- // if we're in record mode and this is an AzEntity node, remove the node to the buses we listen to for notification of changes
- if (pAnimNode->GetType() == AnimNodeType::AzEntity && GetIEditor()->GetAnimation()->IsRecordMode())
- {
- ConnectToBusesForRecording(pAnimNode->GetAzEntityId(), false);
- }
- }
- break;
- }
- }
- switch (type)
- {
- case ITrackViewSequenceListener::eNodeChangeType_Enabled:
- // Fall through
- case ITrackViewSequenceListener::eNodeChangeType_Hidden:
- // Fall through
- case ITrackViewSequenceListener::eNodeChangeType_SetAsActiveDirector:
- // Fall through
- case ITrackViewSequenceListener::eNodeChangeType_NodeOwnerChanged:
- ForceAnimation();
- break;
- }
- }
- // Mark Layer with Sequence Object as dirty for non-internal or non-UI changes
- if (type != ITrackViewSequenceListener::eNodeChangeType_NodeOwnerChanged &&
- type != ITrackViewSequenceListener::eNodeChangeType_Selected &&
- type != ITrackViewSequenceListener::eNodeChangeType_Deselected &&
- type != ITrackViewSequenceListener::eNodeChangeType_Collapsed &&
- type != ITrackViewSequenceListener::eNodeChangeType_Expanded)
- {
- MarkAsModified();
- }
- if (m_bNoNotifications)
- {
- return;
- }
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnNodeChanged(node, type);
- }
- }
- void CTrackViewSequence::OnNodeRenamed(CTrackViewNode* node, const char* pOldName)
- {
- // Marks Layer with Sequence Object as dirty
- MarkAsModified();
- if (m_bNoNotifications)
- {
- return;
- }
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnNodeRenamed(node, pOldName);
- }
- }
- void CTrackViewSequence::OnSequenceSettingsChanged()
- {
- MarkAsModified();
- if (m_bNoNotifications)
- {
- return;
- }
- CTrackViewSequenceNoNotificationContext context(this);
- for (auto iter = m_sequenceListeners.begin(); iter != m_sequenceListeners.end(); ++iter)
- {
- (*iter)->OnSequenceSettingsChanged(this);
- }
- }
- void CTrackViewSequence::MarkAsModified()
- {
- if (m_pAnimSequence)
- {
- Maestro::EditorSequenceComponentRequestBus::Event(
- m_pAnimSequence->GetSequenceEntityId(), &Maestro::EditorSequenceComponentRequestBus::Events::MarkEntityAsDirty);
- }
- }
- void CTrackViewSequence::QueueNotifications()
- {
- m_bQueueNotifications = true;
- ++m_selectionRecursionLevel;
- }
- void CTrackViewSequence::DequeueNotifications()
- {
- AZ_Assert(m_selectionRecursionLevel > 0, "QueueNotifications should be called before DequeueNotifications()");
- --m_selectionRecursionLevel;
- if (m_selectionRecursionLevel == 0)
- {
- m_bQueueNotifications = false;
- }
- }
- void CTrackViewSequence::SubmitPendingNotifications(bool force)
- {
- if (force)
- {
- m_selectionRecursionLevel = 1;
- }
- AZ_Assert(m_selectionRecursionLevel > 0, "Dangling SubmitPendingNotifications()");
- if (m_selectionRecursionLevel > 0)
- {
- --m_selectionRecursionLevel;
- }
- if (m_selectionRecursionLevel == 0)
- {
- m_bQueueNotifications = false;
- if (m_bNodeSelectionChanged)
- {
- OnNodeSelectionChanged();
- }
- if (m_bKeysChanged)
- {
- OnKeysChanged();
- }
- if (m_bKeySelectionChanged)
- {
- OnKeySelectionChanged();
- }
- if (m_bForceAnimation)
- {
- ForceAnimation();
- }
- m_bForceAnimation = false;
- m_bKeysChanged = false;
- m_bNodeSelectionChanged = false;
- m_bKeySelectionChanged = false;
- }
- }
- void CTrackViewSequence::OnSequenceRemoved(CTrackViewSequence* removedSequence)
- {
- if (removedSequence == this)
- {
- // submit any queued notifications before removing
- if (m_bQueueNotifications)
- {
- SubmitPendingNotifications(true);
- }
- // remove ourselves as listeners from the undo manager
- GetIEditor()->GetUndoManager()->RemoveListener(this);
- }
- }
- void CTrackViewSequence::OnSequenceAdded(CTrackViewSequence* addedSequence)
- {
- if (addedSequence == this)
- {
- GetIEditor()->GetUndoManager()->AddListener(this);
- }
- }
- void CTrackViewSequence::DeleteSelectedNodes()
- {
- if (IsSelected())
- {
- GetIEditor()->GetSequenceManager()->DeleteSequence(this);
- return;
- }
- // Don't notify in the above IsSelected() case,
- // because 'this' will become deleted and invalid.
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewAnimNodeBundle selectedNodes = GetSelectedAnimNodes();
- const unsigned int numSelectedNodes = selectedNodes.GetCount();
- // Call RemoveEntityToAnimate on any nodes that are able to be removed right here. If we wait to do it inside
- // of RemoveSubNode() it will fail because the EditorSequenceComponentRequestBus will be disconnected
- // by the Deactivate / Activate of the sequence entity.
- if (nullptr != m_pAnimSequence)
- {
- AZ::EntityId sequenceEntityId = m_pAnimSequence->GetSequenceEntityId();
- if (sequenceEntityId.IsValid())
- {
- for (unsigned int i = 0; i < numSelectedNodes; ++i)
- {
- AZ::EntityId removedNodeId = selectedNodes.GetNode(i)->GetAzEntityId();
- if (removedNodeId.IsValid())
- {
- Maestro::EditorSequenceComponentRequestBus::Event(
- m_pAnimSequence->GetSequenceEntityId(), &Maestro::EditorSequenceComponentRequestBus::Events::RemoveEntityToAnimate,
- removedNodeId);
- }
- }
- }
- }
- // Deactivate the sequence entity while we are potentially removing things from it.
- // We need to allow the full removal operation (node and children) to complete before
- // OnActivate happens on the Sequence again. If we don't deactivate the sequence entity
- // OnActivate will get called by the entity system as components are removed.
- // In some cases this will erroneously cause some components to be added
- // back to the sequence that were just deleted.
- bool sequenceEntityWasActive = false;
- AZ::Entity* sequenceEntity = nullptr;
- if (GetSequenceComponentEntityId().IsValid())
- {
- AZ::ComponentApplicationBus::BroadcastResult(sequenceEntity, &AZ::ComponentApplicationBus::Events::FindEntity, GetSequenceComponentEntityId());
- if (sequenceEntity != nullptr)
- {
- if (sequenceEntity->GetState() == AZ::Entity::State::Active)
- {
- sequenceEntityWasActive = true;
- sequenceEntity->Deactivate();
- }
- }
- }
- CTrackViewTrackBundle selectedTracks = GetSelectedTracks();
- const unsigned int numSelectedTracks = selectedTracks.GetCount();
- for (int i = numSelectedTracks - 1; i >= 0; i--)
- {
- CTrackViewTrack* pTrack = selectedTracks.GetTrack(i);
- // Ignore sub tracks
- if (!pTrack->IsSubTrack())
- {
- pTrack->GetAnimNode()->RemoveTrack(pTrack);
- }
- }
- // GetSelectedAnimNodes() will add parent nodes first and then children to the selected
- // node bundle list. So iterating backwards here causes child nodes to be deleted first,
- // and then parents. If parent nodes get deleted first, node->GetParentNode() will return
- // a bad pointer if it happens to be one of the nodes that was deleted.
- for (int i = numSelectedNodes - 1; i >= 0; i--)
- {
- CTrackViewAnimNode* node = selectedNodes.GetNode(i);
- CTrackViewAnimNode* pParentNode = static_cast<CTrackViewAnimNode*>(node->GetParentNode());
- pParentNode->RemoveSubNode(node);
- }
- if (sequenceEntityWasActive && sequenceEntity != nullptr)
- {
- sequenceEntity->Activate();
- }
- }
- void CTrackViewSequence::SelectSelectedNodesInViewport()
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CTrackViewAnimNodeBundle selectedNodes = GetSelectedAnimNodes();
- const unsigned int numSelectedNodes = selectedNodes.GetCount();
- AZStd::vector<AZ::EntityId> entitiesToBeSelected;
- for (unsigned int i = 0; i < numSelectedNodes; ++i)
- {
- CTrackViewAnimNode* node = selectedNodes.GetNode(i);
- ETrackViewNodeType nodeType = node->GetNodeType();
- if (nodeType == eTVNT_Sequence)
- {
- CTrackViewSequence* seqNode = static_cast<CTrackViewSequence*>(node);
- entitiesToBeSelected.push_back(seqNode->GetSequenceComponentEntityId());
- }
- else
- {
- // TrackView AnimNode
- entitiesToBeSelected.push_back(node->GetAzEntityId());
- }
- }
- // remove duplicate entities
- AZStd::sort(entitiesToBeSelected.begin(), entitiesToBeSelected.end());
- entitiesToBeSelected.erase(
- AZStd::unique(entitiesToBeSelected.begin(), entitiesToBeSelected.end()), entitiesToBeSelected.end());
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entitiesToBeSelected);
- }
- bool CTrackViewSequence::SetName(const char* name)
- {
- // Check if there is already a sequence with that name
- const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
- if (pSequenceManager->GetSequenceByName(name))
- {
- return false;
- }
- AZStd::string oldName = GetName();
- if (name != oldName)
- {
- m_pAnimSequence->SetName(name);
- MarkAsModified();
- AzToolsFramework::ScopedUndoBatch undoBatch("Rename Sequence");
- GetSequence()->OnNodeRenamed(this, oldName.c_str());
- undoBatch.MarkEntityDirty(m_pAnimSequence->GetSequenceEntityId());
- }
- return true;
- }
- void CTrackViewSequence::DeleteSelectedKeys()
- {
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- for (int k = (int)selectedKeys.GetKeyCount() - 1; k >= 0; --k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(k);
- skey.Delete();
- }
- // The selected keys are deleted, so notify the selection was just changed.
- OnKeySelectionChanged();
- }
- void CTrackViewSequence::CopyKeysToClipboard(const bool bOnlySelectedKeys, const bool bOnlyFromSelectedTracks)
- {
- XmlNodeRef copyNode = XmlHelpers::CreateXmlNode("CopyKeysNode");
- CopyKeysToClipboard(copyNode, bOnlySelectedKeys, bOnlyFromSelectedTracks);
- CClipboard clip(nullptr);
- clip.Put(copyNode, "Track view keys");
- }
- void CTrackViewSequence::CopyKeysToClipboard(XmlNodeRef& xmlNode, const bool bOnlySelectedKeys, const bool bOnlyFromSelectedTracks)
- {
- for (auto iter = m_childNodes.begin(); iter != m_childNodes.end(); ++iter)
- {
- CTrackViewNode* pChildNode = (*iter).get();
- pChildNode->CopyKeysToClipboard(xmlNode, bOnlySelectedKeys, bOnlyFromSelectedTracks);
- }
- }
- void CTrackViewSequence::PasteKeysFromClipboard(CTrackViewAnimNode* pTargetNode, CTrackViewTrack* pTargetTrack, const float timeOffset)
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CClipboard clipboard(nullptr);
- XmlNodeRef clipboardContent = clipboard.Get();
- if (clipboardContent)
- {
- AZStd::vector<TMatchedTrackLocation> matchedLocations = GetMatchedPasteLocations(clipboardContent, pTargetNode, pTargetTrack);
- for (auto iter = matchedLocations.begin(); iter != matchedLocations.end(); ++iter)
- {
- const TMatchedTrackLocation& location = *iter;
- CTrackViewTrack* pTrack = location.first;
- const XmlNodeRef& trackNode = location.second;
- pTrack->PasteKeys(trackNode, timeOffset);
- }
- OnKeysChanged();
- }
- }
- AZStd::vector<CTrackViewSequence::TMatchedTrackLocation>
- CTrackViewSequence::GetMatchedPasteLocations(XmlNodeRef clipboardContent, CTrackViewAnimNode* pTargetNode, CTrackViewTrack* pTargetTrack)
- {
- AZStd::vector<TMatchedTrackLocation> matchedLocations;
- bool bPastingSingleNode = false;
- XmlNodeRef singleNode;
- bool bPastingSingleTrack = false;
- XmlNodeRef singleTrack;
- // Check if the XML tree only contains one node and if so if that node only contains one track
- for (XmlNodeRef currentNode = clipboardContent; currentNode->getChildCount() > 0; currentNode = currentNode->getChild(0))
- {
- bool bAllChildsAreTracks = true;
- const unsigned int numChilds = currentNode->getChildCount();
- for (unsigned int i = 0; i < numChilds; ++i)
- {
- XmlNodeRef childNode = currentNode->getChild(i);
- if (strcmp(currentNode->getChild(0)->getTag(), "Track") != 0)
- {
- bAllChildsAreTracks = false;
- break;
- }
- }
- if (bAllChildsAreTracks)
- {
- bPastingSingleNode = true;
- singleNode = currentNode;
- if (currentNode->getChildCount() == 1)
- {
- bPastingSingleTrack = true;
- singleTrack = currentNode->getChild(0);
- }
- }
- else if (currentNode->getChildCount() != 1)
- {
- break;
- }
- }
- if (bPastingSingleTrack && pTargetNode && pTargetTrack)
- {
- // We have a target node & track, so try to match the value type
- int valueType = 0;
- if (singleTrack->getAttr("valueType", valueType))
- {
- if (pTargetTrack->GetValueType() == static_cast<AnimValueType>(valueType))
- {
- matchedLocations.push_back(TMatchedTrackLocation(pTargetTrack, singleTrack));
- return matchedLocations;
- }
- }
- }
- if (bPastingSingleNode && pTargetNode)
- {
- // Set of tracks that were already matched
- AZStd::vector<CTrackViewTrack*> matchedTracks;
- // We have a single node to paste and have been given a target node
- // so try to match the tracks by param type
- const unsigned int numTracks = singleNode->getChildCount();
- for (unsigned int i = 0; i < numTracks; ++i)
- {
- XmlNodeRef trackNode = singleNode->getChild(i);
- // Try to match the track
- auto matchingTracks = GetMatchingTracks(pTargetNode, trackNode);
- for (auto iter = matchingTracks.begin(); iter != matchingTracks.end(); ++iter)
- {
- CTrackViewTrack* pMatchedTrack = *iter;
- // Pick the first track that was matched *and* was not already matched
- if (!AZStd::find(matchedTracks.begin(), matchedTracks.end(), pMatchedTrack))
- {
- stl::push_back_unique(matchedTracks, pMatchedTrack);
- matchedLocations.push_back(TMatchedTrackLocation(pMatchedTrack, trackNode));
- break;
- }
- }
- }
- // Return if matching succeeded
- if (matchedLocations.size() > 0)
- {
- return matchedLocations;
- }
- }
- if (!bPastingSingleNode)
- {
- // Ok, we're pasting keys from multiple nodes, haven't been given any target
- // or matching the targets failed. Ignore given target pointers and start
- // a recursive match at the sequence root.
- GetMatchedPasteLocationsRec(matchedLocations, this, clipboardContent);
- }
- return matchedLocations;
- }
- AZStd::deque<CTrackViewTrack*> CTrackViewSequence::GetMatchingTracks(CTrackViewAnimNode* pAnimNode, XmlNodeRef trackNode)
- {
- AZStd::deque<CTrackViewTrack*> matchingTracks;
- const AZStd::string trackName = trackNode->getAttr("name");
- CAnimParamType animParamType;
- animParamType.LoadFromXml(trackNode);
- int valueType;
- if (!trackNode->getAttr("valueType", valueType))
- {
- return matchingTracks;
- }
- CTrackViewTrackBundle tracks = pAnimNode->GetTracksByParam(animParamType);
- const unsigned int trackCount = tracks.GetCount();
- if (trackCount > 0)
- {
- // Search for a track with the given name and value type
- for (unsigned int i = 0; i < trackCount; ++i)
- {
- CTrackViewTrack* pTrack = tracks.GetTrack(i);
- if (pTrack->GetValueType() == static_cast<AnimValueType>(valueType))
- {
- if (pTrack->GetName() == trackName)
- {
- matchingTracks.push_back(pTrack);
- }
- }
- }
- // Then with lower precedence add the tracks that only match the value
- for (unsigned int i = 0; i < trackCount; ++i)
- {
- CTrackViewTrack* pTrack = tracks.GetTrack(i);
- if (pTrack->GetValueType() == static_cast<AnimValueType>(valueType))
- {
- stl::push_back_unique(matchingTracks, pTrack);
- }
- }
- }
- return matchingTracks;
- }
- void CTrackViewSequence::GetMatchedPasteLocationsRec(AZStd::vector<TMatchedTrackLocation>& locations, CTrackViewNode* pCurrentNode, XmlNodeRef clipboardNode)
- {
- if (pCurrentNode->GetNodeType() == eTVNT_Sequence)
- {
- if (strcmp(clipboardNode->getTag(), "CopyKeysNode") != 0)
- {
- return;
- }
- }
- const unsigned int numChildNodes = clipboardNode->getChildCount();
- for (unsigned int nodeIndex = 0; nodeIndex < numChildNodes; ++nodeIndex)
- {
- XmlNodeRef xmlChildNode = clipboardNode->getChild(nodeIndex);
- const AZStd::string tagName = xmlChildNode->getTag();
- if (tagName == "Node")
- {
- const AZStd::string nodeName = xmlChildNode->getAttr("name");
- int nodeType = static_cast<int>(AnimNodeType::Invalid);
- xmlChildNode->getAttr("type", nodeType);
- const unsigned int childCount = pCurrentNode->GetChildCount();
- for (unsigned int i = 0; i < childCount; ++i)
- {
- CTrackViewNode* pChildNode = pCurrentNode->GetChild(i);
- if (pChildNode->GetNodeType() == eTVNT_AnimNode)
- {
- CTrackViewAnimNode* pAnimNode = static_cast<CTrackViewAnimNode*>(pChildNode);
- if (pAnimNode->GetName() == nodeName && pAnimNode->GetType() == static_cast<AnimNodeType>(nodeType))
- {
- GetMatchedPasteLocationsRec(locations, pChildNode, xmlChildNode);
- }
- }
- }
- }
- else if (tagName == "Track")
- {
- const AZStd::string trackName = xmlChildNode->getAttr("name");
- CAnimParamType trackParamType;
- trackParamType.Serialize(xmlChildNode, true);
- int trackParamValue = static_cast<int>(AnimValueType::Unknown);
- xmlChildNode->getAttr("valueType", trackParamValue);
- const unsigned int childCount = pCurrentNode->GetChildCount();
- for (unsigned int i = 0; i < childCount; ++i)
- {
- CTrackViewNode* node = pCurrentNode->GetChild(i);
- if (node->GetNodeType() == eTVNT_Track)
- {
- CTrackViewTrack* pTrack = static_cast<CTrackViewTrack*>(node);
- if (pTrack->GetName() == trackName && pTrack->GetParameterType() == trackParamType)
- {
- locations.push_back(TMatchedTrackLocation(pTrack, xmlChildNode));
- }
- }
- }
- }
- }
- }
- void CTrackViewSequence::AdjustKeysToTimeRange(Range newTimeRange)
- {
- // Set new time range
- Range oldTimeRange = GetTimeRange();
- float offset = newTimeRange.start - oldTimeRange.start;
- // Calculate scale ratio.
- float scale = newTimeRange.Length() / oldTimeRange.Length();
- SetTimeRange(newTimeRange);
- CTrackViewKeyBundle keyBundle = GetAllKeys();
- const unsigned int numKeys = keyBundle.GetKeyCount();
- // Do not notify listeners until all the times are set, otherwise the
- // keys will be sorted and the indices inside the CTrackViewKeyHandle
- // will become invalid.
- bool notifyListeners = false;
- for (unsigned int i = 0; i < numKeys; ++i)
- {
- CTrackViewKeyHandle keyHandle = keyBundle.GetKey(i);
- float scaled = (keyHandle.GetTime() - oldTimeRange.start) * scale;
- keyHandle.SetTime(offset + scaled + oldTimeRange.start, notifyListeners);
- }
- // notifyListeners was disabled in the above SetTime() calls so
- // notify all the keys changes now.
- OnKeysChanged();
- MarkAsModified();
- }
- void CTrackViewSequence::SetTimeRange(Range timeRange)
- {
- m_pAnimSequence->SetTimeRange(timeRange);
- OnSequenceSettingsChanged();
- }
- Range CTrackViewSequence::GetTimeRange() const
- {
- return m_pAnimSequence->GetTimeRange();
- }
- void CTrackViewSequence::SetFlags(IAnimSequence::EAnimSequenceFlags flags)
- {
- m_pAnimSequence->SetFlags(flags);
- OnSequenceSettingsChanged();
- }
- IAnimSequence::EAnimSequenceFlags CTrackViewSequence::GetFlags() const
- {
- return (IAnimSequence::EAnimSequenceFlags)m_pAnimSequence->GetFlags();
- }
- void CTrackViewSequence::DeselectAllKeys()
- {
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- for (unsigned int i = 0; i < selectedKeys.GetKeyCount(); ++i)
- {
- CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(i);
- keyHandle.Select(false);
- }
- }
- void CTrackViewSequence::OffsetSelectedKeys(const float timeOffset)
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- // Set notifyListeners to false and wait until all keys
- // have been updated, otherwise the indexes in CTrackViewKeyHandle
- // may become invalid after sorted with a new time.
- bool notifyListeners = false;
- for (int k = 0; k < (int)selectedKeys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(k);
- skey.Offset(timeOffset, notifyListeners);
- }
- if (selectedKeys.GetKeyCount() > 0)
- {
- OnKeysChanged();
- }
- }
- float CTrackViewSequence::ClipTimeOffsetForOffsetting(const float timeOffset)
- {
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- float newTimeOffset = timeOffset;
- for (int k = 0; k < (int)selectedKeys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(k);
- const float keyTime = skey.GetTime();
- float newKeyTime = keyTime + timeOffset;
- Range extendedTimeRange(0.0f, GetTimeRange().end);
- extendedTimeRange.ClipValue(newKeyTime);
- float offset = newKeyTime - keyTime;
- if (fabs(offset) < fabs(newTimeOffset))
- {
- newTimeOffset = offset;
- }
- }
- return newTimeOffset;
- }
- float CTrackViewSequence::ClipTimeOffsetForScaling(float timeOffset)
- {
- if (timeOffset <= 0)
- {
- return timeOffset;
- }
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- float newTimeOffset = timeOffset;
- for (int k = 0; k < (int)selectedKeys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(k);
- float keyTime = skey.GetTime();
- float newKeyTime = keyTime * timeOffset;
- GetTimeRange().ClipValue(newKeyTime);
- float offset = newKeyTime / keyTime;
- if (offset < newTimeOffset)
- {
- newTimeOffset = offset;
- }
- }
- return newTimeOffset;
- }
- void CTrackViewSequence::ScaleSelectedKeys(const float timeOffset)
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CTrackViewSequenceNotificationContext context(this);
- if (timeOffset <= 0)
- {
- return;
- }
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- const CTrackViewTrack* pTrack = nullptr;
- for (int k = 0; k < (int)selectedKeys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(k);
- if (pTrack != skey.GetTrack())
- {
- pTrack = skey.GetTrack();
- }
- float keyt = skey.GetTime() * timeOffset;
- skey.SetTime(keyt);
- }
- }
- float CTrackViewSequence::ClipTimeOffsetForSliding(const float timeOffset)
- {
- CTrackViewKeyBundle keys = GetSelectedKeys();
- AZStd::set<CTrackViewTrack*> tracks;
- AZStd::set<CTrackViewTrack*>::const_iterator pTrackIter;
- Range timeRange = GetTimeRange();
- // Get the first key in the timeline among selected and
- // also gather tracks.
- float time0 = timeRange.end;
- for (int k = 0; k < (int)keys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = keys.GetKey(k);
- tracks.insert(skey.GetTrack());
- float keyTime = skey.GetTime();
- if (keyTime < time0)
- {
- time0 = keyTime;
- }
- }
- // If 'bAll' is true, slide all tracks.
- // (Otherwise, slide only selected tracks.)
- bool bAll = Qt::AltModifier & QApplication::queryKeyboardModifiers();
- if (bAll)
- {
- keys = GetKeysInTimeRange(time0, timeRange.end);
- // Gather tracks again.
- tracks.clear();
- for (int k = 0; k < (int)keys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = keys.GetKey(k);
- tracks.insert(skey.GetTrack());
- }
- }
- float newTimeOffset = timeOffset;
- for (pTrackIter = tracks.begin(); pTrackIter != tracks.end(); ++pTrackIter)
- {
- CTrackViewTrack* pTrack = *pTrackIter;
- for (unsigned int i = 0; i < pTrack->GetKeyCount(); ++i)
- {
- const CTrackViewKeyHandle& keyHandle = pTrack->GetKey(i);
- const float keyTime = keyHandle.GetTime();
- if (keyTime >= time0)
- {
- float newKeyTime = keyTime + timeOffset;
- timeRange.ClipValue(newKeyTime);
- float offset = newKeyTime - keyTime;
- if (fabs(offset) < fabs(newTimeOffset))
- {
- newTimeOffset = offset;
- }
- }
- }
- }
- return newTimeOffset;
- }
- void CTrackViewSequence::SlideKeys(float timeOffset)
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewKeyBundle keys = GetSelectedKeys();
- AZStd::set<CTrackViewTrack*> tracks;
- AZStd::set<CTrackViewTrack*>::const_iterator pTrackIter;
- Range timeRange = GetTimeRange();
- // Get the first key in the timeline among selected and
- // also gather tracks.
- float time0 = timeRange.end;
- for (int k = 0; k < (int)keys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = keys.GetKey(k);
- tracks.insert(skey.GetTrack());
- float keyTime = skey.GetTime();
- if (keyTime < time0)
- {
- time0 = keyTime;
- }
- }
- // If 'bAll' is true, slide all tracks.
- // (Otherwise, slide only selected tracks.)
- bool bAll = Qt::AltModifier & QApplication::queryKeyboardModifiers();
- if (bAll)
- {
- keys = GetKeysInTimeRange(time0, timeRange.end);
- // Gather tracks again.
- tracks.clear();
- for (int k = 0; k < (int)keys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = keys.GetKey(k);
- tracks.insert(skey.GetTrack());
- }
- }
- for (pTrackIter = tracks.begin(); pTrackIter != tracks.end(); ++pTrackIter)
- {
- CTrackViewTrack* pTrack = *pTrackIter;
- pTrack->SlideKeys(time0, timeOffset);
- }
- }
- void CTrackViewSequence::CloneSelectedKeys()
- {
- AZ_Assert(CUndo::IsRecording(), "Undo is not recording");
- CTrackViewSequenceNotificationContext context(this);
- CTrackViewKeyBundle selectedKeys = GetSelectedKeys();
- const CTrackViewTrack* pTrack = nullptr;
- // In case of multiple cloning, indices cannot be used as a solid pointer to the original.
- // So use the time of keys as an identifier, instead.
- AZStd::vector<float> selectedKeyTimes;
- for (size_t k = 0; k < selectedKeys.GetKeyCount(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(static_cast<unsigned int>(k));
- if (pTrack != skey.GetTrack())
- {
- pTrack = skey.GetTrack();
- }
- selectedKeyTimes.push_back(skey.GetTime());
- }
- // Now, do the actual cloning.
- for (size_t k = 0; k < selectedKeyTimes.size(); ++k)
- {
- CTrackViewKeyHandle skey = selectedKeys.GetKey(static_cast<unsigned int>(k));
- skey = skey.GetTrack()->GetKeyByTime(selectedKeyTimes[k]);
- AZ_Assert(skey.IsValid(), "Key is not valid");
- if (!skey.IsValid())
- {
- continue;
- }
- CTrackViewKeyHandle newKey = skey.Clone();
- // Select new key.
- newKey.Select(true);
- // Deselect cloned key.
- skey.Select(false);
- }
- }
- void CTrackViewSequence::BeginUndoTransaction()
- {
- QueueNotifications();
- }
- void CTrackViewSequence::EndUndoTransaction()
- {
- // if the sequence was added during a redo, it will add itself as an UndoManagerListener in the process and we'll
- // get an EndUndoTransaction without a corresponding BeginUndoTransaction() call - only SubmitPendingNotifications()
- // if we're queued
- if (m_bQueueNotifications)
- {
- SubmitPendingNotifications();
- }
- }
- void CTrackViewSequence::BeginRestoreTransaction()
- {
- QueueNotifications();
- }
- void CTrackViewSequence::EndRestoreTransaction()
- {
- // if the sequence was added during a restore, it will add itself as an UndoManagerListener in the process and we'll
- // get an EndUndoTransaction without a corresponding BeginUndoTransaction() call - only SubmitPendingNotifications()
- // if we're queued
- if (m_bQueueNotifications)
- {
- SubmitPendingNotifications();
- }
- }
- bool CTrackViewSequence::IsActiveSequence() const
- {
- return GetIEditor()->GetAnimation()->GetSequence() == this;
- }
- const float CTrackViewSequence::GetTime() const
- {
- return m_time;
- }
- CTrackViewSequence* CTrackViewSequence::LookUpSequenceByEntityId(const AZ::EntityId& sequenceId)
- {
- CTrackViewSequence* sequence = nullptr;
- IEditor* editor = nullptr;
- AzToolsFramework::EditorRequests::Bus::BroadcastResult(editor, &AzToolsFramework::EditorRequests::Bus::Events::GetEditor);
- if (editor)
- {
- ITrackViewSequenceManager* sequenceManager = editor->GetSequenceManager();
- if (sequenceManager)
- {
- sequence = sequenceManager->GetSequenceByEntityId(sequenceId);
- }
- }
- return sequence;
- }
|