Codechange: Reorganise hotkey initialisation. (#10951)

Hotkeys are now initialized inline, and use std::vector instead of
separate static C-arrays and std::string instead of char *. The list end
marker is no longer required.
This commit is contained in:
PeterN
2023-06-05 18:12:30 +01:00
committed by GitHub
parent 921f5afc4d
commit f814c86389
15 changed files with 410 additions and 502 deletions

View File

@@ -764,44 +764,38 @@ struct BuildRailToolbarWindow : Window {
if (this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT)) CheckRedrawWaypointCoverage(this);
}
static HotkeyList hotkeys;
/**
* Handler for global hotkeys of the BuildRailToolbarWindow.
* @param hotkey Hotkey
* @return ES_HANDLED if hotkey was accepted.
*/
static EventState RailToolbarGlobalHotkeys(int hotkey)
{
if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
extern RailType _last_built_railtype;
Window *w = ShowBuildRailToolbar(_last_built_railtype);
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
static inline HotkeyList hotkeys{"railtoolbar", {
Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
Hotkey('2', "build_x", WID_RAT_BUILD_X),
Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
Hotkey('4', "build_y", WID_RAT_BUILD_Y),
Hotkey({'5', 'A' | WKC_GLOBAL_HOTKEY}, "autorail", WID_RAT_AUTORAIL),
Hotkey('6', "demolish", WID_RAT_DEMOLISH),
Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
Hotkey('9', "station", WID_RAT_BUILD_STATION),
Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
Hotkey('R', "remove", WID_RAT_REMOVE),
Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
}, RailToolbarGlobalHotkeys};
};
/**
* Handler for global hotkeys of the BuildRailToolbarWindow.
* @param hotkey Hotkey
* @return ES_HANDLED if hotkey was accepted.
*/
static EventState RailToolbarGlobalHotkeys(int hotkey)
{
if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
extern RailType _last_built_railtype;
Window *w = ShowBuildRailToolbar(_last_built_railtype);
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
static Hotkey railtoolbar_hotkeys[] = {
Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
Hotkey('2', "build_x", WID_RAT_BUILD_X),
Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
Hotkey('4', "build_y", WID_RAT_BUILD_Y),
Hotkey(_railtoolbar_autorail_keys, "autorail", WID_RAT_AUTORAIL),
Hotkey('6', "demolish", WID_RAT_DEMOLISH),
Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
Hotkey('9', "station", WID_RAT_BUILD_STATION),
Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
Hotkey('R', "remove", WID_RAT_REMOVE),
Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
HOTKEY_LIST_END
};
HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys, RailToolbarGlobalHotkeys);
static const NWidgetPart _nested_build_rail_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
@@ -1502,27 +1496,23 @@ public:
this->SetDirty();
}};
static HotkeyList hotkeys;
};
/**
* Handler for global hotkeys of the BuildRailStationWindow.
* @param hotkey Hotkey
* @return ES_HANDLED if hotkey was accepted.
*/
static EventState BuildRailStationGlobalHotkeys(int hotkey)
{
if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
Window *w = ShowStationBuilder(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL));
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
/**
* Handler for global hotkeys of the BuildRailStationWindow.
* @param hotkey Hotkey
* @return ES_HANDLED if hotkey was accepted.
*/
static EventState BuildRailStationGlobalHotkeys(int hotkey)
{
if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
Window *w = ShowStationBuilder(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL));
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
static Hotkey buildrailstation_hotkeys[] = {
Hotkey('F', "focus_filter_box", BRASHK_FOCUS_FILTER_BOX),
HOTKEY_LIST_END
static inline HotkeyList hotkeys{"buildrailstation", {
Hotkey('F', "focus_filter_box", BRASHK_FOCUS_FILTER_BOX),
}, BuildRailStationGlobalHotkeys};
};
HotkeyList BuildRailStationWindow::hotkeys("buildrailstation", buildrailstation_hotkeys, BuildRailStationGlobalHotkeys);
Listing BuildRailStationWindow::last_sorting = { false, 0 };
Filtering BuildRailStationWindow::last_filtering = { false, 0 };