Mercurial > hg > openttd
changeset 18628:718c69c25a56 draft
(svn r23475) -Codechange: queue critical error messages, so when multiple happen you won't miss any
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 10 Dec 2011 15:14:11 +0000 |
parents | 1972f6346144 |
children | a55c2ad0bf2c |
files | src/error.h src/error_gui.cpp src/fios_gui.cpp src/genworld_gui.cpp src/intro_gui.cpp src/network/network_client.cpp |
diffstat | 6 files changed, 53 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/error.h +++ b/src/error.h @@ -23,5 +23,6 @@ }; void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL); +void ClearErrorMessages(); #endif /* ERROR_H */
--- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -25,6 +25,7 @@ #include "window_gui.h" #include "table/strings.h" +#include <list> /** Widgets of the error message windows */ enum ErrorMessageWidgets { @@ -82,6 +83,7 @@ Point position; ///< Position of the error message window. CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present. +public: /** * Copy the given data into our instace. * @param data The data to copy. @@ -91,7 +93,6 @@ *this = data; } -public: /** * Display an error message in a window. * @param summary_msg General error message showed in first line. Must be valid. @@ -122,6 +123,11 @@ } }; +/** Define a queue with errors. */ +typedef std::list<ErrorMessageData> ErrorList; +/** The actual queue with errors. */ +ErrorList _errors; + /** Window class for displaying an error message window. */ struct ErrmsgWindow : public Window, ErrorMessageData { private: @@ -255,6 +261,11 @@ ~ErrmsgWindow() { SetRedErrorSquare(INVALID_TILE); + + if (!_errors.empty()) { + new ErrmsgWindow(_errors.front()); + _errors.pop_front(); + } } virtual EventState OnKeyPress(uint16 key, uint16 keycode) @@ -263,9 +274,26 @@ delete this; return ES_HANDLED; } + + /** + * Check whether the currently shown error message was critical or not. + * @return True iff the message was critical. + */ + bool IsCritical() + { + return this->duration == 0; + } }; /** + * Clear all errors from the queue. + */ +void ClearErrorMessages() +{ + _errors.clear(); +} + +/** * Display an error message in a window. * @param summary_msg General error message showed in first line. Must be valid. * @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID. @@ -304,7 +332,19 @@ if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return; - DeleteWindowById(WC_ERRMSG, 0); - ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? _settings_client.gui.errmsg_duration : 0, x, y, textref_stack_size, textref_stack); - new ErrmsgWindow(data); + ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_size, textref_stack); + + ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); + if (w != NULL && w->IsCritical()) { + /* A critical error is currently shown. */ + if (wl == WL_CRITICAL) { + /* Push another critical error in the queue of errors, + * but do not put other errors in the queue. */ + _errors.push_back(data); + } + } else { + /* Nothing or a non-critical error was shown. */ + delete w; + new ErrmsgWindow(data); + } }
--- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -546,7 +546,7 @@ strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title)); - + ClearErrorMessages(); delete this; } break;
--- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -29,6 +29,7 @@ #include "core/geometry_func.hpp" #include "core/random_func.hpp" #include "progress.h" +#include "error.h" #include "table/strings.h" #include "table/sprites.h" @@ -305,6 +306,7 @@ static void StartGeneratingLandscape(GenenerateLandscapeWindowMode mode) { DeleteAllNonVitalWindows(); + ClearErrorMessages(); /* Copy all XXX_newgame to XXX when coming from outside the editor */ MakeNewgameSettingsLive();
--- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -333,7 +333,10 @@ static void AskExitToGameMenuCallback(Window *w, bool confirmed) { - if (confirmed) _switch_mode = SM_MENU; + if (confirmed) { + _switch_mode = SM_MENU; + ClearErrorMessages(); + } } void AskExitToGameMenu()
--- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -841,6 +841,7 @@ lf->Reset(); /* The map is done downloading, load it */ + ClearErrorMessages(); bool load_success = SafeLoad(NULL, SL_LOAD, GM_NORMAL, NO_DIRECTORY, lf); /* Long savegame loads shouldn't affect the lag calculation! */