UiTooltipComponent.h 4.3 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/UiCanvasUpdateNotificationBus.h>
  10. #include <LyShine/Bus/UiInteractableBus.h>
  11. #include <LyShine/Bus/UiCanvasBus.h>
  12. #include <LyShine/Bus/UiTooltipDisplayBus.h>
  13. #include <LyShine/Bus/UiTooltipDataPopulatorBus.h>
  14. #include <LyShine/Bus/UiTooltipBus.h>
  15. #include <LyShine/UiComponentTypes.h>
  16. #include <AzCore/Component/Component.h>
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////
  18. class UiTooltipComponent
  19. : public AZ::Component
  20. , public UiCanvasUpdateNotificationBus::Handler
  21. , public UiInteractableNotificationBus::Handler
  22. , public UiCanvasInputNotificationBus::Handler
  23. , public UiTooltipDisplayNotificationBus::Handler
  24. , public UiTooltipDataPopulatorBus::Handler
  25. , public UiTooltipBus::Handler
  26. {
  27. public: // member functions
  28. AZ_COMPONENT(UiTooltipComponent, LyShine::UiTooltipComponentUuid, AZ::Component);
  29. UiTooltipComponent();
  30. ~UiTooltipComponent() override;
  31. // UiCanvasUpdateNotification
  32. void Update(float deltaTime) override;
  33. // ~UiCanvasUpdateNotification
  34. // UiInteractableNotifications
  35. void OnHoverStart() override;
  36. void OnHoverEnd() override;
  37. void OnPressed() override;
  38. void OnReleased() override;
  39. // ~UiInteractableNotifications
  40. // UiCanvasInputNotifications
  41. void OnCanvasPrimaryReleased(AZ::EntityId entityId) override;
  42. // ~UiCanvasInputNotifications
  43. // UiTooltipDisplayNotifications
  44. void OnHiding() override;
  45. void OnHidden() override;
  46. // ~UiTooltipDisplayNotifications
  47. // UiTooltipDataPopulatorInterface
  48. void PushDataToDisplayElement(AZ::EntityId displayEntityId) override;
  49. // ~UiTooltipDataPopulatorInterface
  50. // UiTooltipInterface
  51. AZStd::string GetText() override;
  52. void SetText(const AZStd::string& text) override;
  53. // ~UiTooltipInterface
  54. public: // static member functions
  55. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  56. {
  57. provided.push_back(AZ_CRC("UiTooltipService", 0x78437544));
  58. }
  59. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  60. {
  61. incompatible.push_back(AZ_CRC("UiTooltipService", 0x78437544));
  62. incompatible.push_back(AZ_CRC("UiTooltipDisplayService", 0xb2f093fd));
  63. }
  64. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  65. {
  66. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  67. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  68. required.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  69. }
  70. static void Reflect(AZ::ReflectContext* context);
  71. protected: // member functions
  72. // AZ::Component
  73. void Activate() override;
  74. void Deactivate() override;
  75. // ~AZ::Component
  76. AZ_DISABLE_COPY_MOVE(UiTooltipComponent);
  77. // Hide the tooltip or cancel it from showing if in delay
  78. void HideDisplayElement();
  79. // Handle the tooltip being hidden implicitly or explicitly
  80. void HandleDisplayElementHidden();
  81. // Trigger the tooltip for display
  82. void TriggerTooltip(UiTooltipDisplayInterface::TriggerMode triggerMode);
  83. // Return true if the tooltip has been triggered for display or is already showing.
  84. // Return false if tooltip is hiding or is hidden
  85. bool IsTriggered();
  86. // Return whether the tooltip has been triggered for display by the specified mode
  87. bool IsTriggeredWithMode(UiTooltipDisplayInterface::TriggerMode triggerMode);
  88. // Get the display element's trigger mode which could have changed after the tooltip
  89. // was triggered to display and may be different from m_curTriggerMode
  90. UiTooltipDisplayInterface::TriggerMode GetDisplayElementTriggerMode();
  91. protected: // data
  92. //! The tooltip text
  93. AZStd::string m_text;
  94. // Valid when the tooltip has been triggered to show or is already showing.
  95. // Invalid when the tooltip is hiding or is hidden
  96. AZ::EntityId m_curDisplayElementId;
  97. // The trigger mode that caused the tooltip to currently display
  98. UiTooltipDisplayInterface::TriggerMode m_curTriggerMode;
  99. };