EditorGridComponent.cpp 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <Grid/EditorGridComponent.h>
  9. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  10. #include <AzCore/Asset/AssetManager.h>
  11. #include <AzCore/RTTI/BehaviorContext.h>
  12. namespace AZ
  13. {
  14. namespace Render
  15. {
  16. void EditorGridComponent::Reflect(AZ::ReflectContext* context)
  17. {
  18. BaseClass::Reflect(context);
  19. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<EditorGridComponent, BaseClass>()
  22. ->Version(1, ConvertToEditorRenderComponentAdapter<1>);
  23. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  24. {
  25. editContext->Class<EditorGridComponent>(
  26. "Grid", "Adds grid to the scene")
  27. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  28. ->Attribute(AZ::Edit::Attributes::Category, "Graphics/Other")
  29. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
  30. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg")
  31. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  32. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  33. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/grid/")
  34. ;
  35. editContext->Class<GridComponentController>(
  36. "GridComponentController", "")
  37. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentController::m_configuration, "Configuration", "")
  40. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  41. ;
  42. editContext->Class<GridComponentConfig>(
  43. "GridComponentConfig", "")
  44. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  45. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  46. ->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_gridSize, "Grid Size", "Grid width and depth")
  47. ->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinGridSize)
  48. ->Attribute(AZ::Edit::Attributes::Max, GridComponentController::MaxGridSize)
  49. ->Attribute(AZ::Edit::Attributes::Suffix, " m")
  50. ->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_primarySpacing, "Primary Grid Spacing", "Amount of space between grid lines")
  51. ->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinSpacing)
  52. ->Attribute(AZ::Edit::Attributes::Suffix, " m")
  53. ->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_secondarySpacing, "Secondary Grid Spacing", "Amount of space between sub-grid lines")
  54. ->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinSpacing)
  55. ->Attribute(AZ::Edit::Attributes::Suffix, " m")
  56. ->DataElement(AZ::Edit::UIHandlers::Color, &GridComponentConfig::m_axisColor, "Axis Color", "Color of the grid axis")
  57. ->DataElement(AZ::Edit::UIHandlers::Color, &GridComponentConfig::m_primaryColor, "Primary Color", "Color of the primary grid lines")
  58. ->DataElement(AZ::Edit::UIHandlers::Color, &GridComponentConfig::m_secondaryColor, "Secondary Color", "Color of the secondary grid lines")
  59. ;
  60. }
  61. }
  62. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  63. {
  64. behaviorContext->Class<EditorGridComponent>()->RequestBus("GridComponentRequestBus");
  65. behaviorContext->ConstantProperty("EditorGridComponentTypeId", BehaviorConstant(Uuid(EditorGridComponentTypeId)))
  66. ->Attribute(AZ::Script::Attributes::Module, "render")
  67. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  68. }
  69. }
  70. EditorGridComponent::EditorGridComponent(const GridComponentConfig& config)
  71. : BaseClass(config)
  72. {
  73. }
  74. } // namespace Render
  75. } // namespace AZ