mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
Codechange: add SetDParamStr that accepts std::string&
This commit is contained in:
parent
f313a539a5
commit
6bca9e090d
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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: {
|
||||
|
@ -296,6 +296,17 @@ 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.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user