Close #18318: Refactor MapTooltip window to class (#19914)

This commit is contained in:
Tulio Leao 2023-04-13 14:16:14 -03:00 committed by GitHub
parent 78aa02fe8a
commit d0c7d0f6fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 53 deletions

View File

@ -23,16 +23,7 @@ static Widget window_map_tooltip_widgets[] = {
WIDGETS_END,
};
static void WindowMapTooltipUpdate(WindowBase *w);
static void WindowMapTooltipPaint(WindowBase *w, DrawPixelInfo& dpi);
static WindowEventList window_map_tooltip_events([](auto& events)
{
events.update = &WindowMapTooltipUpdate;
events.paint = &WindowMapTooltipPaint;
});
// clang-format on
#define MAP_TOOLTIP_ARGS
static ScreenCoordsXY _lastCursor;
@ -42,6 +33,33 @@ static void WindowMapTooltipOpen();
static Formatter _mapTooltipArgs;
class MapTooltip final : public Window
{
public:
MapTooltip()
{
widgets = window_map_tooltip_widgets;
}
void OnUpdate() override
{
Invalidate();
}
void OnDraw(DrawPixelInfo& dpi) override
{
StringId stringId;
std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(StringId));
if (stringId == STR_NONE)
{
return;
}
auto stringCoords = windowPos + ScreenCoordsXY{ width / 2, height / 2 };
DrawTextWrapped(dpi, stringCoords, width, STR_MAP_TOOLTIP_STRINGID, _mapTooltipArgs, { TextAlignment::CENTRE });
}
};
void SetMapTooltip(Formatter& ft)
{
_mapTooltipArgs = ft;
@ -52,10 +70,6 @@ const Formatter& GetMapTooltip()
return _mapTooltipArgs;
}
/**
*
* rct2: 0x006EE77A
*/
void WindowMapTooltipUpdateVisibility()
{
if (ThemeGetFlags() & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR)
@ -94,58 +108,23 @@ void WindowMapTooltipUpdateVisibility()
}
}
/**
*
* rct2: 0x006A7C43
*/
static void WindowMapTooltipOpen()
{
WindowBase* w;
constexpr int32_t width = 200;
constexpr int32_t height = 44;
const CursorState* state = ContextGetCursorState();
ScreenCoordsXY pos = { state->position.x - (width / 2), state->position.y + 15 };
auto pos = state->position + ScreenCoordsXY{ -width / 2, 15 };
w = WindowFindByClass(WindowClass::MapTooltip);
if (w == nullptr)
{
w = WindowCreate(
pos, width, height, &window_map_tooltip_events, WindowClass::MapTooltip,
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
w->widgets = window_map_tooltip_widgets;
}
else
if (auto w = WindowFindByClass(WindowClass::MapTooltip))
{
w->Invalidate();
w->windowPos = pos;
w->width = width;
w->height = height;
}
}
/**
*
* rct2: 0x006EE8CE
*/
static void WindowMapTooltipUpdate(WindowBase* w)
{
w->Invalidate();
}
/**
*
* rct2: 0x006EE894
*/
static void WindowMapTooltipPaint(WindowBase* w, DrawPixelInfo& dpi)
{
StringId stringId;
std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(StringId));
if (stringId == STR_NONE)
else
{
return;
w = WindowCreate<MapTooltip>(
WindowClass::MapTooltip, pos, width, height, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
}
ScreenCoordsXY stringCoords(w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2));
DrawTextWrapped(dpi, stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, _mapTooltipArgs, { TextAlignment::CENTRE });
}