Disable the ability to instantiate into closed prefabs, and to move the root prefab in focus mode. (#6320)

* Disable "Move Up" and "Move Down" for focused prefab containers.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>

* Disable the ability to instantiate prefabs inside closed prefab instances.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>

* Minor comment fix.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
monroegm-disable-blank-issue-2
Danilo Aimini 4 years ago committed by GitHub
parent 586f146a84
commit 0dfb8d42c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,6 +27,7 @@
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/FocusMode/FocusModeInterface.h>
#include <AzToolsFramework/Viewport/ViewportMessages.h>
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
#include <AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h>
@ -154,9 +155,15 @@ namespace AzToolsFramework
{
initEntityOutlinerWidgetResources();
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
m_editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
m_editorEntityUiInterface = AZ::Interface<AzToolsFramework::EditorEntityUiInterface>::Get();
AZ_Assert(m_editorEntityUiInterface != nullptr, "EntityOutlinerWidget requires a EditorEntityUiInterface instance on Initialize.");
m_focusModeInterface = AZ::Interface<AzToolsFramework::FocusModeInterface>::Get();
AZ_Assert(m_focusModeInterface != nullptr, "EntityOutlinerWidget requires a FocusModeInterface instance on Initialize.");
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::Get();
AZ_Assert(
(m_readOnlyEntityPublicInterface != nullptr),
@ -609,23 +616,27 @@ namespace AzToolsFramework
{
AZ::EntityId entityId = m_selectedEntityIds[0];
AZ::EntityId parentId;
EditorEntityInfoRequestBus::EventResult(parentId, entityId, &EditorEntityInfoRequestBus::Events::GetParent);
// Don't allow moving the entity if it's the focus root.
if (m_focusModeInterface->GetFocusRoot(m_editorEntityContextId) != entityId)
{
AZ::EntityId parentId;
EditorEntityInfoRequestBus::EventResult(parentId, entityId, &EditorEntityInfoRequestBus::Events::GetParent);
EntityOrderArray entityOrderArray = GetEntityChildOrder(parentId);
EntityOrderArray entityOrderArray = GetEntityChildOrder(parentId);
if (entityOrderArray.size() > 1)
{
if (AZStd::find(entityOrderArray.begin(), entityOrderArray.end(), entityId) != entityOrderArray.end())
if (entityOrderArray.size() > 1)
{
if (entityOrderArray.front() != entityId)
{
contextMenu->addAction(m_actionToMoveEntityUp);
}
if (entityOrderArray.back() != entityId)
if (AZStd::find(entityOrderArray.begin(), entityOrderArray.end(), entityId) != entityOrderArray.end())
{
contextMenu->addAction(m_actionToMoveEntityDown);
if (entityOrderArray.front() != entityId)
{
contextMenu->addAction(m_actionToMoveEntityUp);
}
if (entityOrderArray.back() != entityId)
{
contextMenu->addAction(m_actionToMoveEntityDown);
}
}
}
}

@ -43,6 +43,7 @@ namespace AzToolsFramework
class EntityOutlinerListModel;
class EntityOutlinerContainerProxyModel;
class EntityOutlinerSortFilterProxyModel;
class FocusModeInterface;
class ReadOnlyEntityPublicInterface;
namespace EntityOutliner
@ -204,7 +205,10 @@ namespace AzToolsFramework
EntityOutliner::DisplaySortMode m_sortMode;
bool m_sortContentQueued;
AzFramework::EntityContextId m_editorEntityContextId = AzFramework::EntityContextId::CreateNull();
EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
FocusModeInterface* m_focusModeInterface = nullptr;
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
};

@ -277,6 +277,26 @@ namespace AzToolsFramework
}
}
bool onlySelectedEntityIsFocusedPrefabContainer = false;
bool onlySelectedEntityIsClosedPrefabContainer = false;
if (selectedEntities.size() == 1)
{
AZ::EntityId selectedEntity = selectedEntities.front();
if (s_prefabPublicInterface->IsInstanceContainerEntity(selectedEntity))
{
if (s_prefabFocusPublicInterface->IsOwningPrefabBeingFocused(selectedEntity))
{
onlySelectedEntityIsFocusedPrefabContainer = true;
}
else
{
onlySelectedEntityIsClosedPrefabContainer = true;
}
}
}
bool itemWasShown = false;
// Create Prefab
@ -284,8 +304,7 @@ namespace AzToolsFramework
if (!selectedEntities.empty())
{
// Hide if the only selected entity is the Focused Instance Container
if (selectedEntities.size() > 1 ||
selectedEntities[0] != s_prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(s_editorEntityContextId))
if (!onlySelectedEntityIsFocusedPrefabContainer)
{
bool layerInSelection = false;
@ -322,7 +341,7 @@ namespace AzToolsFramework
}
// Instantiate Prefab
if (!readOnlyEntityInSelection)
if (selectedEntities.size() == 1 && !readOnlyEntityInSelection && !onlySelectedEntityIsClosedPrefabContainer)
{
QAction* instantiateAction = menu->addAction(QObject::tr("Instantiate Prefab..."));
instantiateAction->setToolTip(QObject::tr("Instantiates a prefab file in the scene."));
@ -330,17 +349,15 @@ namespace AzToolsFramework
QObject::connect(
instantiateAction, &QAction::triggered, instantiateAction, [] { ContextMenu_InstantiatePrefab(); });
itemWasShown = true;
}
// Instantiate Procedural Prefab
if (AZ::Prefab::ProceduralPrefabAsset::UseProceduralPrefabs() && !readOnlyEntityInSelection)
{
QAction* action = menu->addAction(QObject::tr("Instantiate Procedural Prefab..."));
action->setToolTip(QObject::tr("Instantiates a procedural prefab file in a prefab."));
// Instantiate Procedural Prefab
if (AZ::Prefab::ProceduralPrefabAsset::UseProceduralPrefabs())
{
QAction* action = menu->addAction(QObject::tr("Instantiate Procedural Prefab..."));
action->setToolTip(QObject::tr("Instantiates a procedural prefab file in a prefab."));
QObject::connect(
action, &QAction::triggered, action, [] { ContextMenu_InstantiateProceduralPrefab(); });
QObject::connect(
action, &QAction::triggered, action, [] { ContextMenu_InstantiateProceduralPrefab(); });
}
itemWasShown = true;
}
@ -362,14 +379,34 @@ namespace AzToolsFramework
{
if (!s_prefabFocusPublicInterface->IsOwningPrefabBeingFocused(selectedEntity))
{
// Edit Prefab
QAction* editAction = menu->addAction(QObject::tr("Open/Edit Prefab"));
editAction->setShortcut(QKeySequence(Qt::Key_Plus));
editAction->setToolTip(QObject::tr("Edit the prefab in focus mode."));
QObject::connect(editAction, &QAction::triggered, editAction, [selectedEntity] {
ContextMenu_EditPrefab(selectedEntity);
});
if (s_prefabPublicInterface->IsOwnedByProceduralPrefabInstance(selectedEntity))
{
// Inspect Prefab
QAction* editAction = menu->addAction(QObject::tr("Inspect Procedural Prefab"));
editAction->setShortcut(QKeySequence(Qt::Key_Plus));
editAction->setToolTip(QObject::tr("See the procedural prefab contents in focus mode."));
QObject::connect(
editAction, &QAction::triggered, editAction,
[selectedEntity]
{
ContextMenu_EditPrefab(selectedEntity);
});
}
else
{
// Edit Prefab
QAction* editAction = menu->addAction(QObject::tr("Open/Edit Prefab"));
editAction->setShortcut(QKeySequence(Qt::Key_Plus));
editAction->setToolTip(QObject::tr("Edit the prefab in focus mode."));
QObject::connect(
editAction, &QAction::triggered, editAction,
[selectedEntity]
{
ContextMenu_EditPrefab(selectedEntity);
});
}
}
else
{
@ -420,21 +457,17 @@ namespace AzToolsFramework
}
// Detach Prefab
if (selectedEntities.size() == 1)
if (onlySelectedEntityIsClosedPrefabContainer)
{
AZ::EntityId selectedEntityId = selectedEntities[0];
AZ::EntityId selectedEntityId = selectedEntities.front();
if (s_prefabPublicInterface->IsInstanceContainerEntity(selectedEntityId) &&
selectedEntityId != s_prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(s_editorEntityContextId))
{
QAction* detachPrefabAction = menu->addAction(QObject::tr("Detach Prefab..."));
QObject::connect(
detachPrefabAction, &QAction::triggered, detachPrefabAction,
[selectedEntityId]
{
ContextMenu_DetachPrefab(selectedEntityId);
});
}
QAction* detachPrefabAction = menu->addAction(QObject::tr("Detach Prefab..."));
QObject::connect(
detachPrefabAction, &QAction::triggered, detachPrefabAction,
[selectedEntityId]
{
ContextMenu_DetachPrefab(selectedEntityId);
});
}
}

@ -75,7 +75,7 @@ namespace AzToolsFramework
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2& point, int flags) override;
// EditorEventsBus overrides ...
void OnEscape();
void OnEscape() override;
// EntityOutlinerSourceDropHandlingBus overrides ...
void HandleSourceFileType(AZStd::string_view sourceFilePath, AZ::EntityId parentId, AZ::Vector3 position) const override;

Loading…
Cancel
Save