summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-07-03 13:28:48 +0000
committeryexo <yexo@openttd.org>2010-07-03 13:28:48 +0000
commit44a49ac849de127c5729370958aeab4b6aa743ee (patch)
tree756e84eb3be67de597f160892608b0c842d3b71b
parent258ca288197f60cfec79af7ea3a27805e6147c18 (diff)
downloadopenttd-44a49ac849de127c5729370958aeab4b6aa743ee.tar.xz
(svn r20056) -Feature: customizable hotkeys for the terraform toolbar
-rw-r--r--src/hotkeys.cpp2
-rw-r--r--src/terraform_gui.cpp36
2 files changed, 21 insertions, 17 deletions
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index f05c921ef..3123a82ae 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 9f3355b79..32de9e0ba 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,7 +281,21 @@ struct TerraformToolbarWindow : Window {
{
this->RaiseButtons();
}
+
+ static Hotkey<TerraformToolbarWindow> terraform_hotkeys[];
+};
+
+Hotkey<TerraformToolbarWindow> TerraformToolbarWindow::terraform_hotkeys[] = {
+ Hotkey<TerraformToolbarWindow>('Q', "lower", TTW_LOWER_LAND),
+ Hotkey<TerraformToolbarWindow>('W', "raise", TTW_RAISE_LAND),
+ Hotkey<TerraformToolbarWindow>('E', "level", TTW_LEVEL_LAND),
+ Hotkey<TerraformToolbarWindow>('D', "dynamite", TTW_DEMOLISH),
+ Hotkey<TerraformToolbarWindow>('U', "buyland", TTW_BUY_LAND),
+ Hotkey<TerraformToolbarWindow>('I', "trees", TTW_PLANT_TREES),
+ Hotkey<TerraformToolbarWindow>('O', "placesign", TTW_PLACE_SIGN),
+ HOTKEY_LIST_END(TerraformToolbarWindow)
};
+Hotkey<TerraformToolbarWindow> *_terraform_hotkeys = TerraformToolbarWindow::terraform_hotkeys;
static const NWidgetPart _nested_terraform_widgets[] = {
NWidget(NWID_HORIZONTAL),