2014-10-07 18:57:38 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-05-04 19:24:41 +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
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2017-08-12 23:06:12 +02:00
|
|
|
#include <openrct2-ui/input/KeyboardShortcuts.h>
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Window.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
|
|
|
#include <openrct2/config/Config.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-07 18:57:38 +02:00
|
|
|
|
2020-05-05 22:26:14 +02:00
|
|
|
static constexpr const rct_string_id WINDOW_TITLE = STR_SHORTCUT_CHANGE_TITLE;
|
2020-05-09 17:05:01 +02:00
|
|
|
static constexpr const int32_t WW = 250;
|
|
|
|
static constexpr const int32_t WH = 60;
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-10-07 18:57:38 +02:00
|
|
|
enum WINDOW_SHORTCUT_CHANGE_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
2014-10-07 18:57:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// 0x9DE4E0
|
|
|
|
static rct_widget window_shortcut_change_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-10-07 18:57:38 +02:00
|
|
|
};
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_shortcut_change_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_shortcut_change_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2017-05-11 11:45:59 +02:00
|
|
|
// 0x9A3F7C
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_shortcut_change_events([](auto& events)
|
|
|
|
{
|
|
|
|
events.mouse_up = &window_shortcut_change_mouseup;
|
|
|
|
events.paint = &window_shortcut_change_paint;
|
|
|
|
});
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2020-04-05 11:40:19 +02:00
|
|
|
static rct_string_id CurrentShortcutKeyStringId{};
|
|
|
|
|
2020-08-21 17:07:38 +02:00
|
|
|
rct_window* window_shortcut_change_open(OpenRCT2::Input::Shortcut shortcut, rct_string_id key_string_id)
|
2017-06-11 16:16:47 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Move this to window_shortcut_change_open
|
|
|
|
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
2020-04-05 11:40:19 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Save the item we are selecting for new window
|
2020-08-21 04:54:43 +02:00
|
|
|
gKeyboardShortcutChangeId = shortcut;
|
2020-04-05 11:40:19 +02:00
|
|
|
CurrentShortcutKeyStringId = key_string_id;
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0);
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets = window_shortcut_change_widgets;
|
|
|
|
w->enabled_widgets = (1ULL << WIDX_CLOSE);
|
|
|
|
window_init_scroll_widgets(w);
|
2017-06-11 16:16:47 +02:00
|
|
|
return w;
|
2014-10-07 18:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E3AE0
|
|
|
|
*/
|
|
|
|
static void window_shortcut_change_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2015-07-10 02:39:16 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-10-07 18:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E3A9F
|
|
|
|
*/
|
|
|
|
static void window_shortcut_change_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2015-07-10 02:39:16 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_draw_widgets(w, dpi);
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2020-05-10 06:00:26 +02:00
|
|
|
ScreenCoordsXY stringCoords(w->windowPos.x + 125, w->windowPos.y + 30);
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2020-09-30 23:42:04 +02:00
|
|
|
auto ft = Formatter();
|
2020-04-21 21:16:27 +02:00
|
|
|
ft.Add<rct_string_id>(CurrentShortcutKeyStringId);
|
2020-09-30 23:42:04 +02:00
|
|
|
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
|
2015-12-21 05:03:37 +01:00
|
|
|
}
|