From fda69b2be3aa1a934c03d311e05d20e09cb53b09 Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 3 Jul 2010 13:29:01 +0000 Subject: (svn r20057) -Feature: customizable hotkeys for the terraform toolbar in scenario editor --- src/terraform_gui.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/terraform_gui.cpp') diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 32de9e0ba..f4a9426a3 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -578,17 +578,6 @@ static void EditorTerraformClick_Transmitter(Window *w) HandlePlacePushButton(w, ETTW_PLACE_TRANSMITTER, SPR_CURSOR_TRANSMITTER, HT_RECT, PlaceProc_Transmitter); } -static const uint16 _editor_terraform_keycodes[] = { - 'D', - 'Q', - 'W', - 'E', - 'R', - 'T', - 'Y' -}; - -typedef void OnButtonClick(Window *w); static OnButtonClick * const _editor_terraform_button_proc[] = { EditorTerraformClick_Dynamite, EditorTerraformClick_LowerBigLand, @@ -666,13 +655,10 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - for (uint i = 0; i != lengthof(_editor_terraform_keycodes); i++) { - if (keycode == _editor_terraform_keycodes[i]) { - _editor_terraform_button_proc[i](this); - return ES_HANDLED; - } - } - return ES_NOT_HANDLED; + int num = CheckHotkeyMatch(terraform_editor_hotkeys, keycode, this); + if (num == -1) return ES_NOT_HANDLED; + this->OnClick(Point(), num, 1); + return ES_HANDLED; } virtual void OnClick(Point pt, int widget, int click_count) @@ -751,8 +737,24 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { this->RaiseButtons(); this->SetDirty(); } + + static Hotkey terraform_editor_hotkeys[]; +}; + +Hotkey ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys[] = { + Hotkey('D', "dynamite", ETTW_DEMOLISH), + Hotkey('Q', "lower", ETTW_LOWER_LAND), + Hotkey('W', "raise", ETTW_RAISE_LAND), + Hotkey('E', "level", ETTW_LEVEL_LAND), + Hotkey('R', "rocky", ETTW_PLACE_ROCKS), + Hotkey('T', "desertlighthouse", ETTW_PLACE_DESERT_LIGHTHOUSE), + Hotkey('Y', "transmitter", ETTW_PLACE_TRANSMITTER), + HOTKEY_LIST_END(ScenarioEditorLandscapeGenerationWindow) }; +Hotkey *_terraform_editor_hotkeys = ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys; + + static const WindowDesc _scen_edit_land_gen_desc( WDP_AUTO, 0, 0, WC_SCEN_LAND_GEN, WC_NONE, -- cgit v1.2.3-54-g00ecf