OpenTTD
Data Structures | Functions | Variables
strings_func.h File Reference

Functions related to OTTD's strings. More...

#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)
 
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...
 
void InjectDParam (uint amount)
 Shift the string parameters in the global string parameter array by amount positions, making room at the beginning. 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 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...
 
int CDECL StringIDSorter (const StringID *a, const StringID *b)
 
void CheckForMissingGlyphs (bool base_font=true, MissingGlyphSearcher *search=NULL)
 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_fontWhether to look at the base font as well.
searcherThe methods to use to search for strings to check. If NULL the loaded language pack searcher is used.

Definition at line 2089 of file strings.cpp.

References MissingGlyphSearcher::FindMissingGlyphs().

Referenced by TextfileWindow::LoadTextfile(), and MissingGlyphSearcher::~MissingGlyphSearcher().

◆ ConvertDisplaySpeedToKmhishSpeed()

uint ConvertDisplaySpeedToKmhishSpeed ( uint  speed)

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

Parameters
speedthe speed to convert
Returns
the converted speed.

Definition at line 755 of file strings.cpp.

References _settings_game, 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
speedthe speed to convert
Returns
the converted speed.

Definition at line 745 of file strings.cpp.

References _settings_game, 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
offsIndex in the global array to copy the first string parameter to.
srcSource array of string parameters.
numNumber of string parameters to copy.

Definition at line 138 of file strings.cpp.

References MemCpyT().

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

◆ CopyOutDParam() [1/2]

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

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

Parameters
dstDestination array of string parameters.
offsIndex in the global array to copy the first string parameter from.
numNumber of string parameters to copy.

Definition at line 149 of file strings.cpp.

References MemCpyT().

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

◆ CopyOutDParam() [2/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
dstDestination array of string parameters.
stringsDestination array for clone of the raw strings. Must be of same length as dst. Deallocation left to the caller.
stringThe string used to determine where raw strings are and where there are no raw strings.
numNumber of string parameters to copy.

Definition at line 162 of file strings.cpp.

References DRAW_STRING_BUFFER.

◆ GetCurrentLanguageIsoCode()

const char* GetCurrentLanguageIsoCode ( )

Get the ISO language code of the currently loaded language.

Returns
the ISO code.

Definition at line 1992 of file strings.cpp.

References LanguagePackHeader::isocode.

Referenced by GameOptionsWindow::DrawWidget(), GetDParam(), 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
nIndex of the string parameter.
Returns
Value of the requested string parameter.

Definition at line 231 of file strings_func.h.

References _current_text_dir, GetCurrentLanguageIsoCode(), and InitializeLanguagePacks().

◆ GetDParamX()

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

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

Parameters
sArray of string parameters.
nIndex of the string parameter.
Returns
Value of the requested string parameter.

Definition at line 221 of file strings_func.h.

◆ GetStringIndex()

static uint GetStringIndex ( StringID  str)
inlinestatic

Extract the StringIndex from a StringID.

Parameters
strString identifier
Returns
StringIndex from str

Definition at line 38 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
strString identifier
Returns
StringTab from str

Definition at line 25 of file strings_func.h.

References TAB_SIZE_BITS, TEXT_TAB_GAMESCRIPT_START, and TEXT_TAB_NEWGRF_START.

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
buffrPointer to a string buffer where the formatted string should be written to.
string
argsArguments for the string.
lastPointer just past the end of buffr.
case_indexThe "case index". This will only be set when FormatString wants to print the string in a different case.
game_scriptThe string is coming directly from a game script.
Returns
Pointer to the final zero byte of the formatted string.

Definition at line 216 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 1944 of file strings.cpp.

References FOR_ALL_SEARCHPATHS.

Referenced by GetDParam().

◆ InjectDParam()

void InjectDParam ( uint  amount)

Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.

Parameters
amountNumber of positions to shift.

Definition at line 288 of file strings.cpp.

◆ MakeStringID()

static StringID MakeStringID ( StringTab  tab,
uint  index 
)
inlinestatic

Create a StringID.

Parameters
tabStringTab
indexStringIndex
Returns
StringID composed from tab and index

Definition at line 49 of file strings_func.h.

References 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
nIndex of the string parameter.
vValue of the string parameter.

Definition at line 201 of file strings_func.h.

References CopyInDParam(), CopyOutDParam(), FS_NORMAL, SetDParamMaxDigits(), SetDParamMaxValue(), and SetDParamStr().

Referenced by AdvertiseIndustryOpening(), AgeVehicle(), AircraftHandleDestTooFar(), CcBuildIndustry(), CheckCompanyHasMoney(), ClientNetworkGameSocketHandler::CheckConnection(), CheckforTownRating(), CheckIndustries(), CmdDecreaseLoan(), CompanyCheckBankrupt(), CrashAirplane(), StationViewWindow::DrawAcceptedCargo(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawPrice(), SelectGameWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), StatusBarWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), MusicWindow::DrawWidget(), TooltipsWindow::DrawWidget(), CompanyWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), EngineNameSorter(), ErrorUnknownCallbackResult(), CompanyNewsInformation::FillData(), FloodVehicle(), IndustryDirectoryWindow::GetIndustryString(), GetNameOfOwner(), GetSaveLoadErrorString(), BaseGraphWindow::GetYLabelWidth(), GRFLoadConfig(), VehicleGroupWindow::GroupNameSorter(), Vehicle::HandlePathfindingResult(), IndustryDirectoryWindow::IndustryNameSorter(), MenuClickLargeWorldScreenshot(), NetworkHandlePauseChange(), WaypointWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), StationViewWindow::OnClick(), VehicleDetailsWindow::OnClick(), CompanyWindow::OnClick(), GenerateLandscapeWindow::OnDropdownSelect(), SelectCompanyManagerFaceWindow::OnInit(), HighScoreWindow::OnPaint(), DepotWindow::OnRightClick(), StoryBookWindow::RefreshSelectedPage(), RoadVehArrivesAt(), SaveHighScoreValue(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), NetworkSocketHandler::SendCompanyInformation(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), SetDParamMaxDigits(), SetDParamStr(), NIHelper::SetObjectAtStringParameters(), NIHelper::SetSimpleStringParameters(), GoalListWindow::SetStringParameters(), ContentTextfileWindow::SetStringParameters(), ExtraViewportWindow::SetStringParameters(), WaypointWindow::SetStringParameters(), OskWindow::SetStringParameters(), AIListWindow::SetStringParameters(), BuildObjectWindow::SetStringParameters(), SetDateWindow::SetStringParameters(), BaseSetTextfileWindow< TBaseSet >::SetStringParameters(), SmallMapWindow::SetStringParameters(), TownAuthorityWindow::SetStringParameters(), SignListWindow::SetStringParameters(), NewGRFParametersWindow::SetStringParameters(), BuildAirportWindow::SetStringParameters(), CompanyFinancesWindow::SetStringParameters(), MusicTrackSelectionWindow::SetStringParameters(), GameOptionsWindow::SetStringParameters(), AISettingsWindow::SetStringParameters(), ReplaceVehicleWindow::SetStringParameters(), TownViewWindow::SetStringParameters(), GenerateLandscapeWindow::SetStringParameters(), TimetableWindow::SetStringParameters(), NewsWindow::SetStringParameters(), GoalQuestionWindow::SetStringParameters(), DepotWindow::SetStringParameters(), VehicleGroupWindow::SetStringParameters(), StoryBookWindow::SetStringParameters(), SignWindow::SetStringParameters(), CompanyStationsWindow::SetStringParameters(), NetworkGameWindow::SetStringParameters(), BuildRailToolbarWindow::SetStringParameters(), NewGRFTextfileWindow::SetStringParameters(), ScriptTextfileWindow::SetStringParameters(), RefitWindow::SetStringParameters(), TownDirectoryWindow::SetStringParameters(), AIConfigWindow::SetStringParameters(), NewGRFWindow::SetStringParameters(), IndustryViewWindow::SetStringParameters(), CreateScenarioWindow::SetStringParameters(), QueryStringWindow::SetStringParameters(), NetworkStartServerWindow::SetStringParameters(), QueryWindow::SetStringParameters(), BuildRailStationWindow::SetStringParameters(), IndustryDirectoryWindow::SetStringParameters(), BuildVehicleWindow::SetStringParameters(), StationViewWindow::SetStringParameters(), VehicleListWindow::SetStringParameters(), BuildSignalWindow::SetStringParameters(), CompanyInfrastructureWindow::SetStringParameters(), GameSettingsWindow::SetStringParameters(), VehicleDetailsWindow::SetStringParameters(), IndustryCargoesWindow::SetStringParameters(), CompanyWindow::SetStringParameters(), CustomCurrencyWindow::SetStringParameters(), BuyCompanyWindow::SetStringParameters(), VehicleViewWindow::SetStringParameters(), SetTimetableParams(), SetupSubsidyDecodeParam(), SettingEntry::SetValueDParams(), ShipArrivesAt(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), SignList::SignNameFilter(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), ToolbarScenDatePanel(), TownDirectoryWindow::TownNameSorter(), TrainEnterStation(), SettingEntry::UpdateFilterState(), Waypoint::UpdateVirtCoord(), Sign::UpdateVirtCoord(), Town::UpdateVirtCoord(), SelectGameWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), and VehicleNameSorter().

◆ SetDParamMaxDigits()

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

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

Parameters
nIndex of the string parameter.
countNumber of digits which shall be displayable.
sizeFont of the number

Definition at line 121 of file strings.cpp.

References GetBroadestDigit(), and SetDParam().

Referenced by SetDParam(), SetDParamMaxValue(), DepotWindow::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
nIndex of the string parameter.
max_valueThe biggest value which shall be displayed. For the result only the number of digits of max_value matter.
min_countMinimum number of digits independent of max.
sizeFont of the number

Definition at line 105 of file strings.cpp.

References max(), and SetDParamMaxDigits().

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

◆ SetDParamStr()

void SetDParamStr ( uint  n,
const char *  str 
)

◆ 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
sArray of string parameters.
nIndex of the string parameter.
vValue of the string parameter.

Definition at line 191 of file strings_func.h.