diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj
index 5b8f36c976..ba9bae664d 100644
--- a/src/openrct2-ui/libopenrct2ui.vcxproj
+++ b/src/openrct2-ui/libopenrct2ui.vcxproj
@@ -167,7 +167,6 @@
-
diff --git a/src/openrct2-ui/windows/ShortcutKeyChange.cpp b/src/openrct2-ui/windows/ShortcutKeyChange.cpp
deleted file mode 100644
index 837f9c7ced..0000000000
--- a/src/openrct2-ui/windows/ShortcutKeyChange.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014-2020 OpenRCT2 developers
- *
- * For a complete list of all authors, please refer to contributors.md
- * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
- *
- * OpenRCT2 is licensed under the GNU General Public License version 3.
- *****************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace OpenRCT2::Ui;
-
-static constexpr const rct_string_id WINDOW_TITLE = STR_SHORTCUT_CHANGE_TITLE;
-static constexpr const int32_t WW = 250;
-static constexpr const int32_t WH = 60;
-
-// clang-format off
-enum WINDOW_SHORTCUT_CHANGE_WIDGET_IDX {
- WIDX_BACKGROUND,
- WIDX_TITLE,
- WIDX_CLOSE,
-};
-
-// 0x9DE4E0
-static rct_widget window_shortcut_change_widgets[] = {
- WINDOW_SHIM(WINDOW_TITLE, WW, WH),
- { WIDGETS_END }
-};
-
-static void window_shortcut_change_close(rct_window *w);
-static void window_shortcut_change_mouseup(rct_window *w, rct_widgetindex widgetIndex);
-static void window_shortcut_change_paint(rct_window *w, rct_drawpixelinfo *dpi);
-
-// 0x9A3F7C
-static rct_window_event_list window_shortcut_change_events([](auto& events)
-{
- events.close = &window_shortcut_change_close;
- events.mouse_up = &window_shortcut_change_mouseup;
- events.paint = &window_shortcut_change_paint;
-});
-// clang-format on
-
-static rct_string_id _shortcutLocalisedName{};
-static std::string _shortcutCustomName{};
-
-rct_window* window_shortcut_change_open(const std::string_view& shortcutId)
-{
- // Save the item we are selecting for new window
- auto& shortcutManager = GetShortcutManager();
- auto registeredShortcut = shortcutManager.GetShortcut(shortcutId);
- if (registeredShortcut != nullptr)
- {
- _shortcutLocalisedName = registeredShortcut->LocalisedName;
- _shortcutCustomName = registeredShortcut->CustomName;
-
- window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
- auto w = WindowCreateCentred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0);
- w->widgets = window_shortcut_change_widgets;
- w->enabled_widgets = (1ULL << WIDX_CLOSE);
- WindowInitScrollWidgets(w);
-
- shortcutManager.SetPendingShortcutChange(registeredShortcut->Id);
- return w;
- }
- else
- {
- return nullptr;
- }
-}
-
-static void window_shortcut_change_close(rct_window* w)
-{
- auto& shortcutManager = GetShortcutManager();
- shortcutManager.SetPendingShortcutChange({});
-}
-
-/**
- *
- * rct2: 0x006E3AE0
- */
-static void window_shortcut_change_mouseup(rct_window* w, rct_widgetindex widgetIndex)
-{
- switch (widgetIndex)
- {
- case WIDX_CLOSE:
- window_close(w);
- break;
- }
-}
-
-/**
- *
- * rct2: 0x006E3A9F
- */
-static void window_shortcut_change_paint(rct_window* w, rct_drawpixelinfo* dpi)
-{
- WindowDrawWidgets(w, dpi);
-
- ScreenCoordsXY stringCoords(w->windowPos.x + 125, w->windowPos.y + 30);
-
- auto ft = Formatter();
- if (_shortcutCustomName.empty())
- {
- ft.Add(_shortcutLocalisedName);
- }
- else
- {
- ft.Add(STR_STRING);
- ft.Add(_shortcutCustomName.c_str());
- }
- gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
-}
diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp
index a97a353e39..3518469cb4 100644
--- a/src/openrct2-ui/windows/ShortcutKeys.cpp
+++ b/src/openrct2-ui/windows/ShortcutKeys.cpp
@@ -10,13 +10,11 @@
#include "../input/ShortcutManager.h"
#include "Window.h"
-#include
#include
-#include
-#include
#include
#include
+using namespace OpenRCT2;
using namespace OpenRCT2::Ui;
static constexpr const rct_string_id WINDOW_TITLE = STR_SHORTCUTS_TITLE;
@@ -26,10 +24,8 @@ static constexpr const int32_t WH = 280;
static constexpr const int32_t WW_SC_MAX = 1200;
static constexpr const int32_t WH_SC_MAX = 800;
-using namespace OpenRCT2;
-
-// clang-format off
-enum WINDOW_SHORTCUT_WIDGET_IDX {
+enum WINDOW_SHORTCUT_WIDGET_IDX
+{
WIDX_BACKGROUND,
WIDX_TITLE,
WIDX_CLOSE,
@@ -37,262 +33,305 @@ enum WINDOW_SHORTCUT_WIDGET_IDX {
WIDX_RESET
};
-// 0x9DE48C
+// clang-format off
static rct_widget window_shortcut_widgets[] = {
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
MakeWidget({4, 18}, {412, 245}, WindowWidgetType::Scroll, WindowColour::Primary, SCROLL_VERTICAL, STR_SHORTCUT_LIST_TIP ),
MakeWidget({4, WH-15}, {150, 12}, WindowWidgetType::Button, WindowColour::Primary, STR_SHORTCUT_ACTION_RESET, STR_SHORTCUT_ACTION_RESET_TIP),
{ WIDGETS_END }
};
+// clang-format on
-static void window_shortcut_mouseup(rct_window *w, rct_widgetindex widgetIndex);
-static void window_shortcut_resize(rct_window *w);
-static void window_shortcut_invalidate(rct_window *w);
-static void window_shortcut_paint(rct_window *w, rct_drawpixelinfo *dpi);
-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, const ScreenCoordsXY& screenCoords);
-static void window_shortcut_scrollmouseover(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
-static void window_shortcut_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
+static constexpr const rct_string_id CHANGE_WINDOW_TITLE = STR_SHORTCUT_CHANGE_TITLE;
+static constexpr const int32_t CHANGE_WW = 250;
+static constexpr const int32_t CHANGE_WH = 60;
-static rct_window_event_list window_shortcut_events([](auto& events)
-{
- events.mouse_up = &window_shortcut_mouseup;
- events.resize = &window_shortcut_resize;
- events.get_scroll_size = &window_shortcut_scrollgetsize;
- events.scroll_mousedown = &window_shortcut_scrollmousedown;
- events.scroll_mouseover = &window_shortcut_scrollmouseover;
- events.invalidate = &window_shortcut_invalidate;
- events.paint = &window_shortcut_paint;
- events.scroll_paint = &window_shortcut_scrollpaint;
-});
-
-struct ShortcutStringPair
-{
- size_t ShortcutIndex;
- std::string ShortcutId;
- rct_string_id StringId = STR_NONE;
- std::string CustomString;
+// clang-format off
+static rct_widget window_shortcut_change_widgets[] = {
+ WINDOW_SHIM(CHANGE_WINDOW_TITLE, CHANGE_WW, CHANGE_WH),
+ { WIDGETS_END }
};
+// clang-format on
-static std::vector _shortcutList;
-
-static void InitialiseShortcutList()
+class ChangeShortcutWindow final : public Window
{
- _shortcutList.clear();
+private:
+ rct_string_id _shortcutLocalisedName{};
+ std::string _shortcutCustomName;
- size_t index = 0;
- std::string group;
- auto& shortcutManager = GetShortcutManager();
- for (auto& shortcut : shortcutManager.Shortcuts)
+public:
+ static ChangeShortcutWindow* Open(std::string_view shortcutId)
{
- if (group.empty())
+ auto& shortcutManager = GetShortcutManager();
+ auto registeredShortcut = shortcutManager.GetShortcut(shortcutId);
+ if (registeredShortcut != nullptr)
{
- group = shortcut.GetGroup();
+ window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
+ auto w = WindowCreate(WC_CHANGE_KEYBOARD_SHORTCUT, CHANGE_WW, CHANGE_WH, WF_CENTRE_SCREEN);
+ if (w != nullptr)
+ {
+ w->_shortcutLocalisedName = registeredShortcut->LocalisedName;
+ w->_shortcutCustomName = registeredShortcut->CustomName;
+ shortcutManager.SetPendingShortcutChange(registeredShortcut->Id);
+ return w;
+ }
+ }
+ return nullptr;
+ }
+
+ void OnOpen() override
+ {
+ widgets = window_shortcut_change_widgets;
+ enabled_widgets = (1ULL << WIDX_CLOSE);
+ WindowInitScrollWidgets(this);
+ }
+
+ void OnClose() override
+ {
+ auto& shortcutManager = GetShortcutManager();
+ shortcutManager.SetPendingShortcutChange({});
+ NotifyShortcutKeysWindow();
+ }
+
+ void OnMouseUp(rct_widgetindex widgetIndex) override
+ {
+ switch (widgetIndex)
+ {
+ case WIDX_CLOSE:
+ Close();
+ break;
+ }
+ }
+
+ void OnDraw(rct_drawpixelinfo& dpi) override
+ {
+ DrawWidgets(dpi);
+
+ ScreenCoordsXY stringCoords(windowPos.x + 125, windowPos.y + 30);
+
+ auto ft = Formatter();
+ if (_shortcutCustomName.empty())
+ {
+ ft.Add(_shortcutLocalisedName);
}
else
{
- auto groupName = shortcut.GetGroup();
- if (group != groupName)
+ ft.Add(STR_STRING);
+ ft.Add(_shortcutCustomName.c_str());
+ }
+ gfx_draw_string_centred_wrapped(&dpi, ft.Data(), stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
+ }
+
+private:
+ void NotifyShortcutKeysWindow();
+};
+
+class ShortcutKeysWindow final : public Window
+{
+private:
+ struct ShortcutStringPair
+ {
+ size_t ShortcutIndex{};
+ std::string ShortcutId;
+ rct_string_id StringId = STR_NONE;
+ std::string CustomString;
+ std::string Binding;
+ };
+
+ std::vector _list;
+ std::optional _highlightedItem;
+
+public:
+ void OnOpen() override
+ {
+ InitialiseList();
+
+ widgets = window_shortcut_widgets;
+ enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET);
+ WindowInitScrollWidgets(this);
+
+ min_width = WW;
+ min_height = WH;
+ max_width = WW_SC_MAX;
+ max_height = WH_SC_MAX;
+ }
+
+ void OnResize() override
+ {
+ window_set_resize(this, min_width, min_height, max_width, max_height);
+ }
+
+ void OnMouseUp(rct_widgetindex widgetIndex) override
+ {
+ switch (widgetIndex)
+ {
+ case WIDX_CLOSE:
+ Close();
+ break;
+ case WIDX_RESET:
+ ResetAll();
+ Invalidate();
+ break;
+ }
+ }
+
+ void OnPrepareDraw() override
+ {
+ widgets[WIDX_BACKGROUND].right = width - 1;
+ widgets[WIDX_BACKGROUND].bottom = height - 1;
+ widgets[WIDX_TITLE].right = width - 2;
+ widgets[WIDX_CLOSE].right = width - 3;
+ widgets[WIDX_CLOSE].left = width - 13;
+ widgets[WIDX_SCROLL].right = width - 5;
+ widgets[WIDX_SCROLL].bottom = height - 18;
+ widgets[WIDX_RESET].top = height - 15;
+ widgets[WIDX_RESET].bottom = height - 4;
+ }
+
+ void OnDraw(rct_drawpixelinfo& dpi) override
+ {
+ DrawWidgets(dpi);
+ }
+
+ ScreenSize OnScrollGetSize(int32_t scrollIndex) override
+ {
+ return { 0, static_cast(_list.size() * SCROLLABLE_ROW_HEIGHT) };
+ }
+
+ void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
+ {
+ auto index = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT);
+ if (index < _list.size())
+ {
+ _highlightedItem = index;
+ Invalidate();
+ }
+ }
+
+ void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
+ {
+ auto selectedItem = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT);
+ if (selectedItem < _list.size())
+ {
+ // Is this a separator?
+ if (!_list[selectedItem].ShortcutId.empty())
{
- // Add separator
- group = groupName;
- _shortcutList.emplace_back();
+ auto& shortcut = _list[selectedItem];
+ ChangeShortcutWindow::Open(shortcut.ShortcutId);
}
}
-
- ShortcutStringPair ssp;
- ssp.ShortcutIndex = index;
- ssp.ShortcutId = shortcut.Id;
- ssp.StringId = shortcut.LocalisedName;
- ssp.CustomString = shortcut.CustomName;
- _shortcutList.push_back(std::move(ssp));
- index++;
}
-}
-static void FormatKeyChordsString(size_t index, char* dst, size_t dstLen)
-{
- if (dstLen == 0)
- return;
-
- auto& shortcutManager = GetShortcutManager();
- auto shortcutIndex = _shortcutList[index].ShortcutIndex;
- const auto& shortcut = shortcutManager.Shortcuts[shortcutIndex];
- auto numChords = shortcut.Current.size();
- *dst = '\0';
- for (size_t i = 0; i < numChords; i++)
+ void OnScrollDraw(int32_t scrollIndex, rct_drawpixelinfo& dpi) override
{
- const auto &kc = shortcut.Current[i];
- auto szkc = kc.ToString();
- String::Append(dst, dstLen, szkc.c_str());
- if (i < numChords - 1)
+ auto dpiCoords = ScreenCoordsXY{ dpi.x, dpi.y };
+ gfx_fill_rect(
+ &dpi, { dpiCoords, dpiCoords + ScreenCoordsXY{ dpi.width - 1, dpi.height - 1 } }, ColourMapA[colours[1]].mid_light);
+
+ // TODO: the line below is a workaround for what is presumably a bug with dpi->width
+ // see https://github.com/OpenRCT2/OpenRCT2/issues/11238 for details
+ const auto scrollWidth = width - SCROLLBAR_WIDTH - 10;
+
+ for (size_t i = 0; i < _list.size(); ++i)
{
- String::Append(dst, dstLen, " or ");
+ auto y = static_cast(1 + i * SCROLLABLE_ROW_HEIGHT);
+ if (y > dpi.y + dpi.height)
+ {
+ break;
+ }
+
+ if (y + SCROLLABLE_ROW_HEIGHT < dpi.y)
+ {
+ continue;
+ }
+
+ // Is this a separator?
+ if (_list[i].ShortcutId.empty())
+ {
+ DrawSeparator(dpi, y, scrollWidth);
+ }
+ else
+ {
+ auto isHighlighted = _highlightedItem == i;
+ DrawItem(dpi, y, scrollWidth, _list[i], isHighlighted);
+ }
}
}
-}
-/**
- *
- * rct2: 0x006E3884
- */
-rct_window* window_shortcut_keys_open()
-{
- rct_window* w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST);
- if (w == nullptr)
+ void RefreshBindings()
{
- InitialiseShortcutList();
-
- w = WindowCreateAutoPos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE);
-
- w->widgets = window_shortcut_widgets;
- w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET);
- WindowInitScrollWidgets(w);
-
- w->no_list_items = static_cast(_shortcutList.size());
- 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;
+ InitialiseList();
}
- return w;
-}
-/**
- *
- * rct2: 0x006E39E4
- */
-static void window_shortcut_mouseup(rct_window* w, rct_widgetindex widgetIndex)
-{
- switch (widgetIndex)
+private:
+ void InitialiseList()
{
- case WIDX_CLOSE:
- window_close(w);
- break;
- case WIDX_RESET:
- KeyboardShortcutsReset();
- KeyboardShortcutsSave();
- w->Invalidate();
- break;
+ _list.clear();
+
+ size_t index = 0;
+ std::string group;
+ auto& shortcutManager = GetShortcutManager();
+ for (auto& shortcut : shortcutManager.Shortcuts)
+ {
+ if (group.empty())
+ {
+ group = shortcut.GetGroup();
+ }
+ else
+ {
+ auto groupName = shortcut.GetGroup();
+ if (group != groupName)
+ {
+ // Add separator
+ group = groupName;
+ _list.emplace_back();
+ }
+ }
+
+ ShortcutStringPair ssp;
+ ssp.ShortcutIndex = index;
+ ssp.ShortcutId = shortcut.Id;
+ ssp.StringId = shortcut.LocalisedName;
+ ssp.CustomString = shortcut.CustomName;
+ ssp.Binding = FormatKeyChordsString(shortcut);
+ _list.push_back(std::move(ssp));
+ index++;
+ }
}
-}
-static void window_shortcut_resize(rct_window* w)
-{
- window_set_resize(w, w->min_width, w->min_height, w->max_width, w->max_height);
-}
-
-static void window_shortcut_invalidate(rct_window* w)
-{
- 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;
-}
-
-/**
- *
- * rct2: 0x006E38E0
- */
-static void window_shortcut_paint(rct_window* w, rct_drawpixelinfo* dpi)
-{
- WindowDrawWidgets(w, dpi);
-}
-
-/**
- *
- * rct2: 0x006E3A07
- */
-static void window_shortcut_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
-{
- *height = w->no_list_items * SCROLLABLE_ROW_HEIGHT;
-}
-
-/**
- *
- * rct2: 0x006E3A3E
- */
-static void window_shortcut_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
-{
- int32_t selected_item = (screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT;
- if (selected_item >= w->no_list_items)
- return;
-
- // Is this a separator?
- if (_shortcutList[selected_item].ShortcutId.empty())
- return;
-
- auto& shortcut = _shortcutList[selected_item];
- window_shortcut_change_open(shortcut.ShortcutId);
-}
-
-/**
- *
- * rct2: 0x006E3A16
- */
-static void window_shortcut_scrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
-{
- int32_t selected_item = (screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT;
- if (selected_item >= w->no_list_items)
- return;
-
- w->selected_list_item = selected_item;
-
- w->Invalidate();
-}
-
-/**
- *
- * rct2: 0x006E38E6
- */
-static void window_shortcut_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
-{
- auto dpiCoords = ScreenCoordsXY{ dpi->x, dpi->y };
- gfx_fill_rect(
- dpi, { dpiCoords, dpiCoords + ScreenCoordsXY{ dpi->width - 1, dpi->height - 1 } }, ColourMapA[w->colours[1]].mid_light);
-
- // TODO: the line below is a workaround for what is presumably a bug with dpi->width
- // see https://github.com/OpenRCT2/OpenRCT2/issues/11238 for details
- const auto scrollWidth = w->width - SCROLLBAR_WIDTH - 10;
-
- for (int32_t i = 0; i < w->no_list_items; ++i)
+ void ResetAll()
{
- int32_t y = 1 + i * SCROLLABLE_ROW_HEIGHT;
- if (y > dpi->y + dpi->height)
+ auto& shortcutManager = GetShortcutManager();
+ for (const auto& item : _list)
{
- break;
+ auto shortcut = shortcutManager.GetShortcut(item.ShortcutId);
+ if (shortcut != nullptr)
+ {
+ shortcut->Current = shortcut->Default;
+ }
}
+ shortcutManager.SaveUserBindings();
+ RefreshBindings();
+ }
- if (y + SCROLLABLE_ROW_HEIGHT < dpi->y)
- {
- continue;
- }
+ void DrawSeparator(rct_drawpixelinfo& dpi, int32_t y, int32_t scrollWidth)
+ {
+ const int32_t top = y + (SCROLLABLE_ROW_HEIGHT / 2) - 1;
+ gfx_fill_rect(&dpi, { { 0, top }, { scrollWidth, top } }, ColourMapA[colours[0]].mid_dark);
+ gfx_fill_rect(&dpi, { { 0, top + 1 }, { scrollWidth, top + 1 } }, ColourMapA[colours[0]].lightest);
+ }
- // Is this a separator?
- if (_shortcutList[i].ShortcutId.empty())
- {
- const int32_t top = y + (SCROLLABLE_ROW_HEIGHT / 2) - 1;
- gfx_fill_rect(dpi, { { 0, top }, { scrollWidth, top } }, ColourMapA[w->colours[0]].mid_dark);
- gfx_fill_rect(dpi, { { 0, top + 1 }, { scrollWidth, top + 1 } }, ColourMapA[w->colours[0]].lightest);
- continue;
- }
-
- int32_t format = STR_BLACK_STRING;
- if (i == w->selected_list_item)
+ void DrawItem(
+ rct_drawpixelinfo& dpi, int32_t y, int32_t scrollWidth, const ShortcutStringPair& shortcut, bool isHighlighted)
+ {
+ auto format = STR_BLACK_STRING;
+ if (isHighlighted)
{
format = STR_WINDOW_COLOUR_2_STRINGID;
- gfx_filter_rect(dpi, 0, y - 1, scrollWidth, y + (SCROLLABLE_ROW_HEIGHT - 2), FilterPaletteID::PaletteDarken1);
+ gfx_filter_rect(&dpi, 0, y - 1, scrollWidth, y + (SCROLLABLE_ROW_HEIGHT - 2), FilterPaletteID::PaletteDarken1);
}
- const auto& shortcut = _shortcutList[i];
-
- const int32_t bindingOffset = scrollWidth - 150;
+ auto bindingOffset = scrollWidth - 150;
auto ft = Formatter();
ft.Add(STR_SHORTCUT_ENTRY_FORMAT);
if (shortcut.CustomString.empty())
@@ -304,18 +343,49 @@ static void window_shortcut_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i
ft.Add(STR_STRING);
ft.Add(shortcut.CustomString.c_str());
}
- DrawTextEllipsised(dpi, { 0, y - 1 }, bindingOffset, format, ft, COLOUR_BLACK);
+ DrawTextEllipsised(&dpi, { 0, y - 1 }, bindingOffset, format, ft, COLOUR_BLACK);
- char keybinding[128];
- FormatKeyChordsString(i, keybinding, sizeof(keybinding));
-
- if (strlen(keybinding) > 0)
+ if (!shortcut.Binding.empty())
{
- const int32_t maxWidth = 150;
ft = Formatter();
ft.Add(STR_STRING);
- ft.Add(keybinding);
- DrawTextEllipsised(dpi, { bindingOffset, y - 1 }, maxWidth, format, ft, COLOUR_BLACK);
+ ft.Add(shortcut.Binding.c_str());
+ DrawTextEllipsised(&dpi, { bindingOffset, y - 1 }, 150, format, ft, COLOUR_BLACK);
}
}
+
+ static std::string FormatKeyChordsString(const RegisteredShortcut& shortcut)
+ {
+ std::string result;
+ auto numChords = shortcut.Current.size();
+ for (size_t i = 0; i < numChords; i++)
+ {
+ const auto& kc = shortcut.Current[i];
+ result += kc.ToString();
+ if (i < numChords - 1)
+ {
+ result += " or ";
+ }
+ }
+ return result;
+ }
+};
+
+void ChangeShortcutWindow::NotifyShortcutKeysWindow()
+{
+ auto w = window_find_by_class(WC_KEYBOARD_SHORTCUT_LIST);
+ if (w != nullptr)
+ {
+ static_cast(w)->RefreshBindings();
+ }
+}
+
+rct_window* window_shortcut_keys_open()
+{
+ auto w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST);
+ if (w == nullptr)
+ {
+ w = WindowCreate(WC_KEYBOARD_SHORTCUT_LIST, WW, WH, WF_RESIZABLE);
+ }
+ return w;
}
diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h
index 8a62957b27..9b55984a20 100644
--- a/src/openrct2-ui/windows/Window.h
+++ b/src/openrct2-ui/windows/Window.h
@@ -64,7 +64,6 @@ rct_window* window_save_prompt_open();
rct_window* window_server_list_open();
rct_window* window_server_start_open();
#endif
-rct_window* window_shortcut_change_open(const std::string_view& shortcutId);
rct_window* window_shortcut_keys_open();
rct_window* window_staff_list_open();
rct_window* window_staff_open(Peep* peep);