2014-10-17 03:01:58 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2014-10-17 03:01:58 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-10-17 03:01:58 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-10-17 03:01:58 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
#include "../interface/Theme.h"
|
2017-08-02 00:20:32 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-10-21 17:57:37 +02:00
|
|
|
#include <openrct2/Context.h>
|
2017-12-12 14:52:57 +01:00
|
|
|
#include <openrct2/Input.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2021-12-12 00:06:06 +01:00
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-10-17 03:01:58 +02:00
|
|
|
static rct_widget window_map_tooltip_widgets[] = {
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget({0, 0}, {200, 30}, WindowWidgetType::ImgBtn, WindowColour::Primary),
|
2021-09-26 11:11:42 +02:00
|
|
|
WIDGETS_END,
|
2014-10-17 03:01:58 +02:00
|
|
|
};
|
|
|
|
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowMapTooltipUpdate(rct_window *w);
|
|
|
|
static void WindowMapTooltipPaint(rct_window *w, rct_drawpixelinfo *dpi);
|
2015-07-10 02:39:16 +02:00
|
|
|
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_map_tooltip_events([](auto& events)
|
|
|
|
{
|
2021-11-23 14:18:07 +01:00
|
|
|
events.update = &WindowMapTooltipUpdate;
|
|
|
|
events.paint = &WindowMapTooltipPaint;
|
2020-09-28 20:36:15 +02:00
|
|
|
});
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2015-10-20 20:16:30 +02:00
|
|
|
#define MAP_TOOLTIP_ARGS
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2019-12-15 03:30:55 +01:00
|
|
|
static ScreenCoordsXY _lastCursor;
|
2018-06-20 17:28:51 +02:00
|
|
|
static int32_t _cursorHoldDuration;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowMapTooltipOpen();
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2020-09-29 02:45:28 +02:00
|
|
|
static Formatter _mapTooltipArgs;
|
|
|
|
|
|
|
|
void SetMapTooltip(Formatter& ft)
|
|
|
|
{
|
|
|
|
_mapTooltipArgs = ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Formatter& GetMapTooltip()
|
|
|
|
{
|
|
|
|
return _mapTooltipArgs;
|
|
|
|
}
|
|
|
|
|
2014-10-17 03:01:58 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006EE77A
|
|
|
|
*/
|
2021-11-23 14:18:07 +01:00
|
|
|
void WindowMapTooltipUpdateVisibility()
|
2014-10-17 03:01:58 +02:00
|
|
|
{
|
2020-11-03 11:59:00 +01:00
|
|
|
if (ThemeGetFlags() & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR)
|
2017-08-16 22:27:20 +02:00
|
|
|
{
|
|
|
|
// The map tooltip is drawn by the bottom toolbar
|
|
|
|
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
const CursorState* state = context_get_cursor_state();
|
2019-12-15 03:30:55 +01:00
|
|
|
auto cursor = state->position;
|
2019-12-18 03:33:07 +01:00
|
|
|
auto cursorChange = cursor - _lastCursor;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Check for cursor movement
|
|
|
|
_cursorHoldDuration++;
|
2022-05-21 09:39:13 +02:00
|
|
|
if (abs(cursorChange.x) > 5 || abs(cursorChange.y) > 5 || (input_test_flag(INPUT_FLAG_5))
|
|
|
|
|| input_get_state() == InputState::ViewportRight)
|
2017-06-06 23:24:18 +02:00
|
|
|
_cursorHoldDuration = 0;
|
|
|
|
|
2019-12-15 03:30:55 +01:00
|
|
|
_lastCursor = cursor;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Show or hide tooltip
|
|
|
|
rct_string_id stringId;
|
2020-09-29 02:45:28 +02:00
|
|
|
std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(rct_string_id));
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (_cursorHoldDuration < 25 || stringId == STR_NONE
|
2020-11-02 14:43:35 +01:00
|
|
|
|| InputTestPlaceObjectModifier(
|
2020-04-19 14:08:22 +02:00
|
|
|
static_cast<PLACE_OBJECT_MODIFIER>(PLACE_OBJECT_MODIFIER_COPY_Z | PLACE_OBJECT_MODIFIER_SHIFT_Z))
|
2018-06-22 23:21:44 +02:00
|
|
|
|| window_find_by_class(WC_ERROR) != nullptr)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close_by_class(WC_MAP_TOOLTIP);
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-23 14:18:07 +01:00
|
|
|
WindowMapTooltipOpen();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-10-17 03:01:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-17 03:01:58 +02:00
|
|
|
* rct2: 0x006A7C43
|
|
|
|
*/
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowMapTooltipOpen()
|
2014-10-17 03:01:58 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* w;
|
|
|
|
|
2019-12-15 03:30:55 +01:00
|
|
|
constexpr int32_t width = 200;
|
|
|
|
constexpr int32_t height = 44;
|
2018-06-22 23:21:44 +02:00
|
|
|
const CursorState* state = context_get_cursor_state();
|
2019-12-15 03:30:55 +01:00
|
|
|
ScreenCoordsXY pos = { state->position.x - (width / 2), state->position.y + 15 };
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
w = window_find_by_class(WC_MAP_TOOLTIP);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (w == nullptr)
|
|
|
|
{
|
2020-11-04 05:52:23 +01:00
|
|
|
w = WindowCreate(
|
2019-12-15 03:30:55 +01:00
|
|
|
pos, width, height, &window_map_tooltip_events, WC_MAP_TOOLTIP,
|
2018-06-22 23:21:44 +02:00
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets = window_map_tooltip_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2020-03-01 20:32:35 +01:00
|
|
|
w->windowPos = pos;
|
2017-06-06 23:24:18 +02:00
|
|
|
w->width = width;
|
|
|
|
w->height = height;
|
|
|
|
}
|
2014-10-17 03:01:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-17 03:01:58 +02:00
|
|
|
* rct2: 0x006EE8CE
|
|
|
|
*/
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowMapTooltipUpdate(rct_window* w)
|
2014-10-17 03:01:58 +02:00
|
|
|
{
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2014-10-17 03:01:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-17 03:01:58 +02:00
|
|
|
* rct2: 0x006EE894
|
|
|
|
*/
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowMapTooltipPaint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-10-17 03:01:58 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_string_id stringId;
|
2020-09-29 02:45:28 +02:00
|
|
|
std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(rct_string_id));
|
2018-06-22 23:21:44 +02:00
|
|
|
if (stringId == STR_NONE)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2020-05-10 06:00:26 +02:00
|
|
|
ScreenCoordsXY stringCoords(w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2));
|
2021-02-27 17:17:17 +01:00
|
|
|
DrawTextWrapped(dpi, stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, _mapTooltipArgs, { TextAlignment::CENTRE });
|
2015-12-21 05:03:37 +01:00
|
|
|
}
|