From b1eb975529f42ed93dbe5d2a6e18d93f5a969fb5 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 12 Dec 2020 17:53:02 +0000 Subject: [PATCH] Re-add show change dialog --- src/openrct2-ui/input/ShortcutManager.cpp | 10 +++++ src/openrct2-ui/input/ShortcutManager.h | 2 + src/openrct2-ui/windows/ShortcutKeyChange.cpp | 40 +++++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/openrct2-ui/input/ShortcutManager.cpp b/src/openrct2-ui/input/ShortcutManager.cpp index 1749249db9..fb3cbb3c6a 100644 --- a/src/openrct2-ui/input/ShortcutManager.cpp +++ b/src/openrct2-ui/input/ShortcutManager.cpp @@ -234,6 +234,16 @@ void ShortcutManager::RegisterShortcut(RegisteredShortcut&& shortcut) Shortcuts.push_back(shortcut); } +RegisteredShortcut* ShortcutManager::GetShortcut(std::string_view id) +{ + auto result = std::find_if(Shortcuts.begin(), Shortcuts.end(), [id](const RegisteredShortcut& s) { return s.Id == id; }); + return result == Shortcuts.end() ? nullptr : &(*result); +} + +void ShortcutManager::SetPendingShortcutChange(std::string_view id) +{ +} + static ShortcutManager _shortcutManager; ShortcutManager& OpenRCT2::Ui::GetShortcutManager() diff --git a/src/openrct2-ui/input/ShortcutManager.h b/src/openrct2-ui/input/ShortcutManager.h index 480922a264..863c14d63e 100644 --- a/src/openrct2-ui/input/ShortcutManager.h +++ b/src/openrct2-ui/input/ShortcutManager.h @@ -86,6 +86,8 @@ namespace OpenRCT2::Ui void RegisterShortcut(RegisteredShortcut&& shortcut); void RegisterDefaultShortcuts(); + RegisteredShortcut* GetShortcut(std::string_view id); + void SetPendingShortcutChange(std::string_view id); }; ShortcutManager& GetShortcutManager(); diff --git a/src/openrct2-ui/windows/ShortcutKeyChange.cpp b/src/openrct2-ui/windows/ShortcutKeyChange.cpp index 9287ba2081..86d782ea15 100644 --- a/src/openrct2-ui/windows/ShortcutKeyChange.cpp +++ b/src/openrct2-ui/windows/ShortcutKeyChange.cpp @@ -8,6 +8,7 @@ *****************************************************************************/ #include +#include #include #include #include @@ -15,6 +16,8 @@ #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; @@ -43,25 +46,30 @@ static rct_window_event_list window_shortcut_change_events([](auto& events) }); // clang-format on -static rct_string_id CurrentShortcutKeyStringId{}; +static rct_string_id _shortcutLocalisedName{}; rct_window* window_shortcut_change_open(const std::string_view& shortcutId) { - return nullptr; + // Save the item we are selecting for new window + auto& shortcutManager = GetShortcutManager(); + auto registeredShortcut = shortcutManager.GetShortcut(shortcutId); + if (registeredShortcut != nullptr) + { + _shortcutLocalisedName = registeredShortcut->LocalisedName; -// // Move this to window_shortcut_change_open -// window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); -// -// // Save the item we are selecting for new window -// gKeyboardShortcutChangeId = selected_key; -// CurrentShortcutKeyStringId = key_string_id; -// -// rct_window* w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); -// -// w->widgets = window_shortcut_change_widgets; -// w->enabled_widgets = (1ULL << WIDX_CLOSE); -// window_init_scroll_widgets(w); -// return w; + 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; + } } /** @@ -89,6 +97,6 @@ static void window_shortcut_change_paint(rct_window* w, rct_drawpixelinfo* dpi) ScreenCoordsXY stringCoords(w->windowPos.x + 125, w->windowPos.y + 30); auto ft = Formatter(); - ft.Add(CurrentShortcutKeyStringId); + ft.Add(_shortcutLocalisedName); gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK); }