OpenTTD Source: src/strings_func.h File Reference

OpenTTD Source 13.2.1

Data Structures | Functions | Variables
strings_func.h File Reference
`#include "strings_type.h"`
`#include "string_type.h"`
`#include "gfx_type.h"`
`#include "core/bitmath_func.hpp"`

Go to the source code of this file.

## Data Structures
class | StringParameters
class | MissingGlyphSearcher
| A searcher for missing glyphs. More...

## Functions
static StringTab | GetStringTab (StringID str)
| Extract the StringTab from a StringID. More...
static uint | GetStringIndex (StringID str)
| Extract the StringIndex from a StringID. More...
static StringID | MakeStringID (StringTab tab, uint index)
| Create a StringID. More...
char * | GetString (char *buffr, StringID string, const char *last)
std::string | GetString (StringID string)
| Resolve the given StringID into a std::string with all the associated DParam lookups and formatting. More...
char * | GetStringWithArgs (char *buffr, StringID string, StringParameters *args, const char *last, uint case_index=0, bool game_script=false)
| Get a parsed string with most special stringcodes replaced by the string parameters. More...
const char * | GetStringPtr (StringID string)
uint | ConvertKmhishSpeedToDisplaySpeed (uint speed)
| Convert the given km/h-ish speed to the display speed. More...
uint | ConvertDisplaySpeedToKmhishSpeed (uint speed)
| Convert the given display speed to the km/h-ish speed. More...
static void | SetDParamX (uint64 *s, uint n, uint64 v)
| Set a string parameter v at index n in a given array s. More...
static void | SetDParam (uint n, uint64 v)
| Set a string parameter v at index n in the global string parameter array. More...
void | SetDParamMaxValue (uint n, uint64 max_value, uint min_count=0, FontSize size=FS_NORMAL)
| Set DParam n to some number that is suitable for string size computations. More...
void | SetDParamMaxDigits (uint n, uint count, FontSize size=FS_NORMAL)
| Set DParam n to some number that is suitable for string size computations. More...
void | SetDParamStr (uint n, const char *str)
| This function is used to "bind" a C string to a OpenTTD dparam slot. More...
void | SetDParamStr (uint n, const std::string &str)
| This function is used to "bind" the C string of a std::string to a OpenTTD dparam slot. More...
void | SetDParamStr (uint n, std::string &&str)=delete
void | CopyInDParam (int offs, const uint64 *src, int num)
| Copy num string parameters from array src into the global string parameter array. More...
void | CopyOutDParam (uint64 *dst, int offs, int num)
| Copy num string parameters from the global string parameter array to the dst array. More...
void | CopyOutDParam (uint64 *dst, const char **strings, StringID string, int num)
| Copy num string parameters from the global string parameter array to the dst array. More...
static uint64 | GetDParamX (const uint64 *s, uint n)
| Get the current string parameter at index n from parameter array s. More...
static uint64 | GetDParam (uint n)
| Get the current string parameter at index n from the global string parameter array. More...
void | InitializeLanguagePacks ()
| Make a list of the available language packs. More...
const char * | GetCurrentLanguageIsoCode ()
| Get the ISO language code of the currently loaded language. More...
bool | StringIDSorter (const StringID &a, const StringID &b)
void | CheckForMissingGlyphs (bool base_font=true, MissingGlyphSearcher *search=nullptr)
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support. More...

## Variables
StringParameters | _global_string_params
TextDirection | _current_text_dir
| Text direction of the currently selected language.

## Detailed Description

Functions related to OTTD's strings.

Definition in file strings_func.h.

## Function Documentation

## ◆ CheckForMissingGlyphs()

void CheckForMissingGlyphs | ( | bool | base_font,
|  | MissingGlyphSearcher * | searcher
| ) |  |

Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

If this is the case an error message will be shown in English. The error message will not be localized because that would mean it might use characters that are not in the font, which is the whole reason this check has been added.

Parameters

  base_font | Whether to look at the base font as well.
  searcher | The methods to use to search for strings to check. If nullptr the loaded language pack searcher is used.

Definition at line 2158 of file strings.cpp.

References MissingGlyphSearcher::FindMissingGlyphs().

Referenced by GameOptionsWindow::OnDropdownSelect().

## ◆ ConvertDisplaySpeedToKmhishSpeed()

uint ConvertDisplaySpeedToKmhishSpeed | ( | uint | speed | ) |

Convert the given display speed to the km/h-ish speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 798 of file strings.cpp.

References _settings_game, _units_velocity, Units::c, UnitConversion::FromDisplay(), GameSettings::locale, and LocaleSettings::units_velocity.

Referenced by TimetableWindow::OnQueryTextFinished().

## ◆ ConvertKmhishSpeedToDisplaySpeed()

uint ConvertKmhishSpeedToDisplaySpeed | ( | uint | speed | ) |

Convert the given km/h-ish speed to the display speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 788 of file strings.cpp.

References _settings_game, _units_velocity, Units::c, GameSettings::locale, UnitConversion::ToDisplay(), and LocaleSettings::units_velocity.

## ◆ CopyInDParam()

void CopyInDParam | ( | int | offs,
|  | const uint64 * | src,
|  | int | num
| ) |  |

Copy num string parameters from array src into the global string parameter array.

Parameters

  offs | Index in the global array to copy the first string parameter to.
  src | Source array of string parameters.
  num | Number of string parameters to copy.

Definition at line 129 of file strings.cpp.

References MemCpyT().

Referenced by ErrmsgWindow::DrawWidget(), ErrmsgWindow::SetStringParameters(), QueryWindow::SetStringParameters(), and ErrmsgWindow::UpdateWidgetSize().

## ◆ CopyOutDParam() [1/2]

void CopyOutDParam | ( | uint64 * | dst,
|  | const char ** | strings,
|  | StringID | string,
|  | int | num
| ) |  |

Copy num string parameters from the global string parameter array to the dst array.

Furthermore clone raw string parameters into strings and amend the data in dst.

Parameters

  dst | Destination array of string parameters.
  strings | Destination array for clone of the raw strings. Must be of same length as dst. Deallocation left to the caller.
  string | The string used to determine where raw strings are and where there are no raw strings.
  num | Number of string parameters to copy.

Definition at line 153 of file strings.cpp.

References DRAW_STRING_BUFFER, GetString(), lastof, and MemCpyT().

## ◆ CopyOutDParam() [2/2]

void CopyOutDParam | ( | uint64 * | dst,
|  | int | offs,
|  | int | num
| ) |  |

Copy num string parameters from the global string parameter array to the dst array.

Parameters

  dst | Destination array of string parameters.
  offs | Index in the global array to copy the first string parameter from.
  num | Number of string parameters to copy.

Definition at line 140 of file strings.cpp.

References MemCpyT().

Referenced by ErrorMessageData::CopyOutDParams(), and NewsItem::NewsItem().

## ◆ GetCurrentLanguageIsoCode()

const char* GetCurrentLanguageIsoCode | ( |  | ) |

Get the ISO language code of the currently loaded language.

Returns
  the ISO code.

Definition at line 2051 of file strings.cpp.

Referenced by GameOptionsWindow::DrawWidget(), and GameOptionsWindow::UpdateWidgetSize().

## ◆ GetDParam()

static uint64 GetDParam | ( | uint | n | ) |
| inlinestatic

Get the current string parameter at index n from the global string parameter array.

Parameters

  n | Index of the string parameter.

Returns
  Value of the requested string parameter.

Definition at line 228 of file strings_func.h.

## ◆ GetDParamX()

static uint64 GetDParamX | ( | const uint64 * | s,
|  | uint | n
| ) |  |
| inlinestatic

Get the current string parameter at index n from parameter array s.

Parameters

  s | Array of string parameters.
  n | Index of the string parameter.

Returns
  Value of the requested string parameter.

Definition at line 218 of file strings_func.h.

## ◆ GetString()

std::string GetString | ( | StringID | string | ) |

Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.

Parameters

  string | The unique identifier of the translatable string.

Returns
  The std::string of the translated string.

Definition at line 285 of file strings.cpp.

References DRAW_STRING_BUFFER, GetString(), and lastof.

Referenced by CopyOutDParam(), and GetString().

## ◆ GetStringIndex()

static uint GetStringIndex | ( | StringID | str | ) |
| inlinestatic

Extract the StringIndex from a StringID.

Parameters

  str | String identifier

Returns
  StringIndex from str

Definition at line 36 of file strings_func.h.

References GetStringTab(), and TAB_SIZE_BITS.

Referenced by GetStringWithArgs().

## ◆ GetStringTab()

static StringTab GetStringTab | ( | StringID | str | ) |
| inlinestatic

Extract the StringTab from a StringID.

Parameters

  str | String identifier

Returns
  StringTab from str

Definition at line 23 of file strings_func.h.

Referenced by CopyFromOldName(), GetStringIndex(), and GetStringWithArgs().

## ◆ GetStringWithArgs()

char* GetStringWithArgs | ( | char * | buffr,
|  | StringID | string,
|  | StringParameters * | args,
|  | const char * | last,
|  | uint | case_index,
|  | bool | game_script
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  buffr | Pointer to a string buffer where the formatted string should be written to.
  string |
  args | Arguments for the string.
  last | Pointer just past the end of buffr.
  case_index | The "case index". This will only be set when FormatString wants to print the string in a different case.
  game_script | The string is coming directly from a game script.

Returns
  Pointer to the final zero byte of the formatted string.

Definition at line 222 of file strings.cpp.

References GetStringIndex(), GetStringTab(), and GetStringWithArgs().

Referenced by GetStringWithArgs(), and GetTownName().

## ◆ InitializeLanguagePacks()

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

Put the data in _languages list.

< Matching the language in the configuration file or the current locale

< Using pt_PT for pt_BR locale when pt_BR is not available

< Fallback when no locale-matching language has been found

Definition at line 2002 of file strings.cpp.

## ◆ MakeStringID()

static StringID MakeStringID | ( | StringTab | tab,
|  | uint | index
| ) |  |
| inlinestatic

Create a StringID.

Parameters

  tab | StringTab
  index | StringIndex

Returns
  StringID composed from tab and index

Definition at line 47 of file strings_func.h.

References TAB_SIZE, TAB_SIZE_BITS, TAB_SIZE_GAMESCRIPT, TAB_SIZE_NEWGRF, TEXT_TAB_END, TEXT_TAB_GAMESCRIPT_START, and TEXT_TAB_NEWGRF_START.

## ◆ SetDParam()

static void SetDParam | ( | uint | n,
|  | uint64 | v
| ) |  |
| inlinestatic

Set a string parameter v at index n in the global string parameter array.

Parameters

  n | Index of the string parameter.
  v | Value of the string parameter.

Definition at line 196 of file strings_func.h.

Referenced by AdvertiseIndustryOpening(), AgeVehicle(), AircraftHandleDestTooFar(), Subsidy::AwardTo(), VehicleGroupWindow::BuildGroupList(), BuildReplacementVehicle(), NetworkChatWindow::ChatTabCompletionNextItem(), CheckCompanyHasMoney(), ClientNetworkGameSocketHandler::CheckConnection(), CheckforTownRating(), CheckIndustries(), CheckTrainCollision(), CheckTrainsLengths(), CmdCompanyCtrl(), CompanyNewsInformation::CompanyNewsInformation(), CrashAirplane(), StationViewWindow::DrawAcceptedCargo(), StationViewWindow::DrawCargoRatings(), DrawPrice(), TownAuthorityWindow::DrawRatings(), EnginePreviewWindow::DrawWidget(), StatusBarWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectGameWindow::DrawWidget(), TownViewWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), TooltipsWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), CompanyWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), ErrorUnknownCallbackResult(), FloodVehicle(), GenerateDefaultSaveName(), BuildBridgeWindow::GetBridgeSelectString(), RefitWindow::GetCapacityString(), IndustryDirectoryWindow::GetIndustryString(), GetNameOfOwner(), GetSaveLoadErrorString(), BaseGraphWindow::GetYLabelWidth(), GRFLoadConfig(), Vehicle::HandlePathfindingResult(), CommandHelperBase::InternalExecuteProcessResult(), BuildIndustryWindow::MakeCargoListString(), MakeScreenshotWithConfirm(), NetworkHandlePauseChange(), WaypointWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), StationViewWindow::OnClick(), VehicleViewWindow::OnClick(), GenerateLandscapeWindow::OnDropdownSelect(), SelectCompanyManagerFaceWindow::OnInit(), HighScoreWindow::OnPaint(), GameSettingsWindow::OnPaint(), DepotWindow::OnRightClick(), StoryBookWindow::RefreshSelectedPage(), RoadVehArrivesAt(), SaveHighScoreValue(), SaveHighScoreValueNetwork(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), SetDParamMaxDigits(), SetDParamStr(), SelectCompanyManagerFaceWindow::SetFaceStringParameters(), NIHelper::SetObjectAtStringParameters(), NIHelper::SetSimpleStringParameters(), GoalListWindow::SetStringParameters(), ContentTextfileWindow::SetStringParameters(), ExtraViewportWindow::SetStringParameters(), WaypointWindow::SetStringParameters(), OskWindow::SetStringParameters(), AIListWindow::SetStringParameters(), BaseSetTextfileWindow< TBaseSet >::SetStringParameters(), SetDateWindow::SetStringParameters(), SmallMapWindow::SetStringParameters(), BuildObjectWindow::SetStringParameters(), TownAuthorityWindow::SetStringParameters(), SignListWindow::SetStringParameters(), NewGRFParametersWindow::SetStringParameters(), GameOptionsWindow::SetStringParameters(), BuildAirportWindow::SetStringParameters(), TimetableWindow::SetStringParameters(), BuildRoadToolbarWindow::SetStringParameters(), CompanyFinancesWindow::SetStringParameters(), GoalQuestionWindow::SetStringParameters(), TownViewWindow::SetStringParameters(), ReplaceVehicleWindow::SetStringParameters(), NewsWindow::SetStringParameters(), DepotWindow::SetStringParameters(), GenerateLandscapeWindow::SetStringParameters(), MusicTrackSelectionWindow::SetStringParameters(), VehicleGroupWindow::SetStringParameters(), SignWindow::SetStringParameters(), BuildRailToolbarWindow::SetStringParameters(), CompanyStationsWindow::SetStringParameters(), NewGRFTextfileWindow::SetStringParameters(), ScriptTextfileWindow::SetStringParameters(), StoryBookWindow::SetStringParameters(), AIConfigWindow::SetStringParameters(), NewGRFWindow::SetStringParameters(), TownDirectoryWindow::SetStringParameters(), SelectCompanyLiveryWindow::SetStringParameters(), RefitWindow::SetStringParameters(), IndustryViewWindow::SetStringParameters(), QueryStringWindow::SetStringParameters(), NetworkStartServerWindow::SetStringParameters(), CreateScenarioWindow::SetStringParameters(), AIDebugWindow::SetStringParameters(), QueryWindow::SetStringParameters(), BuildRailStationWindow::SetStringParameters(), StationViewWindow::SetStringParameters(), BuildVehicleWindow::SetStringParameters(), IndustryDirectoryWindow::SetStringParameters(), BuildSignalWindow::SetStringParameters(), NetworkClientListWindow::SetStringParameters(), CompanyInfrastructureWindow::SetStringParameters(), VehicleListWindow::SetStringParameters(), GameSettingsWindow::SetStringParameters(), ScenarioEditorToolbarWindow::SetStringParameters(), VehicleDetailsWindow::SetStringParameters(), CompanyWindow::SetStringParameters(), IndustryCargoesWindow::SetStringParameters(), CustomCurrencyWindow::SetStringParameters(), BuyCompanyWindow::SetStringParameters(), VehicleViewWindow::SetStringParameters(), SetTimetableParams(), SetupSubsidyDecodeParam(), SettingEntry::SetValueDParams(), ShipArrivesAt(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), ToolbarScenDatePanel(), TrainEnterStation(), UpdateFillingPercent(), SettingEntry::UpdateFilterState(), Waypoint::UpdateVirtCoord(), Sign::UpdateVirtCoord(), Town::UpdateVirtCoord(), TownAuthorityWindow::UpdateWidgetSize(), SelectGameWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), and CustomCurrencyWindow::UpdateWidgetSize().

## ◆ SetDParamMaxDigits()

void SetDParamMaxDigits | ( | uint | n,
|  | uint | count,
|  | FontSize | size
| ) |  |

Set DParam n to some number that is suitable for string size computations.

Parameters

  n | Index of the string parameter.
  count | Number of digits which shall be displayable.
  size | Font of the number

Definition at line 111 of file strings.cpp.

References GetBroadestDigit(), and SetDParam().

Referenced by SetDParamMaxValue(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), and ScanProgressWindow::UpdateWidgetSize().

## ◆ SetDParamMaxValue()

void SetDParamMaxValue | ( | uint | n,
|  | uint64 | max_value,
|  | uint | min_count,
|  | FontSize | size
| ) |  |

Set DParam n to some number that is suitable for string size computations.

Parameters

  n | Index of the string parameter.
  max_value | The biggest value which shall be displayed. For the result only the number of digits of max_value matter.
  min_count | Minimum number of digits independent of max.
  size | Font of the number

Definition at line 95 of file strings.cpp.

References SetDParamMaxDigits().

Referenced by TimetableWindow::DrawWidget(), OrdersWindow::DrawWidget(), SetDateWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), and VehicleDetailsWindow::UpdateWidgetSize().

## ◆ SetDParamStr() [1/2]

void SetDParamStr | ( | uint | n,
|  | const char * | str
| ) |  |

This function is used to "bind" a C string to a OpenTTD dparam slot.

Parameters

  n | slot of the string
  str | string to bind

Definition at line 297 of file strings.cpp.

References SetDParam().

Referenced by CmdCompanyCtrl(), CmdCustomNewsItem(), GoalListWindow::DrawListColumn(), GSConfigWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), ErrorUnknownCallbackResult(), StoryBookWindow::GetHeadHeight(), StoryBookWindow::GetPageElementHeight(), GetSavegameFormat(), GetSaveLoadErrorString(), GRFLoadConfig(), BuildIndustryWindow::MakeCargoListString(), NetworkClientListWindow::OnClick(), IConsoleWindow::OnPaint(), GoalListWindow::OnPaint(), SaveFileError(), SetDParamStr(), ContentTextfileWindow::SetStringParameters(), BaseSetTextfileWindow< TBaseSet >::SetStringParameters(), ScriptLeagueWindow::SetStringParameters(), NetworkChatWindow::SetStringParameters(), MusicTrackSelectionWindow::SetStringParameters(), AboutWindow::SetStringParameters(), NewGRFTextfileWindow::SetStringParameters(), ScriptTextfileWindow::SetStringParameters(), StoryBookWindow::SetStringParameters(), NewGRFWindow::SetStringParameters(), AIDebugWindow::SetStringParameters(), NetworkClientListWindow::SetStringParameters(), NetworkAskRelayWindow::SetStringParameters(), CustomCurrencyWindow::SetStringParameters(), ShowNewGrfVehicleError(), LandInfoWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GoalQuestionWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), and WarnCorruptSprite().

## ◆ SetDParamStr() [2/2]

void SetDParamStr | ( | uint | n,
|  | const std::string & | 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.

Parameters

  n | slot of the string
  str | string to bind

Definition at line 308 of file strings.cpp.

References SetDParamStr().

## ◆ SetDParamX()

static void SetDParamX | ( | uint64 * | s,
|  | uint | n,
|  | uint64 | v
| ) |  |
| inlinestatic

Set a string parameter v at index n in a given array s.

Parameters

  s | Array of string parameters.
  n | Index of the string parameter.
  v | Value of the string parameter.

Definition at line 186 of file strings_func.h.