From 44a49ac849de127c5729370958aeab4b6aa743ee Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 3 Jul 2010 13:28:48 +0000 Subject: [PATCH] (svn r20056) -Feature: customizable hotkeys for the terraform toolbar --- src/hotkeys.cpp | 2 ++ src/terraform_gui.cpp | 36 +++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index f05c921ef8..3123a82ae7 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -227,6 +227,7 @@ void SaveLoadHotkeyGroup(IniGroup *group, T *hotkey_list, bool save) } } +struct TerraformToolbarWindow; static void SaveLoadHotkeys(bool save) { @@ -240,6 +241,7 @@ static void SaveLoadHotkeys(bool save) group = ini->GetGroup(#name);\ SaveLoadHotkeyGroup(group, _##name##_hotkeys, save); + SL_HOTKEYS(terraform, TerraformToolbarWindow); #undef SL_HOTKEYS diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 9f3355b793..32de9e0ba2 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -30,6 +30,7 @@ #include "landscape_type.h" #include "tilehighlight_func.h" #include "strings_func.h" +#include "hotkeys.h" #include "table/sprites.h" #include "table/strings.h" @@ -133,16 +134,6 @@ bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_t typedef void OnButtonClick(Window *w); -static const uint16 _terraform_keycodes[] = { - 'Q', - 'W', - 'E', - 'D', - 'U', - 'I', - 'O', -}; - static void PlaceProc_BuyLand(TileIndex tile) { DoCommandP(tile, 0, 0, CMD_PURCHASE_LAND_AREA | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E); @@ -248,13 +239,10 @@ struct TerraformToolbarWindow : Window { virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - for (uint i = 0; i != lengthof(_terraform_keycodes); i++) { - if (keycode == _terraform_keycodes[i]) { - _terraform_button_proc[i](this); - return ES_HANDLED; - } - } - return ES_NOT_HANDLED; + int num = CheckHotkeyMatch(terraform_hotkeys, keycode, this); + if (num == -1) return ES_NOT_HANDLED; + this->OnClick(Point(), num, 1); + return ES_HANDLED; } virtual void OnPlaceObject(Point pt, TileIndex tile) @@ -293,8 +281,22 @@ struct TerraformToolbarWindow : Window { { this->RaiseButtons(); } + + static Hotkey terraform_hotkeys[]; }; +Hotkey TerraformToolbarWindow::terraform_hotkeys[] = { + Hotkey('Q', "lower", TTW_LOWER_LAND), + Hotkey('W', "raise", TTW_RAISE_LAND), + Hotkey('E', "level", TTW_LEVEL_LAND), + Hotkey('D', "dynamite", TTW_DEMOLISH), + Hotkey('U', "buyland", TTW_BUY_LAND), + Hotkey('I', "trees", TTW_PLANT_TREES), + Hotkey('O', "placesign", TTW_PLACE_SIGN), + HOTKEY_LIST_END(TerraformToolbarWindow) +}; +Hotkey *_terraform_hotkeys = TerraformToolbarWindow::terraform_hotkeys; + static const NWidgetPart _nested_terraform_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),