From a31ff7e02e7069974da5895090058fe85415bad3 Mon Sep 17 00:00:00 2001 From: Rik Smeets <30838294+rik-smeets@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:22:05 +0200 Subject: [PATCH] Add prompt before resetting shortcut keys (#19905) --- data/language/en-GB.txt | 3 + distribution/changelog.txt | 1 + src/openrct2-ui/interface/Theme.cpp | 1 + src/openrct2-ui/windows/ShortcutKeys.cpp | 101 +++++++++++++++++++---- src/openrct2/interface/WindowClasses.h | 1 + src/openrct2/localisation/StringIds.h | 3 + 6 files changed, 94 insertions(+), 16 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 30aa68feb1..ca5f02587b 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3683,6 +3683,9 @@ STR_6577 :Block brake speed STR_6578 :Set speed limit for block brakes. In block section mode, adjacent brakes with a slower speed are linked to the block brake. STR_6579 :Block brakes will be set to default speed when saved as track design +STR_6580 :Reset +STR_6581 :Are you sure you want to reset all shortcut keys on this tab? + ############# # Scenarios # ################ diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 1a961dc0dd..4a526d32a6 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -9,6 +9,7 @@ - Improved: [#18996] When marketing campaigns are disabled, disable the Marketing tab in the Finances window. - Improved: [#19764] Miscellaneous scenery tab now grouped next to the all-scenery tab. - Improved: [#19830] “Highlight path issues” will now hide wall elements. +- Improved: [#19905] Add prompt before resetting shortcut keys. - Fix: [#12598] Number of holes is not set correctly when saving track designs. - Fix: [#13130] Android always defaulting to UK locale for language, currency and temperature. - Fix: [#18895] Responding mechanic blocked at level crossing. diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index 7e89daeb75..0f6feb6a84 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -148,6 +148,7 @@ static constexpr const WindowThemeDesc WindowThemeDescriptors[] = { WindowClass::NewCampaign, "WC_NEW_CAMPAIGN", STR_THEMES_WINDOW_NEW_CAMPAIGN, COLOURS_3(COLOUR_DARK_YELLOW, COLOUR_DARK_YELLOW, COLOUR_DARK_YELLOW ) }, { WindowClass::KeyboardShortcutList, "WC_KEYBOARD_SHORTCUT_LIST", STR_THEMES_WINDOW_KEYBOARD_SHORTCUT_LIST, COLOURS_3(COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE ) }, { WindowClass::ChangeKeyboardShortcut, "WC_CHANGE_KEYBOARD_SHORTCUT", STR_THEMES_WINDOW_CHANGE_KEYBOARD_SHORTCUT, COLOURS_3(COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE ) }, + { WindowClass::ResetShortcutKeysPrompt, "WC_RESET_SHORTCUT_KEYS_PROMPT", STR_SHORTCUT_ACTION_RESET, COLOURS_1(TRANSLUCENT(COLOUR_BORDEAUX_RED) ) }, { WindowClass::Map, "WC_MAP", STR_THEMES_WINDOW_MAP, COLOURS_2(COLOUR_DARK_GREEN, COLOUR_DARK_BROWN ) }, { WindowClass::Banner, "WC_BANNER", STR_THEMES_WINDOW_BANNER, COLOURS_3(COLOUR_DARK_BROWN, COLOUR_DARK_BROWN, COLOUR_DARK_BROWN ) }, { WindowClass::EditorObjectSelection, "WC_EDITOR_OBJECT_SELECTION", STR_THEMES_WINDOW_EDITOR_OBJECT_SELECTION, COLOURS_3(COLOUR_LIGHT_PURPLE, COLOUR_GREY, COLOUR_GREY ) }, diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index 67b075fae4..e66a65a882 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -19,6 +19,8 @@ using namespace OpenRCT2; using namespace OpenRCT2::Ui; +WindowBase* ResetShortcutKeysPromptOpen(); + static constexpr const StringId WINDOW_TITLE = STR_SHORTCUTS_TITLE; static constexpr const int32_t WW = 420; static constexpr const int32_t WH = 280; @@ -193,6 +195,11 @@ public: max_height = WH_SC_MAX; } + void OnClose() override + { + WindowCloseByClass(WindowClass::ResetShortcutKeysPrompt); + } + void OnResize() override { WindowSetResize(*this, min_width, min_height, max_width, max_height); @@ -219,7 +226,7 @@ public: Close(); break; case WIDX_RESET: - ResetAll(); + ResetShortcutKeysPromptOpen(); break; default: { @@ -336,6 +343,21 @@ public: InitialiseList(); } + void ResetAllOnActiveTab() + { + auto& shortcutManager = GetShortcutManager(); + for (const auto& item : _list) + { + auto shortcut = shortcutManager.GetShortcut(item.ShortcutId); + if (shortcut != nullptr) + { + shortcut->Current = shortcut->Default; + } + } + shortcutManager.SaveUserBindings(); + RefreshBindings(); + } + private: bool IsInCurrentTab(const RegisteredShortcut& shortcut) { @@ -451,21 +473,6 @@ private: } } - void ResetAll() - { - auto& shortcutManager = GetShortcutManager(); - for (const auto& item : _list) - { - auto shortcut = shortcutManager.GetShortcut(item.ShortcutId); - if (shortcut != nullptr) - { - shortcut->Current = shortcut->Default; - } - } - shortcutManager.SaveUserBindings(); - RefreshBindings(); - } - void DrawTabImages(DrawPixelInfo& dpi) const { for (size_t i = 0; i < _tabs.size(); i++) @@ -553,3 +560,65 @@ WindowBase* WindowShortcutKeysOpen() } return w; } + +#pragma region Reset prompt +static constexpr const int32_t RESET_PROMPT_WW = 200; +static constexpr const int32_t RESET_PROMPT_WH = 80; + +enum +{ + WIDX_RESET_PROMPT_BACKGROUND, + WIDX_RESET_PROMPT_TITLE, + WIDX_RESET_PROMPT_CLOSE, + WIDX_RESET_PROMPT_LABEL, + WIDX_RESET_PROMPT_RESET, + WIDX_RESET_PROMPT_CANCEL +}; + +static Widget WindowResetShortcutKeysPromptWidgets[] = { + WINDOW_SHIM_WHITE(STR_SHORTCUT_ACTION_RESET, RESET_PROMPT_WW, RESET_PROMPT_WH), + MakeWidget( + { 2, 30 }, { RESET_PROMPT_WW - 4, 12 }, WindowWidgetType::LabelCentred, WindowColour::Primary, + STR_RESET_SHORTCUT_KEYS_PROMPT), + MakeWidget({ 8, RESET_PROMPT_WH - 22 }, { 85, 14 }, WindowWidgetType::Button, WindowColour::Primary, STR_RESET), + MakeWidget( + { RESET_PROMPT_WW - 95, RESET_PROMPT_WH - 22 }, { 85, 14 }, WindowWidgetType::Button, WindowColour::Primary, + STR_SAVE_PROMPT_CANCEL), + WIDGETS_END, +}; + +class ResetShortcutKeysPrompt final : public Window +{ + void OnOpen() override + { + widgets = WindowResetShortcutKeysPromptWidgets; + } + + void OnMouseUp(WidgetIndex widgetIndex) override + { + switch (widgetIndex) + { + case WIDX_RESET_PROMPT_RESET: + { + auto w = WindowFindByClass(WindowClass::KeyboardShortcutList); + if (w != nullptr) + { + static_cast(w)->ResetAllOnActiveTab(); + } + Close(); + break; + } + case WIDX_RESET_PROMPT_CANCEL: + case WIDX_RESET_PROMPT_CLOSE: + Close(); + break; + } + } +}; + +WindowBase* ResetShortcutKeysPromptOpen() +{ + return WindowFocusOrCreate( + WindowClass::ResetShortcutKeysPrompt, RESET_PROMPT_WW, RESET_PROMPT_WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); +} +#pragma endregion diff --git a/src/openrct2/interface/WindowClasses.h b/src/openrct2/interface/WindowClasses.h index 08be0e4c86..6e869499fd 100644 --- a/src/openrct2/interface/WindowClasses.h +++ b/src/openrct2/interface/WindowClasses.h @@ -87,6 +87,7 @@ enum class WindowClass : uint8_t PatrolArea = 133, Transparency = 134, AssetPacks = 135, + ResetShortcutKeysPrompt = 136, // Only used for colour schemes Staff = 220, diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 950d14d41b..979b4b8817 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -3981,6 +3981,9 @@ enum : uint16_t STR_RIDE_CONSTRUCTION_BLOCK_BRAKE_SPEED_LIMIT_TIP = 6578, STR_TRACK_DESIGN_BLOCK_BRAKE_SPEED_RESET = 6579, + STR_RESET = 6580, + STR_RESET_SHORTCUT_KEYS_PROMPT = 6581 + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings };