UiAnimViewSequenceManager.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #pragma once
  9. #include "UiAnimViewSequence.h"
  10. #include <LyShine/Animation/IUiAnimation.h>
  11. #include "UiEditorAnimationBus.h"
  12. #include "UiAnimUndoManager.h"
  13. #include "CryCommon/StlUtils.h"
  14. #include <IEditor.h>
  15. struct IUiAnimViewSequenceManagerListener
  16. {
  17. virtual void OnSequenceAdded([[maybe_unused]] CUiAnimViewSequence* pSequence) {}
  18. virtual void OnSequenceRemoved([[maybe_unused]] CUiAnimViewSequence* pSequence) {}
  19. };
  20. class CUiAnimViewSequenceManager
  21. : public IEditorNotifyListener
  22. , public UiEditorAnimationBus::Handler
  23. {
  24. friend class CAbstractUndoSequenceTransaction;
  25. public:
  26. CUiAnimViewSequenceManager();
  27. ~CUiAnimViewSequenceManager();
  28. void OnEditorNotifyEvent(EEditorNotifyEvent event) override;
  29. unsigned int GetCount() const { return static_cast<unsigned int>(m_sequences.size()); }
  30. void CreateSequence(QString name);
  31. void DeleteSequence(CUiAnimViewSequence* pSequence);
  32. CUiAnimViewSequence* GetSequenceByName(QString name) const;
  33. CUiAnimViewSequence* GetSequenceByIndex(unsigned int index) const;
  34. CUiAnimViewSequence* GetSequenceByAnimSequence(IUiAnimSequence* pAnimSequence) const;
  35. CUiAnimViewAnimNodeBundle GetAllRelatedAnimNodes(const AZ::Entity* pEntityObject) const;
  36. CUiAnimViewAnimNode* GetActiveAnimNode(const AZ::Entity* pEntityObject) const;
  37. void AddListener(IUiAnimViewSequenceManagerListener* pListener) { stl::push_back_unique(m_listeners, pListener); }
  38. void RemoveListener(IUiAnimViewSequenceManagerListener* pListener) { stl::find_and_erase(m_listeners, pListener); }
  39. // UI_ANIMATION_REVISIT, made this a singleton for now
  40. static CUiAnimViewSequenceManager* GetSequenceManager();
  41. static void Create();
  42. static void Destroy();
  43. // UiEditorAnimationInterface
  44. CUiAnimationContext* GetAnimationContext() override;
  45. IUiAnimationSystem* GetAnimationSystem() override;
  46. CUiAnimViewSequence* GetCurrentSequence() override;
  47. void ActiveCanvasChanged() override;
  48. // ~UiEditorAnimationInterface
  49. private:
  50. void DeleteAllSequences();
  51. void CreateSequencesFromAnimationSystem();
  52. void SortSequences();
  53. void OnSequenceAdded(CUiAnimViewSequence* pSequence);
  54. void OnSequenceRemoved(CUiAnimViewSequence* pSequence);
  55. std::vector<IUiAnimViewSequenceManagerListener*> m_listeners;
  56. std::vector<std::unique_ptr<CUiAnimViewSequence> > m_sequences;
  57. uint32 m_nextSequenceId;
  58. // Used to handle object attach/detach
  59. std::unordered_map<CUiAnimViewNode*, Matrix34> m_prevTransforms;
  60. static CUiAnimViewSequenceManager* s_instance;
  61. IUiAnimationSystem* m_animationSystem;
  62. CUiAnimationContext* m_animationContext;
  63. UiAnimUndoManager m_undoManager;
  64. };