LyShineSystemComponent.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <AzCore/Component/Component.h>
  10. #include <AzFramework/InGameUI/UiFrameworkBus.h>
  11. #include <LmbrCentral/Rendering/TextureAsset.h>
  12. #include <ILevelSystem.h>
  13. #include <LyShine/Bus/UiSystemBus.h>
  14. #include <LyShine/Bus/UiCanvasManagerBus.h>
  15. #include <LyShine/Bus/Tools/UiSystemToolsBus.h>
  16. #include <LyShine/UiComponentTypes.h>
  17. #include "LyShine.h"
  18. #if !defined(LYSHINE_BUILDER) && !defined(LYSHINE_TESTS)
  19. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  20. #endif
  21. namespace LyShine
  22. {
  23. class LyShineSystemComponent
  24. : public AZ::Component
  25. , protected UiSystemBus::Handler
  26. , protected UiSystemToolsBus::Handler
  27. , protected UiFrameworkBus::Handler
  28. , protected CrySystemEventBus::Handler
  29. , public ILevelSystemListener
  30. {
  31. public:
  32. AZ_COMPONENT(LyShineSystemComponent, lyShineSystemComponentUuid);
  33. static void Reflect(AZ::ReflectContext* context);
  34. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  35. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  36. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  37. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  38. static void SetLyShineComponentDescriptors(const AZStd::list<AZ::ComponentDescriptor*>* descriptors);
  39. LyShineSystemComponent();
  40. protected:
  41. ////////////////////////////////////////////////////////////////////////
  42. // AZ::Component interface implementation
  43. void Init() override;
  44. void Activate() override;
  45. void Deactivate() override;
  46. ////////////////////////////////////////////////////////////////////////
  47. ////////////////////////////////////////////////////////////////////////
  48. // UiSystemBus interface implementation
  49. void RegisterComponentTypeForMenuOrdering(const AZ::Uuid& typeUuid) override;
  50. const AZStd::vector<AZ::Uuid>* GetComponentTypesForMenuOrdering() override;
  51. const AZStd::list<AZ::ComponentDescriptor*>* GetLyShineComponentDescriptors() override;
  52. ////////////////////////////////////////////////////////////////////////
  53. ////////////////////////////////////////////////////////////////////////
  54. // UiSystemToolsInterface interface implementation
  55. CanvasAssetHandle* LoadCanvasFromStream(AZ::IO::GenericStream& stream, const AZ::ObjectStream::FilterDescriptor& filterDesc) override;
  56. void SaveCanvasToStream(CanvasAssetHandle* canvas, AZ::IO::FileIOStream& stream) override;
  57. AZ::SliceComponent* GetRootSliceSliceComponent(CanvasAssetHandle* canvas) override;
  58. AZ::Entity* GetRootSliceEntity(CanvasAssetHandle* canvas) override;
  59. AZ::Entity* GetCanvasEntity(CanvasAssetHandle* canvas) override;
  60. void ReplaceRootSliceSliceComponent(CanvasAssetHandle* canvas, AZ::SliceComponent* newSliceComponent) override;
  61. void ReplaceCanvasEntity(UiSystemToolsInterface::CanvasAssetHandle* canvas, AZ::Entity* newCanvasEntity) override;
  62. void DestroyCanvas(CanvasAssetHandle* canvas) override;
  63. ////////////////////////////////////////////////////////////////////////
  64. ////////////////////////////////////////////////////////////////////////
  65. // UiFrameworkInterface interface implementation
  66. bool HasUiElementComponent(AZ::Entity* entity) override;
  67. void AddEditorOnlyEntity(AZ::Entity* editorOnlyEntity, EntityIdSet& editorOnlyEntities) override;
  68. void HandleEditorOnlyEntities(const EntityList& exportSliceEntities, const EntityIdSet& editorOnlyEntityIds) override;
  69. ////////////////////////////////////////////////////////////////////////
  70. // CrySystemEventBus ///////////////////////////////////////////////////////
  71. void OnCrySystemInitialized(ISystem& system, const SSystemInitParams&) override;
  72. void OnCrySystemShutdown(ISystem&) override;
  73. ////////////////////////////////////////////////////////////////////////////
  74. ////////////////////////////////////////////////////////////////////////
  75. // ILevelSystemListener interface implementation
  76. void OnUnloadComplete(const char* levelName) override;
  77. void BroadcastCursorImagePathname();
  78. #if !defined(LYSHINE_BUILDER) && !defined(LYSHINE_TESTS)
  79. // Load pass template mappings for this gem
  80. void LoadPassTemplateMappings();
  81. #endif
  82. protected: // data
  83. AZStd::unique_ptr<ILyShine> m_lyShine;
  84. AzFramework::SimpleAssetReference<LmbrCentral::TextureAsset> m_cursorImagePathname;
  85. // The components types registers in order to control their order in the add component
  86. // menu and the properties pane - may go away soon
  87. AZStd::vector<AZ::Uuid> m_componentTypes;
  88. // We only store this in order to generate metrics on LyShine specific components
  89. static const AZStd::list<AZ::ComponentDescriptor*>* m_componentDescriptors;
  90. #if !defined(LYSHINE_BUILDER) && !defined(LYSHINE_TESTS)
  91. AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler m_loadTemplatesHandler;
  92. #endif
  93. };
  94. }