BoolTrack.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "BoolTrack.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include "UiAnimSerialize.h"
  11. //////////////////////////////////////////////////////////////////////////
  12. UiBoolTrack::UiBoolTrack()
  13. : m_bDefaultValue(true)
  14. {
  15. }
  16. //////////////////////////////////////////////////////////////////////////
  17. void UiBoolTrack::GetKeyInfo([[maybe_unused]] int index, const char*& description, float& duration)
  18. {
  19. description = 0;
  20. duration = 0;
  21. }
  22. //////////////////////////////////////////////////////////////////////////
  23. void UiBoolTrack::GetValue(float time, bool& value)
  24. {
  25. value = m_bDefaultValue;
  26. CheckValid();
  27. int nkeys = static_cast<int>(m_keys.size());
  28. if (nkeys < 1)
  29. {
  30. return;
  31. }
  32. int key = 0;
  33. while ((key < nkeys) && (time >= m_keys[key].time))
  34. {
  35. key++;
  36. }
  37. if (m_bDefaultValue)
  38. {
  39. value = !(key & 1); // True if even key.
  40. }
  41. else
  42. {
  43. value = (key & 1); // False if even key.
  44. }
  45. }
  46. //////////////////////////////////////////////////////////////////////////
  47. void UiBoolTrack::SetValue([[maybe_unused]] float time, [[maybe_unused]] const bool& value, [[maybe_unused]] bool bDefault)
  48. {
  49. Invalidate();
  50. }
  51. //////////////////////////////////////////////////////////////////////////
  52. void UiBoolTrack::SetDefaultValue(const bool bDefaultValue)
  53. {
  54. m_bDefaultValue = bDefaultValue;
  55. }
  56. //////////////////////////////////////////////////////////////////////////
  57. template<>
  58. inline void TUiAnimTrack<IBoolKey>::Reflect(AZ::SerializeContext* serializeContext)
  59. {
  60. serializeContext->ClassDeprecate("TUiAnimTrack_IBoolKey", AZ::Uuid("{7C2942C1-0ACE-404E-BF2B-E095A1B69A5B}"),
  61. [](AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& rootElement)
  62. {
  63. AZStd::vector<AZ::SerializeContext::DataElementNode> childNodeElements;
  64. for (int index = 0; index < rootElement.GetNumSubElements(); ++index)
  65. {
  66. childNodeElements.push_back(rootElement.GetSubElement(index));
  67. }
  68. // Convert the rootElement now, the existing child DataElmentNodes are now removed
  69. rootElement.Convert<TUiAnimTrack<IBoolKey>>(context);
  70. for (AZ::SerializeContext::DataElementNode& childNodeElement : childNodeElements)
  71. {
  72. rootElement.AddElement(AZStd::move(childNodeElement));
  73. }
  74. return true;
  75. });
  76. serializeContext->Class<TUiAnimTrack<IBoolKey> >()
  77. ->Version(1)
  78. ->Field("Flags", &TUiAnimTrack<IBoolKey>::m_flags)
  79. ->Field("Range", &TUiAnimTrack<IBoolKey>::m_timeRange)
  80. ->Field("ParamType", &TUiAnimTrack<IBoolKey>::m_nParamType)
  81. ->Field("ParamData", &TUiAnimTrack<IBoolKey>::m_componentParamData)
  82. ->Field("Keys", &TUiAnimTrack<IBoolKey>::m_keys);
  83. }
  84. //////////////////////////////////////////////////////////////////////////
  85. void UiBoolTrack::Reflect(AZ::SerializeContext* serializeContext)
  86. {
  87. TUiAnimTrack<IBoolKey>::Reflect(serializeContext);
  88. serializeContext->Class<UiBoolTrack, TUiAnimTrack<IBoolKey> >()
  89. ->Version(1)
  90. ;
  91. }