CaptureKeyUIControls.cpp 3.0 KB

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