UiCanvasFileObject.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/RTTI/TypeInfo.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <LyShine/Bus/Tools/UiSystemToolsBus.h>
  12. #include <AzCore/Script/ScriptAsset.h>
  13. ////////////////////////////////////////////////////////////////////////////////////////////////////
  14. //! Wrapper class for canvas file. This allows us to make changes to what the top
  15. //! level objects are in the canvas file and do some conversion
  16. class UiCanvasFileObject
  17. : public UiSystemToolsInterface::CanvasAssetHandle
  18. {
  19. public:
  20. ~UiCanvasFileObject() override { }
  21. AZ_CLASS_ALLOCATOR(UiCanvasFileObject, AZ::SystemAllocator);
  22. AZ_RTTI(UiCanvasFileObject, "{1F02632F-F113-49B1-85AD-8CD0FA78B8AA}");
  23. // Load canvas from stream with an optional asset filter. No asset references are ignored by default
  24. static UiCanvasFileObject* LoadCanvasFromStream(AZ::IO::GenericStream& stream, const AZ::ObjectStream::FilterDescriptor& filterDesc = AZ::ObjectStream::FilterDescriptor());
  25. static void SaveCanvasToStream(AZ::IO::GenericStream& stream, UiCanvasFileObject* canvasFileObject);
  26. static AZ::Entity* LoadCanvasEntitiesFromStream(AZ::IO::GenericStream& stream, AZ::Entity*& rootSliceEntity);
  27. static void Reflect(AZ::ReflectContext* context);
  28. public: // data
  29. AZ::Entity* m_canvasEntity = nullptr;
  30. AZ::Entity* m_rootSliceEntity = nullptr;
  31. private: // static methods
  32. static UiCanvasFileObject* LoadCanvasEntitiesFromOldFormatFile(const char* buffer, size_t bufferSize, const AZ::ObjectStream::FilterDescriptor& filterDesc = AZ::ObjectStream::FilterDescriptor());
  33. static UiCanvasFileObject* LoadCanvasFromNewFormatStream(AZ::IO::GenericStream& stream, const AZ::ObjectStream::FilterDescriptor& filterDesc = AZ::ObjectStream::FilterDescriptor());
  34. static AZ::SerializeContext::DataElementNode* FindRootElementInCanvasEntity(
  35. AZ::SerializeContext& context,
  36. AZ::SerializeContext::DataElementNode& canvasEntityNode);
  37. static bool CreateRootSliceNodeAndCopyInEntities(
  38. AZ::SerializeContext& context,
  39. AZ::SerializeContext::DataElementNode& canvasFileObjectNode,
  40. AZStd::vector<AZ::SerializeContext::DataElementNode>& copiedEntities);
  41. static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
  42. };