diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 6a66d22ba1..2d176fa71e 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -896,7 +896,7 @@ struct DepotWindow : Window { SetDParam(1, loaded[cargo_type]); // {CARGO} #2 SetDParam(2, cargo_type); // {SHORTCARGO} #1 SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2 - details += GetString(STR_DEPOT_VEHICLE_TOOLTIP_CARGO); + AppendStringInPlace(details, STR_DEPOT_VEHICLE_TOOLTIP_CARGO); } /* Show tooltip window */ diff --git a/src/error_gui.cpp b/src/error_gui.cpp index d6877fcd4b..1276e9fb2d 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -394,11 +394,11 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel std::string message = GetString(summary_msg); if (detailed_msg != INVALID_STRING_ID) { message += " "; - message += GetString(detailed_msg); + AppendStringInPlace(message, detailed_msg); } if (extra_msg != INVALID_STRING_ID) { message += " "; - message += GetString(extra_msg); + AppendStringInPlace(message, extra_msg); } if (textref_stack_size > 0) StopTextRefStackUsage(); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 5eeaa10403..2d38c282f4 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -386,7 +386,7 @@ class BuildIndustryWindow : public Window { } SetDParam(0, CargoSpec::Get(cargolist[j])->name); SetDParamStr(1, cargo_suffix[j].text); - cargostring += GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION); + AppendStringInPlace(cargostring, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION); } if (numcargo > 0) { diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 02f2718e3c..100e6d6273 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -394,7 +394,7 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond) const auto time = link.time ? back_time ? ((link.time + back_time) / 2) : link.time : back_time; if (time > 0) { SetDParam(0, time); - tooltip_extension += GetString(STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION); + AppendStringInPlace(tooltip_extension, STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION); } SetDParam(0, link.cargo); SetDParam(1, link.Usage()); diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 358a27bbaf..a548b5a458 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -60,10 +60,10 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r) SetDParam(0, cid); SetDParam(1, max_cargo[cid]); - capacity += GetString(STR_JUST_CARGO); + AppendStringInPlace(capacity, STR_JUST_CARGO); if (subtype_text[cid] != STR_NULL) { - capacity += GetString(subtype_text[cid]); + AppendStringInPlace(capacity, subtype_text[cid]); } first = false; diff --git a/src/strings.cpp b/src/strings.cpp index 7fa1bad9c1..d95ff909b3 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -322,6 +322,19 @@ std::string GetString(StringID string) return GetStringWithArgs(string, _global_string_params); } +/** + * Resolve the given StringID and append in place into an existing std::string with all the associated + * DParam lookups and formatting. + * @param result The std::string to place the translated string. + * @param string The unique identifier of the translatable string. + */ +void AppendStringInPlace(std::string &result, StringID string) +{ + _global_string_params.PrepareForNextRun(); + StringBuilder builder(result); + GetStringWithArgs(builder, string, _global_string_params); +} + /** * Get a parsed string with most special stringcodes replaced by the string parameters. * @param string The ID of the string to parse. diff --git a/src/strings_func.h b/src/strings_func.h index 3ee91a0af5..8dcd410319 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -61,6 +61,7 @@ inline StringID MakeStringID(StringTab tab, uint index) std::string GetString(StringID string); const char *GetStringPtr(StringID string); +void AppendStringInPlace(std::string &result, StringID string); uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type); uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);