1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Add remove button to clear a shortcut

This commit is contained in:
Ted John
2021-02-23 21:34:32 +00:00
parent 817edff4bd
commit aedd93ef33
3 changed files with 29 additions and 2 deletions

View File

@@ -3686,6 +3686,8 @@ STR_6429 :Joy {INT32}
STR_6430 :LMB
STR_6431 :RMB
STR_6432 :Mouse {INT32}
STR_6433 :Remove
STR_6434 :Remove all bindings for this shortcut.
#############
# Scenarios #

View File

@@ -48,11 +48,17 @@ static rct_widget window_shortcut_widgets[] = {
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 constexpr const int32_t CHANGE_WH = 80;
enum
{
WIDX_REMOVE = 3
};
// clang-format off
static rct_widget window_shortcut_change_widgets[] = {
WINDOW_SHIM(CHANGE_WINDOW_TITLE, CHANGE_WW, CHANGE_WH),
MakeWidget({ 75, 56 }, { 100, 12 }, WindowWidgetType::Button, WindowColour::Primary, STR_SHORTCUT_REMOVE, STR_SHORTCUT_REMOVE_TIP),
{ WIDGETS_END }
};
// clang-format on
@@ -60,6 +66,7 @@ static rct_widget window_shortcut_change_widgets[] = {
class ChangeShortcutWindow final : public Window
{
private:
std::string _shortcutId;
rct_string_id _shortcutLocalisedName{};
std::string _shortcutCustomName;
@@ -74,6 +81,7 @@ public:
auto w = WindowCreate<ChangeShortcutWindow>(WC_CHANGE_KEYBOARD_SHORTCUT, CHANGE_WW, CHANGE_WH, WF_CENTRE_SCREEN);
if (w != nullptr)
{
w->_shortcutId = shortcutId;
w->_shortcutLocalisedName = registeredShortcut->LocalisedName;
w->_shortcutCustomName = registeredShortcut->CustomName;
shortcutManager.SetPendingShortcutChange(registeredShortcut->Id);
@@ -86,7 +94,7 @@ public:
void OnOpen() override
{
widgets = window_shortcut_change_widgets;
enabled_widgets = (1ULL << WIDX_CLOSE);
enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_REMOVE);
WindowInitScrollWidgets(this);
}
@@ -104,6 +112,9 @@ public:
case WIDX_CLOSE:
Close();
break;
case WIDX_REMOVE:
Remove();
break;
}
}
@@ -128,6 +139,17 @@ public:
private:
void NotifyShortcutKeysWindow();
void Remove()
{
auto& shortcutManager = GetShortcutManager();
auto* shortcut = shortcutManager.GetShortcut(_shortcutId);
if (shortcut != nullptr)
{
shortcut->Current.clear();
}
Close();
}
};
class ShortcutKeysWindow final : public Window

View File

@@ -3946,6 +3946,9 @@ enum
STR_SHORTCUT_MOUSE_RIGHT = 6431,
STR_SHORTCUT_MOUSE_NUMBER = 6432,
STR_SHORTCUT_REMOVE = 6433,
STR_SHORTCUT_REMOVE_TIP = 6434,
// 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
};