GotoKeyUIControls.cpp 2.4 KB

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