EventKeyUIControls.cpp 3.4 KB

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