2022-04-18 07:34:05 +00:00
|
|
|
#ifndef GAME_CLIENT_COMPONENTS_TOOLTIPS_H
|
|
|
|
#define GAME_CLIENT_COMPONENTS_TOOLTIPS_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <game/client/component.h>
|
|
|
|
#include <game/client/ui.h>
|
|
|
|
|
2022-04-29 23:00:50 +00:00
|
|
|
#include <optional>
|
2022-04-18 07:34:05 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
struct CTooltip
|
|
|
|
{
|
2022-04-18 07:34:21 +00:00
|
|
|
CUIRect m_Rect;
|
|
|
|
const char *m_pText;
|
|
|
|
float m_WidthHint;
|
2022-04-30 08:05:28 +00:00
|
|
|
bool m_OnScreen; // used to know if the tooltip should be rendered.
|
2022-04-18 07:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A component that manages and renders UI tooltips.
|
2022-07-08 16:33:33 +00:00
|
|
|
*
|
2022-04-18 07:34:05 +00:00
|
|
|
* Should be among the last components to render.
|
|
|
|
*/
|
|
|
|
class CTooltips : public CComponent
|
|
|
|
{
|
2022-04-18 07:34:21 +00:00
|
|
|
std::unordered_map<uintptr_t, CTooltip> m_Tooltips;
|
2022-04-29 23:00:50 +00:00
|
|
|
std::optional<std::reference_wrapper<CTooltip>> m_ActiveTooltip;
|
2022-07-10 13:33:23 +00:00
|
|
|
int64_t m_HoverTime;
|
2022-04-18 07:34:05 +00:00
|
|
|
|
2022-04-18 07:34:21 +00:00
|
|
|
/**
|
2022-07-08 16:33:33 +00:00
|
|
|
* The passed tooltip is only actually set if there is no currently active tooltip.
|
|
|
|
*
|
|
|
|
* @param Tooltip A reference to the tooltip that should be active.
|
|
|
|
*/
|
2022-04-18 07:34:21 +00:00
|
|
|
void SetActiveTooltip(CTooltip &Tooltip);
|
2022-04-18 07:34:05 +00:00
|
|
|
|
2022-04-18 07:34:21 +00:00
|
|
|
inline void ClearActiveTooltip();
|
2022-04-18 07:34:05 +00:00
|
|
|
|
|
|
|
public:
|
2022-04-18 07:34:21 +00:00
|
|
|
CTooltips();
|
|
|
|
virtual int Sizeof() const override { return sizeof(*this); }
|
2022-04-18 07:34:05 +00:00
|
|
|
|
2022-04-18 07:34:21 +00:00
|
|
|
/**
|
2022-04-18 07:34:05 +00:00
|
|
|
* Adds the tooltip to a cache and renders it when active.
|
2022-07-08 16:33:33 +00:00
|
|
|
*
|
|
|
|
* On the first call to this function, the data passed is cached, afterwards the calls are used to detect if the tooltip should be activated.
|
|
|
|
*
|
2022-04-18 07:34:05 +00:00
|
|
|
* For now only works correctly with single line tooltips, since Text width calculation gets broken when there are multiple lines.
|
|
|
|
*
|
|
|
|
* @param pID The ID of the tooltip. Usually a reference to some g_Config value.
|
|
|
|
* @param pNearTo Place the tooltip near this rect.
|
|
|
|
* @param pText The text to display in the tooltip
|
|
|
|
*/
|
2022-04-18 07:34:21 +00:00
|
|
|
void DoToolTip(const void *pID, const CUIRect *pNearRect, const char *pText, float WidthHint = -1.0f);
|
2022-04-18 07:34:05 +00:00
|
|
|
|
2022-04-18 07:34:21 +00:00
|
|
|
virtual void OnReset() override;
|
|
|
|
virtual void OnRender() override;
|
2022-04-18 07:34:05 +00:00
|
|
|
};
|
|
|
|
|
2022-04-18 07:55:50 +00:00
|
|
|
#endif
|