SequenceKeyUIControls.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. // CryCommon
  10. #include <CryCommon/Maestro/Types/AnimParamType.h>
  11. // Editor
  12. #include "KeyUIControls.h"
  13. #include "TrackViewDialog.h"
  14. //////////////////////////////////////////////////////////////////////////
  15. bool CSequenceKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  16. {
  17. if (!selectedKeys.AreAllKeysOfSameType())
  18. {
  19. return false;
  20. }
  21. bool bAssigned = false;
  22. if (selectedKeys.GetKeyCount() == 1)
  23. {
  24. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  25. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  26. if (paramType == AnimParamType::Sequence)
  27. {
  28. CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
  29. /////////////////////////////////////////////////////////////////////////////////
  30. // fill sequence comboBox with available sequences
  31. mv_sequence.SetEnumList(nullptr);
  32. // Insert '<None>' empty enum
  33. mv_sequence->AddEnumItem(QObject::tr("<None>"), CTrackViewDialog::GetEntityIdAsString(AZ::EntityId(AZ::EntityId::InvalidEntityId)));
  34. const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  35. for (unsigned int i = 0; i < pSequenceManager->GetCount(); ++i)
  36. {
  37. CTrackViewSequence* pCurrentSequence = pSequenceManager->GetSequenceByIndex(i);
  38. bool bNotMe = pCurrentSequence != pSequence;
  39. bool bNotParent = !bNotMe || pCurrentSequence->IsAncestorOf(pSequence) == false;
  40. if (bNotMe && bNotParent)
  41. {
  42. AZStd::string seqName = pCurrentSequence->GetName();
  43. QString ownerIdString = CTrackViewDialog::GetEntityIdAsString(pCurrentSequence->GetSequenceComponentEntityId());
  44. mv_sequence->AddEnumItem(seqName.c_str(), ownerIdString);
  45. }
  46. }
  47. /////////////////////////////////////////////////////////////////////////////////
  48. // fill Key Properties with selected key values
  49. ISequenceKey sequenceKey;
  50. keyHandle.GetKey(&sequenceKey);
  51. QString entityIdString = CTrackViewDialog::GetEntityIdAsString((sequenceKey.sequenceEntityId));
  52. mv_sequence = entityIdString;
  53. mv_overrideTimes = sequenceKey.bOverrideTimes;
  54. if (!sequenceKey.bOverrideTimes)
  55. {
  56. IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
  57. if (movieSystem)
  58. {
  59. IAnimSequence* pSequence2 = movieSystem->FindSequence(sequenceKey.sequenceEntityId);
  60. if (pSequence2)
  61. {
  62. sequenceKey.fStartTime = pSequence2->GetTimeRange().start;
  63. sequenceKey.fEndTime = pSequence2->GetTimeRange().end;
  64. }
  65. else
  66. {
  67. sequenceKey.fStartTime = 0.0f;
  68. sequenceKey.fEndTime = 0.0f;
  69. }
  70. }
  71. }
  72. // Don't trigger an OnUIChange event, since this code is the one
  73. // updating the start/end ui elements, not the user setting new values.
  74. m_skipOnUIChange = true;
  75. mv_startTime = sequenceKey.fStartTime;
  76. mv_endTime = sequenceKey.fEndTime;
  77. m_skipOnUIChange = false;
  78. bAssigned = true;
  79. }
  80. }
  81. return bAssigned;
  82. }
  83. // Called when UI variable changes.
  84. void CSequenceKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  85. {
  86. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  87. if (!sequence || !selectedKeys.AreAllKeysOfSameType() || m_skipOnUIChange)
  88. {
  89. return;
  90. }
  91. IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
  92. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  93. {
  94. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  95. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  96. if (paramType == AnimParamType::Sequence)
  97. {
  98. ISequenceKey sequenceKey;
  99. keyHandle.GetKey(&sequenceKey);
  100. AZ::EntityId seqOwnerId;
  101. if (pVar == mv_sequence.GetVar())
  102. {
  103. QString entityIdString = mv_sequence;
  104. seqOwnerId = AZ::EntityId(static_cast<AZ::u64>(entityIdString.toULongLong()));
  105. sequenceKey.szSelection.clear(); // clear deprecated legacy data
  106. sequenceKey.sequenceEntityId = seqOwnerId;
  107. }
  108. SyncValue(mv_overrideTimes, sequenceKey.bOverrideTimes, false, pVar);
  109. IAnimSequence* pSequence = movieSystem ? movieSystem->FindSequence(seqOwnerId) : nullptr;
  110. if (!sequenceKey.bOverrideTimes)
  111. {
  112. if (pSequence)
  113. {
  114. sequenceKey.fStartTime = pSequence->GetTimeRange().start;
  115. sequenceKey.fEndTime = pSequence->GetTimeRange().end;
  116. }
  117. else
  118. {
  119. sequenceKey.fStartTime = 0.0f;
  120. sequenceKey.fEndTime = 0.0f;
  121. }
  122. }
  123. else
  124. {
  125. SyncValue(mv_startTime, sequenceKey.fStartTime, false, pVar);
  126. SyncValue(mv_endTime, sequenceKey.fEndTime, false, pVar);
  127. }
  128. sequenceKey.fDuration = sequenceKey.fEndTime - sequenceKey.fStartTime > 0 ? sequenceKey.fEndTime - sequenceKey.fStartTime : 0.0f;
  129. if (movieSystem)
  130. {
  131. movieSystem->SetStartEndTime(pSequence, sequenceKey.fStartTime, sequenceKey.fEndTime);
  132. }
  133. bool isDuringUndo = false;
  134. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  135. if (isDuringUndo)
  136. {
  137. keyHandle.SetKey(&sequenceKey);
  138. }
  139. else
  140. {
  141. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  142. keyHandle.SetKey(&sequenceKey);
  143. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  144. }
  145. }
  146. }
  147. }