2016-05-04 19:24:41 +02:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
2014-10-17 03:01:58 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
2014-10-17 03:01:58 +02:00
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
2014-10-17 03:01:58 +02:00
|
|
|
*****************************************************************************/
|
2016-05-04 19:24:41 +02:00
|
|
|
#pragma endregion
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
#include "../input.h"
|
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
2017-02-18 16:45:10 +01:00
|
|
|
#include "../localisation/localisation.h"
|
|
|
|
#include "../platform/platform.h"
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
static rct_widget window_map_tooltip_widgets[] = {
|
2016-07-14 14:07:49 +02:00
|
|
|
{ WWT_IMGBTN, 0, 0, 199, 0, 29, 0xFFFFFFFF, STR_NONE },
|
2014-10-17 03:01:58 +02:00
|
|
|
{ WIDGETS_END }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void window_map_tooltip_update(rct_window *w);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_map_tooltip_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
|
|
|
|
static rct_window_event_list window_map_tooltip_events = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-10-17 03:01:58 +02:00
|
|
|
window_map_tooltip_update,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-10-17 03:01:58 +02:00
|
|
|
window_map_tooltip_paint,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL
|
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
|
|
|
|
2017-01-04 22:17:08 +01:00
|
|
|
static sint32 _lastCursorX;
|
|
|
|
static sint32 _lastCursorY;
|
|
|
|
static sint32 _cursorHoldDuration;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
static void window_map_tooltip_open();
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006EE77A
|
|
|
|
*/
|
|
|
|
void window_map_tooltip_update_visibility()
|
|
|
|
{
|
2017-02-27 20:20:41 +01:00
|
|
|
sint32 cursorX, cursorY;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2016-09-05 23:37:57 +02:00
|
|
|
cursorX = gCursorState.x;
|
|
|
|
cursorY = gCursorState.y;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
// Check for cursor movement
|
|
|
|
_cursorHoldDuration++;
|
2017-02-27 20:20:41 +01:00
|
|
|
if (abs(cursorX - _lastCursorX) > 5 || abs(cursorY - _lastCursorY) > 5 || (input_test_flag(INPUT_FLAG_5)))
|
2014-10-17 03:01:58 +02:00
|
|
|
_cursorHoldDuration = 0;
|
|
|
|
|
|
|
|
_lastCursorX = cursorX;
|
|
|
|
_lastCursorY = cursorY;
|
|
|
|
|
|
|
|
// Show or hide tooltip
|
2016-05-18 01:00:08 +02:00
|
|
|
rct_string_id stringId;
|
|
|
|
memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id));
|
|
|
|
|
|
|
|
if (_cursorHoldDuration < 25 ||
|
|
|
|
stringId == STR_NONE ||
|
2017-02-27 20:20:41 +01:00
|
|
|
(input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z | PLACE_OBJECT_MODIFIER_SHIFT_Z)) ||
|
2014-10-17 03:01:58 +02:00
|
|
|
window_find_by_class(WC_ERROR) != NULL
|
|
|
|
) {
|
|
|
|
window_close_by_class(WC_MAP_TOOLTIP);
|
|
|
|
} else {
|
|
|
|
window_map_tooltip_open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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;
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 x, y, width, height;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
width = 200;
|
|
|
|
height = 44;
|
2016-09-05 23:37:57 +02:00
|
|
|
x = gCursorState.x - (width / 2);
|
|
|
|
y = gCursorState.y + 15;
|
2014-10-17 03:01:58 +02:00
|
|
|
|
|
|
|
w = window_find_by_class(WC_MAP_TOOLTIP);
|
|
|
|
if (w == NULL) {
|
2014-10-21 12:07:11 +02:00
|
|
|
w = window_create(
|
2015-10-03 16:48:25 +02:00
|
|
|
x, y, width, height, &window_map_tooltip_events, WC_MAP_TOOLTIP, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND
|
2014-10-21 12:07:11 +02:00
|
|
|
);
|
|
|
|
w->widgets = window_map_tooltip_widgets;
|
2014-10-17 03:01:58 +02:00
|
|
|
} else {
|
|
|
|
window_invalidate(w);
|
|
|
|
w->x = x;
|
|
|
|
w->y = y;
|
|
|
|
w->width = width;
|
|
|
|
w->height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-17 03:01:58 +02:00
|
|
|
* rct2: 0x006EE8CE
|
|
|
|
*/
|
|
|
|
static void window_map_tooltip_update(rct_window *w)
|
|
|
|
{
|
|
|
|
window_invalidate(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-17 03:01:58 +02:00
|
|
|
* rct2: 0x006EE894
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_map_tooltip_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-10-17 03:01:58 +02:00
|
|
|
{
|
2016-05-18 01:00:08 +02:00
|
|
|
rct_string_id stringId;
|
|
|
|
memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id));
|
|
|
|
if (stringId == STR_NONE) {
|
2014-10-17 03:01:58 +02:00
|
|
|
return;
|
2016-05-18 01:00:08 +02:00
|
|
|
}
|
2014-10-17 03:01:58 +02:00
|
|
|
|
2016-11-13 18:20:30 +01:00
|
|
|
gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, w->x + (w->width / 2), w->y + (w->height / 2), w->width, STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK);
|
2015-12-21 05:03:37 +01:00
|
|
|
}
|