# HG changeset patch # User yexo # Date 2010-07-03 18:18:58 # Node ID d32a94848de64cb75862aab38fb79ff24b7dce91 # Parent 7239f4bba8bfe58f72ed9bd11edf777adb521a88 (svn r20063) -Feature: customizable hotkeys for the dock toolbar diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -28,6 +28,7 @@ #include "tilehighlight_func.h" #include "company_base.h" #include "station_type.h" +#include "hotkeys.h" #include "table/sprites.h" #include "table/strings.h" @@ -189,18 +190,9 @@ struct BuildDocksToolbarWindow : Window virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - switch (keycode) { - case '1': BuildDocksClick_Canal(this); break; - case '2': BuildDocksClick_Lock(this); break; - case '3': BuildDocksClick_Demolish(this); break; - case '4': BuildDocksClick_Depot(this); break; - case '5': BuildDocksClick_Dock(this); break; - case '6': BuildDocksClick_Buoy(this); break; - case '7': BuildDocksClick_River(this); break; - case 'B': - case '8': BuildDocksClick_Aqueduct(this); break; - default: return ES_NOT_HANDLED; - } + int num = CheckHotkeyMatch(dockstoolbar_hotkeys, keycode, this); + if (num == -1) return ES_NOT_HANDLED; + this->OnClick(Point(), num, 1); return ES_HANDLED; } @@ -254,8 +246,24 @@ struct BuildDocksToolbarWindow : Window VpSetPresizeRange(tile_from, tile_to); } + + static Hotkey dockstoolbar_hotkeys[]; }; +const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0}; + +Hotkey BuildDocksToolbarWindow::dockstoolbar_hotkeys[] = { + Hotkey('1', "canal", DTW_CANAL), + Hotkey('2', "lock", DTW_LOCK), + Hotkey('3', "demolish", DTW_DEMOLISH), + Hotkey('4', "depot", DTW_DEPOT), + Hotkey('5', "dock", DTW_STATION), + Hotkey('6', "buoy", DTW_BUOY), + Hotkey('7', "river", DTW_RIVER), + Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", DTW_BUILD_AQUEDUCT), + HOTKEY_LIST_END(BuildDocksToolbarWindow) +}; +Hotkey *_dockstoolbar_hotkeys = BuildDocksToolbarWindow::dockstoolbar_hotkeys; /** * Nested widget parts of docks toolbar, game version. diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -232,6 +232,7 @@ struct TerraformToolbarWindow; struct ScenarioEditorLandscapeGenerationWindow; struct OrdersWindow; struct BuildAirToolbarWindow; +struct BuildDocksToolbarWindow; static void SaveLoadHotkeys(bool save) { @@ -250,6 +251,7 @@ static void SaveLoadHotkeys(bool save) SL_HOTKEYS(terraform_editor, ScenarioEditorLandscapeGenerationWindow); SL_HOTKEYS(order, OrdersWindow); SL_HOTKEYS(airtoolbar, BuildAirToolbarWindow); + SL_HOTKEYS(dockstoolbar, BuildDocksToolbarWindow); #undef SL_HOTKEYS