mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 05:23:04 +01:00
* Indent definitions in About, AssetPacks windows * Indent definitions in Banner, Changelog, CustomCurrency windows * Indent DebugPaint, DemolishRidePrompt windows * Indent EditorBottomToolbar, EditorInventionsList * Indent EditorObjectiveOptions, EditorScenarioOptions * Indent Finances * Indent Footpath * Indent GameBottomToolbar * Indent Guest window * Indent GuestList, InstallTrack windows * Indent Land, LandRights windows * Indent LoadSave, Main, MapGen, MapTooltip windows * Indent MazeConstruction * Indent Multiplayer * Indent NetworkStatus * Indent NewCampaign * Indent NewRide window * Indent News window * Indent NewsOptions window * Indent ObjectLoadError window * Indent Options window * Indent Park window * Indent PatrolArea window * Indent Player window * Indent RefurbishRidePrompt window * Indent Research window * Indent Ride window * Indent RideConstruction * Indent RideList * Indent SavePrompt * Indent ScenarioSelect widgets * Indent scenario window * Indent scenery scatter window defs * Indent server list window * Indent server start window§ * Indent ShortcutKeys window * Indent Sign window * Indent Staff window * Indent StaffFirePrompt window * Indent StaffList window defs * Indent Themes window defs * Indent TileInspector window defs * Indent TitleExit, TitleMenu, TitleOptions, Tooltip windows * Indent TrackDesignManage window defs * Indent TrackDesignPlace defs * Indent TrackList def * Indent Transparency window defs * Indent ViewClipping window defs * Indent Viewport window defs * Indent Water window defs
131 lines
4.0 KiB
C++
131 lines
4.0 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
|
*
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
*
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
*****************************************************************************/
|
|
|
|
#include <openrct2-ui/UiContext.h>
|
|
#include <openrct2-ui/input/InputManager.h>
|
|
#include <openrct2-ui/interface/Theme.h>
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
#include <openrct2-ui/windows/Window.h>
|
|
#include <openrct2/Context.h>
|
|
#include <openrct2/Input.h>
|
|
#include <openrct2/drawing/Drawing.h>
|
|
#include <openrct2/localisation/Formatter.h>
|
|
|
|
namespace OpenRCT2::Ui::Windows
|
|
{
|
|
// clang-format off
|
|
static Widget window_map_tooltip_widgets[] = {
|
|
MakeWidget({0, 0}, {200, 30}, WindowWidgetType::ImgBtn, WindowColour::Primary),
|
|
kWidgetsEnd,
|
|
};
|
|
// clang-format on
|
|
|
|
static ScreenCoordsXY _lastCursor;
|
|
static int32_t _cursorHoldDuration;
|
|
|
|
static void WindowMapTooltipOpen();
|
|
|
|
static Formatter _mapTooltipArgs;
|
|
|
|
class MapTooltip final : public Window
|
|
{
|
|
public:
|
|
void OnOpen() override
|
|
{
|
|
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;
|
|
}
|
|
|
|
const Formatter& GetMapTooltip()
|
|
{
|
|
return _mapTooltipArgs;
|
|
}
|
|
|
|
void WindowMapTooltipUpdateVisibility()
|
|
{
|
|
if (ThemeGetFlags() & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR)
|
|
{
|
|
// The map tooltip is drawn by the bottom toolbar
|
|
WindowInvalidateByClass(WindowClass::BottomToolbar);
|
|
return;
|
|
}
|
|
|
|
const CursorState* state = ContextGetCursorState();
|
|
auto cursor = state->position;
|
|
auto cursorChange = cursor - _lastCursor;
|
|
|
|
// Check for cursor movement
|
|
_cursorHoldDuration++;
|
|
if (abs(cursorChange.x) > 5 || abs(cursorChange.y) > 5 || (InputTestFlag(INPUT_FLAG_5))
|
|
|| InputGetState() == InputState::ViewportRight)
|
|
_cursorHoldDuration = 0;
|
|
|
|
_lastCursor = cursor;
|
|
|
|
// Show or hide tooltip
|
|
StringId stringId;
|
|
std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(StringId));
|
|
|
|
auto& im = GetInputManager();
|
|
if (_cursorHoldDuration < 25 || stringId == STR_NONE || im.IsModifierKeyPressed(ModifierKey::ctrl)
|
|
|| im.IsModifierKeyPressed(ModifierKey::shift) || WindowFindByClass(WindowClass::Error) != nullptr)
|
|
{
|
|
WindowCloseByClass(WindowClass::MapTooltip);
|
|
}
|
|
else
|
|
{
|
|
WindowMapTooltipOpen();
|
|
}
|
|
}
|
|
|
|
static void WindowMapTooltipOpen()
|
|
{
|
|
constexpr int32_t width = 200;
|
|
constexpr int32_t height = 44;
|
|
const CursorState* state = ContextGetCursorState();
|
|
auto pos = state->position + ScreenCoordsXY{ -width / 2, 15 };
|
|
|
|
if (auto w = WindowFindByClass(WindowClass::MapTooltip))
|
|
{
|
|
w->Invalidate();
|
|
w->windowPos = pos;
|
|
w->width = width;
|
|
w->height = height;
|
|
}
|
|
else
|
|
{
|
|
w = WindowCreate<MapTooltip>(
|
|
WindowClass::MapTooltip, pos, width, height, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
|
|
}
|
|
}
|
|
} // namespace OpenRCT2::Ui::Windows
|