mirror of https://github.com/OpenTTD/OpenTTD
Add: AppendStringInPlace() to append translated string ID into an existing string. (#12969)
This allows avoiding a string copy when building strings.pull/12982/head
parent
3cd1200668
commit
14b986609b
|
@ -896,7 +896,7 @@ struct DepotWindow : Window {
|
||||||
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
|
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
|
||||||
SetDParam(2, cargo_type); // {SHORTCARGO} #1
|
SetDParam(2, cargo_type); // {SHORTCARGO} #1
|
||||||
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
|
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
|
||||||
details += GetString(STR_DEPOT_VEHICLE_TOOLTIP_CARGO);
|
AppendStringInPlace(details, STR_DEPOT_VEHICLE_TOOLTIP_CARGO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show tooltip window */
|
/* Show tooltip window */
|
||||||
|
|
|
@ -394,11 +394,11 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
|
||||||
std::string message = GetString(summary_msg);
|
std::string message = GetString(summary_msg);
|
||||||
if (detailed_msg != INVALID_STRING_ID) {
|
if (detailed_msg != INVALID_STRING_ID) {
|
||||||
message += " ";
|
message += " ";
|
||||||
message += GetString(detailed_msg);
|
AppendStringInPlace(message, detailed_msg);
|
||||||
}
|
}
|
||||||
if (extra_msg != INVALID_STRING_ID) {
|
if (extra_msg != INVALID_STRING_ID) {
|
||||||
message += " ";
|
message += " ";
|
||||||
message += GetString(extra_msg);
|
AppendStringInPlace(message, extra_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textref_stack_size > 0) StopTextRefStackUsage();
|
if (textref_stack_size > 0) StopTextRefStackUsage();
|
||||||
|
|
|
@ -386,7 +386,7 @@ class BuildIndustryWindow : public Window {
|
||||||
}
|
}
|
||||||
SetDParam(0, CargoSpec::Get(cargolist[j])->name);
|
SetDParam(0, CargoSpec::Get(cargolist[j])->name);
|
||||||
SetDParamStr(1, cargo_suffix[j].text);
|
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) {
|
if (numcargo > 0) {
|
||||||
|
|
|
@ -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;
|
const auto time = link.time ? back_time ? ((link.time + back_time) / 2) : link.time : back_time;
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
SetDParam(0, time);
|
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(0, link.cargo);
|
||||||
SetDParam(1, link.Usage());
|
SetDParam(1, link.Usage());
|
||||||
|
|
|
@ -60,10 +60,10 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
|
||||||
|
|
||||||
SetDParam(0, cid);
|
SetDParam(0, cid);
|
||||||
SetDParam(1, max_cargo[cid]);
|
SetDParam(1, max_cargo[cid]);
|
||||||
capacity += GetString(STR_JUST_CARGO);
|
AppendStringInPlace(capacity, STR_JUST_CARGO);
|
||||||
|
|
||||||
if (subtype_text[cid] != STR_NULL) {
|
if (subtype_text[cid] != STR_NULL) {
|
||||||
capacity += GetString(subtype_text[cid]);
|
AppendStringInPlace(capacity, subtype_text[cid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
|
|
@ -322,6 +322,19 @@ std::string GetString(StringID string)
|
||||||
return GetStringWithArgs(string, _global_string_params);
|
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.
|
* Get a parsed string with most special stringcodes replaced by the string parameters.
|
||||||
* @param string The ID of the string to parse.
|
* @param string The ID of the string to parse.
|
||||||
|
|
|
@ -61,6 +61,7 @@ inline StringID MakeStringID(StringTab tab, uint index)
|
||||||
|
|
||||||
std::string GetString(StringID string);
|
std::string GetString(StringID string);
|
||||||
const char *GetStringPtr(StringID string);
|
const char *GetStringPtr(StringID string);
|
||||||
|
void AppendStringInPlace(std::string &result, StringID string);
|
||||||
|
|
||||||
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type);
|
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type);
|
||||||
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);
|
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);
|
||||||
|
|
Loading…
Reference in New Issue