diff options
-rw-r--r-- | src/error.h | 2 | ||||
-rw-r--r-- | src/error_gui.cpp | 19 | ||||
-rw-r--r-- | src/main_gui.cpp | 14 | ||||
-rw-r--r-- | src/news_gui.cpp | 22 | ||||
-rw-r--r-- | src/news_gui.h | 1 |
5 files changed, 40 insertions, 18 deletions
diff --git a/src/error.h b/src/error.h index 78ee9c591..8aa8ac225 100644 --- a/src/error.h +++ b/src/error.h @@ -55,6 +55,8 @@ public: void ScheduleErrorMessage(const ErrorMessageData &data); void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr); +bool HideActiveErrorMessage(); + void ClearErrorMessages(); void ShowFirstError(); void UnshowCriticalError(); diff --git a/src/error_gui.cpp b/src/error_gui.cpp index 7cbe1d95e..381d67a96 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -315,13 +315,6 @@ public: if (_window_system_initialized) ShowFirstError(); } - EventState OnKeyPress(WChar key, uint16 keycode) override - { - if (keycode != WKC_SPACE) return ES_NOT_HANDLED; - delete this; - return ES_HANDLED; - } - /** * Check whether the currently shown error message was critical or not. * @return True iff the message was critical. @@ -424,6 +417,18 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel } } + +/** + * Close active error message window + * @return true if a window was closed. + */ +bool HideActiveErrorMessage() { + ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); + if (w == nullptr) return false; + delete w; + return true; +} + /** * Schedule a list of errors. * Note: This does not try to display the error now. This is useful if the window system is not yet running. diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 5343e2ed1..5877fb938 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -31,6 +31,8 @@ #include "tilehighlight_func.h" #include "hotkeys.h" #include "guitimer_func.h" +#include "error.h" +#include "news_gui.h" #include "saveload/saveload.h" @@ -235,6 +237,8 @@ enum { GHK_CHAT_ALL, GHK_CHAT_COMPANY, GHK_CHAT_SERVER, + GHK_CLOSE_NEWS, + GHK_CLOSE_ERROR, }; struct MainWindow : Window @@ -427,6 +431,14 @@ struct MainWindow : Window } break; + case GHK_CLOSE_NEWS: // close active news window + if (!HideActiveNewsMessage()) return ES_NOT_HANDLED; + break; + + case GHK_CLOSE_ERROR: // close active error window + if (!HideActiveErrorMessage()) return ES_NOT_HANDLED; + break; + default: return ES_NOT_HANDLED; } return ES_HANDLED; @@ -520,6 +532,8 @@ static Hotkey global_hotkeys[] = { Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL), Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY), Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER), + Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS), + Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR), HOTKEY_LIST_END }; HotkeyList MainWindow::hotkeys("global", global_hotkeys); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index da613c55e..a3f73d729 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -519,16 +519,6 @@ struct NewsWindow : Window { } } - EventState OnKeyPress(WChar key, uint16 keycode) override - { - if (keycode == WKC_SPACE) { - /* Don't continue. */ - delete this; - return ES_HANDLED; - } - return ES_NOT_HANDLED; - } - /** * Some data on this window has become invalid. * @param data Information about the changed data. @@ -603,7 +593,6 @@ private: /* static */ int NewsWindow::duration = 0; // Instance creation. - /** Open up an own newspaper window for the news item */ static void ShowNewspaper(const NewsItem *ni) { @@ -1033,6 +1022,17 @@ static void ShowNewsMessage(const NewsItem *ni) } } +/** + * Close active news message window + * @return true if a window was closed. + */ +bool HideActiveNewsMessage() { + NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0); + if (w == nullptr) return false; + delete w; + return true; +} + /** Show previous news item */ void ShowLastNewsMessage() { diff --git a/src/news_gui.h b/src/news_gui.h index e6f4bb38b..059d51ad3 100644 --- a/src/news_gui.h +++ b/src/news_gui.h @@ -14,6 +14,7 @@ void ShowLastNewsMessage(); void ShowMessageHistory(); +bool HideActiveNewsMessage(); extern NewsItem *_latest_news; |