Changeset - r19338:93490e71d186
[Not reviewed]
master
0 2 0
frosch - 12 years ago 2012-05-14 21:01:54
frosch@openttd.org
(svn r24249) -Codechange: Split the extraction of current DParams from the ErrorMessageData constructor into a separate function.
2 files changed with 30 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/error.h
Show inline comments
 
@@ -38,12 +38,14 @@ protected:
 
	CompanyID face;                 ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
 

	
 
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);
 
void ClearErrorMessages();
 
void ShowFirstError();
 
void UnshowCriticalError();
src/error_gui.cpp
Show inline comments
 
@@ -98,29 +98,47 @@ ErrorMessageData::~ErrorMessageData()
 
 * @param textref_stack Values to put on the #TextRefStack.
 
 */
 
ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration, int x, int y, uint textref_stack_size, const uint32 *textref_stack) :
 
	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. */
 
ErrorList _error_list;
 
/** Whether the window system is initialized or not. */
 
bool _window_system_initialized = false;
 
@@ -349,12 +367,13 @@ void ShowErrorMessage(StringID summary_m
 

	
 
	bool no_timeout = wl == WL_CRITICAL;
 

	
 
	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()) {
 
		/* A critical error is currently shown. */
 
		if (wl == WL_CRITICAL) {
 
			/* Push another critical error in the queue of errors,
0 comments (0 inline, 0 general)