UiTooltipDisplayComponent.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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/UiTooltipDisplayBus.h>
  10. #include <LyShine/Bus/UiInitializationBus.h>
  11. #include <LyShine/Bus/UiTransformBus.h>
  12. #include <LyShine/Animation/IUiAnimation.h>
  13. #include <LyShine/UiComponentTypes.h>
  14. #include <AzCore/Component/Component.h>
  15. #include <AzCore/Serialization/SerializeContext.h>
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////
  17. class UiTooltipDisplayComponent
  18. : public AZ::Component
  19. , public UiTooltipDisplayBus::Handler
  20. , public UiInitializationBus::Handler
  21. , public IUiAnimationListener
  22. {
  23. public: //types
  24. using EntityComboBoxVec = AZStd::vector<AZStd::pair<AZ::EntityId, AZStd::string> >;
  25. using SequenceComboBoxVec = AZStd::vector<AZStd::string>;
  26. enum class State
  27. {
  28. Hiding,
  29. Hidden,
  30. DelayBeforeShow,
  31. Showing,
  32. Shown
  33. };
  34. public: // member functions
  35. AZ_COMPONENT(UiTooltipDisplayComponent, LyShine::UiTooltipDisplayComponentUuid, AZ::Component);
  36. UiTooltipDisplayComponent();
  37. ~UiTooltipDisplayComponent() override;
  38. // UiTooltipDisplayInterface
  39. TriggerMode GetTriggerMode() override;
  40. void SetTriggerMode(TriggerMode triggerMode) override;
  41. bool GetAutoPosition() override;
  42. void SetAutoPosition(bool autoPosition) override;
  43. AutoPositionMode GetAutoPositionMode() override;
  44. void SetAutoPositionMode(AutoPositionMode autoPositionMode) override;
  45. const AZ::Vector2& GetOffset() override;
  46. void SetOffset(const AZ::Vector2& offset) override;
  47. bool GetAutoSize() override;
  48. void SetAutoSize(bool autoSize) override;
  49. AZ::EntityId GetTextEntity() override;
  50. void SetTextEntity(AZ::EntityId textEntity) override;
  51. float GetDelayTime() override;
  52. void SetDelayTime(float delayTime) override;
  53. float GetDisplayTime() override;
  54. void SetDisplayTime(float displayTime) override;
  55. void PrepareToShow(AZ::EntityId tooltipElement) override;
  56. void Hide() override;
  57. void Update() override;
  58. // ~UiTooltipDisplayInterface
  59. // UiInitializationInterface
  60. void InGamePostActivate() override;
  61. // ~UiInitializationInterface
  62. //! IUiAnimationListener
  63. void OnUiAnimationEvent(EUiAnimationEvent uiAnimationEvent, IUiAnimSequence* pAnimSequence) override;
  64. // ~IUiAnimationListener
  65. State GetState();
  66. public: // static member functions
  67. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  68. {
  69. provided.push_back(AZ_CRC("UiTooltipDisplayService", 0xb2f093fd));
  70. }
  71. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  72. {
  73. incompatible.push_back(AZ_CRC("UiTooltipService", 0x78437544));
  74. incompatible.push_back(AZ_CRC("UiTooltipDisplayService", 0xb2f093fd));
  75. }
  76. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  77. {
  78. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  79. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  80. }
  81. static void Reflect(AZ::ReflectContext* context);
  82. protected: // member functions
  83. // AZ::Component
  84. void Activate() override;
  85. void Deactivate() override;
  86. // ~AZ::Component
  87. AZ_DISABLE_COPY_MOVE(UiTooltipDisplayComponent);
  88. //! Set the current state of the tooltip
  89. void SetState(State state);
  90. //! Skip to the next state if the current state is a transitional one
  91. void EndTransitionState();
  92. //! Show the display element
  93. void Show();
  94. //! Resize the display element so that its child text element is the same size as the
  95. //! text string. The text element's anchors are assumed to be set up so that the text
  96. //! element grows/shrinks with its parent.
  97. void AutoResize();
  98. //! Resize an element by a specified delta
  99. void ResizeElementByDelta(AZ::EntityId entityId, const AZ::Vector2& delta);
  100. //! Position the display element according to the positioning mode
  101. void AutoPosition();
  102. //! Move the display element to a specified position
  103. void MoveToPosition(const AZ::Vector2& point, const AZ::Vector2& offsetFromPoint);
  104. //! Change the vertical position of the display element if it exceeds a bounding rect.
  105. //! If the element exceeds the top of the rect, move it so that its top is a certain
  106. //! distance below the specified point. If the element exceeds the bottom of the rect,
  107. //! move it so that its bottom is a certain distance above the specified point.
  108. void CheckBoundsAndChangeYPosition(const UiTransformInterface::Rect& boundsRect, float yPoint, float yOffsetFromPoint);
  109. //! Constrain the display element to a bounding rect
  110. void ConstrainToBounds(const UiTransformInterface::Rect& boundsRect);
  111. //! Get the axis aligned rect of the display element
  112. UiTransformInterface::Rect GetAxisAlignedRect();
  113. //! Get the canvas's animation system
  114. IUiAnimationSystem* GetAnimationSystem();
  115. //! Get a sequence that is owned by the canvas's animation system
  116. IUiAnimSequence* GetSequence(const AZStd::string& sequenceName, IUiAnimationSystem*& animSystemOut);
  117. //! Initialize the sequence before playing
  118. void PrepareSequenceForPlay(const AZStd::string& sequenceName, IUiAnimSequence*& sequence, IUiAnimationSystem*& animSystemOut);
  119. EntityComboBoxVec PopulateTextEntityList();
  120. SequenceComboBoxVec PopulateSequenceList();
  121. private: // static member functions
  122. static bool VersionConverter(AZ::SerializeContext& context,
  123. AZ::SerializeContext::DataElementNode& classElement);
  124. protected: // data
  125. TriggerMode m_triggerMode;
  126. bool m_autoPosition;
  127. AutoPositionMode m_autoPositionMode;
  128. AZ::Vector2 m_offset;
  129. AZ::EntityId m_textEntity;
  130. bool m_autoSize;
  131. float m_delayTime;
  132. float m_displayTime;
  133. AZStd::string m_showSequenceName;
  134. AZStd::string m_hideSequenceName;
  135. State m_state;
  136. float m_stateStartTime;
  137. float m_curDelayTime;
  138. float m_timeSinceLastShown;
  139. AZ::EntityId m_tooltipElement;
  140. float m_maxWrapTextWidth;
  141. IUiAnimSequence* m_showSequence;
  142. IUiAnimSequence* m_hideSequence;
  143. bool m_listeningForAnimationEvents = false;
  144. };