Esempio n. 1
0
/**
 * Collect a paste error without calling PastingState::DoCommand or PastingState::CollectCost.
 *
 * The function works similary to PastingState::DoCommand and PastingState::CollectCost,
 * but it only generates an error. After return, call PastingState::IsInterrupted to test whether
 * the paste operation is allowd to be continued.
 *
 * @param tile The tile the error concerns.
 * @param error_message Error message.
 * @param error_message Summary error message.
 *
 * @see PastingState::IsInterrupted
 * @see PastingState::CollectCost
 * @see PastingState::DoCommand
 */
void PastingState::CollectError(TileIndex tile, StringID error_message, StringID error_summary)
{
	/* store the error only if it is more important then the previous one */
	if (GetPasteErrorImportance(error_message) > GetPasteErrorImportance(this->err_message)) {
		this->err_tile = IsValidTile(tile) ? tile : INVALID_TILE;
		this->err_message = error_message;
		this->err_summary = error_summary;
		CopyOutDParam(this->err_params, 0, lengthof(this->err_params));
	}

	this->last_result = CommandCost(error_message);
}
Esempio n. 2
0
/**
 * 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_grffile, 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;
	}
}
Esempio n. 3
0
	/**
	 * 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.
	 * @param duration     The amount of time to show this error message.
	 * @param x            World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
	 * @param y            World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
	 * @param textref_stack_size Number of uint32 values to put on the #TextRefStack for the error message; 0 if the #TextRefStack shall not be used.
	 * @param textref_stack Values to put on the #TextRefStack.
	 */
	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)
	{
		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;

		assert(summary_msg != INVALID_STRING_ID);
	}
Esempio n. 4
0
/**
 * Add a new newsitem to be shown.
 * @param string String to display
 * @param type news category
 * @param flags display flags for the news
 * @param reftype1 Type of ref1
 * @param ref1     Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleteing the news when the object is deleted.
 * @param reftype2 Type of ref2
 * @param ref2     Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news when the object is deleted.
 * @param free_data Pointer to data that must be freed once the news message is cleared
 *
 * @see NewsSubtype
 */
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
{
	if (_game_mode == GM_MENU) return;

	/* Create new news item node */
	NewsItem *ni = new NewsItem;

	ni->string_id = string;
	ni->type = type;
	ni->flags = flags;

	/* show this news message in colour? */
	if (_cur_year >= _settings_client.gui.coloured_news_year) ni->flags |= NF_INCOLOUR;

	ni->reftype1 = reftype1;
	ni->reftype2 = reftype2;
	ni->ref1 = ref1;
	ni->ref2 = ref2;
	ni->free_data = free_data;
	ni->date = _date;
	CopyOutDParam(ni->params, 0, lengthof(ni->params));

	if (_total_news++ == 0) {
		assert(_oldest_news == NULL);
		_oldest_news = ni;
		ni->prev = NULL;
	} else {
		assert(_latest_news->next == NULL);
		_latest_news->next = ni;
		ni->prev = _latest_news;
	}

	ni->next = NULL;
	_latest_news = ni;

	SetWindowDirty(WC_MESSAGE_HISTORY, 0);
}