OpenTTD Source
20241120-master-g6d3adc6169
|
Functions related to OTTD's strings. More...
#include "strings_type.h"
#include "string_type.h"
#include "gfx_type.h"
#include "core/bitmath_func.hpp"
#include "core/strong_typedef_type.hpp"
#include "vehicle_type.h"
Go to the source code of this file.
Data Structures | |
class | MissingGlyphSearcher |
A searcher for missing glyphs. More... | |
Functions | |
StringTab | GetStringTab (StringID str) |
Extract the StringTab from a StringID. More... | |
uint | GetStringIndex (StringID str) |
Extract the StringIndex from a StringID. More... | |
StringID | MakeStringID (StringTab tab, uint index) |
Create a StringID. More... | |
std::string | GetString (StringID string) |
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting. More... | |
const char * | GetStringPtr (StringID string) |
void | AppendStringInPlace (std::string &result, StringID string) |
Resolve the given StringID and append in place into an existing std::string with all the associated DParam lookups and formatting. More... | |
uint | ConvertKmhishSpeedToDisplaySpeed (uint speed, VehicleType type) |
Convert the given km/h-ish speed to the display speed. More... | |
uint | ConvertDisplaySpeedToKmhishSpeed (uint speed, VehicleType type) |
Convert the given display speed to the km/h-ish speed. More... | |
int64_t | PackVelocity (uint speed, VehicleType type) |
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter. More... | |
void | SetDParam (size_t n, uint64_t v) |
Set a string parameter v at index n in the global string parameter array. More... | |
void | SetDParamMaxValue (size_t n, uint64_t 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 (size_t n, uint count, FontSize size=FS_NORMAL) |
Set DParam n to some number that is suitable for string size computations. More... | |
template<typename T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0> | |
void | SetDParam (size_t n, T v) |
template<typename T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0> | |
void | SetDParamMaxValue (size_t n, T max_value, uint min_count=0, FontSize size=FS_NORMAL) |
void | SetDParamStr (size_t n, const char *str) |
This function is used to "bind" a C string to a OpenTTD dparam slot. More... | |
void | SetDParamStr (size_t 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 (size_t n, std::string &&str) |
This function is used to "bind" the std::string to a OpenTTD dparam slot. More... | |
void | CopyInDParam (const std::span< const StringParameterData > backup) |
Copy the parameters from the backup into the global string parameter array. More... | |
void | CopyOutDParam (std::vector< StringParameterData > &backup, size_t num) |
Copy num string parameters from the global string parameter array to the backup. More... | |
bool | HaveDParamChanged (const std::span< const StringParameterData > backup) |
Checks whether the global string parameters have changed compared to the given backup. More... | |
uint64_t | GetDParam (size_t 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... | |
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 | |
TextDirection | _current_text_dir |
Text direction of the currently selected language. | |
Functions related to OTTD's strings.
Definition in file strings_func.h.
void AppendStringInPlace | ( | std::string & | result, |
StringID | string | ||
) |
Resolve the given StringID and append in place into an existing std::string with all the associated DParam lookups and formatting.
result | The std::string to place the translated string. |
string | The unique identifier of the translatable string. |
Definition at line 331 of file strings.cpp.
Referenced by BuildIndustryWindow::MakeCargoListString().
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.
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 2265 of file strings.cpp.
References MissingGlyphSearcher::FindMissingGlyphs().
Referenced by TextfileWindow::LoadText().
uint ConvertDisplaySpeedToKmhishSpeed | ( | uint | speed, |
VehicleType | type | ||
) |
Convert the given display speed to the km/h-ish speed.
speed | the speed to convert |
Definition at line 902 of file strings.cpp.
References Units::c, UnitConversion::FromDisplay(), and GetVelocityUnits().
uint ConvertKmhishSpeedToDisplaySpeed | ( | uint | speed, |
VehicleType | type | ||
) |
Convert the given km/h-ish speed to the display speed.
speed | the speed to convert |
Definition at line 892 of file strings.cpp.
References Units::c, GetVelocityUnits(), and UnitConversion::ToDisplay().
void CopyInDParam | ( | const std::span< const StringParameterData > | backup | ) |
Copy the parameters from the backup into the global string parameter array.
backup | The backup to copy from. |
Definition at line 159 of file strings.cpp.
void CopyOutDParam | ( | std::vector< StringParameterData > & | backup, |
size_t | num | ||
) |
Copy num string parameters from the global string parameter array to the backup.
backup | The backup to write to. |
num | Number of string parameters to copy. |
Definition at line 171 of file strings.cpp.
Referenced by NewsItem::NewsItem().
const char* GetCurrentLanguageIsoCode | ( | ) |
Get the ISO language code of the currently loaded language.
Definition at line 2157 of file strings.cpp.
uint64_t GetDParam | ( | size_t | n | ) |
Get the current string parameter at index n from the global string parameter array.
n | Index of the string parameter. |
Definition at line 114 of file strings.cpp.
std::string GetString | ( | StringID | string | ) |
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
string | The unique identifier of the translatable string. |
Definition at line 319 of file strings.cpp.
Referenced by StringFilter::AddLine(), Textbuf::Assign(), Subsidy::AwardTo(), CargoSpecNameSorter(), ClassTagNameFilter(), CmdGiveMoney(), CompanyNewsInformation::CompanyNewsInformation(), DrawString(), DrawStringMultiLine(), BuildVehicleWindow::FilterByText(), GetKeyboardLayout(), BaseSet< T, Tnum_files, Tsearch_in_tars >::GetListLabel(), GetStringBoundingBox(), GetStringHeight(), GetStringLineCount(), IndustryTypeNameSorter(), BuildIndustryWindow::MakeCargoListString(), SignListWindow::OnInit(), SelectGameWindow::OnResize(), ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), StoryBookWindow::RefreshSelectedPage(), SaveHighScoreValueNetwork(), Script_CreateDummy(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), ServerNetworkAdminSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), ShowNewGrfVehicleError(), TownActionRoadRebuild(), TypeTagNameFilter(), ScanProgressWindow::UpdateNewGRFScanStatus(), and ViewportSign::UpdatePosition().
|
inline |
Extract the StringIndex from a StringID.
str | String identifier |
Definition at line 38 of file strings_func.h.
References GetStringTab(), and TAB_SIZE_BITS.
Referenced by GetStringWithArgs().
Extract the StringTab from a StringID.
str | String identifier |
Definition at line 25 of file strings_func.h.
Referenced by CopyFromOldName(), GetStringIndex(), and GetStringWithArgs().
bool HaveDParamChanged | ( | const std::span< const StringParameterData > | backup | ) |
Checks whether the global string parameters have changed compared to the given backup.
backup | The backup to check against. |
Definition at line 184 of file strings.cpp.
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 2110 of file strings.cpp.
Create a StringID.
tab | StringTab |
index | StringIndex |
Definition at line 49 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.
|
inline |
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
speed | Display speed for parameter. |
type | Type of vehicle for parameter. |
Definition at line 75 of file strings_func.h.
Referenced by BuildBridgeWindow::GetBridgeSelectString().
void SetDParam | ( | size_t | n, |
uint64_t | v | ||
) |
Set a string parameter v at index n in the global string parameter array.
n | Index of the string parameter. |
v | Value of the string parameter. |
Definition at line 104 of file strings.cpp.
Referenced by AdvertiseIndustryOpening(), AgeVehicle(), AircraftHandleDestTooFar(), Subsidy::AwardTo(), BuildReplacementVehicle(), CheckCompanyHasMoney(), ClientNetworkGameSocketHandler::CheckConnection(), CheckEngines(), CheckforTownRating(), CheckIndustries(), CheckTownRoadTypes(), CheckTrainCollision(), CheckTrainsLengths(), CmdCompanyCtrl(), CmdGiveMoney(), CmdIncreaseLoan(), CompanyCheckBankrupt(), CompanyNewsInformation::CompanyNewsInformation(), CrashAirplane(), StationViewWindow::DrawAcceptedCargo(), TimetableWindow::DrawArrivalDeparturePanel(), StationViewWindow::DrawCargoRatings(), DrawPrice(), TownAuthorityWindow::DrawRatings(), BuildVehicleWindow::FilterByText(), FloodVehicle(), GenerateDefaultSaveName(), BuildBridgeWindow::GetBridgeSelectString(), RefitWindow::GetCapacityString(), IndustryDirectoryWindow::GetIndustryString(), BaseSet< T, Tnum_files, Tsearch_in_tars >::GetListLabel(), BaseGraphWindow::GetYLabelWidth(), GRFLoadConfig(), Vehicle::HandlePathfindingResult(), CommandHelperBase::InternalExecuteProcessResult(), BuildIndustryWindow::MakeCargoListString(), MakeScreenshotWithConfirm(), NetworkHandlePauseChange(), NewVehicleAvailable(), SelectCompanyManagerFaceWindow::OnInit(), GameSettingsWindow::OnPaint(), CompanyWindow::OnResize(), SelectGameWindow::OnResize(), StoryBookWindow::RefreshSelectedPage(), RoadVehArrivesAt(), SaveHighScoreValueNetwork(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), SetDParamMaxDigits(), SetDParamsForOwnedBy(), SelectCompanyManagerFaceWindow::SetFaceStringParameters(), NIHelper::SetObjectAtStringParameters(), NIHelper::SetSimpleStringParameters(), SettingsValueAbsolute(), SetupSubsidyDecodeParam(), IntSettingDesc::SetValueDParams(), ShipArrivesAt(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), ToolbarScenDatePanel(), TownActionRoadRebuild(), TrainEnterStation(), UpdateFillingPercent(), and SettingEntry::UpdateFilterState().
void SetDParamMaxDigits | ( | size_t | n, |
uint | count, | ||
FontSize | size | ||
) |
Set DParam n to some number that is suitable for string size computations.
n | Index of the string parameter. |
count | Number of digits which shall be displayable. |
size | Font of the number |
Definition at line 143 of file strings.cpp.
References GetBroadestDigit(), and SetDParam().
Referenced by GetUnitNumberWidth(), and SetDParamMaxValue().
void SetDParamMaxValue | ( | size_t | n, |
uint64_t | max_value, | ||
uint | min_count, | ||
FontSize | size | ||
) |
Set DParam n to some number that is suitable for string size computations.
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 127 of file strings.cpp.
References SetDParamMaxDigits().
Referenced by TimetableWindow::DrawTimetablePanel().
void SetDParamStr | ( | size_t | n, |
const char * | str | ||
) |
This function is used to "bind" a C string to a OpenTTD dparam slot.
n | slot of the string |
str | string to bind |
Definition at line 357 of file strings.cpp.
Referenced by Subsidy::AwardTo(), CmdCompanyCtrl(), CmdCustomNewsItem(), CompanyCheckBankrupt(), GoalListWindow::DrawListColumn(), StoryBookWindow::GetHeadHeight(), BaseSet< T, Tnum_files, Tsearch_in_tars >::GetListLabel(), StoryBookWindow::GetPageElementHeight(), GetSavegameFormat(), GetSaveLoadErrorMessage(), GraphicsSetLoadConfig(), GRFLoadConfig(), LoadTownData(), BuildIndustryWindow::MakeCargoListString(), IConsoleWindow::OnPaint(), GoalListWindow::OnPaint(), ShowNewGrfVehicleError(), TownActionRoadRebuild(), and WarnCorruptSprite().
void SetDParamStr | ( | size_t | 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.
n | slot of the string |
str | string to bind |
Definition at line 368 of file strings.cpp.
void SetDParamStr | ( | size_t | n, |
std::string && | str | ||
) |
This function is used to "bind" the std::string to a OpenTTD dparam slot.
Contrary to the other SetDParamStr
functions, this moves the string into the parameter slot.
n | slot of the string |
str | string to bind |
Definition at line 380 of file strings.cpp.