diff --git a/Code/Legacy/CryCommon/LyShine/Bus/UiCanvasBus.h b/Code/Legacy/CryCommon/LyShine/Bus/UiCanvasBus.h index 894f97c9fe..744cb19a12 100644 --- a/Code/Legacy/CryCommon/LyShine/Bus/UiCanvasBus.h +++ b/Code/Legacy/CryCommon/LyShine/Bus/UiCanvasBus.h @@ -20,14 +20,6 @@ struct IUiAnimationSystem; class UiCanvasInterface : public AZ::ComponentBus { -public: // types - - enum class ErrorCode - { - NoError, - PrefabContainsExternalEntityRefs - }; - public: // member functions //! Deleting a canvas will delete all its child elements recursively and all of their components @@ -110,23 +102,6 @@ public: // member functions //! \return true if no error virtual bool SaveToXml(const string& assetIdPathname, const string& sourceAssetPathname) = 0; - //! Save the given UI element entity to the given path as a prefab - //! \param pathname the path to save the prefab to - //! \param entity pointer to the entity to save as a prefab - //! \return true if no error - virtual bool SaveAsPrefab(const string& pathname, AZ::Entity* entity) = 0; - - //! Check if it is OK to save the given UI element entity to the given path as a prefab - //! \param entity pointer to the entity to save as a prefab - //! \return errorCode which is NoError if OK to save - virtual ErrorCode CheckElementValidToSaveAsPrefab(AZ::Entity* entity) = 0; - - //! Load a prefab element from the given file and optionally insert as child of given entity - //! \return the top level entity created - virtual AZ::Entity* LoadFromPrefab(const string& pathname, - bool makeUniqueName, - AZ::Entity* optionalInsertionPoint) = 0; - //! Initialize a set of entities that have been added to the canvas //! Used when instantiating a slice or for undo/redo, copy/paste //! \param topLevelEntities - The elements that were created diff --git a/Gems/LyShine/Code/Editor/EditorCommon.h b/Gems/LyShine/Code/Editor/EditorCommon.h index 04dc03f8a0..f6b9dc1458 100644 --- a/Gems/LyShine/Code/Editor/EditorCommon.h +++ b/Gems/LyShine/Code/Editor/EditorCommon.h @@ -112,7 +112,6 @@ enum class FusibleCommand #include "FileHelpers.h" #include "ComponentHelpers.h" #include "HierarchyHelpers.h" -#include "PrefabHelpers.h" #include "UiSliceManager.h" #include "SelectionHelpers.h" #include "ViewportInteraction.h" @@ -173,8 +172,6 @@ bool ClipboardContainsOurDataType(); #define UICANVASEDITOR_COORDINATE_SYSTEM_CYCLE_SHORTCUT_KEY_SEQUENCE QKeySequence(Qt::CTRL + Qt::Key_W) #define UICANVASEDITOR_SNAP_TO_GRID_TOGGLE_SHORTCUT_KEY_SEQUENCE QKeySequence(Qt::Key_G) -#define UICANVASEDITOR_PREFAB_EXTENSION "uiprefab" - #define UICANVASEDITOR_CANVAS_DIRECTORY "UI/Canvases" #define UICANVASEDITOR_CANVAS_EXTENSION "uicanvas" diff --git a/Gems/LyShine/Code/Editor/EditorMenu.cpp b/Gems/LyShine/Code/Editor/EditorMenu.cpp index 039ed7f3ca..ec56c316ee 100644 --- a/Gems/LyShine/Code/Editor/EditorMenu.cpp +++ b/Gems/LyShine/Code/Editor/EditorMenu.cpp @@ -146,19 +146,6 @@ void EditorWindow::AddMenu_File() menu->addSeparator(); - // "Save as Prefab..." file menu option - { - HierarchyWidget* widget = GetHierarchy(); - QAction* action = PrefabHelpers::CreateSavePrefabAction(widget); - action->setEnabled(canvasLoaded); - - // This menu option is always available to the user - menu->addAction(action); - addAction(action); // Also add the action to the window until the shortcut dispatcher can find the menu action - } - - menu->addSeparator(); - // Close the active canvas { QAction* action = CreateCloseCanvasAction(GetCanvas()); diff --git a/Gems/LyShine/Code/Editor/EditorWindow.cpp b/Gems/LyShine/Code/Editor/EditorWindow.cpp index 0edc1e6151..7db6de5fc4 100644 --- a/Gems/LyShine/Code/Editor/EditorWindow.cpp +++ b/Gems/LyShine/Code/Editor/EditorWindow.cpp @@ -128,7 +128,6 @@ EditorWindow::EditorWindow(QWidget* parent, Qt::WindowFlags flags) , m_previewActionLogDockWidget(nullptr) , m_previewAnimationListDockWidget(nullptr) , m_editorMode(UiEditorMode::Edit) - , m_prefabFiles() , m_actionsEnabledWithSelection() , m_pasteAsSiblingAction(nullptr) , m_pasteAsChildAction(nullptr) @@ -160,8 +159,6 @@ EditorWindow::EditorWindow(QWidget* parent, Qt::WindowFlags flags) connect(m_hierarchy, &HierarchyWidget::SetUserSelection, this, &EditorWindow::UpdateActionsEnabledState); m_clipboardConnection = connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &EditorWindow::UpdateActionsEnabledState); - UpdatePrefabFiles(); - // Create the cursor to be used when picking an element in the hierarchy or viewport during object pick mode. // Uses the default hot spot which is the center of the image m_entityPickerCursor = QCursor(QPixmap(UICANVASEDITOR_ENTITY_PICKER_CURSOR)); @@ -1551,46 +1548,6 @@ AssetTreeEntry* EditorWindow::GetSliceLibraryTree() return m_sliceLibraryTree; } -void EditorWindow::UpdatePrefabFiles() -{ - m_prefabFiles.clear(); - - // IMPORTANT: ScanDirectory() is VERY slow. It can easily take as much - // as a whole second to execute. That's why we want to cache its result - // up front and ONLY access the cached data. - GetIEditor()->GetFileUtil()->ScanDirectory("", "*." UICANVASEDITOR_PREFAB_EXTENSION, m_prefabFiles); - SortPrefabsList(); -} - -IFileUtil::FileArray& EditorWindow::GetPrefabFiles() -{ - return m_prefabFiles; -} - -void EditorWindow::AddPrefabFile(const QString& prefabFilename) -{ - IFileUtil::FileDesc fd; - fd.filename = prefabFilename; - m_prefabFiles.push_back(fd); - SortPrefabsList(); -} - -void EditorWindow::SortPrefabsList() -{ - AZStd::sort(m_prefabFiles.begin(), m_prefabFiles.end(), - [](const IFileUtil::FileDesc& fd1, const IFileUtil::FileDesc& fd2) - { - // Some of the files in the list are in different directories, so we - // explicitly sort by filename only. - AZStd::string fd1Filename; - AzFramework::StringFunc::Path::GetFileName(fd1.filename.toUtf8().data(), fd1Filename); - - AZStd::string fd2Filename; - AzFramework::StringFunc::Path::GetFileName(fd2.filename.toUtf8().data(), fd2Filename); - return fd1Filename < fd2Filename; - }); -} - void EditorWindow::ToggleEditorMode() { m_editorMode = (m_editorMode == UiEditorMode::Edit) ? UiEditorMode::Preview : UiEditorMode::Edit; diff --git a/Gems/LyShine/Code/Editor/EditorWindow.h b/Gems/LyShine/Code/Editor/EditorWindow.h index 0f2dd39210..b00ae7ab95 100644 --- a/Gems/LyShine/Code/Editor/EditorWindow.h +++ b/Gems/LyShine/Code/Editor/EditorWindow.h @@ -139,11 +139,6 @@ public: // member functions AssetTreeEntry* GetSliceLibraryTree(); - //! WARNING: This is a VERY slow function. - void UpdatePrefabFiles(); - IFileUtil::FileArray& GetPrefabFiles(); - void AddPrefabFile(const QString& prefabFilename); - //! Returns the current mode of the editor (Edit or Preview) UiEditorMode GetEditorMode() { return m_editorMode; } @@ -325,8 +320,6 @@ private: // member functions QAction* CreateCloseAllOtherCanvasesAction(AZ::EntityId canvasEntityId, bool forContextMenu = false); QAction* CreateCloseAllCanvasesAction(bool forContextMenu = false); - void SortPrefabsList(); - void SaveModeSettings(UiEditorMode mode, bool syncSettings); void RestoreModeSettings(UiEditorMode mode); @@ -391,8 +384,6 @@ private: // data //! This tree caches the folder view of all the slice assets under the slice library path AssetTreeEntry* m_sliceLibraryTree = nullptr; - IFileUtil::FileArray m_prefabFiles; - //! Values for setting up undoable canvas/entity changes SerializeHelpers::SerializedEntryList m_preChangeState; bool m_haveValidEntitiesPreChangeState = false; diff --git a/Gems/LyShine/Code/Editor/HierarchyMenu.cpp b/Gems/LyShine/Code/Editor/HierarchyMenu.cpp index 3758041f7a..72868dccdb 100644 --- a/Gems/LyShine/Code/Editor/HierarchyMenu.cpp +++ b/Gems/LyShine/Code/Editor/HierarchyMenu.cpp @@ -26,8 +26,7 @@ HierarchyMenu::HierarchyMenu(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList selectedItems = hierarchy->selectedItems(); - if (showMask & (Show::kNew_EmptyElement | Show::kNew_ElementFromPrefabs | - Show::kNew_EmptyElementAtRoot | Show::kNew_ElementFromPrefabsAtRoot)) + if (showMask & (Show::kNew_EmptyElement | Show::kNew_EmptyElementAtRoot)) { QMenu* menu = (addMenuForNewElement ? addMenu("&New...") : this); @@ -40,11 +39,6 @@ HierarchyMenu::HierarchyMenu(HierarchyWidget* hierarchy, { New_ElementFromSlice(hierarchy, selectedItems, menu, (showMask & Show::kNew_InstantiateSliceAtRoot), optionalPos); } - - if (showMask & (Show::kNew_ElementFromPrefabs | Show::kNew_ElementFromPrefabsAtRoot)) - { - New_ElementFromPrefabs(hierarchy, selectedItems, menu, (showMask & Show::kNew_ElementFromPrefabsAtRoot), optionalPos); - } } if (showMask & (Show::kNewSlice | Show::kPushToSlice)) @@ -52,11 +46,6 @@ HierarchyMenu::HierarchyMenu(HierarchyWidget* hierarchy, SliceMenuItems(hierarchy, selectedItems, showMask); } - if (showMask & Show::kSavePrefab) - { - SavePrefab(hierarchy, selectedItems); - } - addSeparator(); if (showMask & Show::kCutCopyPaste) @@ -192,21 +181,6 @@ void HierarchyMenu::CutCopyPaste(HierarchyWidget* hierarchy, } } -void HierarchyMenu::SavePrefab(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems) -{ - QAction* action = PrefabHelpers::CreateSavePrefabAction(hierarchy); - - // Only enable "save as prefab" option if exactly one element is selected - // in the hierarchy pane - if (selectedItems.size() != 1) - { - action->setEnabled(false); - } - - addAction(action); -} - void HierarchyMenu::SliceMenuItems(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList& selectedItems, size_t showMask) @@ -404,19 +378,6 @@ void HierarchyMenu::New_EmptyElement(HierarchyWidget* hierarchy, optionalPos)); } -void HierarchyMenu::New_ElementFromPrefabs(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems, - QMenu* menu, - bool addAtRoot, - const QPoint* optionalPos) -{ - PrefabHelpers::CreateAddPrefabMenu(hierarchy, - selectedItems, - menu, - addAtRoot, - optionalPos); -} - void HierarchyMenu::New_ElementFromSlice(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList& selectedItems, QMenu* menu, diff --git a/Gems/LyShine/Code/Editor/HierarchyMenu.h b/Gems/LyShine/Code/Editor/HierarchyMenu.h index 69432a4d24..9d73c083f9 100644 --- a/Gems/LyShine/Code/Editor/HierarchyMenu.h +++ b/Gems/LyShine/Code/Editor/HierarchyMenu.h @@ -26,11 +26,8 @@ public: kNone = 0x0000, kCutCopyPaste = 0x0001, - kSavePrefab = 0x0002, kNew_EmptyElement = 0x0004, kNew_EmptyElementAtRoot = 0x0008, - kNew_ElementFromPrefabs = 0x0010, - kNew_ElementFromPrefabsAtRoot = 0x0020, kAddComponents = 0x0040, kDeleteElement = 0x0080, kNewSlice = 0x0100, @@ -52,9 +49,6 @@ private: void CutCopyPaste(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList& selectedItems); - void SavePrefab(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems); - void SliceMenuItems(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList& selectedItems, size_t showMask); @@ -64,11 +58,6 @@ private: QMenu* menu, bool addAtRoot, const QPoint* optionalPos); - void New_ElementFromPrefabs(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems, - QMenu* menu, - bool addAtRoot, - const QPoint* optionalPos); void New_ElementFromSlice(HierarchyWidget* hierarchy, QTreeWidgetItemRawPtrQList& selectedItems, QMenu* menu, diff --git a/Gems/LyShine/Code/Editor/HierarchyWidget.cpp b/Gems/LyShine/Code/Editor/HierarchyWidget.cpp index 9b72f2407f..e5d39282b2 100644 --- a/Gems/LyShine/Code/Editor/HierarchyWidget.cpp +++ b/Gems/LyShine/Code/Editor/HierarchyWidget.cpp @@ -235,9 +235,7 @@ void HierarchyWidget::contextMenuEvent(QContextMenuEvent* ev) { HierarchyMenu contextMenu(this, (HierarchyMenu::Show::kCutCopyPaste | - HierarchyMenu::Show::kSavePrefab | HierarchyMenu::Show::kNew_EmptyElement | - HierarchyMenu::Show::kNew_ElementFromPrefabs | HierarchyMenu::Show::kDeleteElement | HierarchyMenu::Show::kNewSlice | HierarchyMenu::Show::kNew_InstantiateSlice | diff --git a/Gems/LyShine/Code/Editor/NewElementToolbarSection.cpp b/Gems/LyShine/Code/Editor/NewElementToolbarSection.cpp index c8de5afb11..d9342fe412 100644 --- a/Gems/LyShine/Code/Editor/NewElementToolbarSection.cpp +++ b/Gems/LyShine/Code/Editor/NewElementToolbarSection.cpp @@ -21,7 +21,6 @@ NewElementToolbarSection::NewElementToolbarSection(QToolBar* parent, bool addSep { HierarchyMenu contextMenu(editorWindow->GetHierarchy(), (HierarchyMenu::Show::kNew_EmptyElementAtRoot | - HierarchyMenu::Show::kNew_ElementFromPrefabsAtRoot | HierarchyMenu::Show::kNew_InstantiateSliceAtRoot), false); diff --git a/Gems/LyShine/Code/Editor/PrefabHelpers.cpp b/Gems/LyShine/Code/Editor/PrefabHelpers.cpp deleted file mode 100644 index c6f81dd56e..0000000000 --- a/Gems/LyShine/Code/Editor/PrefabHelpers.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ -#include "UiCanvasEditor_precompiled.h" - -#include "EditorCommon.h" -#include "AzFramework/StringFunc/StringFunc.h" -#include "Util/PathUtil.h" - -#include -#include - -namespace PrefabHelpers -{ - QAction* CreateSavePrefabAction(HierarchyWidget* hierarchy) - { - QAction* action = new QAction("(Deprecated) Save as Prefab...", hierarchy); - QObject::connect(action, - &QAction::triggered, - hierarchy, - [ hierarchy ]([[maybe_unused]] bool checked) - { - // Note that selectedItems() can be expensive, so call it once and save the value. - QTreeWidgetItemRawPtrQList selectedItems(hierarchy->selectedItems()); - if (selectedItems.isEmpty()) - { - QMessageBox(QMessageBox::Information, - "Selection Needed", - "Please select an element in the Hierarchy pane", - QMessageBox::Ok, hierarchy->GetEditorWindow()).exec(); - - return; - } - else if (selectedItems.size() > 1) - { - QMessageBox(QMessageBox::Information, - "Too Many Items Selected", - "Please select only one element in the Hierarchy pane", - QMessageBox::Ok, hierarchy->GetEditorWindow()).exec(); - - return; - } - - QString selectedFile = QFileDialog::getSaveFileName(nullptr, - QString(), - FileHelpers::GetAbsoluteGameDir(), - "*." UICANVASEDITOR_PREFAB_EXTENSION, - nullptr, - QFileDialog::DontConfirmOverwrite); - if (selectedFile.isEmpty()) - { - // Nothing to do. - return; - } - - FileHelpers::AppendExtensionIfNotPresent(selectedFile, UICANVASEDITOR_PREFAB_EXTENSION); - - AZ::EntityId canvasEntityId = hierarchy->GetEditorWindow()->GetCanvas(); - - // We've already checked if selectedItems is empty, so calling front() should be fine here - HierarchyItem* hierarchyItem = HierarchyItem::RttiCast(selectedItems.front()); - AZ::Entity* element = hierarchyItem->GetElement(); - - // Check if this element is OK to save as a prefab - UiCanvasInterface::ErrorCode errorCode = UiCanvasInterface::ErrorCode::NoError; - EBUS_EVENT_ID_RESULT(errorCode, canvasEntityId, UiCanvasBus, CheckElementValidToSaveAsPrefab, - element); - - if (errorCode != UiCanvasInterface::ErrorCode::NoError) - { - if (errorCode == UiCanvasInterface::ErrorCode::PrefabContainsExternalEntityRefs) - { - QMessageBox box(QMessageBox::Question, - "External references", - "The selected element contains references to elements that will not be in the prefab.\n" - "If saved these references will be cleared in the prefab.\n\n" - "Do you wish to save as prefab anyway?", - (QMessageBox::Yes | QMessageBox::No), hierarchy->GetEditorWindow()); - box.setDefaultButton(QMessageBox::No); - - int result = box.exec(); - if (result == QMessageBox::No) - { - return; - } - } - else - { - // this should never happen, but will if we forget to update this code when a new error is - // added - QMessageBox(QMessageBox::Information, - "Cannot save as prefab", - "Unknown error", - QMessageBox::Ok, hierarchy->GetEditorWindow()).exec(); - return; - } - } - - FileHelpers::SourceControlAddOrEdit(selectedFile.toStdString().c_str(), hierarchy->GetEditorWindow()); - - bool saveSuccessful = false; - EBUS_EVENT_ID_RESULT(saveSuccessful, canvasEntityId, UiCanvasBus, SaveAsPrefab, - selectedFile.toStdString().c_str(), element); - - // Refresh the menu to update "Add prefab...". - if (saveSuccessful) - { - QString gamePath(Path::FullPathToGamePath(selectedFile)); - hierarchy->GetEditorWindow()->AddPrefabFile(gamePath); - - return; - } - - QMessageBox(QMessageBox::Critical, - "Error", - "Unable to save file. Is the file read-only?", - QMessageBox::Ok, hierarchy->GetEditorWindow()).exec(); - }); - - return action; - } - - void CreateAddPrefabMenu(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems, - QMenu* parent, - bool addAtRoot, - const QPoint* optionalPos) - { - // Find all the prefabs in the project directory and in any enabled Gems - IFileUtil::FileArray& files = hierarchy->GetEditorWindow()->GetPrefabFiles(); - if (files.empty()) - { - // Since this feature is deprecated we don't show the menu unles there are prefabs - return; - } - - QMenu* prefabMenu = parent->addMenu(QString("(Deprecated) Element%1 from prefab").arg(!addAtRoot && selectedItems.size() > 1 ? "s" : "")); - - QList result; - { - for (auto file : files) - { - // Get the filepath from the engine root directory - QString fullFileName = Path::GamePathToFullPath(file.filename); - QString filepath(fullFileName); - - // Extract the filename without its extension, get it from fullFileName rather than - // file.filename because the former preserves case - AZStd::string filename; - AzFramework::StringFunc::Path::GetFileName(fullFileName.toUtf8().data(), filename); - - QAction* action = new QAction(filename.c_str(), prefabMenu); - QObject::connect(action, - &QAction::triggered, - hierarchy, - [filepath, hierarchy, addAtRoot, optionalPos]([[maybe_unused]] bool checked) - { - if (addAtRoot) - { - hierarchy->clearSelection(); - } - - CommandHierarchyItemCreateFromData::Push(hierarchy->GetEditorWindow()->GetActiveStack(), - hierarchy, - hierarchy->selectedItems(), - true, - [hierarchy, filepath, optionalPos](HierarchyItem* parent, - LyShine::EntityArray& listOfNewlyCreatedTopLevelElements) - { - AZ::Entity* newEntity = nullptr; - EBUS_EVENT_ID_RESULT(newEntity, - hierarchy->GetEditorWindow()->GetCanvas(), - UiCanvasBus, - LoadFromPrefab, - filepath.toStdString().c_str(), - true, - (parent ? parent->GetElement() : nullptr)); - if (newEntity) - { - if (optionalPos) - { - EntityHelpers::MoveElementToGlobalPosition(newEntity, *optionalPos); - } - - listOfNewlyCreatedTopLevelElements.push_back(newEntity); - } - }, - "Prefab"); - }); - result.push_back(action); - } - } - - prefabMenu->addActions(result); - } -} // namespace PrefabHelpers diff --git a/Gems/LyShine/Code/Editor/PrefabHelpers.h b/Gems/LyShine/Code/Editor/PrefabHelpers.h deleted file mode 100644 index 5d39513715..0000000000 --- a/Gems/LyShine/Code/Editor/PrefabHelpers.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ -#pragma once - -namespace PrefabHelpers -{ - QAction* CreateSavePrefabAction(HierarchyWidget* hierarchy); - - void CreateAddPrefabMenu(HierarchyWidget* hierarchy, - QTreeWidgetItemRawPtrQList& selectedItems, - QMenu* parent, - bool addAtRoot, - const QPoint* optionalPos); -} // namespace PrefabHelpers diff --git a/Gems/LyShine/Code/Editor/ViewportWidget.cpp b/Gems/LyShine/Code/Editor/ViewportWidget.cpp index fd1374f31a..af0f93d8fa 100644 --- a/Gems/LyShine/Code/Editor/ViewportWidget.cpp +++ b/Gems/LyShine/Code/Editor/ViewportWidget.cpp @@ -428,9 +428,7 @@ void ViewportWidget::contextMenuEvent(QContextMenuEvent* e) const QPoint pos = e->pos(); HierarchyMenu contextMenu(m_editorWindow->GetHierarchy(), HierarchyMenu::Show::kCutCopyPaste | - HierarchyMenu::Show::kSavePrefab | HierarchyMenu::Show::kNew_EmptyElement | - HierarchyMenu::Show::kNew_ElementFromPrefabs | HierarchyMenu::Show::kDeleteElement | HierarchyMenu::Show::kNewSlice | HierarchyMenu::Show::kNew_InstantiateSlice | diff --git a/Gems/LyShine/Code/Source/UiCanvasComponent.cpp b/Gems/LyShine/Code/Source/UiCanvasComponent.cpp index b678089cb4..1978aa8909 100644 --- a/Gems/LyShine/Code/Source/UiCanvasComponent.cpp +++ b/Gems/LyShine/Code/Source/UiCanvasComponent.cpp @@ -590,174 +590,6 @@ bool UiCanvasComponent::SaveToXml(const string& assetIdPathname, const string& s return result; } -//////////////////////////////////////////////////////////////////////////////////////////////////// -UiCanvasInterface::ErrorCode UiCanvasComponent::CheckElementValidToSaveAsPrefab(AZ::Entity* entity) -{ - AZ_Assert(entity, "null entity ptr passed to SaveAsPrefab"); - - // Check that none of the EntityId's in this entity or its children reference entities that - // are not part of the prefab. - // First make a list of all entityIds that will be in the prefab - AZStd::vector entitiesInPrefab = GetEntityIdsOfElementAndDescendants(entity); - - // Next check all entity refs in the element to see if any are externel - // We use ReplaceEntityRefs even though we don't want to change anything - bool foundRefOutsidePrefab = false; - AZ::SerializeContext* context = nullptr; - EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext); - AZ_Assert(context, "No serialization context found"); - AZ::EntityUtils::ReplaceEntityRefs(entity, [&](const AZ::EntityId& key, bool /*isEntityId*/) -> AZ::EntityId - { - if (key.IsValid()) - { - auto iter = AZStd::find(entitiesInPrefab.begin(), entitiesInPrefab.end(), key); - if (iter == entitiesInPrefab.end()) - { - foundRefOutsidePrefab = true; - } - } - return key; // always leave key unchanged - }, context); - - if (foundRefOutsidePrefab) - { - return UiCanvasInterface::ErrorCode::PrefabContainsExternalEntityRefs; - } - - return UiCanvasInterface::ErrorCode::NoError; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -bool UiCanvasComponent::SaveAsPrefab(const string& pathname, AZ::Entity* entity) -{ - AZ_Assert(entity, "null entity ptr passed to SaveAsPrefab"); - - AZ::SerializeContext* context = nullptr; - EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext); - AZ_Assert(context, "No serialization context found"); - - // To be sure that we do not save an invalid prefab, if this entity contains entity references - // outside of the prefab set them to invalid references - // First make a list of all entityIds that will be in the prefab - AZStd::vector entitiesInPrefab = GetEntityIdsOfElementAndDescendants(entity); - - // Next make a serializable object containing all the entities to save (in order to check for invalid refs) - AZ::SliceComponent::InstantiatedContainer sourceObjects(false); - for (const AZ::EntityId& id : entitiesInPrefab) - { - AZ::Entity* sourceEntity = nullptr; - EBUS_EVENT_RESULT(sourceEntity, AZ::ComponentApplicationBus, FindEntity, id); - if (sourceEntity) - { - sourceObjects.m_entities.push_back(sourceEntity); - } - } - - // clone all the objects in order to replace external references - AZ::SliceComponent::InstantiatedContainer* clonedObjects = context->CloneObject(&sourceObjects); - AZ::Entity* clonedRootEntity = clonedObjects->m_entities[0]; - - // use ReplaceEntityRefs to replace external references with invalid IDs - // Note that we are not generating new IDs so we do not need to fixup internal references - AZ::EntityUtils::ReplaceEntityRefs(clonedObjects, [&](const AZ::EntityId& key, bool /*isEntityId*/) -> AZ::EntityId - { - if (key.IsValid()) - { - auto iter = AZStd::find(entitiesInPrefab.begin(), entitiesInPrefab.end(), key); - if (iter == entitiesInPrefab.end()) - { - return AZ::EntityId(); - } - } - return key; // leave key unchanged - }, context); - - // make a wrapper object around the prefab entity so that we have an opportunity to change what - // is in a prefab file in future. - UiSerialize::PrefabFileObject fileObject; - fileObject.m_rootEntityId = clonedRootEntity->GetId(); - - // add all of the entities that are not the root entity to a childEntities list - for (auto descendant : clonedObjects->m_entities) - { - fileObject.m_entities.push_back(descendant); - } - - bool result = AZ::Utils::SaveObjectToFile(pathname.c_str(), AZ::ObjectStream::ST_XML, &fileObject); - - // now delete the cloned entities we created, fixed up and saved - delete clonedObjects; - - return result; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -AZ::Entity* UiCanvasComponent::LoadFromPrefab(const string& pathname, bool makeUniqueName, AZ::Entity* optionalInsertionPoint) -{ - AZ::Entity* newEntity = nullptr; - - // Currently LoadObjectFromFile will hang if the file cannot be parsed - // (LMBR-10078). So first check that it is in the right format - if (!IsValidAzSerializedFile(pathname)) - { - return nullptr; - } - - // The top level object in the file is a wrapper object called PrefabFileObject - // this is to give us more protection against changes to what we store in the file in future - // NOTE: this read doesn't support pak files but that is OK because prefab files are an - // editor only feature. - UiSerialize::PrefabFileObject* fileObject = - AZ::Utils::LoadObjectFromFile(pathname.c_str()); - AZ_Assert(fileObject, "Failed to load prefab"); - - if (fileObject) - { - // We want new IDs so generate them and fixup all references within the list of entities - { - AZ::SerializeContext* context = nullptr; - EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext); - AZ_Assert(context, "No serialization context found"); - - AZ::SliceComponent::EntityIdToEntityIdMap entityIdMap; - AZ::IdUtils::Remapper::GenerateNewIdsAndFixRefs(fileObject, entityIdMap, context); - } - - // add all of the entities to this canvases EntityContext - m_entityContext->AddUiEntities(fileObject->m_entities); - - EBUS_EVENT_RESULT(newEntity, AZ::ComponentApplicationBus, FindEntity, fileObject->m_rootEntityId); - - delete fileObject; // we do not keep the file wrapper object around - - if (makeUniqueName) - { - AZ::EntityId parentEntityId; - if (optionalInsertionPoint) - { - parentEntityId = optionalInsertionPoint->GetId(); - } - AZStd::string uniqueName = GetUniqueChildName(parentEntityId, newEntity->GetName(), nullptr); - newEntity->SetName(uniqueName); - } - - UiElementComponent* elementComponent = newEntity->FindComponent(); - AZ_Assert(elementComponent, "No element component found on prefab entity"); - - AZ::Entity* parent = (optionalInsertionPoint) ? optionalInsertionPoint : GetRootElement(); - - // recursively visit all the elements and set their canvas and parent pointers - elementComponent->FixupPostLoad(newEntity, this, parent, true); - - // add this new entity as a child of the parent (insertionPoint or root) - UiElementComponent* parentElementComponent = parent->FindComponent(); - AZ_Assert(parentElementComponent, "No element component found on parent entity"); - parentElementComponent->AddChild(newEntity); - } - - return newEntity; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// void UiCanvasComponent::FixupCreatedEntities(LyShine::EntityArray topLevelEntities, bool makeUniqueNamesAndIds, AZ::Entity* optionalInsertionPoint) { diff --git a/Gems/LyShine/Code/Source/UiCanvasComponent.h b/Gems/LyShine/Code/Source/UiCanvasComponent.h index df904684ec..b4815f4a76 100644 --- a/Gems/LyShine/Code/Source/UiCanvasComponent.h +++ b/Gems/LyShine/Code/Source/UiCanvasComponent.h @@ -99,11 +99,6 @@ public: // member functions AZ::EntityId FindInteractableToHandleEvent(AZ::Vector2 point) override; bool SaveToXml(const string& assetIdPathname, const string& sourceAssetPathname) override; - bool SaveAsPrefab(const string& pathname, AZ::Entity* entity) override; - UiCanvasInterface::ErrorCode CheckElementValidToSaveAsPrefab(AZ::Entity* entity) override; - AZ::Entity* LoadFromPrefab(const string& pathname, - bool makeUniqueName, - AZ::Entity* optionalInsertionPoint) override; void FixupCreatedEntities(LyShine::EntityArray topLevelEntities, bool makeUniqueNamesAndIds, AZ::Entity* optionalInsertionPoint) override; void AddElement(AZ::Entity* element, AZ::Entity* parent, AZ::Entity* insertBefore) override; void ReinitializeElements() override; diff --git a/Gems/LyShine/Code/Source/UiSerialize.cpp b/Gems/LyShine/Code/Source/UiSerialize.cpp index 80ff9113f2..639821930a 100644 --- a/Gems/LyShine/Code/Source/UiSerialize.cpp +++ b/Gems/LyShine/Code/Source/UiSerialize.cpp @@ -556,11 +556,6 @@ namespace UiSerialize serializeContext->Class >()-> Serializer(&AZ::Serialize::StaticInstance::s_instance); - serializeContext->Class() - ->Version(2, &PrefabFileObject::VersionConverter) - ->Field("RootEntity", &PrefabFileObject::m_rootEntityId) - ->Field("Entities", &PrefabFileObject::m_entities); - serializeContext->Class() ->Version(1) ->Field("SerializeString", &AnimationData::m_serializeData); @@ -607,54 +602,6 @@ namespace UiSerialize } } - //////////////////////////////////////////////////////////////////////////////////////////////////// - bool PrefabFileObject::VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement) - { - if (classElement.GetVersion() == 1) - { - // this is an old UI prefab (prior to UI Slices). We need to move all of the owned child entities into a - // separate list and have the references to them be via entity ID - - // Find the m_rootEntity in the PrefabFileObject, in the old format this is an entity, - // we will replace it with an entityId - int rootEntityIndex = classElement.FindElement(AZ_CRC("RootEntity", 0x3cead042)); - if (rootEntityIndex == -1) - { - return false; - } - AZ::SerializeContext::DataElementNode& rootEntityNode = classElement.GetSubElement(rootEntityIndex); - - // All UI element entities will be copied to this container and then added to the m_childEntities list - AZStd::vector copiedEntities; - - // recursively process the root element and all of its child elements, copying their child entities to the - // entities container and replacing them with EntityIds - if (!UiElementComponent::MoveEntityAndDescendantsToListAndReplaceWithEntityId(context, rootEntityNode, -1, copiedEntities)) - { - return false; - } - - // Create the child entities member (which is a generic vector) - using entityVector = AZStd::vector; - AZ::SerializeContext::ClassData* classData = AZ::SerializeGenericTypeInfo::GetGenericInfo()->GetClassData(); - int entitiesIndex = classElement.AddElement(context, "Entities", *classData); - if (entitiesIndex == -1) - { - return false; - } - AZ::SerializeContext::DataElementNode& entitiesNode = classElement.GetSubElement(entitiesIndex); - - // now add all of the copied entities to the entities vector node - for (AZ::SerializeContext::DataElementNode& entityElement : copiedEntities) - { - entityElement.SetName("element"); // all elements in the Vector should have this name - entitiesNode.AddElement(entityElement); - } - } - - return true; - } - //////////////////////////////////////////////////////////////////////////////////////////////// // Helper function to VersionConverter to move three state actions from the derived interactable // to the interactable base class diff --git a/Gems/LyShine/Code/Source/UiSerialize.h b/Gems/LyShine/Code/Source/UiSerialize.h index 9bdddceba2..c3ad18420d 100644 --- a/Gems/LyShine/Code/Source/UiSerialize.h +++ b/Gems/LyShine/Code/Source/UiSerialize.h @@ -16,20 +16,6 @@ namespace UiSerialize //! Define the Cry and UI types for the AZ Serialize system void ReflectUiTypes(AZ::ReflectContext* context); - //! Wrapper class for prefab file. This allows us to make changes to what the top - //! level objects are in the prefab file and do some conversion - //! NOTE: This is only used for old pre-slices UI prefabs - class PrefabFileObject - { - public: - virtual ~PrefabFileObject() { } - AZ_CLASS_ALLOCATOR(PrefabFileObject, AZ::SystemAllocator, 0); - AZ_RTTI(PrefabFileObject, "{C264CC6F-E50C-4813-AAE6-F7AB0B1774D0}"); - static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement); - AZ::EntityId m_rootEntityId; - AZStd::vector m_entities; - }; - //! Wrapper class for animation system data file. This allows us to use the old Cry //! serialize for the animation data class AnimationData diff --git a/Gems/LyShine/Code/lyshine_uicanvaseditor_files.cmake b/Gems/LyShine/Code/lyshine_uicanvaseditor_files.cmake index 84a5f560c7..7d6e995d10 100644 --- a/Gems/LyShine/Code/lyshine_uicanvaseditor_files.cmake +++ b/Gems/LyShine/Code/lyshine_uicanvaseditor_files.cmake @@ -108,8 +108,6 @@ set(FILES Editor/PivotPresets.h Editor/PivotPresetsWidget.cpp Editor/PivotPresetsWidget.h - Editor/PrefabHelpers.cpp - Editor/PrefabHelpers.h Editor/PresetButton.cpp Editor/PresetButton.h Editor/PreviewActionLog.cpp diff --git a/Gems/UiBasics/Assets/UI/Prefabs/Button.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/Button.uiprefab deleted file mode 100644 index b4e44904e7..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/Button.uiprefab +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/Checkbox.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/Checkbox.uiprefab deleted file mode 100644 index 4342f051c9..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/Checkbox.uiprefab +++ /dev/null @@ -1,346 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/Image.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/Image.uiprefab deleted file mode 100644 index 14aebe3ed0..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/Image.uiprefab +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/LayoutColumn.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/LayoutColumn.uiprefab deleted file mode 100644 index 46a09c2228..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/LayoutColumn.uiprefab +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/LayoutGrid.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/LayoutGrid.uiprefab deleted file mode 100644 index 84a23fbbb2..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/LayoutGrid.uiprefab +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/LayoutRow.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/LayoutRow.uiprefab deleted file mode 100644 index 35577ee608..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/LayoutRow.uiprefab +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarHorizontal.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarHorizontal.uiprefab deleted file mode 100644 index 2911354397..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarHorizontal.uiprefab +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarVertical.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarVertical.uiprefab deleted file mode 100644 index 44f8303729..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBarVertical.uiprefab +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBox.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/ScrollBox.uiprefab deleted file mode 100644 index 1019b8b098..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/ScrollBox.uiprefab +++ /dev/null @@ -1,526 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/Slider.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/Slider.uiprefab deleted file mode 100644 index 35a669bdb2..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/Slider.uiprefab +++ /dev/null @@ -1,339 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/Text.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/Text.uiprefab deleted file mode 100644 index 69646878b8..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/Text.uiprefab +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/TextInput.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/TextInput.uiprefab deleted file mode 100644 index 593d6dc220..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/TextInput.uiprefab +++ /dev/null @@ -1,351 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Gems/UiBasics/Assets/UI/Prefabs/TooltipDisplay.uiprefab b/Gems/UiBasics/Assets/UI/Prefabs/TooltipDisplay.uiprefab deleted file mode 100644 index b0dea29b0e..0000000000 --- a/Gems/UiBasics/Assets/UI/Prefabs/TooltipDisplay.uiprefab +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -