AnimNode.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. // Description : Base of all Animation Nodes
  9. #pragma once
  10. #include <LyShine/Animation/IUiAnimation.h>
  11. #include "UiAnimationSystem.h"
  12. /*!
  13. Base class for all Animation nodes,
  14. can host multiple animation tracks, and execute them other time.
  15. Animation node is reference counted.
  16. */
  17. class CUiAnimNode
  18. : public IUiAnimNode
  19. {
  20. public:
  21. AZ_CLASS_ALLOCATOR(CUiAnimNode, AZ::SystemAllocator)
  22. AZ_RTTI(CUiAnimNode, "{1ECF3B73-FCED-464D-82E8-CFAF31BB63DC}", IUiAnimNode);
  23. struct SParamInfo
  24. {
  25. SParamInfo()
  26. : name("")
  27. , valueType(eUiAnimValue_Float)
  28. , flags(ESupportedParamFlags(0)) {};
  29. SParamInfo(const char* _name, CUiAnimParamType _paramType, EUiAnimValue _valueType, ESupportedParamFlags _flags)
  30. : name(_name)
  31. , paramType(_paramType)
  32. , valueType(_valueType)
  33. , flags(_flags) {};
  34. AZStd::string name; // parameter name.
  35. CUiAnimParamType paramType; // parameter id.
  36. EUiAnimValue valueType; // value type, defines type of track to use for animating this parameter.
  37. ESupportedParamFlags flags; // combination of flags from ESupportedParamFlags.
  38. };
  39. public:
  40. CUiAnimNode(const CUiAnimNode& other);
  41. CUiAnimNode(const int id, EUiAnimNodeType nodeType);
  42. CUiAnimNode();
  43. ~CUiAnimNode();
  44. EUiAnimNodeType GetType() const override { return m_nodeType; }
  45. //////////////////////////////////////////////////////////////////////////
  46. void add_ref() override;
  47. void release() override;
  48. //////////////////////////////////////////////////////////////////////////
  49. void SetName(const char* name) override { m_name = name; };
  50. AZStd::string GetName() override { return m_name; };
  51. void SetSequence(IUiAnimSequence* pSequence) override { m_pSequence = pSequence; }
  52. // Return Animation Sequence that owns this node.
  53. IUiAnimSequence* GetSequence() const override { return m_pSequence; };
  54. void SetFlags(int flags) override;
  55. int GetFlags() const override;
  56. IUiAnimationSystem* GetUiAnimationSystem() const override { return m_pSequence->GetUiAnimationSystem(); };
  57. virtual void OnStart() {}
  58. void OnReset() override {}
  59. virtual void OnResetHard() { OnReset(); }
  60. virtual void OnPause() {}
  61. virtual void OnResume() {}
  62. virtual void OnStop() {}
  63. virtual void OnLoop() {}
  64. virtual Matrix34 GetReferenceMatrix() const;
  65. //////////////////////////////////////////////////////////////////////////
  66. bool IsParamValid(const CUiAnimParamType& paramType) const override;
  67. AZStd::string GetParamName(const CUiAnimParamType& param) const override;
  68. EUiAnimValue GetParamValueType(const CUiAnimParamType& paramType) const override;
  69. IUiAnimNode::ESupportedParamFlags GetParamFlags(const CUiAnimParamType& paramType) const override;
  70. unsigned int GetParamCount() const override { return 0; };
  71. bool SetParamValue(float time, CUiAnimParamType param, float val) override;
  72. bool SetParamValue(float time, CUiAnimParamType param, const Vec3& val) override;
  73. bool SetParamValue(float time, CUiAnimParamType param, const Vec4& val) override;
  74. bool GetParamValue(float time, CUiAnimParamType param, float& val) override;
  75. bool GetParamValue(float time, CUiAnimParamType param, Vec3& val) override;
  76. bool GetParamValue(float time, CUiAnimParamType param, Vec4& val) override;
  77. void SetTarget([[maybe_unused]] IUiAnimNode* node) {};
  78. IUiAnimNode* GetTarget() const { return 0; };
  79. void StillUpdate() override {}
  80. void Animate(SUiAnimContext& ec) override;
  81. virtual void PrecacheStatic([[maybe_unused]] float startTime) {}
  82. virtual void PrecacheDynamic([[maybe_unused]] float time) {}
  83. void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  84. void SerializeUiAnims(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  85. void SetNodeOwner(IUiAnimNodeOwner* pOwner) override;
  86. IUiAnimNodeOwner* GetNodeOwner() override { return m_pOwner; };
  87. // Called by sequence when needs to activate a node.
  88. void Activate(bool bActivate) override;
  89. //////////////////////////////////////////////////////////////////////////
  90. void SetParent(IUiAnimNode* pParent) override;
  91. IUiAnimNode* GetParent() const override { return m_pParentNode; };
  92. IUiAnimNode* HasDirectorAsParent() const override;
  93. //////////////////////////////////////////////////////////////////////////
  94. void UpdateDynamicParams() override {};
  95. //////////////////////////////////////////////////////////////////////////
  96. // Track functions.
  97. //////////////////////////////////////////////////////////////////////////
  98. int GetTrackCount() const override;
  99. IUiAnimTrack* GetTrackByIndex(int nIndex) const override;
  100. IUiAnimTrack* GetTrackForParameter(const CUiAnimParamType& paramType) const override;
  101. IUiAnimTrack* GetTrackForParameter(const CUiAnimParamType& paramType, uint32 index) const override;
  102. uint32 GetTrackParamIndex(const IUiAnimTrack* track) const override;
  103. IUiAnimTrack* GetTrackForAzField([[maybe_unused]] const UiAnimParamData& param) const override { return nullptr; }
  104. IUiAnimTrack* CreateTrackForAzField([[maybe_unused]] const UiAnimParamData& param) override { return nullptr; }
  105. void SetTrack(const CUiAnimParamType& paramType, IUiAnimTrack* track) override;
  106. IUiAnimTrack* CreateTrack(const CUiAnimParamType& paramType) override;
  107. void SetTimeRange(Range timeRange) override;
  108. void AddTrack(IUiAnimTrack* track) override;
  109. bool RemoveTrack(IUiAnimTrack* track) override;
  110. void CreateDefaultTracks() override {};
  111. //////////////////////////////////////////////////////////////////////////
  112. void InitPostLoad(IUiAnimSequence* pSequence, bool remapIds, LyShine::EntityIdMap* entityIdMap) override;
  113. virtual void PostLoad();
  114. int GetId() const { return m_id; }
  115. void SetId(int id) { m_id = id; }
  116. const char* GetNameFast() const { return m_name.c_str(); }
  117. void Render() override{}
  118. static void Reflect(AZ::SerializeContext* serializeContext);
  119. protected:
  120. virtual bool GetParamInfoFromType([[maybe_unused]] const CUiAnimParamType& paramType, [[maybe_unused]] SParamInfo& info) const { return false; };
  121. int NumTracks() const { return (int)m_tracks.size(); }
  122. IUiAnimTrack* CreateTrackInternal(const CUiAnimParamType& paramType, EUiAnimCurveType trackType, EUiAnimValue valueType);
  123. IUiAnimTrack* CreateTrackInternalVector2(const CUiAnimParamType& paramType) const;
  124. IUiAnimTrack* CreateTrackInternalVector3(const CUiAnimParamType& paramType) const;
  125. IUiAnimTrack* CreateTrackInternalVector4(const CUiAnimParamType& paramType) const;
  126. IUiAnimTrack* CreateTrackInternalQuat(EUiAnimCurveType trackType, const CUiAnimParamType& paramType) const;
  127. IUiAnimTrack* CreateTrackInternalVector(EUiAnimCurveType trackType, const CUiAnimParamType& paramType, const EUiAnimValue animValue) const;
  128. IUiAnimTrack* CreateTrackInternalFloat(int trackType) const;
  129. UiAnimationSystem* GetUiAnimationSystemImpl() const { return (UiAnimationSystem*)GetUiAnimationSystem(); }
  130. // sets track animNode pointer to this node and sorts tracks
  131. void RegisterTrack(IUiAnimTrack* track);
  132. bool NeedToRender() const override { return false; }
  133. protected:
  134. int m_refCount;
  135. EUiAnimNodeType m_nodeType;
  136. int m_id;
  137. AZStd::string m_name;
  138. IUiAnimSequence* m_pSequence;
  139. IUiAnimNodeOwner* m_pOwner;
  140. IUiAnimNode* m_pParentNode;
  141. int m_parentNodeId;
  142. int m_nLoadedParentNodeId; // only used by old serialize
  143. int m_flags;
  144. unsigned int m_bIgnoreSetParam : 1; // Internal flags.
  145. typedef AZStd::vector<AZStd::intrusive_ptr<IUiAnimTrack>> AnimTracks;
  146. AnimTracks m_tracks;
  147. private:
  148. void SortTracks();
  149. static bool TrackOrder(const AZStd::intrusive_ptr<IUiAnimTrack>& left, const AZStd::intrusive_ptr<IUiAnimTrack>& right);
  150. };
  151. //////////////////////////////////////////////////////////////////////////
  152. class CUiAnimNodeGroup
  153. : public CUiAnimNode
  154. {
  155. public:
  156. CUiAnimNodeGroup(const int id)
  157. : CUiAnimNode(id, eUiAnimNodeType_Group) { SetFlags(GetFlags() | eUiAnimNodeFlags_CanChangeName); }
  158. EUiAnimNodeType GetType() const override { return eUiAnimNodeType_Group; }
  159. CUiAnimParamType GetParamType([[maybe_unused]] unsigned int nIndex) const override { return eUiAnimParamType_Invalid; }
  160. };