Changeset - r25394:5a394214a73a
[Not reviewed]
master
0 11 0
rubidium42 - 4 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
 
@@ -392,7 +392,7 @@ static void FiosGetFileList(SaveLoadOper
 
				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));
 
			}
src/fios_gui.cpp
Show inline comments
 
@@ -537,7 +537,7 @@ public:
 
							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);
src/industry_gui.cpp
Show inline comments
 
@@ -972,7 +972,7 @@ 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);
 
		}
src/music_gui.cpp
Show inline comments
 
@@ -462,7 +462,7 @@ struct MusicTrackSelectionWindow : publi
 
				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;
 
		}
 
	}
src/newgrf_gui.cpp
Show inline comments
 
@@ -51,9 +51,9 @@ void ShowNewGRFError()
 
		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]);
 
		}
 
@@ -70,9 +70,9 @@ static void ShowNewGRFInfo(const GRFConf
 
{
 
	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]);
 
		}
 
@@ -750,7 +750,7 @@ struct NewGRFWindow : public Window, New
 
			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;
 
@@ -783,7 +783,7 @@ struct NewGRFWindow : public Window, New
 
					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
 
@@ -1631,7 +1631,7 @@ static GRFConfig *GRFLoadConfig(IniFile 
 
				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;
src/settings_gui.cpp
Show inline comments
 
@@ -123,7 +123,7 @@ struct BaseSetTextfileWindow : public Te
 
	{
 
		if (widget == WID_TF_CAPTION) {
 
			SetDParam(0, content_type);
 
			SetDParamStr(1, this->baseset->name.c_str());
 
			SetDParamStr(1, this->baseset->name);
 
		}
 
	}
 
};
 
@@ -304,10 +304,10 @@ struct GameOptionsWindow : Window {
 
			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: {
src/strings.cpp
Show inline comments
 
@@ -297,6 +297,17 @@ void SetDParamStr(uint n, const char *st
 
}
 

	
 
/**
 
 * 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.
 
 */
src/strings_func.h
Show inline comments
 
@@ -205,6 +205,7 @@ void SetDParamMaxValue(uint n, uint64 ma
 
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);
src/town_gui.cpp
Show inline comments
 
@@ -435,7 +435,7 @@ public:
 
		}
 

	
 
		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);
 
		}
 
	}
 
@@ -517,7 +517,7 @@ public:
 
		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);
 
		}
 

	
src/widgets/dropdown.cpp
Show inline comments
 
@@ -65,7 +65,7 @@ StringID DropDownListParamStringItem::St
 

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

	
0 comments (0 inline, 0 general)