SequenceKeyUIControls.cpp 6.3 KB

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