AnimSequence.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 : Implementation of IAnimSequence interface.
  9. #pragma once
  10. #include <LyShine/Animation/IUiAnimation.h>
  11. #include "TrackEventTrack.h"
  12. class CUiAnimSequence
  13. : public IUiAnimSequence
  14. {
  15. public:
  16. AZ_CLASS_ALLOCATOR(CUiAnimSequence, AZ::SystemAllocator)
  17. AZ_RTTI(CUiAnimSequence, "{AA5AB4ED-CB98-4166-953E-0FE1EF7AC61F}", IUiAnimSequence);
  18. CUiAnimSequence(); // required for serialization
  19. CUiAnimSequence(IUiAnimationSystem* pUiAnimationSystem, uint32 id);
  20. ~CUiAnimSequence();
  21. //////////////////////////////////////////////////////////////////////////
  22. // for intrusive_ptr support
  23. void add_ref() override;
  24. void release() override;
  25. //////////////////////////////////////////////////////////////////////////
  26. // Animation system.
  27. IUiAnimationSystem* GetUiAnimationSystem() const override { return m_pUiAnimationSystem; };
  28. void SetName(const char* name) override;
  29. const char* GetName() const override;
  30. uint32 GetId() const override { return m_id; }
  31. float GetTime() const { return m_time; }
  32. void SetOwner(IUiAnimSequenceOwner* pOwner) override { m_pOwner = pOwner; }
  33. IUiAnimSequenceOwner* GetOwner() const override { return m_pOwner; }
  34. void SetActiveDirector(IUiAnimNode* pDirectorNode) override;
  35. IUiAnimNode* GetActiveDirector() const override;
  36. void SetFlags(int flags) override;
  37. int GetFlags() const override;
  38. int GetCutSceneFlags(const bool localFlags = false) const override;
  39. void SetParentSequence(IUiAnimSequence* pParentSequence) override;
  40. const IUiAnimSequence* GetParentSequence() const override;
  41. bool IsAncestorOf(const IUiAnimSequence* pSequence) const override;
  42. void SetTimeRange(Range timeRange) override;
  43. Range GetTimeRange() override { return m_timeRange; };
  44. void AdjustKeysToTimeRange(const Range& timeRange) override;
  45. //! Return number of animation nodes in sequence.
  46. int GetNodeCount() const override;
  47. //! Get specified animation node.
  48. IUiAnimNode* GetNode(int index) const override;
  49. IUiAnimNode* FindNodeByName(const char* sNodeName, const IUiAnimNode* pParentDirector) override;
  50. IUiAnimNode* FindNodeById(int nNodeId);
  51. void ReorderNode(IUiAnimNode* node, IUiAnimNode* pPivotNode, bool next) override;
  52. void Reset(bool bSeekToStart) override;
  53. void ResetHard() override;
  54. void Pause() override;
  55. void Resume() override;
  56. bool IsPaused() const override;
  57. virtual void OnStart();
  58. virtual void OnStop();
  59. void OnLoop() override;
  60. //! Add animation node to sequence.
  61. bool AddNode(IUiAnimNode* node) override;
  62. IUiAnimNode* CreateNode(EUiAnimNodeType nodeType) override;
  63. IUiAnimNode* CreateNode(XmlNodeRef node) override;
  64. void RemoveNode(IUiAnimNode* node) override;
  65. //! Add scene node to sequence.
  66. void RemoveAll() override;
  67. void Activate() override;
  68. bool IsActivated() const override { return m_bActive; }
  69. void Deactivate() override;
  70. void PrecacheData(float startTime) override;
  71. void PrecacheStatic(const float startTime);
  72. void PrecacheDynamic(float time);
  73. void StillUpdate() override;
  74. void Animate(const SUiAnimContext& ec) override;
  75. void Render() override;
  76. void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks = true, uint32 overrideId = 0, bool bResetLightAnimSet = false) override;
  77. void InitPostLoad(IUiAnimationSystem* pUiAnimationSystem, bool remapIds, LyShine::EntityIdMap* entityIdMap) override;
  78. void CopyNodes(XmlNodeRef& xmlNode, IUiAnimNode** pSelectedNodes, uint32 count) override;
  79. void PasteNodes(const XmlNodeRef& xmlNode, IUiAnimNode* pParent) override;
  80. //! Add/remove track events in sequence
  81. bool AddTrackEvent(const char* szEvent) override;
  82. bool RemoveTrackEvent(const char* szEvent) override;
  83. bool RenameTrackEvent(const char* szEvent, const char* szNewEvent) override;
  84. bool MoveUpTrackEvent(const char* szEvent) override;
  85. bool MoveDownTrackEvent(const char* szEvent) override;
  86. void ClearTrackEvents() override;
  87. //! Get the track events in the sequence
  88. int GetTrackEventsCount() const override;
  89. char const* GetTrackEvent(int iIndex) const override;
  90. IUiAnimStringTable* GetTrackEventStringTable() override { return m_pEventStrings.get(); }
  91. //! Call to trigger a track event
  92. void TriggerTrackEvent(const char* event, const char* param = nullptr) override;
  93. //! Track event listener
  94. void AddTrackEventListener(IUiTrackEventListener* pListener) override;
  95. void RemoveTrackEventListener(IUiTrackEventListener* pListener) override;
  96. static void Reflect(AZ::SerializeContext* serializeContext);
  97. private:
  98. void ComputeTimeRange();
  99. void CopyNodeChildren(XmlNodeRef& xmlNode, IUiAnimNode* pAnimNode);
  100. void NotifyTrackEvent(IUiTrackEventListener::ETrackEventReason reason,
  101. const char* event, const char* param = nullptr);
  102. // Create a new animation node.
  103. IUiAnimNode* CreateNodeInternal(EUiAnimNodeType nodeType, uint32 nNodeId = -1);
  104. bool AddNodeNeedToRender(IUiAnimNode* pNode);
  105. void RemoveNodeNeedToRender(IUiAnimNode* pNode);
  106. int m_refCount;
  107. typedef AZStd::vector<AZStd::intrusive_ptr<IUiAnimNode>> AnimNodes;
  108. AnimNodes m_nodes;
  109. AnimNodes m_nodesNeedToRender;
  110. uint32 m_id;
  111. AZStd::string m_name;
  112. mutable AZStd::string m_fullNameHolder;
  113. Range m_timeRange;
  114. UiTrackEvents m_events;
  115. AZStd::intrusive_ptr<IUiAnimStringTable> m_pEventStrings;
  116. // Listeners
  117. typedef AZStd::list<IUiTrackEventListener*> TUiTrackEventListeners;
  118. TUiTrackEventListeners m_listeners;
  119. int m_flags;
  120. bool m_precached;
  121. bool m_bResetting;
  122. IUiAnimSequence* m_pParentSequence;
  123. IUiAnimationSystem* m_pUiAnimationSystem;
  124. bool m_bPaused;
  125. bool m_bActive;
  126. uint32 m_nextGenId;
  127. IUiAnimSequenceOwner* m_pOwner;
  128. IUiAnimNode* m_pActiveDirector;
  129. float m_time;
  130. };