TimeRangeKeyUIControls.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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> // for AnimParamType
  11. // Editor
  12. #include "KeyUIControls.h"
  13. #include "TrackViewKeyPropertiesDlg.h" // for CTrackViewKeyUIControls// Editor
  14. //////////////////////////////////////////////////////////////////////////
  15. bool CTimeRangeKeyUIControls::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::TimeRanges)
  27. {
  28. ICharacterKey timeRangeKey;
  29. keyHandle.GetKey(&timeRangeKey);
  30. mv_endTime = timeRangeKey.m_endTime;
  31. mv_startTime = timeRangeKey.m_startTime;
  32. mv_timeScale = timeRangeKey.m_speed;
  33. mv_bLoop = timeRangeKey.m_bLoop;
  34. bAssigned = true;
  35. }
  36. }
  37. return bAssigned;
  38. }
  39. // Called when UI variable changes.
  40. void CTimeRangeKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  41. {
  42. CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
  43. if (!pSequence || !selectedKeys.AreAllKeysOfSameType())
  44. {
  45. return;
  46. }
  47. for (unsigned int keyIndex = 0, num = (int)selectedKeys.GetKeyCount(); keyIndex < num; keyIndex++)
  48. {
  49. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  50. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  51. if (paramType == AnimParamType::TimeRanges)
  52. {
  53. ITimeRangeKey timeRangeKey;
  54. keyHandle.GetKey(&timeRangeKey);
  55. SyncValue(mv_startTime, timeRangeKey.m_startTime, false, pVar);
  56. SyncValue(mv_endTime, timeRangeKey.m_endTime, false, pVar);
  57. SyncValue(mv_timeScale, timeRangeKey.m_speed, false, pVar);
  58. SyncValue(mv_bLoop, timeRangeKey.m_bLoop, false, pVar);
  59. // Clamp values
  60. if (!timeRangeKey.m_bLoop)
  61. {
  62. timeRangeKey.m_endTime = std::min(timeRangeKey.m_duration, timeRangeKey.m_endTime);
  63. }
  64. timeRangeKey.m_startTime = std::min(timeRangeKey.m_duration, timeRangeKey.m_startTime);
  65. timeRangeKey.m_startTime = std::min(timeRangeKey.m_endTime, timeRangeKey.m_startTime);
  66. keyHandle.SetKey(&timeRangeKey);
  67. }
  68. }
  69. }