CommentTrack.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "CommentTrack.h"
  10. //-----------------------------------------------------------------------------
  11. CCommentTrack::CCommentTrack()
  12. {
  13. }
  14. //-----------------------------------------------------------------------------
  15. void CCommentTrack::GetKeyInfo(int key, const char*& description, float& duration)
  16. {
  17. static char desc[128];
  18. assert(key >= 0 && key < (int)m_keys.size());
  19. CheckValid();
  20. description = 0;
  21. duration = m_keys[key].m_duration;
  22. azstrcpy(desc, AZ_ARRAY_SIZE(desc), m_keys[key].m_strComment.c_str());
  23. description = desc;
  24. }
  25. //-----------------------------------------------------------------------------
  26. void CCommentTrack::SerializeKey(ICommentKey& key, XmlNodeRef& keyNode, bool bLoading)
  27. {
  28. if (bLoading)
  29. {
  30. // Load only in the editor for loading performance.
  31. if (gEnv->IsEditor())
  32. {
  33. XmlString xmlComment;
  34. keyNode->getAttr("comment", xmlComment);
  35. key.m_strComment = xmlComment;
  36. keyNode->getAttr("duration", key.m_duration);
  37. const char* strFont = keyNode->getAttr("font");
  38. key.m_strFont = strFont;
  39. Vec4 color(key.m_color.GetR(), key.m_color.GetG(), key.m_color.GetB(), key.m_color.GetA());
  40. keyNode->getAttr("color", color);
  41. key.m_color.Set(color.x, color.y, color.z, color.w);
  42. keyNode->getAttr("size", key.m_size);
  43. int alignment = 0;
  44. keyNode->getAttr("align", alignment);
  45. key.m_align = (ICommentKey::ETextAlign)(alignment);
  46. }
  47. }
  48. else
  49. {
  50. XmlString xmlComment(key.m_strComment.c_str());
  51. keyNode->setAttr("comment", xmlComment);
  52. keyNode->setAttr("duration", key.m_duration);
  53. if (!key.m_strFont.empty())
  54. {
  55. keyNode->setAttr("font", key.m_strFont.c_str());
  56. }
  57. Vec4 color(key.m_color.GetR(), key.m_color.GetG(), key.m_color.GetB(), key.m_color.GetA());
  58. keyNode->setAttr("color", color);
  59. keyNode->setAttr("size", key.m_size);
  60. keyNode->setAttr("align", (int)key.m_align);
  61. }
  62. }
  63. //////////////////////////////////////////////////////////////////////////
  64. static bool CommentTrackVersionConverter(
  65. AZ::SerializeContext& serializeContext,
  66. AZ::SerializeContext::DataElementNode& rootElement)
  67. {
  68. if (rootElement.GetVersion() < 3)
  69. {
  70. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  71. }
  72. return true;
  73. }
  74. template<>
  75. inline void TAnimTrack<ICommentKey>::Reflect(AZ::ReflectContext* context)
  76. {
  77. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  78. {
  79. serializeContext->Class<TAnimTrack<ICommentKey>, IAnimTrack>()
  80. ->Version(3, &CommentTrackVersionConverter)
  81. ->Field("Flags", &TAnimTrack<ICommentKey>::m_flags)
  82. ->Field("Range", &TAnimTrack<ICommentKey>::m_timeRange)
  83. ->Field("ParamType", &TAnimTrack<ICommentKey>::m_nParamType)
  84. ->Field("Keys", &TAnimTrack<ICommentKey>::m_keys)
  85. ->Field("Id", &TAnimTrack<ICommentKey>::m_id);
  86. }
  87. }
  88. //////////////////////////////////////////////////////////////////////////
  89. void CCommentTrack::Reflect(AZ::ReflectContext* context)
  90. {
  91. TAnimTrack<ICommentKey>::Reflect(context);
  92. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  93. {
  94. serializeContext->Class<CCommentTrack, TAnimTrack<ICommentKey>>()
  95. ->Version(1);
  96. }
  97. }