OpenTTD Source 20241224-master-gf74b0cf984
newgrf_text.h File Reference

Header of Action 04 "universal holder" structure and functions. More...

#include "newgrf_text_type.h"
#include "strings_type.h"
#include "table/control_codes.h"

Go to the source code of this file.

Functions

StringID AddGRFString (uint32_t grfid, uint16_t stringid, uint8_t langid, bool new_scheme, bool allow_newlines, std::string_view text_to_add, StringID def_string)
 Add the new read string into our structure.
 
StringID GetGRFStringID (uint32_t grfid, StringID stringid)
 Returns the index for this stringid associated with its grfID.
 
const char * GetGRFStringFromGRFText (const GRFTextList &text_list)
 Get a C-string from a GRFText-list.
 
const char * GetGRFStringFromGRFText (const GRFTextWrapper &text)
 Get a C-string from a GRFText-list.
 
const char * GetGRFStringPtr (uint32_t stringid)
 Get a C-string from a stringid set by a newgrf.
 
void CleanUpStrings ()
 House cleaning.
 
void SetCurrentGrfLangID (uint8_t language_id)
 Equivalence Setter function between game and newgrf langID.
 
std::string TranslateTTDPatchCodes (uint32_t grfid, uint8_t language_id, bool allow_newlines, std::string_view str, StringControlCode byte80=SCC_NEWGRF_PRINT_WORD_STRING_ID)
 Translate TTDPatch string codes into something OpenTTD can handle (better).
 
void AddGRFTextToList (GRFTextList &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add)
 Add a string to a GRFText list.
 
void AddGRFTextToList (GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add)
 Add a string to a GRFText list.
 
void AddGRFTextToList (GRFTextWrapper &list, std::string_view text_to_add)
 Add a GRFText to a GRFText list.
 
bool CheckGrfLangID (uint8_t lang_id, uint8_t grf_version)
 
void StartTextRefStackUsage (const struct GRFFile *grffile, uint8_t numEntries, const uint32_t *values=nullptr)
 
void StopTextRefStackUsage ()
 Stop using the TTDP compatible string code parsing.
 
bool UsingNewGRFTextStack ()
 Check whether the NewGRF text stack is in use.
 
struct TextRefStackCreateTextRefStackBackup ()
 Create a backup of the current NewGRF text stack.
 
void RestoreTextRefStackBackup (struct TextRefStack *backup)
 Restore a copy of the text stack to the used stack.
 

Detailed Description

Header of Action 04 "universal holder" structure and functions.

Definition in file newgrf_text.h.

Function Documentation

◆ AddGRFString()

StringID AddGRFString ( uint32_t  grfid,
uint16_t  stringid,
uint8_t  langid,
bool  new_scheme,
bool  allow_newlines,
std::string_view  text_to_add,
StringID  def_string 
)

Add the new read string into our structure.

Definition at line 543 of file newgrf_text.cpp.

References AddGRFString(), AddGRFTextToList(), MakeStringID(), TAB_SIZE_NEWGRF, TEXT_TAB_NEWGRF_START, and TranslateTTDPatchCodes().

Referenced by AddGRFString(), FeatureTownName(), and TranslateGRFStrings().

◆ AddGRFTextToList() [1/3]

void AddGRFTextToList ( GRFTextList list,
uint8_t  langid,
uint32_t  grfid,
bool  allow_newlines,
std::string_view  text_to_add 
)

Add a string to a GRFText list.

Parameters
listThe list where the text should be added to.
langidThe language of the new text.
grfidThe grfid where this string is defined.
allow_newlinesWhether newlines are allowed in this string.
text_to_addThe text to add to the list.
Note
All text-codes will be translated.

Definition at line 508 of file newgrf_text.cpp.

References AddGRFTextToList(), and TranslateTTDPatchCodes().

◆ AddGRFTextToList() [2/3]

void AddGRFTextToList ( GRFTextWrapper list,
std::string_view  text_to_add 
)

Add a GRFText to a GRFText list.

The text should not contain any text-codes. The text will be added as a 'default language'-text.

Parameters
listThe list where the text should be added to.
text_to_addThe text to add to the list.

Definition at line 534 of file newgrf_text.cpp.

References AddGRFTextToList().

◆ AddGRFTextToList() [3/3]

void AddGRFTextToList ( GRFTextWrapper list,
uint8_t  langid,
uint32_t  grfid,
bool  allow_newlines,
std::string_view  text_to_add 
)

Add a string to a GRFText list.

Parameters
listThe list where the text should be added to.
langidThe language of the new text.
grfidThe grfid where this string is defined.
allow_newlinesWhether newlines are allowed in this string.
text_to_addThe text to add to the list.
Note
All text-codes will be translated.

Definition at line 522 of file newgrf_text.cpp.

References AddGRFTextToList().

◆ CheckGrfLangID()

bool CheckGrfLangID ( uint8_t  lang_id,
uint8_t  grf_version 
)

Definition at line 664 of file newgrf_text.cpp.

◆ CleanUpStrings()

void CleanUpStrings ( )

House cleaning.

Remove all strings.

Definition at line 682 of file newgrf_text.cpp.

Referenced by ResetNewGRFData().

◆ CreateTextRefStackBackup()

struct TextRefStack * CreateTextRefStackBackup ( )

Create a backup of the current NewGRF text stack.

Returns
A copy of the current text stack.

Definition at line 765 of file newgrf_text.cpp.

References _newgrf_textrefstack.

Referenced by FormatString().

◆ GetGRFStringFromGRFText() [1/2]

const char * GetGRFStringFromGRFText ( const GRFTextList text_list)

Get a C-string from a GRFText-list.

If there is a translation for the current language it is returned, otherwise the default translation is returned. If there is neither a default nor a translation for the current language nullptr is returned.

Parameters
text_listThe GRFTextList to get the string from.

Definition at line 606 of file newgrf_text.cpp.

References _currentLangID.

Referenced by GRFFileScanner::AddFile(), NewGRFParametersWindow::DrawWidget(), GRFConfig::GetDescription(), GetGRFStringFromGRFText(), GetGRFStringPtr(), GRFConfig::GetName(), GRFConfig::GetURL(), NewGRFParametersWindow::OnClick(), and NewGRFParametersWindow::UpdateWidgetSize().

◆ GetGRFStringFromGRFText() [2/2]

const char * GetGRFStringFromGRFText ( const GRFTextWrapper text)

Get a C-string from a GRFText-list.

If there is a translation for the current language it is returned, otherwise the default translation is returned. If there is neither a default nor a translation for the current language nullptr is returned.

Parameters
textThe GRFTextList to get the string from.

Definition at line 631 of file newgrf_text.cpp.

References GetGRFStringFromGRFText().

◆ GetGRFStringID()

◆ GetGRFStringPtr()

const char * GetGRFStringPtr ( uint32_t  stringid)

Get a C-string from a stringid set by a newgrf.

Definition at line 639 of file newgrf_text.cpp.

References GetGRFStringFromGRFText().

Referenced by GetStringWithArgs().

◆ RestoreTextRefStackBackup()

void RestoreTextRefStackBackup ( struct TextRefStack backup)

Restore a copy of the text stack to the used stack.

Parameters
backupThe copy to restore.

Definition at line 774 of file newgrf_text.cpp.

References _newgrf_textrefstack.

Referenced by FormatString().

◆ SetCurrentGrfLangID()

void SetCurrentGrfLangID ( uint8_t  language_id)

Equivalence Setter function between game and newgrf langID.

This function will adjust _currentLangID as to what is the LangID of the current language set by the user. This function is called after the user changed language, from strings.cpp:ReadLanguagePack

Parameters
language_idiso code of current selection

Definition at line 659 of file newgrf_text.cpp.

References _currentLangID.

Referenced by ReadLanguagePack().

◆ StopTextRefStackUsage()

◆ TranslateTTDPatchCodes()

std::string TranslateTTDPatchCodes ( uint32_t  grfid,
uint8_t  language_id,
bool  allow_newlines,
std::string_view  str,
StringControlCode  byte80 
)

Translate TTDPatch string codes into something OpenTTD can handle (better).

Parameters
grfidThe (NewGRF) ID associated with this string
language_idThe (NewGRF) language ID associated with this string.
allow_newlinesWhether newlines are allowed in the string or not.
strThe string to translate.
byte80The control code to use as replacement for the 0x80-value.
Returns
The translated string.

Definition at line 236 of file newgrf_text.cpp.

References CS_ALPHANUMERAL, UnmappedChoiceList::Flush(), GB(), LanguageMap::GetLanguageMap(), LanguageMap::GetMapping(), IsValidChar(), MapGRFStringID(), NFO_UTF8_IDENTIFIER, SCC_BIGFONT, SCC_NEWGRF_DISCARD_WORD, SCC_NEWGRF_PRINT_BYTE_HEX, SCC_NEWGRF_PRINT_DWORD_DATE_LONG, SCC_NEWGRF_PRINT_DWORD_FORCE, SCC_NEWGRF_PRINT_DWORD_HEX, SCC_NEWGRF_PRINT_DWORD_SIGNED, SCC_NEWGRF_PRINT_QWORD_CURRENCY, SCC_NEWGRF_PRINT_QWORD_HEX, SCC_NEWGRF_PRINT_WORD_DATE_LONG, SCC_NEWGRF_PRINT_WORD_HEX, SCC_NEWGRF_PRINT_WORD_STATION_NAME, SCC_NEWGRF_PRINT_WORD_VOLUME_LONG, SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG, SCC_NEWGRF_PUSH_WORD, SCC_NEWGRF_ROTATE_TOP_4_WORDS, SCC_NEWGRF_STRINL, SCC_TINYFONT, UnmappedChoiceList::strings, Utf8Decode(), Utf8Encode(), and Utf8EncodedCharLen().

Referenced by AddGRFString(), AddGRFTextToList(), and FeatureTownName().

◆ UsingNewGRFTextStack()

bool UsingNewGRFTextStack ( )

Check whether the NewGRF text stack is in use.

Returns
True iff the NewGRF text stack is used.

Definition at line 756 of file newgrf_text.cpp.

References _newgrf_textrefstack.

Referenced by FormatString().