Changeset - r25394:5a394214a73a
[Not reviewed]
master
0 11 0
rubidium42 - 3 years ago 2021-04-27 18:58:17
rubidium@openttd.org
Codechange: add SetDParamStr that accepts std::string&
11 files changed with 30 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/fios.cpp
Show inline comments
 
@@ -389,13 +389,13 @@ static void FiosGetFileList(SaveLoadOper
 
					strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
 
				fios = &file_list.emplace_back();
 
				fios->type = FIOS_TYPE_DIR;
 
				fios->mtime = 0;
 
				strecpy(fios->name, d_name, lastof(fios->name));
 
				std::string dirname = std::string(d_name) + PATHSEP;
 
				SetDParamStr(0, dirname.c_str());
 
				SetDParamStr(0, dirname);
 
				GetString(fios->title, STR_SAVELOAD_DIRECTORY, lastof(fios->title));
 
				str_validate(fios->title, lastof(fios->title));
 
			}
 
		}
 
		closedir(dir);
 
	}
src/fios_gui.cpp
Show inline comments
 
@@ -534,13 +534,13 @@ public:
 
						/* Companies / AIs */
 
						for (auto &pair : _load_check_data.companies) {
 
							SetDParam(0, pair.first + 1);
 
							const CompanyProperties &c = *pair.second;
 
							if (!c.name.empty()) {
 
								SetDParam(1, STR_JUST_RAW_STRING);
 
								SetDParamStr(2, c.name.c_str());
 
								SetDParamStr(2, c.name);
 
							} else {
 
								SetDParam(1, c.name_1);
 
								SetDParam(2, c.name_2);
 
							}
 
							DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
 
							y += FONT_HEIGHT_NORMAL;
src/industry_gui.cpp
Show inline comments
 
@@ -969,13 +969,13 @@ public:
 
					}
 
				}
 
			}
 
		}
 

	
 
		if (!i->text.empty()) {
 
			SetDParamStr(0, i->text.c_str());
 
			SetDParamStr(0, i->text);
 
			y += WD_PAR_VSEP_WIDE;
 
			y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
 
		}
 

	
 
		return y + WD_FRAMERECT_BOTTOM;
 
	}
src/music_gui.cpp
Show inline comments
 
@@ -459,13 +459,13 @@ struct MusicTrackSelectionWindow : publi
 
	{
 
		switch (widget) {
 
			case WID_MTS_PLAYLIST:
 
				SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
 
				break;
 
			case WID_MTS_CAPTION:
 
				SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str());
 
				SetDParamStr(0, BaseMusic::GetUsedSet()->name);
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
src/newgrf_gui.cpp
Show inline comments
 
@@ -48,15 +48,15 @@ void ShowNewGRFError()
 

	
 
	for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
 
		/* Only show Fatal and Error level messages */
 
		if (c->error == nullptr || (c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL && c->error->severity != STR_NEWGRF_ERROR_MSG_ERROR)) continue;
 

	
 
		SetDParam   (0, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
 
		SetDParamStr(1, c->error->custom_message.c_str());
 
		SetDParamStr(1, c->error->custom_message);
 
		SetDParamStr(2, c->filename);
 
		SetDParamStr(3, c->error->data.c_str());
 
		SetDParamStr(3, c->error->data);
 
		for (uint i = 0; i < lengthof(c->error->param_value); i++) {
 
			SetDParam(4 + i, c->error->param_value[i]);
 
		}
 
		if (c->error->severity == STR_NEWGRF_ERROR_MSG_FATAL) {
 
			ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
 
		} else {
 
@@ -67,15 +67,15 @@ void ShowNewGRFError()
 
}
 

	
 
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint bottom, bool show_params)
 
{
 
	if (c->error != nullptr) {
 
		char message[512];
 
		SetDParamStr(0, c->error->custom_message.c_str()); // is skipped by built-in messages
 
		SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
 
		SetDParamStr(1, c->filename);
 
		SetDParamStr(2, c->error->data.c_str());
 
		SetDParamStr(2, c->error->data);
 
		for (uint i = 0; i < lengthof(c->error->param_value); i++) {
 
			SetDParam(3 + i, c->error->param_value[i]);
 
		}
 
		GetString(message, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
 

	
 
		SetDParamStr(0, message);
 
@@ -747,13 +747,13 @@ struct NewGRFWindow : public Window, New
 
				size->height = std::max(size->height, WD_FRAMERECT_TOP + 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + padding.height + 2);
 
				break;
 

	
 
			case WID_NS_PRESET_LIST: {
 
				Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
 
				for (const auto &i : this->grf_presets) {
 
					SetDParamStr(0, i.c_str());
 
					SetDParamStr(0, i);
 
					d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
 
				}
 
				d.width += padding.width;
 
				*size = maxdim(d, *size);
 
				break;
 
			}
 
@@ -780,13 +780,13 @@ struct NewGRFWindow : public Window, New
 
		switch (widget) {
 
			case WID_NS_PRESET_LIST:
 
				if (this->preset == -1) {
 
					SetDParam(0, STR_NUM_CUSTOM);
 
				} else {
 
					SetDParam(0, STR_JUST_RAW_STRING);
 
					SetDParamStr(1, this->grf_presets[this->preset].c_str());
 
					SetDParamStr(1, this->grf_presets[this->preset]);
 
				}
 
				break;
 
		}
 
	}
 

	
 
	/**
src/settings.cpp
Show inline comments
 
@@ -1628,13 +1628,13 @@ static GRFConfig *GRFLoadConfig(IniFile 
 
			} else if (HasBit(c->flags, GCF_INVALID)) {
 
				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
 
			} else {
 
				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
 
			}
 

	
 
			SetDParamStr(0, StrEmpty(filename) ? item->name.c_str() : filename);
 
			SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
 
			ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
 
			delete c;
 
			continue;
 
		}
 

	
 
		/* Check for duplicate GRFID (will also check for duplicate filenames) */
src/settings_gui.cpp
Show inline comments
 
@@ -120,13 +120,13 @@ struct BaseSetTextfileWindow : public Te
 
	}
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
		if (widget == WID_TF_CAPTION) {
 
			SetDParam(0, content_type);
 
			SetDParamStr(1, this->baseset->name.c_str());
 
			SetDParamStr(1, this->baseset->name);
 
		}
 
	}
 
};
 

	
 
/**
 
 * Open the BaseSet version of the textfile window.
 
@@ -301,16 +301,16 @@ struct GameOptionsWindow : Window {
 
		switch (widget) {
 
			case WID_GO_CURRENCY_DROPDOWN:     SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
 
			case WID_GO_AUTOSAVE_DROPDOWN:     SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
 
			case WID_GO_LANG_DROPDOWN:         SetDParamStr(0, _current_language->own_name); break;
 
			case WID_GO_GUI_ZOOM_DROPDOWN:     SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
 
			case WID_GO_FONT_ZOOM_DROPDOWN:    SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
 
			case WID_GO_BASE_GRF_DROPDOWN:     SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
 
			case WID_GO_BASE_GRF_DROPDOWN:     SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
 
			case WID_GO_BASE_GRF_STATUS:       SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
 
			case WID_GO_BASE_SFX_DROPDOWN:     SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
 
			case WID_GO_BASE_MUSIC_DROPDOWN:   SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
 
			case WID_GO_BASE_SFX_DROPDOWN:     SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
 
			case WID_GO_BASE_MUSIC_DROPDOWN:   SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
 
			case WID_GO_BASE_MUSIC_STATUS:     SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
 
			case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
 
			case WID_GO_RESOLUTION_DROPDOWN: {
 
				auto current_resolution = GetCurrentResolutionIndex();
 

	
 
				if (current_resolution == _resolutions.size()) {
src/strings.cpp
Show inline comments
 
@@ -294,12 +294,23 @@ char *GetString(char *buffr, StringID st
 
void SetDParamStr(uint n, const char *str)
 
{
 
	SetDParam(n, (uint64)(size_t)str);
 
}
 

	
 
/**
 
 * This function is used to "bind" the C string of a std::string to a OpenTTD dparam slot.
 
 * The caller has to ensure that the std::string reference remains valid while the string is shown.
 
 * @param n slot of the string
 
 * @param str string to bind
 
 */
 
void SetDParamStr(uint n, const std::string &str)
 
{
 
	SetDParamStr(n, str.c_str());
 
}
 

	
 
/**
 
 * Shift the string parameters in the global string parameter array by \a amount positions, making room at the beginning.
 
 * @param amount Number of positions to shift.
 
 */
 
void InjectDParam(uint amount)
 
{
 
	_global_string_params.ShiftParameters(amount);
src/strings_func.h
Show inline comments
 
@@ -202,12 +202,13 @@ static inline void SetDParam(uint n, uin
 
}
 

	
 
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
 
void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
 

	
 
void SetDParamStr(uint n, const char *str);
 
void SetDParamStr(uint n, const std::string &str);
 

	
 
void CopyInDParam(int offs, const uint64 *src, int num);
 
void CopyOutDParam(uint64 *dst, int offs, int num);
 
void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
 

	
 
/**
src/town_gui.cpp
Show inline comments
 
@@ -432,13 +432,13 @@ public:
 
			SetDParam(0, this->town->noise_reached);
 
			SetDParam(1, this->town->MaxTownNoise());
 
			DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_NOISE_IN_TOWN);
 
		}
 

	
 
		if (!this->town->text.empty()) {
 
			SetDParamStr(0, this->town->text.c_str());
 
			SetDParamStr(0, this->town->text);
 
			DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
 
		}
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
@@ -514,13 +514,13 @@ public:
 
		}
 
		aimed_height += FONT_HEIGHT_NORMAL;
 

	
 
		if (_settings_game.economy.station_noise_level) aimed_height += FONT_HEIGHT_NORMAL;
 

	
 
		if (!this->town->text.empty()) {
 
			SetDParamStr(0, this->town->text.c_str());
 
			SetDParamStr(0, this->town->text);
 
			aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT);
 
		}
 

	
 
		return aimed_height;
 
	}
 

	
src/widgets/dropdown.cpp
Show inline comments
 
@@ -62,13 +62,13 @@ StringID DropDownListParamStringItem::St
 
	for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
 
	return this->string;
 
}
 

	
 
StringID DropDownListCharStringItem::String() const
 
{
 
	SetDParamStr(0, this->raw_string.c_str());
 
	SetDParamStr(0, this->raw_string);
 
	return this->string;
 
}
 

	
 
DropDownListIconItem::DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked) : DropDownListParamStringItem(string, result, masked), sprite(sprite), pal(pal)
 
{
 
	this->dim = GetSpriteSize(sprite);
0 comments (0 inline, 0 general)