EditorTerrainSurfaceGradientListComponent.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <EditorComponents/EditorTerrainSurfaceGradientListComponent.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. namespace Terrain
  12. {
  13. void EditorTerrainSurfaceGradientListComponent::Reflect(AZ::ReflectContext* context)
  14. {
  15. BaseClassType::ReflectSubClass<EditorTerrainSurfaceGradientListComponent, BaseClassType>(
  16. context, 1,
  17. &LmbrCentral::EditorWrappedComponentBaseVersionConverter<typename BaseClassType::WrappedComponentType,
  18. typename BaseClassType::WrappedConfigType, 1>
  19. );
  20. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. if (auto edit = serialize->GetEditContext())
  23. {
  24. edit->Class<TerrainSurfaceGradientMapping>("Terrain Surface Gradient Mapping", "Mapping between a gradient and a surface.")
  25. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  26. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::Show)
  27. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  28. ->DataElement(
  29. AZ::Edit::UIHandlers::Default, &TerrainSurfaceGradientMapping::m_gradientEntityId,
  30. "Gradient Entity", "ID of Entity providing a gradient.")
  31. ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::AttributesAndValues)
  32. ->UIElement("GradientPreviewer", "Previewer")
  33. ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
  34. ->Attribute(AZ_CRC_CE("GradientEntity"), &TerrainSurfaceGradientMapping::m_gradientEntityId)
  35. ->DataElement(
  36. AZ::Edit::UIHandlers::Default, &TerrainSurfaceGradientMapping::m_surfaceTag, "Surface Tag",
  37. "Surface type to map to this gradient.")
  38. ->Attribute(AZ::Edit::Attributes::EnumValues, &TerrainSurfaceGradientMapping::BuildSelectableTagList)
  39. ;
  40. edit->Class<TerrainSurfaceGradientListConfig>(
  41. "Terrain Surface Gradient List Component", "Provide mapping between gradients and surfaces.")
  42. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  43. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::Show)
  44. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  45. ->DataElement(
  46. AZ::Edit::UIHandlers::Default, &TerrainSurfaceGradientListConfig::m_gradientSurfaceMappings,
  47. "Gradient to Surface Mappings", "Maps Gradient Entities to Surfaces.")
  48. ;
  49. }
  50. }
  51. }
  52. void EditorTerrainSurfaceGradientListComponent::Activate()
  53. {
  54. UpdateConfigurationTagProvider();
  55. BaseClassType::Activate();
  56. }
  57. AZ::u32 EditorTerrainSurfaceGradientListComponent::ConfigurationChanged()
  58. {
  59. UpdateConfigurationTagProvider();
  60. return BaseClassType::ConfigurationChanged();
  61. }
  62. void EditorTerrainSurfaceGradientListComponent::UpdateConfigurationTagProvider()
  63. {
  64. for (TerrainSurfaceGradientMapping& mapping : m_configuration.m_gradientSurfaceMappings)
  65. {
  66. mapping.SetTagListProvider(this);
  67. }
  68. }
  69. AZStd::unordered_set<SurfaceData::SurfaceTag> EditorTerrainSurfaceGradientListComponent::GetSurfaceTagsInUse() const
  70. {
  71. AZStd::unordered_set<SurfaceData::SurfaceTag> tagsInUse;
  72. for (const TerrainSurfaceGradientMapping& mapping : m_configuration.m_gradientSurfaceMappings)
  73. {
  74. tagsInUse.insert(mapping.m_surfaceTag);
  75. }
  76. return AZStd::move(tagsInUse);
  77. }
  78. AZStd::vector<AZStd::pair<AZ::u32, AZStd::string>> TerrainSurfaceGradientMapping::BuildSelectableTagList() const
  79. {
  80. return AZStd::move(Terrain::BuildSelectableTagList(m_tagListProvider, m_surfaceTag));
  81. }
  82. void TerrainSurfaceGradientMapping::SetTagListProvider(const EditorSurfaceTagListProvider* tagListProvider)
  83. {
  84. m_tagListProvider = tagListProvider;
  85. }
  86. }