diff options
author | frosch <frosch@openttd.org> | 2012-05-14 21:01:54 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-05-14 21:01:54 +0000 |
commit | 1ba36d07cf16c8501883f205e1ffb6a094a604c7 (patch) | |
tree | 8a5facbc7c4710da374738bab04a324c86f91bc9 | |
parent | fd6f92a4e893ff8a31df344d4b3f68d9a7ddef21 (diff) | |
download | openttd-1ba36d07cf16c8501883f205e1ffb6a094a604c7.tar.xz |
(svn r24249) -Codechange: Split the extraction of current DParams from the ErrorMessageData constructor into a separate function.
-rw-r--r-- | src/error.h | 2 | ||||
-rw-r--r-- | src/error_gui.cpp | 37 |
2 files changed, 30 insertions, 9 deletions
diff --git a/src/error.h b/src/error.h index 83ac53d84..ec083f1c6 100644 --- a/src/error.h +++ b/src/error.h @@ -41,6 +41,8 @@ public: ErrorMessageData(const ErrorMessageData &data); ~ErrorMessageData(); ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL); + + void CopyOutDParams(); }; 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); diff --git a/src/error_gui.cpp b/src/error_gui.cpp index 43dd5c4b6..b6f1d02a2 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -101,23 +101,41 @@ ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, duration(duration), textref_stack_size(textref_stack_size), summary_msg(summary_msg), - detailed_msg(detailed_msg) + detailed_msg(detailed_msg), + face(INVALID_COMPANY) { this->position.x = x; this->position.y = y; - if (textref_stack_size > 0) StartTextRefStackUsage(textref_stack_size, textref_stack); - CopyOutDParam(this->decode_params, this->strings, detailed_msg == INVALID_STRING_ID ? summary_msg : detailed_msg, lengthof(this->decode_params)); - if (textref_stack_size > 0) { - StopTextRefStackUsage(); - MemCpyT(this->textref_stack, textref_stack, textref_stack_size); - } - CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2); - this->face = (this->detailed_msg == STR_ERROR_OWNED_BY && company < MAX_COMPANIES) ? company : INVALID_COMPANY; + memset(this->decode_params, 0, sizeof(this->decode_params)); + memset(this->strings, 0, sizeof(this->strings)); + + if (textref_stack_size > 0) MemCpyT(this->textref_stack, textref_stack, textref_stack_size); assert(summary_msg != INVALID_STRING_ID); } +/** + * Copy error parameters from current DParams. + */ +void ErrorMessageData::CopyOutDParams() +{ + /* Reset parameters */ + for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]); + memset(this->decode_params, 0, sizeof(this->decode_params)); + memset(this->strings, 0, sizeof(this->strings)); + + /* Get parameters using type information */ + if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_size, this->textref_stack); + CopyOutDParam(this->decode_params, this->strings, this->detailed_msg == INVALID_STRING_ID ? this->summary_msg : this->detailed_msg, lengthof(this->decode_params)); + if (this->textref_stack_size > 0) StopTextRefStackUsage(); + + if (this->detailed_msg == STR_ERROR_OWNED_BY) { + CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2); + if (company < MAX_COMPANIES) face = company; + } +} + /** Define a queue with errors. */ typedef std::list<ErrorMessageData> ErrorList; /** The actual queue with errors. */ @@ -352,6 +370,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return; ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_size, textref_stack); + data.CopyOutDParams(); ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); if (w != NULL && w->IsCritical()) { |