OpenTTD Source 20241224-master-gf74b0cf984
|
Implementation of Action 04 "universal holder" structure and functions. More...
#include "stdafx.h"
#include "newgrf.h"
#include "strings_internal.h"
#include "newgrf_storage.h"
#include "newgrf_text.h"
#include "newgrf_cargo.h"
#include "string_func.h"
#include "timer/timer_game_calendar.h"
#include "debug.h"
#include "core/alloc_type.hpp"
#include "language.h"
#include <sstream>
#include "table/strings.h"
#include "table/control_codes.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | GRFTextEntry |
Holder of the above structure. More... | |
struct | UnmappedChoiceList |
Helper structure for mapping choice lists. More... | |
struct | TextRefStack |
Enumerations | |
enum | GRFBaseLanguages { GRFLB_AMERICAN = 0x01 , GRFLB_ENGLISH = 0x02 , GRFLB_GERMAN = 0x04 , GRFLB_FRENCH = 0x08 , GRFLB_SPANISH = 0x10 , GRFLB_GENERIC = 0x80 } |
Explains the newgrf shift bit positioning. More... | |
enum | GRFExtendedLanguages { GRFLX_AMERICAN = 0x00 , GRFLX_ENGLISH = 0x01 , GRFLX_GERMAN = 0x02 , GRFLX_FRENCH = 0x03 , GRFLX_SPANISH = 0x04 , GRFLX_UNSPECIFIED = 0x7F } |
Functions | |
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). | |
static void | AddGRFTextToList (GRFTextList &list, uint8_t langid, std::string_view text_to_add) |
Add a new text to a GRFText list. | |
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. | |
StringID | AddGRFString (uint32_t grfid, uint16_t stringid, uint8_t langid_to_add, 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 | SetCurrentGrfLangID (uint8_t language_id) |
Equivalence Setter function between game and newgrf langID. | |
bool | CheckGrfLangID (uint8_t lang_id, uint8_t grf_version) |
void | CleanUpStrings () |
House cleaning. | |
bool | UsingNewGRFTextStack () |
Check whether the NewGRF text stack is in use. | |
struct TextRefStack * | CreateTextRefStackBackup () |
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. | |
void | StartTextRefStackUsage (const GRFFile *grffile, uint8_t numEntries, const uint32_t *values) |
Start using the TTDP compatible string code parsing. | |
void | StopTextRefStackUsage () |
Stop using the TTDP compatible string code parsing. | |
char32_t | RemapNewGRFStringControlCode (char32_t scc, const char **str, StringParameters ¶meters, bool modify_parameters) |
FormatString for NewGRF specific "magic" string control codes. | |
Variables | |
static std::vector< GRFTextEntry > | _grf_text |
static uint8_t | _currentLangID = GRFLX_ENGLISH |
by default, english is used. | |
static TextRefStack | _newgrf_textrefstack |
The stack that is used for TTDP compatible string code parsing. | |
Implementation of Action 04 "universal holder" structure and functions.
This file implements a linked-lists of strings, holding everything that the newgrf action 04 will send over to OpenTTD. One of the biggest problems is that Dynamic lang Array uses ISO codes as way to identifying current user lang, while newgrf uses bit shift codes not related to ISO. So equivalence functionality had to be set.
Definition in file newgrf_text.cpp.
enum GRFBaseLanguages |
Explains the newgrf shift bit positioning.
the grf base will not be used in order to find the string, but rather for jumping from standard langID scheme to the new one.
Definition at line 42 of file newgrf_text.cpp.
enum GRFExtendedLanguages |
Definition at line 51 of file newgrf_text.cpp.
StringID AddGRFString | ( | uint32_t | grfid, |
uint16_t | stringid, | ||
uint8_t | langid_to_add, | ||
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().
|
static |
Add a new text to a GRFText list.
list | The list where the text should be added to. |
langid | The The language of the new text. |
text_to_add | The text to add to the list. |
Definition at line 485 of file newgrf_text.cpp.
Referenced by AddGRFString(), AddGRFTextToList(), AddGRFTextToList(), AddGRFTextToList(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), and ChangeGRFURL().
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.
list | The list where the text should be added to. |
langid | The language of the new text. |
grfid | The grfid where this string is defined. |
allow_newlines | Whether newlines are allowed in this string. |
text_to_add | The text to add to the list. |
Definition at line 508 of file newgrf_text.cpp.
References AddGRFTextToList(), and TranslateTTDPatchCodes().
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.
list | The list where the text should be added to. |
text_to_add | The text to add to the list. |
Definition at line 534 of file newgrf_text.cpp.
References AddGRFTextToList().
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.
list | The list where the text should be added to. |
langid | The language of the new text. |
grfid | The grfid where this string is defined. |
allow_newlines | Whether newlines are allowed in this string. |
text_to_add | The text to add to the list. |
Definition at line 522 of file newgrf_text.cpp.
References AddGRFTextToList().
bool CheckGrfLangID | ( | uint8_t | lang_id, |
uint8_t | grf_version | ||
) |
Definition at line 664 of file newgrf_text.cpp.
void CleanUpStrings | ( | ) |
House cleaning.
Remove all strings.
Definition at line 682 of file newgrf_text.cpp.
Referenced by ResetNewGRFData().
struct TextRefStack * CreateTextRefStackBackup | ( | ) |
Create a backup of the current NewGRF text stack.
Definition at line 765 of file newgrf_text.cpp.
References _newgrf_textrefstack.
Referenced by FormatString().
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.
text_list | The 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().
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.
text | The GRFTextList to get the string from. |
Definition at line 631 of file newgrf_text.cpp.
References GetGRFStringFromGRFText().
Returns the index for this stringid associated with its grfID.
Definition at line 587 of file newgrf_text.cpp.
References MakeStringID(), and TEXT_TAB_NEWGRF_START.
Referenced by BridgeChangeInfo(), CheckTrainAttachment(), CmdStartStopVehicle(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), FinaliseIndustriesArray(), FormatString(), GetAirportTextCallback(), GetCargoSubtypeText(), GetCargoSuffix(), GetErrorMessageFromLocationCallbackResult(), GetHouseName(), GetNewGRFAdditionalText(), GlobalVarChangeInfo(), and MapGRFStringID().
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().
char32_t RemapNewGRFStringControlCode | ( | char32_t | scc, |
const char ** | str, | ||
StringParameters & | parameters, | ||
bool | modify_parameters | ||
) |
FormatString for NewGRF specific "magic" string control codes.
scc | the string control code that has been read |
str | the string that we need to write |
parameters | the OpenTTD string formatting parameters |
modify_parameters | When true, modify the OpenTTD string formatting parameters. |
Definition at line 828 of file newgrf_text.cpp.
References _newgrf_textrefstack, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, Debug, GetCargoTranslation(), StringParameters::GetDataLeft(), MapGRFStringID(), NUM_CARGO, TextRefStack::RotateTop4Words(), SCC_NEWGRF_DISCARD_WORD, SCC_NEWGRF_PRINT_BYTE_HEX, SCC_NEWGRF_PRINT_BYTE_SIGNED, SCC_NEWGRF_PRINT_DWORD_CURRENCY, SCC_NEWGRF_PRINT_DWORD_DATE_LONG, SCC_NEWGRF_PRINT_DWORD_DATE_SHORT, 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_CARGO_LONG, SCC_NEWGRF_PRINT_WORD_CARGO_NAME, SCC_NEWGRF_PRINT_WORD_CARGO_SHORT, SCC_NEWGRF_PRINT_WORD_CARGO_TINY, SCC_NEWGRF_PRINT_WORD_DATE_LONG, SCC_NEWGRF_PRINT_WORD_DATE_SHORT, SCC_NEWGRF_PRINT_WORD_HEX, SCC_NEWGRF_PRINT_WORD_POWER, SCC_NEWGRF_PRINT_WORD_SIGNED, SCC_NEWGRF_PRINT_WORD_SPEED, SCC_NEWGRF_PRINT_WORD_STATION_NAME, SCC_NEWGRF_PRINT_WORD_STRING_ID, SCC_NEWGRF_PRINT_WORD_UNSIGNED, SCC_NEWGRF_PRINT_WORD_VOLUME_LONG, SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT, SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG, SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT, SCC_NEWGRF_PUSH_WORD, and SCC_NEWGRF_ROTATE_TOP_4_WORDS.
Referenced by FormatString().
void RestoreTextRefStackBackup | ( | struct TextRefStack * | backup | ) |
Restore a copy of the text stack to the used stack.
backup | The copy to restore. |
Definition at line 774 of file newgrf_text.cpp.
References _newgrf_textrefstack.
Referenced by FormatString().
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
language_id | iso code of current selection |
Definition at line 659 of file newgrf_text.cpp.
References _currentLangID.
Referenced by ReadLanguagePack().
void StartTextRefStackUsage | ( | const GRFFile * | grffile, |
uint8_t | numEntries, | ||
const uint32_t * | 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.
grffile | the NewGRF providing the stack data |
numEntries | number of entries to copy from the registers |
values | values to copy onto the stack; if nullptr the temporary NewGRF registers will be used instead |
Definition at line 798 of file newgrf_text.cpp.
References _newgrf_textrefstack, and GB().
Referenced by ErrorMessageData::CopyOutDParams(), IndustryViewWindow::DrawInfo(), ErrmsgWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), FormatString(), GetCargoSuffix(), GetNewGRFAdditionalText(), ShowErrorMessage(), and ErrmsgWindow::UpdateWidgetSize().
void StopTextRefStackUsage | ( | ) |
Stop using the TTDP compatible string code parsing.
Definition at line 815 of file newgrf_text.cpp.
References _newgrf_textrefstack.
Referenced by ErrorMessageData::CopyOutDParams(), IndustryViewWindow::DrawInfo(), ErrmsgWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), FormatString(), GetCargoSuffix(), GetNewGRFAdditionalText(), ShowErrorMessage(), and ErrmsgWindow::UpdateWidgetSize().
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).
grfid | The (NewGRF) ID associated with this string |
language_id | The (NewGRF) language ID associated with this string. |
allow_newlines | Whether newlines are allowed in the string or not. |
str | The string to translate. |
byte80 | The control code to use as replacement for the 0x80-value. |
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().
bool UsingNewGRFTextStack | ( | ) |
Check whether the NewGRF text stack is in use.
Definition at line 756 of file newgrf_text.cpp.
References _newgrf_textrefstack.
Referenced by FormatString().
|
static |
by default, english is used.
Definition at line 75 of file newgrf_text.cpp.
Referenced by GetGRFStringFromGRFText(), and SetCurrentGrfLangID().
|
static |
Definition at line 74 of file newgrf_text.cpp.
|
static |
The stack that is used for TTDP compatible string code parsing.
Definition at line 750 of file newgrf_text.cpp.
Referenced by CreateTextRefStackBackup(), RemapNewGRFStringControlCode(), RestoreTextRefStackBackup(), StartTextRefStackUsage(), StopTextRefStackUsage(), and UsingNewGRFTextStack().