GotoKeyUIControls.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 CGotoKeyUIControls::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::Goto)
  27. {
  28. IDiscreteFloatKey discreteFloatKey;
  29. keyHandle.GetKey(&discreteFloatKey);
  30. mv_command = discreteFloatKey.m_fValue;
  31. bAssigned = true;
  32. }
  33. }
  34. return bAssigned;
  35. }
  36. //////////////////////////////////////////////////////////////////////////
  37. // Called when UI variable changes.
  38. void CGotoKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  39. {
  40. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  41. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  42. {
  43. return;
  44. }
  45. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  46. {
  47. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  48. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  49. if (paramType == AnimParamType::Goto)
  50. {
  51. IDiscreteFloatKey discreteFloatKey;
  52. keyHandle.GetKey(&discreteFloatKey);
  53. SyncValue(mv_command, discreteFloatKey.m_fValue, false, pVar);
  54. bool isDuringUndo = false;
  55. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  56. if (isDuringUndo)
  57. {
  58. keyHandle.SetKey(&discreteFloatKey);
  59. }
  60. else
  61. {
  62. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  63. keyHandle.SetKey(&discreteFloatKey);
  64. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  65. }
  66. }
  67. }
  68. }