DebugDrawTextComponent.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "DebugDrawTextComponent.h"
  11. namespace DebugDraw
  12. {
  13. void DebugDrawTextElement::Reflect(AZ::ReflectContext* context)
  14. {
  15. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  16. if (serializeContext)
  17. {
  18. serializeContext->Class<DebugDrawTextElement>()
  19. ->Version(1)
  20. ->Field("Text", &DebugDrawTextElement::m_text)
  21. ->Field("Color", &DebugDrawTextElement::m_color)
  22. ->Field("DrawMode", &DebugDrawTextElement::m_drawMode)
  23. ->Field("WorldLocation", &DebugDrawTextElement::m_worldLocation)
  24. ->Field("TargetEntity", &DebugDrawTextElement::m_targetEntityId)
  25. ->Field("Centered", &DebugDrawTextElement::m_centered)
  26. ->Field("Size", &DebugDrawTextElement::m_size)
  27. ;
  28. AZ::EditContext* editContext = serializeContext->GetEditContext();
  29. if (editContext)
  30. {
  31. editContext->Class<DebugDrawTextElement>("DebugDraw Text element settings", "Settings for DebugDraw text element.")
  32. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  33. ->Attribute(AZ::Edit::Attributes::Category, "Debugging")
  34. ->DataElement(0, &DebugDrawTextElement::m_text, "Text", "The Debug Text.")
  35. ->DataElement(0, &DebugDrawTextElement::m_color, "Color", "Text Color.")
  36. ->DataElement(0, &DebugDrawTextElement::m_size, "Size", "Text size.")
  37. ->DataElement(0, &DebugDrawTextElement::m_drawMode, "Draw Mode", "Draw Mode Preference.")
  38. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &DebugDrawTextElement::m_drawMode, "Draw Mode", "Draw Mode Preference.")
  39. ->EnumAttribute(DrawMode::OnScreen, "Screen Space")
  40. ->EnumAttribute(DrawMode::InWorld, "World Space")
  41. ->DataElement(0, &DebugDrawTextElement::m_centered, "Centered", "Center align the text if enabled, otherwise left align.")
  42. // Currently supports World Space placement on component owners location Or exact placement via behavior context / scripting (TBC)
  43. //->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
  44. //->DataElement(AZ::Edit::UIHandlers::Default, &DebugDrawTextElement::m_targetEntityId, "TargetEntity", "The target entity to position debug text at.")
  45. //->Attribute(AZ::Edit::Attributes::Visibility, &DebugDrawTextElement::isWorldSpace)
  46. ;
  47. }
  48. }
  49. }
  50. void DebugDrawTextComponent::Reflect(AZ::ReflectContext* context)
  51. {
  52. DebugDrawTextElement::Reflect(context);
  53. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  54. {
  55. serialize->Class<DebugDrawTextComponent, AZ::Component>()
  56. ->Version(0)
  57. ->Field("TextElement", &DebugDrawTextComponent::m_element)
  58. ;
  59. }
  60. }
  61. DebugDrawTextComponent::DebugDrawTextComponent(const DebugDrawTextElement& textElement)
  62. : m_element(textElement)
  63. {
  64. m_element.m_owningEditorComponent = AZ::InvalidComponentId;
  65. }
  66. void DebugDrawTextComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  67. {
  68. provided.push_back(AZ_CRC_CE("DebugDrawTextService"));
  69. }
  70. void DebugDrawTextComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  71. {
  72. (void)incompatible;
  73. }
  74. void DebugDrawTextComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  75. {
  76. (void)required;
  77. }
  78. void DebugDrawTextComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  79. {
  80. (void)dependent;
  81. }
  82. void DebugDrawTextComponent::Init()
  83. {
  84. }
  85. void DebugDrawTextComponent::Activate()
  86. {
  87. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  88. }
  89. void DebugDrawTextComponent::Deactivate()
  90. {
  91. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  92. }
  93. } // namespace DebugDraw