OpenRCT2/src/openrct2-ui/windows/MapTooltip.cpp

164 lines
3.9 KiB
C++
Raw Normal View History

2014-10-17 03:01:58 +02:00
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
2014-10-17 03:01:58 +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
*
* 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>
2018-06-22 23:21:44 +02:00
#include <openrct2/localisation/Localisation.h>
2014-10-17 03:01:58 +02:00
// clang-format off
2014-10-17 03:01:58 +02:00
static rct_widget window_map_tooltip_widgets[] = {
{ WWT_IMGBTN, 0, 0, 199, 0, 29, 0xFFFFFFFF, STR_NONE },
{ WIDGETS_END }
2014-10-17 03:01:58 +02:00
};
static void window_map_tooltip_update(rct_window *w);
static void window_map_tooltip_paint(rct_window *w, rct_drawpixelinfo *dpi);
static rct_window_event_list window_map_tooltip_events = {
2017-08-15 10:07:44 +02:00
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
window_map_tooltip_update,
2017-08-15 10:07:44 +02:00
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
window_map_tooltip_paint,
2017-08-15 10:07:44 +02:00
nullptr
2014-10-17 03:01:58 +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
static ScreenCoordsXY _lastCursor;
static int32_t _cursorHoldDuration;
2014-10-17 03:01:58 +02:00
static void window_map_tooltip_open();
/**
*
* rct2: 0x006EE77A
*/
void window_map_tooltip_update_visibility()
{
if (theme_get_flags() & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR)
{
// 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();
auto cursor = state->position;
// Check for cursor movement
_cursorHoldDuration++;
if (abs(cursor.x - _lastCursor.x) > 5 || abs(cursor.y - _lastCursor.y) > 5 || (input_test_flag(INPUT_FLAG_5)))
_cursorHoldDuration = 0;
_lastCursor = cursor;
// Show or hide tooltip
rct_string_id stringId;
std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id));
2018-06-22 23:21:44 +02:00
if (_cursorHoldDuration < 25 || stringId == STR_NONE
|| input_test_place_object_modifier(
2019-11-04 14:02:30 +01:00
(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)
{
window_close_by_class(WC_MAP_TOOLTIP);
2018-06-22 23:21:44 +02:00
}
else
{
window_map_tooltip_open();
}
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
*/
static void window_map_tooltip_open()
{
rct_window* w;
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();
ScreenCoordsXY pos = { state->position.x - (width / 2), state->position.y + 15 };
w = window_find_by_class(WC_MAP_TOOLTIP);
2018-06-22 23:21:44 +02:00
if (w == nullptr)
{
w = window_create(
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);
w->widgets = window_map_tooltip_widgets;
2018-06-22 23:21:44 +02:00
}
else
{
w->Invalidate();
w->x = pos.x;
w->y = pos.y;
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
*/
2018-06-22 23:21:44 +02:00
static void window_map_tooltip_update(rct_window* w)
2014-10-17 03:01:58 +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
*/
2018-06-22 23:21:44 +02:00
static void window_map_tooltip_paint(rct_window* w, rct_drawpixelinfo* dpi)
2014-10-17 03:01:58 +02:00
{
rct_string_id stringId;
std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id));
2018-06-22 23:21:44 +02:00
if (stringId == STR_NONE)
{
return;
}
2014-10-17 03:01:58 +02:00
2018-06-22 23:21:44 +02:00
gfx_draw_string_centred_wrapped(
dpi, gMapTooltipFormatArgs, w->x + (w->width / 2), w->y + (w->height / 2), w->width, STR_MAP_TOOLTIP_STRINGID,
2018-06-22 23:21:44 +02:00
COLOUR_BLACK);
2015-12-21 05:03:37 +01:00
}