EditorDebugDrawTextComponent.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include "EditorDebugDrawTextComponent.h"
  11. namespace DebugDraw
  12. {
  13. void EditorDebugDrawTextComponent::Reflect(AZ::ReflectContext* context)
  14. {
  15. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  16. if (serializeContext)
  17. {
  18. serializeContext->Class<EditorDebugDrawTextComponent, EditorComponentBase>()
  19. ->Version(0)
  20. ->Field("Element", &EditorDebugDrawTextComponent::m_element)
  21. ->Field("Settings", &EditorDebugDrawTextComponent::m_settings)
  22. ;
  23. AZ::EditContext* editContext = serializeContext->GetEditContext();
  24. if (editContext)
  25. {
  26. editContext->Class<EditorDebugDrawTextComponent>(
  27. "DebugDraw Text", "Draws debug text on the screen at this entity's location.")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->Attribute(AZ::Edit::Attributes::Category, "Debugging")
  30. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/DebugDrawText.svg")
  31. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/DebugDrawText.svg")
  32. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  33. ->DataElement(0, &EditorDebugDrawTextComponent::m_element, "Text element settings", "Settings for the text element.")
  34. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawTextComponent::OnPropertyUpdate)
  35. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  36. ->DataElement(0, &EditorDebugDrawTextComponent::m_settings, "Visibility settings", "Common settings for DebugDraw components.")
  37. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawTextComponent::OnPropertyUpdate)
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ;
  40. }
  41. }
  42. }
  43. void EditorDebugDrawTextComponent::BuildGameEntity(AZ::Entity* gameEntity)
  44. {
  45. if (m_settings.m_visibleInGame)
  46. {
  47. gameEntity->CreateComponent<DebugDrawTextComponent>(m_element);
  48. }
  49. }
  50. void EditorDebugDrawTextComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  51. {
  52. DebugDrawTextComponent::GetProvidedServices(provided);
  53. }
  54. void EditorDebugDrawTextComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  55. {
  56. DebugDrawTextComponent::GetIncompatibleServices(incompatible);
  57. }
  58. void EditorDebugDrawTextComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  59. {
  60. DebugDrawTextComponent::GetRequiredServices(required);
  61. }
  62. void EditorDebugDrawTextComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  63. {
  64. DebugDrawTextComponent::GetDependentServices(dependent);
  65. }
  66. void EditorDebugDrawTextComponent::Init()
  67. {
  68. m_element.m_owningEditorComponent = GetId();
  69. }
  70. void EditorDebugDrawTextComponent::Activate()
  71. {
  72. if (m_settings.m_visibleInEditor)
  73. {
  74. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  75. }
  76. }
  77. void EditorDebugDrawTextComponent::Deactivate()
  78. {
  79. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  80. }
  81. void EditorDebugDrawTextComponent::OnPropertyUpdate()
  82. {
  83. // Property updated, we need to update the system component (which handles drawing the components) with our new info
  84. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  85. if (m_settings.m_visibleInEditor)
  86. {
  87. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  88. }
  89. }
  90. } // namespace DebugDraw