Merge branch 'development' into memory/benchmarks

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-12-07 18:44:03 -08:00
12 changed files with 193 additions and 31 deletions
@@ -41,6 +41,7 @@
#include <AzToolsFramework/Editor/EditorContextMenuBus.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/Entity/SliceEditorEntityOwnershipServiceBus.h>
#include <AzToolsFramework/Slice/SliceRequestBus.h>
#include <AzToolsFramework/Slice/SliceUtilities.h>
@@ -208,6 +209,9 @@ void SandboxIntegrationManager::Setup()
m_editorEntityAPI = AZ::Interface<AzToolsFramework::EditorEntityAPI>::Get();
AZ_Assert(m_editorEntityAPI, "SandboxIntegrationManager requires an EditorEntityAPI instance to be present on Setup().");
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(m_readOnlyEntityPublicInterface, "SandboxIntegrationManager requires an ReadOnlyEntityPublicInterface instance to be present on Setup().");
AzToolsFramework::Layers::EditorLayerComponentNotificationBus::Handler::BusConnect();
}
@@ -658,15 +662,17 @@ void SandboxIntegrationManager::PopulateEditorGlobalContextMenu(QMenu* menu, con
// when a single entity is selected, entity is created as its child
else if (selected.size() == 1)
{
AZ::EntityId selectedEntityId = selected.front();
bool selectedEntityIsReadOnly = m_readOnlyEntityPublicInterface->IsReadOnly(selectedEntityId);
auto containerEntityInterface = AZ::Interface<AzToolsFramework::ContainerEntityInterface>::Get();
if (!prefabSystemEnabled || (containerEntityInterface && containerEntityInterface->IsContainerOpen(selected.front())))
if (!prefabSystemEnabled || (containerEntityInterface && containerEntityInterface->IsContainerOpen(selectedEntityId) && !selectedEntityIsReadOnly))
{
action = menu->addAction(QObject::tr("Create entity"));
QObject::connect(
action, &QAction::triggered, action,
[selected]
[selectedEntityId]
{
AzToolsFramework::EditorRequestBus::Broadcast(&AzToolsFramework::EditorRequestBus::Handler::CreateNewEntityAsChild, selected.front());
AzToolsFramework::EditorRequestBus::Broadcast(&AzToolsFramework::EditorRequestBus::Handler::CreateNewEntityAsChild, selectedEntityId);
}
);
}
@@ -691,11 +697,27 @@ void SandboxIntegrationManager::PopulateEditorGlobalContextMenu(QMenu* menu, con
SetupSliceContextMenu(menu);
}
action = menu->addAction(QObject::tr("Duplicate"));
QObject::connect(action, &QAction::triggered, action, [this] { ContextMenu_Duplicate(); });
if (selected.size() == 0)
if (!selected.empty())
{
action->setDisabled(true);
// Don't allow duplication if any of the selected entities are direct desendants of a read-only entity
bool selectionContainsDescendantOfReadOnlyEntity = false;
for (const auto& entityId : selected)
{
AZ::EntityId parentEntityId;
AZ::TransformBus::EventResult(parentEntityId, entityId, &AZ::TransformBus::Events::GetParentId);
if (parentEntityId.IsValid() && m_readOnlyEntityPublicInterface->IsReadOnly(parentEntityId))
{
selectionContainsDescendantOfReadOnlyEntity = true;
break;
}
}
if (!selectionContainsDescendantOfReadOnlyEntity)
{
action = menu->addAction(QObject::tr("Duplicate"));
QObject::connect(action, &QAction::triggered, action, [this] { ContextMenu_Duplicate(); });
}
}
if (!prefabSystemEnabled)
@@ -76,6 +76,7 @@ namespace AzToolsFramework
{
class EditorEntityAPI;
class EditorEntityUiInterface;
class ReadOnlyEntityPublicInterface;
namespace AssetBrowser
{
@@ -295,6 +296,7 @@ private:
AzToolsFramework::EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
AzToolsFramework::Prefab::PrefabIntegrationInterface* m_prefabIntegrationInterface = nullptr;
AzToolsFramework::EditorEntityAPI* m_editorEntityAPI = nullptr;
AzToolsFramework::ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
// Overrides UI styling and behavior for Layer Entities
AzToolsFramework::LayerUiHandler m_layerUiOverrideHandler;
@@ -42,6 +42,11 @@ namespace AzToolsFramework
bool ReadOnlyEntitySystemComponent::IsReadOnly(const AZ::EntityId& entityId)
{
if (!entityId.IsValid())
{
return false;
}
if (!m_readOnlystates.contains(entityId))
{
QueryReadOnlyStateForEntity(entityId);
@@ -18,6 +18,7 @@
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
#include <AzToolsFramework/Prefab/Instance/Instance.h>
#include <AzToolsFramework/Prefab/Instance/InstanceEntityIdMapper.h>
@@ -581,7 +582,15 @@ namespace AzToolsFramework
"Cannot add entity because the parent entity (id '%llu') is a closed container entity.",
static_cast<AZ::u64>(parentId)));
}
// If the parent entity is marked as read only, bail.
if (auto readOnlyEntityPublicInterface = AZ::Interface<ReadOnlyEntityPublicInterface>::Get(); readOnlyEntityPublicInterface->IsReadOnly(parentId))
{
return AZ::Failure(AZStd::string::format(
"Cannot add entity because the parent entity (id '%llu') is marked as read only.",
static_cast<AZ::u64>(parentId)));
}
EntityAlias entityAlias = Instance::GenerateEntityAlias();
AliasPath absoluteEntityPath = owningInstanceOfParentEntity->get().GetAbsoluteInstanceAliasPath();
@@ -1210,6 +1219,27 @@ namespace AzToolsFramework
return AZ::Failure(AZStd::string("Cannot delete entities belonging to an instance that is not being edited."));
}
// None of the specified entities can be marked as read only, otherwise this operation is invalid.
if (auto readOnlyEntityPublicInterface = AZ::Interface<ReadOnlyEntityPublicInterface>::Get())
{
AZ::EntityId readOnlyEntityId;
for (const auto& entityId : entityIdsNoFocusContainer)
{
if (readOnlyEntityPublicInterface->IsReadOnly(entityId))
{
readOnlyEntityId = entityId;
break;
}
}
if (readOnlyEntityId.IsValid())
{
return AZ::Failure(AZStd::string::format(
"Cannot delete entities because entity (id '%llu') is marked as read only.",
static_cast<AZ::u64>(readOnlyEntityId)));
}
}
// Retrieve entityList from entityIds
EntityList inputEntityList = EntityIdListToEntityList(entityIdsNoFocusContainer);
@@ -117,8 +117,12 @@ namespace AzToolsFramework
ContainerEntityNotificationBus::Handler::BusConnect(editorEntityContextId);
m_editorEntityUiInterface = AZ::Interface<AzToolsFramework::EditorEntityUiInterface>::Get();
AZ_Assert(m_editorEntityUiInterface != nullptr,
"EntityOutlinerListModel requires a EditorEntityUiInterface instance on Initialize.");
AZ_Assert(m_editorEntityUiInterface != nullptr, "EntityOutlinerListModel requires a EditorEntityUiInterface instance on Initialize.");
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(
(m_readOnlyEntityPublicInterface != nullptr),
"EntityOutlinerListModel requires a ReadOnlyEntityPublicInterface instance on Initialize.");
}
int EntityOutlinerListModel::rowCount(const QModelIndex& parent) const
@@ -451,9 +455,15 @@ namespace AzToolsFramework
if (value.canConvert<Qt::CheckState>())
{
const auto entityId = GetEntityFromIndex(index);
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
if (!entityUiHandler || entityUiHandler->CanToggleLockVisibility(entityId))
// Disable lock and visibility toggling if the UI Handler blocked it.
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
bool canToggleLockVisibility = !entityUiHandler || entityUiHandler->CanToggleLockVisibility(entityId);
// Disable lock and visibility toggling for read-only entities.
bool isReadOnly = m_readOnlyEntityPublicInterface->IsReadOnly(entityId);
if (canToggleLockVisibility && !isReadOnly)
{
switch (index.column())
{
@@ -535,6 +545,15 @@ namespace AzToolsFramework
return Qt::ItemIsDropEnabled;
}
AZ::EntityId entityId = GetEntityFromIndex(index);
// Only allow renaming the entity if the UI Handler did not block it.
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
bool canRename = !entityUiHandler || entityUiHandler->CanRename(entityId);
// Disable renaming for read-only entities.
bool isReadOnly = m_readOnlyEntityPublicInterface->IsReadOnly(entityId);
Qt::ItemFlags itemFlags = QAbstractItemModel::flags(index);
switch (index.column())
{
@@ -544,7 +563,21 @@ namespace AzToolsFramework
break;
case ColumnName:
itemFlags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable;
if (canRename && !isReadOnly)
{
itemFlags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable;
}
else
{
if (isReadOnly)
{
itemFlags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
}
else
{
itemFlags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
}
}
break;
default:
@@ -552,7 +585,8 @@ namespace AzToolsFramework
break;
}
if (AZ::EntityId entityId = GetEntityFromIndex(index); !m_focusModeInterface->IsInFocusSubTree(entityId))
// Disable entities outside the focus subtree.
if (!m_focusModeInterface->IsInFocusSubTree(entityId))
{
itemFlags &= !Qt::ItemIsEnabled;
}
@@ -773,14 +807,21 @@ namespace AzToolsFramework
[[maybe_unused]] int column,
const QModelIndex& parent) const
{
// Disable dropping assets on closed container entities.
AZ::EntityId parentId = GetEntityFromIndex(parent);
// Disable dropping assets on closed container entities.
if (auto containerEntityInterface = AZ::Interface<ContainerEntityInterface>::Get();
!containerEntityInterface->IsContainerOpen(parentId))
{
return false;
}
// Disable dropping assets on read-only entities.
if (m_readOnlyEntityPublicInterface->IsReadOnly(parentId))
{
return false;
}
if (data->hasFormat(AssetBrowser::AssetBrowserEntry::GetMimeType()))
{
return DecodeAssetMimeData(data);
@@ -2211,6 +2252,13 @@ namespace AzToolsFramework
QColor transparentColor(0, 0, 0, 0);
checkboxPalette.setColor(QPalette::ColorRole::Window, transparentColor);
// Disable hover rendering for read-only entities
AZ::EntityId entityId(index.data(EntityOutlinerListModel::EntityIdRole).value<AZ::u64>());
if (m_readOnlyEntityPublicInterface->IsReadOnly(entityId))
{
isHovered = false;
}
// We're only using these check boxes as renderers so their actual state doesn't matter.
// We can set it right before we draw using information from the model data.
if (index.column() == EntityOutlinerListModel::ColumnVisibilityToggle)
@@ -290,6 +290,7 @@ namespace AzToolsFramework
EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
FocusModeInterface* m_focusModeInterface = nullptr;
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
};
class EntityOutlinerCheckBox
@@ -14,6 +14,7 @@
#include <AzCore/std/algorithm.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/UI/EditorEntityUi/EditorEntityUiInterface.h>
#include <AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h>
@@ -35,11 +36,14 @@ namespace AzToolsFramework
setHeaderHidden(true);
m_editorEntityFrameworkInterface = AZ::Interface<AzToolsFramework::EditorEntityUiInterface>::Get();
AZ_Assert((m_editorEntityFrameworkInterface != nullptr),
"EntityOutlinerTreeView requires a EditorEntityFrameworkInterface instance on Construction.");
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(
(m_readOnlyEntityPublicInterface != nullptr),
"EntityOutlinerTreeView requires a ReadOnlyEntityPublicInterface instance on Construction.");
AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull();
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
@@ -157,11 +161,22 @@ namespace AzToolsFramework
void EntityOutlinerTreeView::startDrag(Qt::DropActions supportedActions)
{
QModelIndex index = indexAt(m_queuedMouseEvent->pos());
AZ::EntityId entityId(index.data(EntityOutlinerListModel::EntityIdRole).value<AZ::u64>());
AZ::EntityId parentEntityId;
EditorEntityInfoRequestBus::EventResult(parentEntityId, entityId, &EditorEntityInfoRequestBus::Events::GetParent);
// If the entity is parented to a read-only entity, cancel the drag operation.
if (m_readOnlyEntityPublicInterface->IsReadOnly(parentEntityId))
{
return;
}
//if we are attempting to drag an unselected item then we must special case drag and drop logic
//QAbstractItemView::startDrag only supports selected items
if (m_queuedMouseEvent)
{
QModelIndex index = indexAt(m_queuedMouseEvent->pos());
if (!index.isValid() || index.column() != 0)
{
return;
@@ -26,6 +26,7 @@ class QMouseEvent;
namespace AzToolsFramework
{
class EditorEntityUiInterface;
class ReadOnlyEntityPublicInterface;
//! This class largely exists to emit events for the OutlinerWidget to listen in on.
//! The logic for these events is best off not happening within the tree itself,
@@ -92,7 +93,8 @@ namespace AzToolsFramework
QModelIndex m_currentHoveredIndex;
EditorEntityUiInterface* m_editorEntityFrameworkInterface;
EditorEntityUiInterface* m_editorEntityFrameworkInterface = nullptr;
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
};
}
@@ -26,6 +26,7 @@
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/Viewport/ViewportMessages.h>
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
#include <AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h>
@@ -156,6 +157,11 @@ namespace AzToolsFramework
m_editorEntityUiInterface = AZ::Interface<AzToolsFramework::EditorEntityUiInterface>::Get();
AZ_Assert(m_editorEntityUiInterface != nullptr, "EntityOutlinerWidget requires a EditorEntityUiInterface instance on Initialize.");
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(
(m_readOnlyEntityPublicInterface != nullptr),
"EntityOutlinerListModel requires a ReadOnlyEntityPublicInterface instance on Initialize.");
m_gui = new Ui::EntityOutlinerWidgetUI();
m_gui->setupUi(this);
@@ -585,9 +591,15 @@ namespace AzToolsFramework
if (m_selectedEntityIds.size() == 1)
{
auto entityId = m_selectedEntityIds.front();
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
if (!entityUiHandler || entityUiHandler->CanRename(entityId))
// Only allow renaming the entity if the UI Handler did not block it.
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
bool canRename = !entityUiHandler || entityUiHandler->CanRename(entityId);
// Disable renaming for read-only entities.
bool isReadOnly = m_readOnlyEntityPublicInterface->IsReadOnly(entityId);
if (canRename && !isReadOnly)
{
contextMenu->addAction(m_actionToRenameSelection);
}
@@ -717,9 +729,15 @@ namespace AzToolsFramework
if (m_selectedEntityIds.size() == 1)
{
auto entityId = m_selectedEntityIds.front();
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
if (!entityUiHandler || entityUiHandler->CanRename(entityId))
// Only allow renaming the entity if the UI Handler did not block it.
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
bool canRename = !entityUiHandler || entityUiHandler->CanRename(entityId);
// Disable renaming for read-only entities.
bool isReadOnly = m_readOnlyEntityPublicInterface->IsReadOnly(entityId);
if (canRename && !isReadOnly)
{
const QModelIndex proxyIndex = GetIndexFromEntityId(entityId);
if (proxyIndex.isValid())
@@ -43,6 +43,7 @@ namespace AzToolsFramework
class EntityOutlinerListModel;
class EntityOutlinerContainerProxyModel;
class EntityOutlinerSortFilterProxyModel;
class ReadOnlyEntityPublicInterface;
namespace EntityOutliner
{
@@ -204,6 +205,7 @@ namespace AzToolsFramework
bool m_sortContentQueued;
EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
};
}
@@ -25,6 +25,7 @@
#include <AzToolsFramework/AssetBrowser/Entries/SourceAssetBrowserEntry.h>
#include <AzToolsFramework/ContainerEntity/ContainerEntityInterface.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
#include <AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h>
@@ -141,6 +142,9 @@ namespace AzToolsFramework
return;
}
m_readOnlyEntityPublicInterface = AZ::Interface<ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(m_readOnlyEntityPublicInterface, "Prefab - could not get ReadOnlyEntityPublicInterface on PrefabIntegrationManager construction.");
// Get EditorEntityContextId
EditorEntityContextRequestBus::BroadcastResult(s_editorEntityContextId, &EditorEntityContextRequests::GetEditorEntityContextId);
@@ -263,6 +267,16 @@ namespace AzToolsFramework
AzFramework::ApplicationRequests::Bus::BroadcastResult(
prefabWipFeaturesEnabled, &AzFramework::ApplicationRequests::ArePrefabWipFeaturesEnabled);
bool readOnlyEntityInSelection = false;
for (const auto& entityId : selectedEntities)
{
if (m_readOnlyEntityPublicInterface->IsReadOnly(entityId))
{
readOnlyEntityInSelection = true;
break;
}
}
// Create Prefab
{
if (!selectedEntities.empty())
@@ -289,7 +303,8 @@ namespace AzToolsFramework
}
// Layers can't be in prefabs.
if (!layerInSelection)
// Also don't allow to create a prefab if any of the selected entities are read-only
if (!layerInSelection && !readOnlyEntityInSelection)
{
QAction* createAction = menu->addAction(QObject::tr("Create Prefab..."));
createAction->setToolTip(QObject::tr("Creates a prefab out of the currently selected entities."));
@@ -383,14 +398,13 @@ namespace AzToolsFramework
menu->addSeparator();
}
QAction* deleteAction = menu->addAction(QObject::tr("Delete"));
QObject::connect(deleteAction, &QAction::triggered, deleteAction, [] { ContextMenu_DeleteSelected(); });
if (selectedEntities.empty() ||
(selectedEntities.size() == 1 &&
selectedEntities[0] == s_prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(s_editorEntityContextId)))
if (!selectedEntities.empty() &&
(selectedEntities.size() != 1 ||
selectedEntities[0] != s_prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(s_editorEntityContextId)) &&
!readOnlyEntityInSelection)
{
deleteAction->setDisabled(true);
QAction* deleteAction = menu->addAction(QObject::tr("Delete"));
QObject::connect(deleteAction, &QAction::triggered, deleteAction, [] { ContextMenu_DeleteSelected(); });
}
// Detach Prefab
@@ -29,6 +29,7 @@
namespace AzToolsFramework
{
class ContainerEntityInterface;
class ReadOnlyEntityPublicInterface;
namespace Prefab
{
@@ -169,6 +170,8 @@ namespace AzToolsFramework
static PrefabLoaderInterface* s_prefabLoaderInterface;
static PrefabPublicInterface* s_prefabPublicInterface;
static PrefabSystemComponentInterface* s_prefabSystemComponentInterface;
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
};
}
}