summaryrefslogtreecommitdiff
path: root/src/rail_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-06-15 15:31:22 +0000
committerfrosch <frosch@openttd.org>2013-06-15 15:31:22 +0000
commitfef30983e643943df24a7090a7175cfa66f3ba15 (patch)
tree5129b4c530168788d3a4ebec180d3c910c37b942 /src/rail_gui.cpp
parentee4e68bd5e4882397bc023040a2977047d22ccb7 (diff)
downloadopenttd-fef30983e643943df24a7090a7175cfa66f3ba15.tar.xz
(svn r25414) -Codechange: Move handling of global hotkeys to HotkeyList.
Diffstat (limited to 'src/rail_gui.cpp')
-rw-r--r--src/rail_gui.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 38afd73c6..446268d73 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -755,6 +755,20 @@ struct BuildRailToolbarWindow : Window {
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 || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
+ extern RailType _last_built_railtype;
+ Window *w = ShowBuildRailToolbar(_last_built_railtype);
+ if (w == NULL) return ES_NOT_HANDLED;
+ return w->OnHotkey(hotkey);
+}
+
const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
static Hotkey railtoolbar_hotkeys[] = {
@@ -774,7 +788,7 @@ static Hotkey railtoolbar_hotkeys[] = {
Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
HOTKEY_LIST_END
};
-HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys);
+HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys, RailToolbarGlobalHotkeys);
static const NWidgetPart _nested_build_rail_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -845,17 +859,6 @@ Window *ShowBuildRailToolbar(RailType railtype)
return new BuildRailToolbarWindow(&_build_rail_desc, railtype);
}
-EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode)
-{
- if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
- extern RailType _last_built_railtype;
- int num = BuildRailToolbarWindow::hotkeys.CheckMatch(keycode, true);
- if (num == -1) return ES_NOT_HANDLED;
- Window *w = ShowBuildRailToolbar(_last_built_railtype);
- if (w == NULL) return ES_NOT_HANDLED;
- return w->OnHotkey(num);
-}
-
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
* --pasky */