2014-10-05 15:21:35 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 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-05 15:21:35 +02:00
|
|
|
|
2017-08-06 05:22:00 +02:00
|
|
|
#include "Window.h"
|
2017-08-04 00:21:54 +02:00
|
|
|
|
2018-06-22 23:21:44 +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/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-05 15:21:35 +02:00
|
|
|
|
2017-03-11 22:09:24 +01:00
|
|
|
#define WW 420
|
|
|
|
#define WH 280
|
|
|
|
|
|
|
|
#define WW_SC_MAX 1200
|
|
|
|
#define WH_SC_MAX 800
|
2014-10-05 15:21:35 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-10-05 15:21:35 +02:00
|
|
|
enum WINDOW_SHORTCUT_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_SCROLL,
|
|
|
|
WIDX_RESET
|
2014-10-05 15:21:35 +02:00
|
|
|
};
|
|
|
|
|
2014-10-05 21:56:26 +02:00
|
|
|
// 0x9DE48C
|
2014-10-05 15:21:35 +02:00
|
|
|
static rct_widget window_shortcut_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE },
|
|
|
|
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_SHORTCUTS_TITLE, STR_WINDOW_TITLE_TIP },
|
|
|
|
{ WWT_CLOSEBOX, 0, WW-13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP },
|
|
|
|
{ WWT_SCROLL, 0, 4, WW - 5, 18, WH - 18, SCROLL_VERTICAL, STR_SHORTCUT_LIST_TIP },
|
2018-01-03 20:30:58 +01:00
|
|
|
{ WWT_BUTTON, 0, 4, 153, WH-15, WH - 4, STR_SHORTCUT_ACTION_RESET, STR_SHORTCUT_ACTION_RESET_TIP },
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-10-05 15:21:35 +02:00
|
|
|
};
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_shortcut_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2017-03-11 22:09:24 +01:00
|
|
|
static void window_shortcut_resize(rct_window *w);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_shortcut_invalidate(rct_window *w);
|
|
|
|
static void window_shortcut_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2018-06-20 17:28:51 +02:00
|
|
|
static void window_shortcut_scrollgetsize(rct_window *w, int32_t scrollIndex, int32_t *width, int32_t *height);
|
|
|
|
static void window_shortcut_scrollmousedown(rct_window *w, int32_t scrollIndex, int32_t x, int32_t y);
|
|
|
|
static void window_shortcut_scrollmouseover(rct_window *w, int32_t scrollIndex, int32_t x, int32_t y);
|
|
|
|
static void window_shortcut_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
|
2015-07-10 02:39:16 +02:00
|
|
|
|
|
|
|
static rct_window_event_list window_shortcut_events = {
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_mouseup,
|
|
|
|
window_shortcut_resize,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_scrollgetsize,
|
|
|
|
window_shortcut_scrollmousedown,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_scrollmouseover,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2018-08-04 16:24:24 +02:00
|
|
|
nullptr,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_invalidate,
|
|
|
|
window_shortcut_paint,
|
|
|
|
window_shortcut_scrollpaint
|
2014-10-05 21:56:26 +02:00
|
|
|
};
|
|
|
|
|
2017-08-06 02:26:14 +02:00
|
|
|
const rct_string_id ShortcutStringIds[SHORTCUT_COUNT] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
STR_SHORTCUT_CLOSE_TOP_MOST_WINDOW,
|
|
|
|
STR_SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS,
|
|
|
|
STR_SHORTCUT_CANCEL_CONSTRUCTION_MODE,
|
|
|
|
STR_SHORTCUT_PAUSE_GAME,
|
|
|
|
STR_SHORTCUT_ZOOM_VIEW_OUT,
|
|
|
|
STR_SHORTCUT_ZOOM_VIEW_IN,
|
|
|
|
STR_SHORTCUT_ROTATE_VIEW_CLOCKWISE,
|
|
|
|
STR_SHORTCUT_ROTATE_VIEW_ANTICLOCKWISE,
|
|
|
|
STR_SHORTCUT_ROTATE_CONSTRUCTION_OBJECT,
|
|
|
|
STR_SHORTCUT_UNDERGROUND_VIEW_TOGGLE,
|
|
|
|
STR_SHORTCUT_REMOVE_BASE_LAND_TOGGLE,
|
|
|
|
STR_SHORTCUT_REMOVE_VERTICAL_LAND_TOGGLE,
|
|
|
|
STR_SHORTCUT_SEE_THROUGH_RIDES_TOGGLE,
|
|
|
|
STR_SHORTCUT_SEE_THROUGH_SCENERY_TOGGLE,
|
|
|
|
STR_SHORTCUT_INVISIBLE_SUPPORTS_TOGGLE,
|
|
|
|
STR_SHORTCUT_INVISIBLE_PEOPLE_TOGGLE,
|
|
|
|
STR_SHORTCUT_HEIGHT_MARKS_ON_LAND_TOGGLE,
|
|
|
|
STR_SHORTCUT_HEIGHT_MARKS_ON_RIDE_TRACKS_TOGGLE,
|
|
|
|
STR_SHORTCUT_HEIGHT_MARKS_ON_PATHS_TOGGLE,
|
|
|
|
STR_SHORTCUT_ADJUST_LAND,
|
|
|
|
STR_SHORTCUT_ADJUST_WATER,
|
|
|
|
STR_SHORTCUT_BUILD_SCENERY,
|
|
|
|
STR_SHORTCUT_BUILD_PATHS,
|
|
|
|
STR_SHORTCUT_BUILD_NEW_RIDE,
|
|
|
|
STR_SHORTCUT_SHOW_FINANCIAL_INFORMATION,
|
|
|
|
STR_SHORTCUT_SHOW_RESEARCH_INFORMATION,
|
|
|
|
STR_SHORTCUT_SHOW_RIDES_LIST,
|
|
|
|
STR_SHORTCUT_SHOW_PARK_INFORMATION,
|
|
|
|
STR_SHORTCUT_SHOW_GUEST_LIST,
|
|
|
|
STR_SHORTCUT_SHOW_STAFF_LIST,
|
|
|
|
STR_SHORTCUT_SHOW_RECENT_MESSAGES,
|
|
|
|
STR_SHORTCUT_SHOW_MAP,
|
|
|
|
STR_SHORTCUT_SCREENSHOT,
|
|
|
|
STR_SHORTCUT_REDUCE_GAME_SPEED,
|
|
|
|
STR_SHORTCUT_INCREASE_GAME_SPEED,
|
|
|
|
STR_SHORTCUT_OPEN_CHEATS_WINDOW,
|
|
|
|
STR_SHORTCUT_TOGGLE_VISIBILITY_OF_TOOLBARS,
|
|
|
|
STR_SHORTCUT_SCROLL_MAP_UP,
|
|
|
|
STR_SHORTCUT_SCROLL_MAP_LEFT,
|
|
|
|
STR_SHORTCUT_SCROLL_MAP_DOWN,
|
|
|
|
STR_SHORTCUT_SCROLL_MAP_RIGHT,
|
|
|
|
STR_SEND_MESSAGE,
|
|
|
|
STR_SHORTCUT_QUICK_SAVE_GAME,
|
|
|
|
STR_SHORTCUT_SHOW_OPTIONS,
|
|
|
|
STR_SHORTCUT_MUTE_SOUND,
|
|
|
|
STR_SHORTCUT_WINDOWED_MODE_TOGGLE,
|
|
|
|
STR_SHORTCUT_SHOW_MULTIPLAYER,
|
|
|
|
STR_SHORTCUT_PAINT_ORIGINAL,
|
|
|
|
STR_SHORTCUT_DEBUG_PAINT_TOGGLE,
|
|
|
|
STR_SHORTCUT_SEE_THROUGH_PATHS_TOGGLE,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_LEFT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_RIGHT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_USE_TRACK_DEFAULT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_DOWN,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_UP,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_CHAIN_LIFT_TOGGLE,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_LEFT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_RIGHT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_PREVIOUS_TRACK,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_NEXT_TRACK,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_BUILD_CURRENT,
|
|
|
|
STR_SHORTCUT_RIDE_CONSTRUCTION_DEMOLISH_CURRENT,
|
2017-06-18 19:32:12 +02:00
|
|
|
STR_LOAD_GAME,
|
2017-07-10 23:10:23 +02:00
|
|
|
STR_SHORTCUT_CLEAR_SCENERY,
|
2017-11-22 13:02:23 +01:00
|
|
|
STR_SHORTCUT_GRIDLINES_DISPLAY_TOGGLE,
|
2018-03-23 10:37:13 +01:00
|
|
|
STR_SHORTCUT_VIEW_CLIPPING,
|
|
|
|
STR_SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE,
|
2018-09-15 08:57:50 +02:00
|
|
|
STR_SHORTCUT_OPEN_TILE_INSPECTOR,
|
2015-06-28 14:57:50 +02:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2018-02-01 18:49:14 +01:00
|
|
|
|
2014-10-05 15:21:35 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E3884
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_shortcut_keys_open()
|
2014-10-05 15:21:35 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (w == nullptr)
|
2017-06-11 16:16:47 +02:00
|
|
|
{
|
|
|
|
w = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE);
|
2014-10-05 15:21:35 +02:00
|
|
|
|
2017-06-11 16:16:47 +02:00
|
|
|
w->widgets = window_shortcut_widgets;
|
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET);
|
|
|
|
window_init_scroll_widgets(w);
|
2014-10-05 15:21:35 +02:00
|
|
|
|
2017-06-11 16:16:47 +02:00
|
|
|
w->no_list_items = SHORTCUT_COUNT;
|
|
|
|
w->selected_list_item = -1;
|
|
|
|
w->min_width = WW;
|
|
|
|
w->min_height = WH;
|
|
|
|
w->max_width = WW_SC_MAX;
|
|
|
|
w->max_height = WH_SC_MAX;
|
|
|
|
}
|
|
|
|
return w;
|
2014-10-05 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E39E4
|
|
|
|
*/
|
|
|
|
static void window_shortcut_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-10-05 15:38:15 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_RESET:
|
|
|
|
keyboard_shortcuts_reset();
|
|
|
|
keyboard_shortcuts_save();
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-10-05 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_shortcut_resize(rct_window* w)
|
2017-03-11 22:09:24 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_set_resize(w, w->min_width, w->min_height, w->max_width, w->max_height);
|
2017-03-11 22:09:24 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_shortcut_invalidate(rct_window* w)
|
2015-05-29 18:04:53 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
|
|
|
window_shortcut_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
|
|
|
|
window_shortcut_widgets[WIDX_TITLE].right = w->width - 2;
|
|
|
|
window_shortcut_widgets[WIDX_CLOSE].right = w->width - 3;
|
|
|
|
window_shortcut_widgets[WIDX_CLOSE].left = w->width - 13;
|
|
|
|
window_shortcut_widgets[WIDX_SCROLL].right = w->width - 5;
|
|
|
|
window_shortcut_widgets[WIDX_SCROLL].bottom = w->height - 18;
|
|
|
|
window_shortcut_widgets[WIDX_RESET].top = w->height - 15;
|
|
|
|
window_shortcut_widgets[WIDX_RESET].bottom = w->height - 4;
|
2015-05-29 18:04:53 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 15:38:15 +02:00
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E38E0
|
|
|
|
*/
|
|
|
|
static void window_shortcut_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-10-05 15:38:15 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_draw_widgets(w, dpi);
|
2014-10-05 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E3A07
|
|
|
|
*/
|
|
|
|
static void window_shortcut_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
|
2014-10-05 15:38:15 +02:00
|
|
|
{
|
2017-10-18 09:31:22 +02:00
|
|
|
*height = w->no_list_items * SCROLLABLE_ROW_HEIGHT;
|
2014-10-05 21:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E3A3E
|
|
|
|
*/
|
|
|
|
static void window_shortcut_scrollmousedown(rct_window* w, int32_t scrollIndex, int32_t x, int32_t y)
|
2014-10-05 21:56:26 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t selected_item = (y - 1) / SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
if (selected_item >= w->no_list_items)
|
|
|
|
return;
|
2014-10-05 21:56:26 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_shortcut_change_open(selected_item);
|
2014-10-05 21:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-22 23:21:44 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006E3A16
|
|
|
|
*/
|
|
|
|
static void window_shortcut_scrollmouseover(rct_window* w, int32_t scrollIndex, int32_t x, int32_t y)
|
2014-10-05 21:56:26 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t selected_item = (y - 1) / SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
if (selected_item >= w->no_list_items)
|
|
|
|
return;
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
w->selected_list_item = selected_item;
|
2014-10-07 18:57:38 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate(w);
|
2014-10-05 21:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-05 21:56:26 +02:00
|
|
|
* rct2: 0x006E38E6
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_shortcut_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
|
2014-10-05 21:56:26 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, ColourMapA[w->colours[1]].mid_light);
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < w->no_list_items; ++i)
|
2017-10-17 01:15:42 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t y = 1 + i * SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
if (y > dpi->y + dpi->height)
|
2017-10-17 01:15:42 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
2017-10-17 01:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-10-18 09:31:22 +02:00
|
|
|
if (y + SCROLLABLE_ROW_HEIGHT < dpi->y)
|
2017-10-17 01:15:42 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-27 18:28:45 +01:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t format = STR_BLACK_STRING;
|
2017-10-17 01:15:42 +02:00
|
|
|
if (i == w->selected_list_item)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
format = STR_WINDOW_COLOUR_2_STRINGID;
|
2017-10-18 09:31:22 +02:00
|
|
|
gfx_filter_rect(dpi, 0, y - 1, 800, y + (SCROLLABLE_ROW_HEIGHT - 2), PALETTE_DARKEN_1);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-10-05 21:56:26 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
char templateString[128];
|
2017-06-11 13:30:00 +02:00
|
|
|
keyboard_shortcuts_format_string(templateString, 128, i);
|
2014-10-07 20:12:19 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
set_format_arg(0, rct_string_id, STR_SHORTCUT_ENTRY_FORMAT);
|
|
|
|
set_format_arg(2, rct_string_id, ShortcutStringIds[i]);
|
|
|
|
set_format_arg(4, rct_string_id, STR_STRING);
|
2018-06-22 23:21:44 +02:00
|
|
|
set_format_arg(6, char*, templateString);
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_draw_string_left(dpi, format, gCommonFormatArgs, COLOUR_BLACK, 0, y - 1);
|
|
|
|
}
|
2015-08-20 12:13:08 +02:00
|
|
|
}
|