476e66d902
* First step of procedural prefab styling and read-only registration. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * WIP - Introduce read-only handler for procedural prefabs (not hooked up) Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Introduce read-only entity interface, handler and unit tests. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Introduce temp read-only icon, use new icon hierarchy in Outliner. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Switch from a push paradigm to a pull paradigm - handlers get to implement logic to determine if an entity should be read-only. This allows multiple systems to weigh into whether an entity is read-only. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Fixed to missing call in test Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Post-rebase fixes to class name changes Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Display a lock icon on top of the entity icon in the Entity Outliner. This icon is added programmatically, which prevents having to alter all Outliner icons and future-proofs this functionality. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Minor style changes to procedural prefabs in the Outliner (use white icon) Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Ensure cache is refreshed when the handler is created, and also whenever the focus changes. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Remove Procedural Prefab setreg that was added in the wrong place Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Remove redundant function Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Fix spacing issue caused by rebase Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Change tooltip so that it accurately says "inspect" instead of "edit" for procedural prefabs. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Address minor styling issues mentioned in PR. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
118 lines
5.6 KiB
C++
118 lines
5.6 KiB
C++
/*
|
|
* 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 <Tests/Entity/ReadOnly/ReadOnlyEntityFixture.h>
|
|
|
|
namespace AzToolsFramework
|
|
{
|
|
TEST_F(ReadOnlyEntityFixture, NoHandlerEntityIsNotReadOnlyByDefault)
|
|
{
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, SingleHandlerEntityIsReadOnly)
|
|
{
|
|
// Create a handler that sets all entities to read-only.
|
|
ReadOnlyHandlerAlwaysTrue alwaysTrueHandler;
|
|
|
|
// All entities should be marked read-only now.
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[RootEntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild1EntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild2EntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, SingleHandlerEntityIsNotReadOnly)
|
|
{
|
|
// Create a handler that sets all entities to read-only.
|
|
ReadOnlyHandlerAlwaysFalse alwaysFalseHandler;
|
|
|
|
// All entities should not be marked read-only now.
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[RootEntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild1EntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild2EntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, SingleHandlerWithLogic)
|
|
{
|
|
// Create a handler that sets just the child entity to read-only.
|
|
ReadOnlyHandlerEntityId entityIdHandler(m_entityMap[ChildEntityName]);
|
|
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[RootEntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild1EntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild2EntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, TwoHandlersCanOverlap)
|
|
{
|
|
// Create two handlers that set different entities to read-only.
|
|
ReadOnlyHandlerEntityId entityIdHandler1(m_entityMap[ChildEntityName]);
|
|
ReadOnlyHandlerEntityId entityIdHandler2(m_entityMap[GrandChild2EntityName]);
|
|
|
|
// Both entities should be marked as read-only, while others aren't.
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[RootEntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild1EntityName]));
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[GrandChild2EntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, EnsureCacheIsRefreshedCorrectly)
|
|
{
|
|
// Verify the child entity is not marked as read-only
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
|
|
// Create a handler that sets the child entity to read-only.
|
|
ReadOnlyHandlerEntityId entityIdHandler(m_entityMap[ChildEntityName]);
|
|
|
|
// Communicate to the ReadOnlyEntitySystemComponent that the read-only state for the child entity may have changed.
|
|
// Note that this operation would usually be executed by the handler, hence the Query interface call.
|
|
if (auto readOnlyEntityQueryInterface = AZ::Interface<ReadOnlyEntityQueryInterface>::Get())
|
|
{
|
|
readOnlyEntityQueryInterface->RefreshReadOnlyState({ m_entityMap[ChildEntityName] });
|
|
}
|
|
|
|
// Verify the child entity is marked as read-only
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, EnsureCacheIsClearedCorrectly)
|
|
{
|
|
{
|
|
// Create a handler that sets the child entity to read-only.
|
|
ReadOnlyHandlerEntityId entityIdHandler(m_entityMap[ChildEntityName]);
|
|
|
|
// Verify the child entity is marked as read-only
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
// When the handler goes out of scope, it calls RefreshReadOnlyStateForAllEntities and refreshes the cache.
|
|
|
|
// Verify the child entity is no longer marked as read-only
|
|
EXPECT_FALSE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
|
|
TEST_F(ReadOnlyEntityFixture, EnsureCacheIsClearedCorrectlyEvenIfUnchanged)
|
|
{
|
|
// Create a handler that sets all entities to read-only.
|
|
ReadOnlyHandlerAlwaysTrue alwaysTrueHandler;
|
|
|
|
{
|
|
// Create a handler that sets the child entity to read-only.
|
|
ReadOnlyHandlerEntityId entityIdHandler(m_entityMap[ChildEntityName]);
|
|
|
|
// Verify the child entity is marked as read-only
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
// When the handler goes out of scope, it calls RefreshReadOnlyStateForAllEntities and refreshes the cache.
|
|
|
|
// Verify the child entity is still marked as read-only
|
|
EXPECT_TRUE(m_readOnlyEntityPublicInterface->IsReadOnly(m_entityMap[ChildEntityName]));
|
|
}
|
|
}
|