(svn r23475) -Codechange: queue critical error messages, so when multiple happen you won't miss any

This commit is contained in:
rubidium 2011-12-10 15:14:11 +00:00
parent 58423b26d1
commit 420d358fef
6 changed files with 53 additions and 6 deletions

View File

@ -23,5 +23,6 @@ enum WarningLevel {
};
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 */

View File

@ -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 @@ protected:
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 @@ protected:
*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 @@ public:
}
};
/** 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 @@ public:
~ErrmsgWindow()
{
SetRedErrorSquare(INVALID_TILE);
if (!_errors.empty()) {
new ErrmsgWindow(_errors.front());
_errors.pop_front();
}
}
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
@ -263,8 +274,25 @@ public:
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.
@ -304,7 +332,19 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
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);
}
}

View File

@ -546,7 +546,7 @@ public:
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;

View File

@ -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 const NWidgetPart _nested_heightmap_load_widgets[] = {
static void StartGeneratingLandscape(GenenerateLandscapeWindowMode mode)
{
DeleteAllNonVitalWindows();
ClearErrorMessages();
/* Copy all XXX_newgame to XXX when coming from outside the editor */
MakeNewgameSettingsLive();

View File

@ -333,7 +333,10 @@ void AskExitGame()
static void AskExitToGameMenuCallback(Window *w, bool confirmed)
{
if (confirmed) _switch_mode = SM_MENU;
if (confirmed) {
_switch_mode = SM_MENU;
ClearErrorMessages();
}
}
void AskExitToGameMenu()

View File

@ -841,6 +841,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
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! */