From 9753655d8916ec0d8e397f1f61eec1b387e296e1 Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Mon, 29 Nov 2021 09:48:36 +0000 Subject: [PATCH] Add preferred component types to landscape canvas code. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- .../Code/Source/Editor/MainWindow.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp index 9c72f75a4c..d7f68accda 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp @@ -203,13 +203,12 @@ namespace LandscapeCanvasEditor { using namespace AzToolsFramework; - static const QStringList preferredCategories = { - "Vegetation", - "Atom" - }; + static const QStringList preferredCategories = { "Vegetation", "Atom" }; + + static const AZStd::unordered_map preferredComponentByCategory = { { "Shape", "Shape Reference" } }; // There are a couple of cases where we prefer certain categories of Components - // to be added over others (e.g. a Vegetation Shape Reference instead of actual LmbrCentral shapes), + // 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. ComponentPaletteUtil::ComponentDataTable::const_iterator categoryIt; @@ -228,6 +227,22 @@ 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; }