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