3
0

CommentNode.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <AzCore/Serialization/SerializeContext.h>
  9. #include "CommentNode.h"
  10. #include "AnimSplineTrack.h"
  11. #include "CommentTrack.h"
  12. #include "Maestro/Types/AnimNodeType.h"
  13. #include "Maestro/Types/AnimValueType.h"
  14. #include "Maestro/Types/AnimParamType.h"
  15. //////////////////////////////////////////////////////////////////////////
  16. namespace
  17. {
  18. bool s_nodeParamsInit = false;
  19. AZStd::vector<CAnimNode::SParamInfo> s_nodeParameters;
  20. void AddSupportedParameters(const char* sName, AnimParamType paramId, AnimValueType valueType)
  21. {
  22. CAnimNode::SParamInfo param;
  23. param.name = sName;
  24. param.paramType = paramId;
  25. param.valueType = valueType;
  26. s_nodeParameters.push_back(param);
  27. }
  28. };
  29. //-----------------------------------------------------------------------------
  30. CCommentNode::CCommentNode(const int id)
  31. : CAnimNode(id, AnimNodeType::Comment)
  32. {
  33. CCommentNode::Initialize();
  34. }
  35. CCommentNode::CCommentNode()
  36. : CCommentNode(0)
  37. {
  38. }
  39. //-----------------------------------------------------------------------------
  40. void CCommentNode::Initialize()
  41. {
  42. if (!s_nodeParamsInit)
  43. {
  44. s_nodeParamsInit = true;
  45. s_nodeParameters.reserve(3);
  46. AddSupportedParameters("Text", AnimParamType::CommentText, AnimValueType::Unknown);
  47. AddSupportedParameters("Unit Pos X", AnimParamType::PositionX, AnimValueType::Float);
  48. AddSupportedParameters("Unit Pos Y", AnimParamType::PositionY, AnimValueType::Float);
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. void CCommentNode::Animate([[maybe_unused]] SAnimContext& ac)
  53. {
  54. // It's only for valid operation of key time editing.
  55. // Actual animation process is in the editor side.
  56. CCommentTrack* pCommentTrack = static_cast<CCommentTrack*>(GetTrackForParameter(AnimParamType::CommentText));
  57. if (pCommentTrack)
  58. {
  59. pCommentTrack->ValidateKeyOrder();
  60. }
  61. }
  62. //-----------------------------------------------------------------------------
  63. void CCommentNode::CreateDefaultTracks()
  64. {
  65. CreateTrack(AnimParamType::CommentText);
  66. C2DSplineTrack* pTrack = 0;
  67. pTrack = (C2DSplineTrack*)CreateTrack(AnimParamType::PositionX);
  68. pTrack->SetDefaultValue(Vec2(0, 50));
  69. pTrack = (C2DSplineTrack*)CreateTrack(AnimParamType::PositionY);
  70. pTrack->SetDefaultValue(Vec2(0, 50));
  71. }
  72. //-----------------------------------------------------------------------------
  73. void CCommentNode::OnReset()
  74. {
  75. }
  76. //-----------------------------------------------------------------------------
  77. void CCommentNode::Activate(bool bActivate)
  78. {
  79. CAnimNode::Activate(bActivate);
  80. }
  81. //-----------------------------------------------------------------------------
  82. /// @deprecated Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  83. void CCommentNode::Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks)
  84. {
  85. CAnimNode::Serialize(xmlNode, bLoading, bLoadEmptyTracks);
  86. }
  87. //////////////////////////////////////////////////////////////////////////
  88. void CCommentNode::Reflect(AZ::ReflectContext* context)
  89. {
  90. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  91. {
  92. serializeContext->Class<CCommentNode, CAnimNode>()
  93. ->Version(1);
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. unsigned int CCommentNode::GetParamCount() const
  98. {
  99. return static_cast<unsigned int>(s_nodeParameters.size());
  100. }
  101. //-----------------------------------------------------------------------------
  102. CAnimParamType CCommentNode::GetParamType(unsigned int nIndex) const
  103. {
  104. if (nIndex < s_nodeParameters.size())
  105. {
  106. return s_nodeParameters[nIndex].paramType;
  107. }
  108. return AnimParamType::Invalid;
  109. }
  110. //-----------------------------------------------------------------------------
  111. bool CCommentNode::GetParamInfoFromType(const CAnimParamType& paramId, SParamInfo& info) const
  112. {
  113. for (size_t i = 0; i < s_nodeParameters.size(); ++i)
  114. {
  115. if (s_nodeParameters[i].paramType == paramId)
  116. {
  117. info = s_nodeParameters[i];
  118. return true;
  119. }
  120. }
  121. return false;
  122. }