EditorLandscapeCanvasComponent.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <AzCore/Serialization/EditContext.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  11. #include <LyViewPaneNames.h>
  12. #include <QObject>
  13. #include <LandscapeCanvas/LandscapeCanvasBus.h>
  14. #include "EditorLandscapeCanvasComponent.h"
  15. namespace LandscapeCanvas
  16. {
  17. void EditorLandscapeCanvasComponent::Init()
  18. {
  19. }
  20. void EditorLandscapeCanvasComponent::Activate()
  21. {
  22. }
  23. void EditorLandscapeCanvasComponent::Deactivate()
  24. {
  25. }
  26. void EditorLandscapeCanvasComponent::Reflect(AZ::ReflectContext* reflection)
  27. {
  28. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  29. if (serializeContext)
  30. {
  31. serializeContext->Class<EditorLandscapeCanvasComponent, AzToolsFramework::Components::EditorComponentBase>()
  32. ->Version(2)
  33. ->Field("Graph", &EditorLandscapeCanvasComponent::m_graph)
  34. ;
  35. AZ::EditContext* editContext = serializeContext->GetEditContext();
  36. if (editContext)
  37. {
  38. editContext->Class<EditorLandscapeCanvasComponent>("Landscape Canvas", "The Landscape Canvas component provides a node-based Editor for authoring Dynamic Vegetation")
  39. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  40. ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/LandscapeCanvas.svg")
  41. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/LandscapeCanvas.svg")
  42. ->Attribute(AZ::Edit::Attributes::Category, "Vegetation")
  43. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  44. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  45. ->UIElement(AZ::Edit::UIHandlers::Button, "", "Opens the Landscape Canvas for the current entity")
  46. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorLandscapeCanvasComponent::OnOpenGraphButtonClicked)
  47. ->Attribute(AZ::Edit::Attributes::ButtonText, &EditorLandscapeCanvasComponent::GetOpenGraphButtonText);
  48. }
  49. }
  50. }
  51. AZ::Crc32 EditorLandscapeCanvasComponent::OnOpenGraphButtonClicked()
  52. {
  53. // Make sure the Landscape Canvas tool is open
  54. AzToolsFramework::OpenViewPane(LyViewPane::LandscapeCanvas);
  55. // Tell the Landscape Canvas tool to graph the entity our Landscape Canvas component is attached to
  56. LandscapeCanvas::LandscapeCanvasRequestBus::Broadcast(&LandscapeCanvas::LandscapeCanvasRequests::OnGraphEntity, GetEntityId());
  57. return AZ::Edit::PropertyRefreshLevels::EntireTree;
  58. }
  59. AZStd::string EditorLandscapeCanvasComponent::GetOpenGraphButtonText() const
  60. {
  61. return QObject::tr("Edit").toUtf8().constData();
  62. }
  63. void EditorLandscapeCanvasComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  64. {
  65. AZ_UNUSED(required);
  66. }
  67. void EditorLandscapeCanvasComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  68. {
  69. provided.push_back(AZ_CRC_CE("LandscapeGraphService"));
  70. }
  71. void EditorLandscapeCanvasComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  72. {
  73. incompatible.push_back(AZ_CRC_CE("LandscapeGraphService"));
  74. }
  75. void EditorLandscapeCanvasComponent::BuildGameEntity([[maybe_unused]] AZ::Entity* gameEntity)
  76. {
  77. }
  78. }