| 1 | #ifndef GAME_CLIENT_TOOLTIPS_H |
| 2 | #define GAME_CLIENT_TOOLTIPS_H |
| 3 | |
| 4 | #include <game/client/component.h> |
| 5 | #include <game/client/ui_rect.h> |
| 6 | |
| 7 | #include <cstdint> |
| 8 | #include <functional> |
| 9 | #include <optional> |
| 10 | #include <unordered_map> |
| 11 | |
| 12 | class CTooltip |
| 13 | { |
| 14 | public: |
| 15 | CTooltip(const void *pId, const CUIRect &Rect, const char *pText, float WidthHint, float FontSize, bool Truncated) : |
| 16 | m_pId(pId), m_Rect(Rect), m_pText(pText), m_WidthHint(WidthHint), m_FontSize(FontSize), m_Truncated(Truncated), m_OnScreen(false) {} |
| 17 | |
| 18 | const void *m_pId; |
| 19 | CUIRect m_Rect; |
| 20 | const char *m_pText; |
| 21 | float m_WidthHint; |
| 22 | float m_FontSize; |
| 23 | bool m_Truncated; |
| 24 | bool m_OnScreen; // used to know if the tooltip should be rendered. |
| 25 | }; |
| 26 | |
| 27 | class CUi; |
| 28 | class ITextRender; |
| 29 | |
| 30 | /** |
| 31 | * A component that manages and renders UI tooltips. |
| 32 | * |
| 33 | * Should be among the last components to render. |
| 34 | */ |
| 35 | class CTooltips |
| 36 | { |
| 37 | std::unordered_map<uintptr_t, CTooltip> m_Tooltips; |
| 38 | std::optional<std::reference_wrapper<CTooltip>> m_ActiveTooltip; |
| 39 | std::optional<std::reference_wrapper<CTooltip>> m_PreviousTooltip; |
| 40 | int64_t m_HoverTime; |
| 41 | |
| 42 | /** |
| 43 | * @param Tooltip A reference to the tooltip that should be active. |
| 44 | */ |
| 45 | void SetActiveTooltip(CTooltip &Tooltip); |
| 46 | |
| 47 | inline void ClearActiveTooltip(); |
| 48 | CUi *m_pUi; |
| 49 | ITextRender *m_pTextRender; |
| 50 | CUi *Ui() { return m_pUi; } |
| 51 | ITextRender *TextRender() { return m_pTextRender; } |
| 52 | |
| 53 | public: |
| 54 | CTooltips() = default; |
| 55 | void Init(CUi *pUi, ITextRender *pTextRender); |
| 56 | |
| 57 | void DoToolTip(const CTooltip &Tooltip); |
| 58 | |
| 59 | void OnReset(); |
| 60 | void OnRender(); |
| 61 | }; |
| 62 | |
| 63 | #endif |
| 64 | |