UiSliceManager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <AzToolsFramework/API/ToolsApplicationAPI.h>
  10. #include <AzCore/Slice/SliceComponent.h>
  11. #include <AzCore/Outcome/Outcome.h>
  12. #include <AzFramework/Asset/AssetCatalogBus.h>
  13. #include <AzFramework/Entity/EntityContext.h>
  14. #include "EditorCommon.h"
  15. #include "UiEditorEntityContextBus.h"
  16. class UiSliceManager
  17. : public UiEditorEntityContextNotificationBus::Handler
  18. {
  19. public: // member functions
  20. UiSliceManager(AzFramework::EntityContextId entityContextId);
  21. ~UiSliceManager() override;
  22. //////////////////////////////////////////////////////////////////////////
  23. // UiEditorEntityContextNotificationBus implementation
  24. void OnSliceInstantiationFailed(const AZ::Data::AssetId& sliceAssetId, const AzFramework::SliceInstantiationTicket& ticket) override;
  25. //~UiEditorEntityContextNotificationBus implementation
  26. //! Instantiate an existing slice asset into the UI canvas
  27. void InstantiateSlice(const AZ::Data::AssetId& assetId, AZ::Vector2 viewportPosition, int childIndex = -1);
  28. //! Instantiate an existing slice asset into the UI canvas using a file browser
  29. void InstantiateSliceUsingBrowser(HierarchyWidget* hierarchy, AZ::Vector2 viewportPosition);
  30. //! Create a new slice from the selected items and replace the selected items
  31. //! with an instance of the slice
  32. void MakeSliceFromSelectedItems(HierarchyWidget* hierarchy, bool inheritSlices);
  33. // Get the root slice for the canvas
  34. AZ::SliceComponent* GetRootSlice() const;
  35. //! Given a set of entities return a set that contains these entities plus all of their descendants
  36. AzToolsFramework::EntityIdSet GatherEntitiesAndAllDescendents(const AzToolsFramework::EntityIdList& inputEntities);
  37. //! Brings up the Push to Slice (advanced) dialog
  38. void PushEntitiesModal(const AzToolsFramework::EntityIdList& entities,
  39. AZ::SerializeContext* serializeContext = nullptr);
  40. //! Detach the given entities from the slice instance(s) that they are part of
  41. void DetachSliceEntities(const AzToolsFramework::EntityIdList& entities);
  42. //! Detach all entities in the slice instances that the give entities are part of from their slice instances
  43. void DetachSliceInstances(const AzToolsFramework::EntityIdList& entities);
  44. //! Returns true if the entity has a null parent pointer
  45. bool IsRootEntity(const AZ::Entity& entity) const;
  46. //! Set the entity context that this UI slice manager is operating on
  47. void SetEntityContextId(AzFramework::EntityContextId entityContextId);
  48. //! Get the entity context that this UI slice manager is operating on
  49. AzFramework::EntityContextId GetEntityContextId() const { return m_entityContextId; }
  50. //! Push the given entities back to the given slice asset (they must be part of an instance of that slice)
  51. //! No adds or removes are performed by this operation
  52. AZ::Outcome<void, AZStd::string> PushEntitiesBackToSlice(const AzToolsFramework::EntityIdList& entityIdList, const AZ::Data::Asset<AZ::SliceAsset>& sliceAsset);
  53. //! Push the given set of entities to the given slice instance (handles adds and removes).
  54. AZ::Outcome<void, AZStd::string> QuickPushSliceInstance(const AZ::SliceComponent::SliceInstanceAddress& sliceAddress,
  55. const AzToolsFramework::EntityIdList& entityIdList);
  56. private: // member functions
  57. static AZStd::string MakeTemporaryFilePathForSave(const char* targetFilename);
  58. void MakeSliceFromEntities(AzToolsFramework::EntityIdList& entities, bool inheritSlices);
  59. bool MakeNewSlice(const AzToolsFramework::EntityIdSet& entities,
  60. const char* targetDirectory,
  61. bool inheritSlices,
  62. AZ::SerializeContext* serializeContext = nullptr);
  63. void GetTopLevelEntities(const AZ::SliceComponent::EntityList& entities, AZ::SliceComponent::EntityList& topLevelEntities);
  64. //! Used in slice creation validation/preparation - checks single root for selected entities, generates
  65. //! ordered list of entities to use in slice
  66. AZ::Entity* ValidateSingleRootAndGenerateOrderedEntityList(const AzToolsFramework::EntityIdSet& liveEntities,
  67. AzToolsFramework::EntityIdList& outOrderedEntityList, AZ::Entity*& insertBefore);
  68. //! \return whether user confirmed detach, false if cancelled
  69. bool ConfirmDialog_Detach(const QString& title, const QString& text);
  70. private: // data
  71. AzFramework::EntityContextId m_entityContextId;
  72. };