diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp index d7f68accda..c1eaa32bb6 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp @@ -203,14 +203,29 @@ namespace LandscapeCanvasEditor { using namespace AzToolsFramework; - static const QStringList preferredCategories = { "Vegetation", "Atom" }; + // Check whether the first category has a preferred component and return that if it does. + const AZStd::unordered_map preferredComponentByCategory = { { "Shape", "Shape Reference" } }; + + const AZStd::string firstCategoryName(componentDataTable.begin()->first.toUtf8()); + + const auto& preferredComponentPair = preferredComponentByCategory.find(firstCategoryName); + + if (preferredComponentPair != preferredComponentByCategory.end()) + { + const auto& componentPair = componentDataTable.begin()->second.find(preferredComponentPair->second); - static const AZStd::unordered_map preferredComponentByCategory = { { "Shape", "Shape Reference" } }; + if (componentPair != componentDataTable.begin()->second.end()) + { + return componentPair->second->m_typeId; + } + } // There are a couple of cases where we prefer certain categories of Components // to be added over others, // so if those there are components in those categories, then choose them first. // Otherwise, just pick the first one in the list. + static const QStringList preferredCategories = { "Vegetation", "Atom" }; + ComponentPaletteUtil::ComponentDataTable::const_iterator categoryIt; for (const auto& categoryName : preferredCategories) { @@ -227,22 +242,6 @@ namespace LandscapeCanvasEditor AZ_Assert(categoryIt->second.size(), "No components found that satisfy the missing required service(s)."); - const AZStd::string categoryName(categoryIt->first.toUtf8()); - - // Check whether the selected category has a preferred component and return that if it does. - for (const auto& preferredComponentPair : preferredComponentByCategory) - { - if (categoryName == preferredComponentPair.first) - { - const auto& componentPair = categoryIt->second.find(preferredComponentPair.second); - - if (componentPair != categoryIt->second.end()) - { - return componentPair->second->m_typeId; - } - } - } - const auto& componentPair = categoryIt->second.begin(); return componentPair->second->m_typeId; } diff --git a/Gems/LmbrCentral/Assets/Editor/Icons/Components/ShapeReference.svg b/Gems/LmbrCentral/Assets/Editor/Icons/Components/ShapeReference.svg new file mode 100644 index 0000000000..a304220c48 --- /dev/null +++ b/Gems/LmbrCentral/Assets/Editor/Icons/Components/ShapeReference.svg @@ -0,0 +1,3 @@ + + + diff --git a/Gems/LmbrCentral/Assets/Editor/Icons/Components/Viewport/ShapeReference.svg b/Gems/LmbrCentral/Assets/Editor/Icons/Components/Viewport/ShapeReference.svg new file mode 100644 index 0000000000..fe6abb9fe4 --- /dev/null +++ b/Gems/LmbrCentral/Assets/Editor/Icons/Components/Viewport/ShapeReference.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/Gems/LmbrCentral/Code/Mocks/LmbrCentral/Shape/MockShapes.h b/Gems/LmbrCentral/Code/Mocks/LmbrCentral/Shape/MockShapes.h index 41df0d318d..b0118a914a 100644 --- a/Gems/LmbrCentral/Code/Mocks/LmbrCentral/Shape/MockShapes.h +++ b/Gems/LmbrCentral/Code/Mocks/LmbrCentral/Shape/MockShapes.h @@ -61,7 +61,7 @@ namespace UnitTest { public: AZ::Entity m_entity; - mutable int m_count = 0; + int m_count = 0; MockShape() { diff --git a/Gems/LmbrCentral/Code/Source/Shape/EditorReferenceShapeComponent.h b/Gems/LmbrCentral/Code/Source/Shape/EditorReferenceShapeComponent.h index 312fa852bf..fd98809bcc 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/EditorReferenceShapeComponent.h +++ b/Gems/LmbrCentral/Code/Source/Shape/EditorReferenceShapeComponent.h @@ -8,7 +8,7 @@ #pragma once -#include +#include #include namespace LmbrCentral @@ -24,8 +24,8 @@ namespace LmbrCentral static constexpr const char* const s_categoryName = "Shape"; static constexpr const char* const s_componentName = "Shape Reference"; static constexpr const char* const s_componentDescription = "Enables the entity to reference and reuse shape entities"; - static constexpr const char* const s_icon = "Icons/Components/Component_Placeholder.svg"; - static constexpr const char* const s_viewportIcon = "Icons/Components/Viewport/Component_Placeholder.svg"; + static constexpr const char* const s_icon = "Editor/Icons/Components/ShapeReference.svg"; + static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/ShapeReference.svg"; static constexpr const char* const s_helpUrl = "https://o3de.org/docs/user-guide/components/reference/"; }; } diff --git a/Gems/LmbrCentral/Code/Source/Shape/ReferenceShapeComponent.cpp b/Gems/LmbrCentral/Code/Source/Shape/ReferenceShapeComponent.cpp index 5f33164147..7ed79fe3a3 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/ReferenceShapeComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Shape/ReferenceShapeComponent.cpp @@ -27,7 +27,7 @@ namespace LmbrCentral if (edit) { edit->Class( - "Reference Shape", "") + "Shape Reference", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) diff --git a/Gems/Vegetation/Code/CMakeLists.txt b/Gems/Vegetation/Code/CMakeLists.txt index 735bb35bd9..53fa6bd59f 100644 --- a/Gems/Vegetation/Code/CMakeLists.txt +++ b/Gems/Vegetation/Code/CMakeLists.txt @@ -103,6 +103,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) AZ::AzTest AZ::AzFrameworkTestShared Gem::Vegetation.Static + Gem::LmbrCentral.Mocks ) ly_add_googletest( NAME Gem::Vegetation.Tests diff --git a/Gems/Vegetation/Code/Tests/VegetationComponentFilterTests.cpp b/Gems/Vegetation/Code/Tests/VegetationComponentFilterTests.cpp index abb76c8c2d..221a2da432 100644 --- a/Gems/Vegetation/Code/Tests/VegetationComponentFilterTests.cpp +++ b/Gems/Vegetation/Code/Tests/VegetationComponentFilterTests.cpp @@ -8,6 +8,8 @@ #include "VegetationTest.h" #include "VegetationMocks.h" +#include + #include #include #include diff --git a/Gems/Vegetation/Code/Tests/VegetationMocks.h b/Gems/Vegetation/Code/Tests/VegetationMocks.h index 4c526447d3..ece0833433 100644 --- a/Gems/Vegetation/Code/Tests/VegetationMocks.h +++ b/Gems/Vegetation/Code/Tests/VegetationMocks.h @@ -312,74 +312,6 @@ namespace UnitTest } }; - class MockShape - : public LmbrCentral::ShapeComponentRequestsBus::Handler - { - public: - AZ::Entity m_entity; - mutable int m_count = 0; - - MockShape() - { - LmbrCentral::ShapeComponentRequestsBus::Handler::BusConnect(m_entity.GetId()); - } - - ~MockShape() - { - LmbrCentral::ShapeComponentRequestsBus::Handler::BusDisconnect(); - } - - AZ::Crc32 GetShapeType() override - { - ++m_count; - return AZ_CRC("TestShape", 0x856ca50c); - } - - AZ::Aabb m_aabb = AZ::Aabb::CreateNull(); - AZ::Aabb GetEncompassingAabb() override - { - ++m_count; - return m_aabb; - } - - AZ::Transform m_localTransform = AZ::Transform::CreateIdentity(); - AZ::Aabb m_localBounds = AZ::Aabb::CreateNull(); - void GetTransformAndLocalBounds(AZ::Transform& transform, AZ::Aabb& bounds) override - { - ++m_count; - transform = m_localTransform; - bounds = m_localBounds; - } - - bool m_pointInside = true; - bool IsPointInside([[maybe_unused]] const AZ::Vector3& point) override - { - ++m_count; - return m_pointInside; - } - - float m_distanceSquaredFromPoint = 0.0f; - float DistanceSquaredFromPoint([[maybe_unused]] const AZ::Vector3& point) override - { - ++m_count; - return m_distanceSquaredFromPoint; - } - - AZ::Vector3 m_randomPointInside = AZ::Vector3::CreateZero(); - AZ::Vector3 GenerateRandomPointInside([[maybe_unused]] AZ::RandomDistributionType randomDistribution) override - { - ++m_count; - return m_randomPointInside; - } - - bool m_intersectRay = false; - bool IntersectRay([[maybe_unused]] const AZ::Vector3& src, [[maybe_unused]] const AZ::Vector3& dir, [[maybe_unused]] float& distance) override - { - ++m_count; - return m_intersectRay; - } - }; - struct MockSurfaceHandler : public SurfaceData::SurfaceDataSystemRequestBus::Handler {