From fef30983e643943df24a7090a7175cfa66f3ba15 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 15 Jun 2013 15:31:22 +0000 Subject: (svn r25414) -Codechange: Move handling of global hotkeys to HotkeyList. --- src/ai/ai_gui.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/ai') diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index d172780a8..01803d767 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1402,6 +1402,19 @@ NWidgetBase *MakeCompanyButtonRowsAIDebug(int *biggest_index) return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP); } +/** + * Handler for global hotkeys of the AIDebugWindow. + * @param hotkey Hotkey + * @return ES_HANDLED if hotkey was accepted. + */ +static EventState AIDebugGlobalHotkeys(int hotkey) +{ + if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; + Window *w = ShowAIDebugWindow(INVALID_COMPANY); + if (w == NULL) return ES_NOT_HANDLED; + return w->OnHotkey(hotkey); +} + static Hotkey aidebug_hotkeys[] = { Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START), Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1), @@ -1427,7 +1440,7 @@ static Hotkey aidebug_hotkeys[] = { Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN), HOTKEY_LIST_END }; -HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys); +HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys); /** Widgets for the AI debug window. */ static const NWidgetPart _nested_ai_debug_widgets[] = { @@ -1501,18 +1514,6 @@ Window *ShowAIDebugWindow(CompanyID show_company) return NULL; } -/** - * Handler for global AI debug window hotkeys. - */ -EventState AIDebugGlobalHotkeys(uint16 key, uint16 keycode) -{ - int num = AIDebugWindow::hotkeys.CheckMatch(keycode, true); - if (num == -1) return ES_NOT_HANDLED; - Window *w = ShowAIDebugWindow(INVALID_COMPANY); - if (w == NULL) return ES_NOT_HANDLED; - return w->OnHotkey(num); -} - /** * Reset the AI windows to their initial state. */ -- cgit v1.2.3-54-g00ecf