summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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),