UiMarkupButtonComponent.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #pragma once
  9. #include <LyShine/Bus/UiMarkupButtonBus.h>
  10. #include <LyShine/Bus/UiInteractableBus.h>
  11. #include <LyShine/Bus/UiTextBus.h>
  12. #include <LyShine/UiComponentTypes.h>
  13. #include "UiInteractableComponent.h"
  14. // Only needed for internal unit-testing
  15. #include <LyShine.h>
  16. #include <AzCore/Serialization/SerializeContext.h>
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////
  18. class UiMarkupButtonComponent
  19. : public UiInteractableComponent
  20. , public UiMarkupButtonBus::Handler
  21. , public UiClickableTextNotificationsBus::Handler
  22. {
  23. public: // member functions
  24. AZ_COMPONENT(UiMarkupButtonComponent, LyShine::UiMarkupButtonComponentUuid, UiInteractableComponent);
  25. UiMarkupButtonComponent();
  26. ~UiMarkupButtonComponent() override;
  27. // UiMarkupButtonBus
  28. AZ::Color GetLinkColor() override;
  29. void SetLinkColor(const AZ::Color& linkColor) override;
  30. AZ::Color GetLinkHoverColor() override;
  31. void SetLinkHoverColor(const AZ::Color& linkHoverColor) override;
  32. // ~UiMarkupButtonBus
  33. // UiInteractableInterface
  34. bool HandlePressed(AZ::Vector2 point, bool& shouldStayActive) override;
  35. bool HandleReleased(AZ::Vector2 point) override;
  36. // ~UiInteractableInterface
  37. // UiCanvasUpdateNotification
  38. void Update(float deltaTime) override;
  39. // ~UiCanvasUpdateNotification
  40. // UiClickableTextNotifications
  41. void OnClickableTextChanged() override;
  42. // ~UiClickableTextNotifications
  43. public: // static member functions
  44. #if defined(LYSHINE_INTERNAL_UNIT_TEST)
  45. static void UnitTest(CLyShine* lyshine, IConsoleCmdArgs* cmdArgs);
  46. #endif
  47. protected: // member functions
  48. // AZ::Component
  49. void Activate() override;
  50. void Deactivate() override;
  51. // ~AZ::Component
  52. void UpdateHover();
  53. void HandleClickableHoverStart(int clickableRectIndex);
  54. void HandleClickableHoverEnd();
  55. //! Called when the link color changed
  56. void OnLinkColorChanged();
  57. //! Called when the link hover color changed
  58. void OnLinkHoverColorChanged();
  59. protected: // static member functions
  60. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  61. {
  62. provided.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  63. provided.push_back(AZ_CRC("UiNavigationService"));
  64. provided.push_back(AZ_CRC("UiStateActionsService"));
  65. }
  66. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  67. {
  68. incompatible.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  69. incompatible.push_back(AZ_CRC("UiNavigationService"));
  70. incompatible.push_back(AZ_CRC("UiStateActionsService"));
  71. }
  72. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  73. {
  74. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  75. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  76. required.push_back(AZ_CRC("UiTextService"));
  77. }
  78. static void Reflect(AZ::ReflectContext* context);
  79. private: // member functions
  80. AZ_DISABLE_COPY_MOVE(UiMarkupButtonComponent);
  81. private: // static member functions
  82. static bool VersionConverter(AZ::SerializeContext& context,
  83. AZ::SerializeContext::DataElementNode& classElement);
  84. private: // data
  85. UiClickableTextInterface::ClickableTextRects m_clickableTextRects; //!< Filter all interactions against clickable text rects.
  86. AZ::Color m_linkColor = AZ::Color(0.0f, 0.0f, 1.0f, 1.0f); //!< Color to assign to clickable text
  87. AZ::Color m_linkHoverColor = AZ::Color(1.0f, 0.0f, 0.0f, 1.0f); //!< Hover color for clickable text
  88. int m_clickableRectHoverIndex = -1; //!< Index of the clickable rect currently be hovered
  89. int m_clickableRectPressedIndex = -1; //!< Index of the clickable rect that was pressed
  90. };