CommentKeyUIControls.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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"
  14. //////////////////////////////////////////////////////////////////////////
  15. bool CCommentKeyUIControls::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::CommentText)
  27. {
  28. ICommentKey commentKey;
  29. keyHandle.GetKey(&commentKey);
  30. mv_comment = commentKey.m_strComment.c_str();
  31. mv_duration = commentKey.m_duration;
  32. mv_size = commentKey.m_size;
  33. mv_font = commentKey.m_strFont.c_str();
  34. mv_color = Vec3(commentKey.m_color.GetR(), commentKey.m_color.GetG(), commentKey.m_color.GetB());
  35. mv_align = commentKey.m_align;
  36. bAssigned = true;
  37. }
  38. }
  39. return bAssigned;
  40. }
  41. //////////////////////////////////////////////////////////////////////////
  42. // Called when UI variable changes.
  43. void CCommentKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  44. {
  45. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  46. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  47. {
  48. return;
  49. }
  50. for (size_t keyIndex = 0, num = selectedKeys.GetKeyCount(); keyIndex < num; keyIndex++)
  51. {
  52. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(static_cast<unsigned int>(keyIndex));
  53. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  54. if (paramType == AnimParamType::CommentText)
  55. {
  56. ICommentKey commentKey;
  57. keyHandle.GetKey(&commentKey);
  58. if (!pVar || pVar == mv_comment.GetVar())
  59. {
  60. commentKey.m_strComment = ((QString)mv_comment).toUtf8().data();
  61. }
  62. if (!pVar || pVar == mv_font.GetVar())
  63. {
  64. QString sFont = mv_font;
  65. commentKey.m_strFont = sFont.toUtf8().data();
  66. }
  67. if (!pVar || pVar == mv_align.GetVar())
  68. {
  69. commentKey.m_align = (ICommentKey::ETextAlign)((int)mv_align);
  70. }
  71. SyncValue(mv_duration, commentKey.m_duration, false, pVar);
  72. Vec3 color(commentKey.m_color.GetR(), commentKey.m_color.GetG(), commentKey.m_color.GetB());
  73. SyncValue(mv_color, color, false, pVar);
  74. commentKey.m_color.Set(color.x, color.y, color.z, commentKey.m_color.GetA());
  75. SyncValue(mv_size, commentKey.m_size, false, pVar);
  76. bool isDuringUndo = false;
  77. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  78. if (isDuringUndo)
  79. {
  80. keyHandle.SetKey(&commentKey);
  81. }
  82. else
  83. {
  84. // Let the AZ Undo system manage the nodes on the sequence entity
  85. AzToolsFramework::ScopedUndoBatch undoBatch("Change key");
  86. keyHandle.SetKey(&commentKey);
  87. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  88. }
  89. }
  90. }
  91. }