EventKeyUIControls.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "KeyUIControls.h"
  10. #include "TrackViewKeyPropertiesDlg.h" // for CTrackViewKeyUIControls
  11. #include <CryCommon/Maestro/Types/AnimParamType.h> // AnimParamType
  12. //////////////////////////////////////////////////////////////////////////
  13. bool CEventKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  14. {
  15. if (!selectedKeys.AreAllKeysOfSameType())
  16. {
  17. return false;
  18. }
  19. bool bAssigned = false;
  20. if (selectedKeys.GetKeyCount() == 1)
  21. {
  22. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  23. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  24. if (paramType == AnimParamType::Event)
  25. {
  26. mv_event.SetEnumList(nullptr);
  27. mv_animation.SetEnumList(nullptr);
  28. // Add <None> for empty, unset event
  29. mv_event->AddEnumItem(QObject::tr("<None>"), "");
  30. mv_animation->AddEnumItem(QObject::tr("<None>"), "");
  31. IEventKey eventKey;
  32. keyHandle.GetKey(&eventKey);
  33. mv_event = eventKey.event.c_str();
  34. mv_value = eventKey.eventValue.c_str();
  35. mv_animation = eventKey.animation.c_str();
  36. mv_notrigger_in_scrubbing = eventKey.bNoTriggerInScrubbing;
  37. bAssigned = true;
  38. }
  39. }
  40. return bAssigned;
  41. }
  42. // Called when UI variable changes.
  43. void CEventKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  44. {
  45. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  46. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  47. {
  48. return;
  49. }
  50. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  51. {
  52. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  53. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  54. if (paramType == AnimParamType::Event)
  55. {
  56. IEventKey eventKey;
  57. keyHandle.GetKey(&eventKey);
  58. QByteArray event, value, animation;
  59. event = static_cast<QString>(mv_event).toUtf8();
  60. value = static_cast<QString>(mv_value).toUtf8();
  61. animation = static_cast<QString>(mv_animation).toUtf8();
  62. if (pVar == mv_event.GetVar())
  63. {
  64. eventKey.event = event.data();
  65. }
  66. if (pVar == mv_value.GetVar())
  67. {
  68. eventKey.eventValue = value.data();
  69. }
  70. if (pVar == mv_animation.GetVar())
  71. {
  72. eventKey.animation = animation.data();
  73. }
  74. SyncValue(mv_notrigger_in_scrubbing, eventKey.bNoTriggerInScrubbing, false, pVar);
  75. bool isDuringUndo = false;
  76. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  77. if (isDuringUndo)
  78. {
  79. keyHandle.SetKey(&eventKey);
  80. }
  81. else
  82. {
  83. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  84. keyHandle.SetKey(&eventKey);
  85. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  86. }
  87. }
  88. }
  89. }