diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1340,29 +1340,18 @@ struct AIDebugWindow : public QueryStrin virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - switch (this->HandleEditBoxKey(WID_AID_BREAK_STR_EDIT_BOX, key, keycode, state)) { - case HEBR_CANCEL: - /* Unfocus the text box. */ - this->UnfocusFocusedWidget(); - break; - - case HEBR_NOT_FOCUSED: { - /* Edit boxs is not globally foused => handle hotkeys of AI Debug window. */ - int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this); - if (num == -1) return ES_NOT_HANDLED; - if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) { - this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX); - SetFocusedWindow(this); - state = ES_HANDLED; - } else if (this->show_break_box || num < WID_AID_BREAK_STRING_WIDGETS) { - this->OnClick(Point(), num, 1); - state = ES_HANDLED; - } - break; + if (this->HandleEditBoxKey(WID_AID_BREAK_STR_EDIT_BOX, key, keycode, state) == HEBR_NOT_FOCUSED) { + /* Edit boxs is not globally foused => handle hotkeys of AI Debug window. */ + int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this); + if (num == -1) return ES_NOT_HANDLED; + if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) { + this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX); + SetFocusedWindow(this); + state = ES_HANDLED; + } else if (this->show_break_box || num < WID_AID_BREAK_STRING_WIDGETS) { + this->OnClick(Point(), num, 1); + state = ES_HANDLED; } - - default: - break; } return state; } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -262,6 +262,7 @@ public: default: break; } + this->ok_button = WID_SL_SAVE_GAME; this->afilter = CS_ALPHANUMERAL; this->text.Initialize(this->edit_str_buf, this->edit_str_size); @@ -604,7 +605,12 @@ public: } break; - case WID_SL_DELETE_SELECTION: case WID_SL_SAVE_GAME: // Delete, Save game + case WID_SL_DELETE_SELECTION: // Delete + break; + + case WID_SL_SAVE_GAME: // Save game + /* Note, this is also called via the OSK; and we need to lower the button. */ + this->HandleButtonClick(WID_SL_SAVE_GAME); break; } } @@ -617,10 +623,7 @@ public: } EventState state = ES_NOT_HANDLED; - if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) && - this->HandleEditBoxKey(WID_SL_SAVE_OSK_TITLE, key, keycode, state) == HEBR_CONFIRM) { - this->HandleButtonClick(WID_SL_SAVE_GAME); - } + this->HandleEditBoxKey(WID_SL_SAVE_OSK_TITLE, key, keycode, state); return state; } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -819,6 +819,20 @@ HandleEditBoxResult QueryStringBaseWindo this->OnOSKInput(wid); break; + case HEBR_CONFIRM: + if (this->ok_button >= 0) { + this->OnClick(Point(), this->ok_button, 1); + } + break; + + case HEBR_CANCEL: + if (this->cancel_button >= 0) { + this->OnClick(Point(), this->cancel_button, 1); + } else { + this->UnfocusFocusedWidget(); + } + break; + default: break; } return result; @@ -905,12 +919,7 @@ struct QueryStringWindow : public QueryS virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - switch (this->HandleEditBoxKey(WID_QS_TEXT, key, keycode, state)) { - default: break; - case HEBR_CONFIRM: this->OnOk(); - /* FALL THROUGH */ - case HEBR_CANCEL: delete this; break; // close window, abandon changes - } + this->HandleEditBoxKey(WID_QS_TEXT, key, keycode, state); return state; } diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -512,13 +512,7 @@ struct NetworkChatWindow : public QueryS state = ES_HANDLED; } else { _chat_tab_completion_active = false; - switch (this->HandleEditBoxKey(WID_NC_TEXTBOX, key, keycode, state)) { - default: break; - case HEBR_CONFIRM: - SendChat(this->text.buf, this->dtype, this->dest); - /* FALL THROUGH */ - case HEBR_CANCEL: delete this; break; - } + this->HandleEditBoxKey(WID_NC_TEXTBOX, key, keycode, state); } return state; } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -835,20 +835,15 @@ public: return ES_HANDLED; } - switch (this->HandleEditBoxKey(WID_NG_CLIENT, key, keycode, state)) { - case HEBR_NOT_FOCUSED: - if (this->server != NULL) { - if (keycode == WKC_DELETE) { // Press 'delete' to remove servers - NetworkGameListRemoveItem(this->server); - if (this->server == this->last_joined) this->last_joined = NULL; - this->server = NULL; - this->list_pos = SLP_INVALID; - } + if (this->HandleEditBoxKey(WID_NG_CLIENT, key, keycode, state) == HEBR_NOT_FOCUSED) { + if (this->server != NULL) { + if (keycode == WKC_DELETE) { // Press 'delete' to remove servers + NetworkGameListRemoveItem(this->server); + if (this->server == this->last_joined) this->last_joined = NULL; + this->server = NULL; + this->list_pos = SLP_INVALID; } - break; - - default: - break; + } } return state; @@ -2160,17 +2155,7 @@ struct NetworkCompanyPasswordWindow : pu virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - switch (this->HandleEditBoxKey(WID_NCP_PASSWORD, key, keycode, state)) { - default: break; - - case HEBR_CONFIRM: - this->OnOk(); - /* FALL THROUGH */ - - case HEBR_CANCEL: - delete this; - break; - } + this->HandleEditBoxKey(WID_NCP_PASSWORD, key, keycode, state); return state; } }; diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -1021,6 +1021,7 @@ void SQGSWindow_Register(Squirrel *engin SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_TEXT, "WID_SIL_FILTER_TEXT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_MATCH_CASE_BTN, "WID_SIL_FILTER_MATCH_CASE_BTN"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_CLEAR_BTN, "WID_SIL_FILTER_CLEAR_BTN"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_ENTER_BTN, "WID_SIL_FILTER_ENTER_BTN"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_CAPTION, "WID_QES_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_TEXT, "WID_QES_TEXT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_OK, "WID_QES_OK"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -2144,6 +2144,7 @@ public: WID_SIL_FILTER_TEXT = ::WID_SIL_FILTER_TEXT, ///< Text box for typing a filter string. WID_SIL_FILTER_MATCH_CASE_BTN = ::WID_SIL_FILTER_MATCH_CASE_BTN, ///< Button to toggle if case sensitive filtering should be used. WID_SIL_FILTER_CLEAR_BTN = ::WID_SIL_FILTER_CLEAR_BTN, ///< Button to clear the filter. + WID_SIL_FILTER_ENTER_BTN = ::WID_SIL_FILTER_ENTER_BTN, ///< Scroll to first sign. }; /** Widgets of the #SignWindow class. */ diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -156,6 +156,8 @@ struct SignListWindow : QueryStringBaseW this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); /* Initialize the text edit widget */ + this->ok_button = WID_SIL_FILTER_ENTER_BTN; + this->cancel_button = WID_SIL_FILTER_CLEAR_BTN; this->afilter = CS_ALPHANUMERAL; this->text.Initialize(this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS); ClearFilterTextWidget(); @@ -254,6 +256,14 @@ struct SignListWindow : QueryStringBaseW ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); break; } + + case WID_SIL_FILTER_ENTER_BTN: + if (this->signs.Length() >= 1) { + const Sign *si = this->signs[0]; + ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); + } + break; + case WID_SIL_FILTER_CLEAR_BTN: this->ClearFilterTextWidget(); // Empty the text in the EditBox widget this->SetFilterString(""); // Use empty text as filter text (= view all signs) @@ -296,29 +306,12 @@ struct SignListWindow : QueryStringBaseW virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - switch (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state)) { - case HEBR_CONFIRM: // Enter pressed -> goto first sign in list - if (this->signs.Length() >= 1) { - const Sign *si = this->signs[0]; - ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); - } - return state; - - case HEBR_CANCEL: // ESC pressed, clear filter. - this->OnClick(Point(), WID_SIL_FILTER_CLEAR_BTN, 1); // Simulate click on clear button. - this->UnfocusFocusedWidget(); // Unfocus the text box. - return state; - - case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused. - if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) { - this->SetFocusedWidget(WID_SIL_FILTER_TEXT); - SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. - state = ES_HANDLED; - } - break; - - default: - break; + if (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state) == HEBR_NOT_FOCUSED) { + if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) { + this->SetFocusedWidget(WID_SIL_FILTER_TEXT); + SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. + state = ES_HANDLED; + } } return state; @@ -551,17 +544,7 @@ struct SignWindow : QueryStringBaseWindo virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - switch (this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state)) { - default: break; - - case HEBR_CONFIRM: - if (RenameSign(this->cur_sign, this->text.buf)) break; - /* FALL THROUGH */ - - case HEBR_CANCEL: // close window, abandon changes - delete this; - break; - } + this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state); return state; } }; diff --git a/src/town_gui.cpp b/src/town_gui.cpp --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -1104,9 +1104,7 @@ public: virtual EventState OnKeyPress(uint16 key, uint16 keycode) { EventState state = ES_NOT_HANDLED; - if (this->HandleEditBoxKey(WID_TF_TOWN_NAME_EDITBOX, key, keycode, state) == HEBR_CANCEL) { - this->UnfocusFocusedWidget(); - } + this->HandleEditBoxKey(WID_TF_TOWN_NAME_EDITBOX, key, keycode, state); return state; } diff --git a/src/widgets/sign_widget.h b/src/widgets/sign_widget.h --- a/src/widgets/sign_widget.h +++ b/src/widgets/sign_widget.h @@ -21,6 +21,7 @@ enum SignListWidgets { WID_SIL_FILTER_TEXT, ///< Text box for typing a filter string. WID_SIL_FILTER_MATCH_CASE_BTN, ///< Button to toggle if case sensitive filtering should be used. WID_SIL_FILTER_CLEAR_BTN, ///< Button to clear the filter. + WID_SIL_FILTER_ENTER_BTN, ///< Scroll to first sign. }; /** Widgets of the #SignWindow class. */