Add prompt before resetting shortcut keys (#19905)

This commit is contained in:
Rik Smeets 2023-04-16 11:22:05 +02:00 committed by GitHub
parent 319d759d71
commit a31ff7e02e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 16 deletions

View File

@ -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 #
################

View File

@ -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.

View File

@ -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 ) },

View File

@ -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<ShortcutKeysWindow*>(w)->ResetAllOnActiveTab();
}
Close();
break;
}
case WIDX_RESET_PROMPT_CANCEL:
case WIDX_RESET_PROMPT_CLOSE:
Close();
break;
}
}
};
WindowBase* ResetShortcutKeysPromptOpen()
{
return WindowFocusOrCreate<ResetShortcutKeysPrompt>(
WindowClass::ResetShortcutKeysPrompt, RESET_PROMPT_WW, RESET_PROMPT_WH, WF_CENTRE_SCREEN | WF_TRANSPARENT);
}
#pragma endregion

View File

@ -87,6 +87,7 @@ enum class WindowClass : uint8_t
PatrolArea = 133,
Transparency = 134,
AssetPacks = 135,
ResetShortcutKeysPrompt = 136,
// Only used for colour schemes
Staff = 220,

View File

@ -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
};