mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: use std::string to create the GRF parameter list
This commit is contained in:
parent
fbab94eabb
commit
4fdde00e25
|
@ -714,18 +714,14 @@ GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask)
|
||||||
|
|
||||||
|
|
||||||
/** Build a string containing space separated parameter values, and terminate */
|
/** Build a string containing space separated parameter values, and terminate */
|
||||||
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
|
std::string GRFBuildParamList(const GRFConfig *c)
|
||||||
{
|
{
|
||||||
uint i;
|
std::string result;
|
||||||
|
for (uint i = 0; i < c->num_params; i++) {
|
||||||
/* Return an empty string if there are no parameters */
|
if (!result.empty()) result += ' ';
|
||||||
if (c->num_params == 0) return strecpy(dst, "", last);
|
result += std::to_string(c->param[i]);
|
||||||
|
|
||||||
for (i = 0; i < c->num_params; i++) {
|
|
||||||
if (i > 0) dst = strecpy(dst, " ", last);
|
|
||||||
dst += seprintf(dst, last, "%d", c->param[i]);
|
|
||||||
}
|
}
|
||||||
return dst;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -220,7 +220,7 @@ void ClearGRFConfigList(GRFConfig **config);
|
||||||
void ResetGRFConfig(bool defaults);
|
void ResetGRFConfig(bool defaults);
|
||||||
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
|
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
|
||||||
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
|
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
|
||||||
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
|
std::string GRFBuildParamList(const GRFConfig *c);
|
||||||
|
|
||||||
/* In newgrf_gui.cpp */
|
/* In newgrf_gui.cpp */
|
||||||
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
|
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
|
||||||
|
|
|
@ -112,10 +112,9 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
/* Show GRF parameter list */
|
/* Show GRF parameter list */
|
||||||
if (show_params) {
|
if (show_params) {
|
||||||
if (c->num_params > 0) {
|
if (c->num_params > 0) {
|
||||||
char buff[256];
|
std::string params = GRFBuildParamList(c);
|
||||||
GRFBuildParamList(buff, c, lastof(buff));
|
|
||||||
SetDParam(0, STR_JUST_RAW_STRING);
|
SetDParam(0, STR_JUST_RAW_STRING);
|
||||||
SetDParamStr(1, buff);
|
SetDParamStr(1, params);
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
|
SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1134,12 +1134,9 @@ static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *li
|
||||||
const GRFConfig *c;
|
const GRFConfig *c;
|
||||||
|
|
||||||
for (c = list; c != nullptr; c = c->next) {
|
for (c = list; c != nullptr; c = c->next) {
|
||||||
char params[512];
|
|
||||||
GRFBuildParamList(params, c, lastof(params));
|
|
||||||
|
|
||||||
std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid),
|
std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid),
|
||||||
FormatArrayAsHex(c->ident.md5sum), c->filename);
|
FormatArrayAsHex(c->ident.md5sum), c->filename);
|
||||||
group->GetItem(key, true)->SetValue(params);
|
group->GetItem(key, true)->SetValue(GRFBuildParamList(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue