summaryrefslogtreecommitdiff
path: root/src/error_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-10 15:14:11 +0000
committerrubidium <rubidium@openttd.org>2011-12-10 15:14:11 +0000
commit420d358fef4d88942a5df168ab5c78d68060fe35 (patch)
treebf6a72b3d7035e07ffc29c2e8f8bace5fbc37593 /src/error_gui.cpp
parent58423b26d1d9daa996e151fb3dc3e30dad49b722 (diff)
downloadopenttd-420d358fef4d88942a5df168ab5c78d68060fe35.tar.xz
(svn r23475) -Codechange: queue critical error messages, so when multiple happen you won't miss any
Diffstat (limited to 'src/error_gui.cpp')
-rw-r--r--src/error_gui.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/error_gui.cpp b/src/error_gui.cpp
index d02ebc15c..ee2d5325a 100644
--- 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 @@ 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,9 +274,26 @@ 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.
* @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID.
@@ -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);
+ }
}