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

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

#include "string_type.h"
#include "strings_type.h"
#include "core/smallvec_type.hpp"
#include "table/control_codes.h"

Go to the source code of this file.

Data Structures

struct  LanguageMap
 Mapping of language data between a NewGRF and OpenTTD. More...
 
struct  LanguageMap::Mapping
 Mapping between NewGRF and OpenTTD IDs. More...
 

Functions

StringID AddGRFString (uint32 grfid, uint16 stringid, byte langid, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string)
 Add the new read string into our structure.
 
StringID GetGRFStringID (uint32 grfid, StringID stringid)
 Returns the index for this stringid associated with its grfID.
 
const char * GetGRFStringFromGRFText (const struct GRFText *text)
 
const char * GetGRFStringPtr (uint16 stringid)
 Get a C-string from a stringid set by a newgrf.
 
void CleanUpStrings ()
 House cleaning. More...
 
void SetCurrentGrfLangID (byte language_id)
 Equivalence Setter function between game and newgrf langID. More...
 
char * TranslateTTDPatchCodes (uint32 grfid, uint8 language_id, bool allow_newlines, const char *str, int *olen=NULL, StringControlCode byte80=SCC_NEWGRF_PRINT_WORD_STRING_ID)
 Translate TTDPatch string codes into something OpenTTD can handle (better). More...
 
struct GRFTextDuplicateGRFText (struct GRFText *orig)
 Create a copy of this GRFText list. More...
 
void AddGRFTextToList (struct GRFText **list, struct GRFText *text_to_add)
 Add a GRFText to a GRFText list. More...
 
void AddGRFTextToList (struct GRFText **list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add)
 Add a string to a GRFText list. More...
 
void AddGRFTextToList (struct GRFText **list, const char *text_to_add)
 Add a GRFText to a GRFText list. More...
 
void CleanUpGRFText (struct GRFText *grftext)
 Delete all items of a linked GRFText list. More...
 
bool CheckGrfLangID (byte lang_id, byte grf_version)
 
void StartTextRefStackUsage (const GRFFile *grffile, byte numEntries, const uint32 *values=NULL)
 Start using the TTDP compatible string code parsing. More...
 
void StopTextRefStackUsage ()
 Stop using the TTDP compatible string code parsing.
 
void RewindTextRefStack ()
 
bool UsingNewGRFTextStack ()
 Check whether the NewGRF text stack is in use. More...
 
struct TextRefStackCreateTextRefStackBackup ()
 Create a backup of the current NewGRF text stack. More...
 
void RestoreTextRefStackBackup (struct TextRefStack *backup)
 Restore a copy of the text stack to the used stack. More...
 
uint RemapNewGRFStringControlCode (uint scc, char *buf_start, char **buff, const char **str, int64 *argv, uint argv_size, bool modify_argv)
 FormatString for NewGRF specific "magic" string control codes. More...
 

Variables

static const WChar NFO_UTF8_IDENTIFIER = 0x00DE
 This character, the thorn ('þ'), indicates a unicode string to NFO. More...
 

Detailed Description

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

Definition in file newgrf_text.h.

Function Documentation

◆ AddGRFTextToList() [1/3]

void AddGRFTextToList ( GRFText **  list,
GRFText text_to_add 
)

Add a GRFText to a GRFText list.

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

Definition at line 578 of file newgrf_text.cpp.

References GRFText::langid, GRFText::next, and GRFText::text.

Referenced by AddGRFTextToList(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), ChangeGRFURL(), FindUnknownGRFName(), and ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS().

◆ AddGRFTextToList() [2/3]

void AddGRFTextToList ( struct GRFText **  list,
byte  langid,
uint32  grfid,
bool  allow_newlines,
const char *  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 605 of file newgrf_text.cpp.

References AddGRFTextToList(), free(), GRFText::len, GRFText::New(), and TranslateTTDPatchCodes().

◆ AddGRFTextToList() [3/3]

void AddGRFTextToList ( struct GRFText **  list,
const char *  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 621 of file newgrf_text.cpp.

References AddGRFTextToList(), and GRFText::New().

◆ CleanUpGRFText()

void CleanUpGRFText ( GRFText grftext)

Delete all items of a linked GRFText list.

Parameters
grftextthe head of the list to delete

Definition at line 784 of file newgrf_text.cpp.

References GRFText::next.

Referenced by GRFParameterInfo::~GRFParameterInfo(), and GRFTextWrapper::~GRFTextWrapper().

◆ CleanUpStrings()

void CleanUpStrings ( )

House cleaning.

Remove all strings and reset the text counter.

Definition at line 797 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 900 of file newgrf_text.cpp.

Referenced by FormatString().

◆ DuplicateGRFText()

struct GRFText* DuplicateGRFText ( GRFText orig)

Create a copy of this GRFText list.

Parameters
origThe GRFText list to copy.
Returns
A duplicate of the given GRFText.

Definition at line 631 of file newgrf_text.cpp.

References GRFText::Copy(), and GRFText::next.

Referenced by GRFParameterInfo::GRFParameterInfo().

◆ RemapNewGRFStringControlCode()

uint RemapNewGRFStringControlCode ( uint  scc,
char *  buf_start,
char **  buff,
const char **  str,
int64 *  argv,
uint  argv_size,
bool  modify_argv 
)

◆ 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 909 of file newgrf_text.cpp.

Referenced by FormatString().

◆ SetCurrentGrfLangID()

void SetCurrentGrfLangID ( byte  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 761 of file newgrf_text.cpp.

References _currentLangID.

◆ StartTextRefStackUsage()

void StartTextRefStackUsage ( const GRFFile grffile,
byte  numEntries,
const uint32 *  values 
)

Start using the TTDP compatible string code parsing.

On start a number of values is copied on the TextRefStack. You can then use GetString() and the normal string drawing functions, and they will use the TextRefStack for NewGRF string codes.

However, when you want to draw a string multiple times using the same stack, you have to call RewindTextRefStack() between draws.

After you are done with drawing, you must disable usage of the TextRefStack by calling StopTextRefStackUsage(), so NewGRF string codes operate on the normal string parameters again.

Parameters
grffilethe NewGRF providing the stack data
numEntriesnumber of entries to copy from the registers
valuesvalues to copy onto the stack; if NULL the temporary NewGRF registers will be used instead

Definition at line 933 of file newgrf_text.cpp.

Referenced by ErrorMessageData::CopyOutDParams(), ErrmsgWindow::DrawWidget(), GetCargoSuffix(), and ErrmsgWindow::UpdateWidgetSize().

◆ TranslateTTDPatchCodes()

char* TranslateTTDPatchCodes ( uint32  grfid,
uint8  language_id,
bool  allow_newlines,
const char *  str,
int *  olen,
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.
[out]olenThe length of the final string.
byte80The control code to use as replacement for the 0x80-value.
Returns
The translated string.

Definition at line 336 of file newgrf_text.cpp.

References GRFText::len, NFO_UTF8_IDENTIFIER, Utf8Decode(), and Utf8EncodedCharLen().

Referenced by AddGRFTextToList().

◆ UsingNewGRFTextStack()

bool UsingNewGRFTextStack ( )

Check whether the NewGRF text stack is in use.

Returns
True iff the NewGRF text stack is used.

Definition at line 891 of file newgrf_text.cpp.

Referenced by FormatString().

Variable Documentation

◆ NFO_UTF8_IDENTIFIER

const WChar NFO_UTF8_IDENTIFIER = 0x00DE
static

This character, the thorn ('þ'), indicates a unicode string to NFO.

Definition at line 21 of file newgrf_text.h.

Referenced by TranslateTTDPatchCodes().