From 243075a09658b696f55d348b1a6ae65a7098aa0e Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 3 Jul 2010 18:18:58 +0000 Subject: (svn r20063) -Feature: customizable hotkeys for the dock toolbar --- src/dock_gui.cpp | 32 ++++++++++++++++++++------------ src/hotkeys.cpp | 2 ++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 935e5a16a..72e2b234d 100644 --- 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 index 6b0e1a993..dae73b5d2 100644 --- 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 -- cgit v1.2.3-70-g09d2