CaptureKeyUIControls.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "TrackViewKeyPropertiesDlg.h"
  14. //////////////////////////////////////////////////////////////////////////
  15. bool CCaptureKeyUIControls::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::Capture)
  27. {
  28. ICaptureKey captureKey;
  29. keyHandle.GetKey(&captureKey);
  30. mv_duration = captureKey.duration;
  31. mv_timeStep = captureKey.timeStep;
  32. mv_prefix = captureKey.prefix.c_str();
  33. mv_folder = captureKey.folder.c_str();
  34. mv_once = captureKey.once;
  35. bAssigned = true;
  36. }
  37. }
  38. return bAssigned;
  39. }
  40. // Called when UI variable changes.
  41. void CCaptureKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  42. {
  43. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  44. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  45. {
  46. return;
  47. }
  48. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  49. {
  50. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  51. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  52. if (paramType == AnimParamType::Capture)
  53. {
  54. ICaptureKey captureKey;
  55. keyHandle.GetKey(&captureKey);
  56. SyncValue(mv_duration, captureKey.duration, false, pVar);
  57. SyncValue(mv_timeStep, captureKey.timeStep, false, pVar);
  58. if (pVar == mv_folder.GetVar())
  59. {
  60. QString sFolder = mv_folder;
  61. captureKey.folder = sFolder.toUtf8().data();
  62. }
  63. if (pVar == mv_prefix.GetVar())
  64. {
  65. QString sPrefix = mv_prefix;
  66. captureKey.prefix = sPrefix.toUtf8().data();
  67. }
  68. SyncValue(mv_once, captureKey.once, false, pVar);
  69. bool isDuringUndo = false;
  70. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(
  71. isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  72. if (isDuringUndo)
  73. {
  74. keyHandle.SetKey(&captureKey);
  75. }
  76. else
  77. {
  78. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  79. keyHandle.SetKey(&captureKey);
  80. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  81. }
  82. }
  83. }
  84. }