diff options
author | rubidium42 <rubidium@openttd.org> | 2021-04-27 20:58:17 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-06 21:45:36 +0200 |
commit | 6bca9e090dc6637fd7b6ed6a5a37d65f151849e9 (patch) | |
tree | 062edb9db599f8e3244f6ed4acf3ad85f39912ae /src | |
parent | f313a539a54efe09850bcab0680d281e3cc54444 (diff) | |
download | openttd-6bca9e090dc6637fd7b6ed6a5a37d65f151849e9.tar.xz |
Codechange: add SetDParamStr that accepts std::string&
Diffstat (limited to 'src')
-rw-r--r-- | src/fios.cpp | 2 | ||||
-rw-r--r-- | src/fios_gui.cpp | 2 | ||||
-rw-r--r-- | src/industry_gui.cpp | 2 | ||||
-rw-r--r-- | src/music_gui.cpp | 2 | ||||
-rw-r--r-- | src/newgrf_gui.cpp | 12 | ||||
-rw-r--r-- | src/settings.cpp | 2 | ||||
-rw-r--r-- | src/settings_gui.cpp | 8 | ||||
-rw-r--r-- | src/strings.cpp | 11 | ||||
-rw-r--r-- | src/strings_func.h | 1 | ||||
-rw-r--r-- | src/town_gui.cpp | 4 | ||||
-rw-r--r-- | src/widgets/dropdown.cpp | 2 |
11 files changed, 30 insertions, 18 deletions
diff --git a/src/fios.cpp b/src/fios.cpp index 3b11bcbe0..c56e505fa 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -392,7 +392,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c 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)); } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 8de6235d6..e4de1acaa 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -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); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index aa4d86da6..d0c916ef7 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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); } diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 28cb6ce4e..16245a0b2 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -462,7 +462,7 @@ struct MusicTrackSelectionWindow : public Window { 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; } } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 6316a7c4b..9e86a575f 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -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 GRFConfig *c, uint x, uint y, uint right, uint { 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, NewGRFScanCallback { 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, NewGRFScanCallback { 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; } diff --git a/src/settings.cpp b/src/settings.cpp index c0b0dd8ed..855bedd18 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1631,7 +1631,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati 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; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 34c073fe9..9935d596c 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -123,7 +123,7 @@ struct BaseSetTextfileWindow : public TextfileWindow { { 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: { diff --git a/src/strings.cpp b/src/strings.cpp index 048971459..2b6dbc3ef 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -297,6 +297,17 @@ void SetDParamStr(uint n, const char *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. */ diff --git a/src/strings_func.h b/src/strings_func.h index e4b779105..be59b091a 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -205,6 +205,7 @@ void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize si 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); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index a189c7ccb..22f8b757f 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -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); } diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 8f4a8634e..4b89b4809 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -65,7 +65,7 @@ StringID DropDownListParamStringItem::String() const StringID DropDownListCharStringItem::String() const { - SetDParamStr(0, this->raw_string.c_str()); + SetDParamStr(0, this->raw_string); return this->string; } |