|
OpenTTD Source 20260711-master-g3fb3006dff
|
Implementation of Action 04 "universal holder" structure and functions. More...
#include "stdafx.h"#include "debug.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 "core/string_builder.hpp"#include "core/string_consumer.hpp"#include "language.h"#include <ranges>#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 |
Typedefs | |
| using | OldGRFLanguages = EnumBitSet<GRFLanguage, uint8_t> |
| The bitmask of the old GRF languages, which are conveniently the same as the first few GRFLanguages. | |
Functions | |
| std::string | TranslateTTDPatchCodes (GrfID grfid, GRFLanguage 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, GRFLanguage langid, std::string_view text_to_add) |
| Add a new text to a GRFText list. | |
| void | AddGRFTextToList (GRFTextList &list, GRFLanguage langid, GrfID grfid, bool allow_newlines, std::string_view text_to_add) |
| Add a string to a GRFText list. | |
| void | AddGRFTextToList (GRFTextWrapper &list, GRFLanguage langid, GrfID 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. | |
| static StringID | AddGRFString (GrfID grfid, GRFStringID stringid, GRFLanguage langid_to_add, bool allow_newlines, std::string_view text_to_add, StringID def_string) |
| Add the new read string into our structure. | |
| StringID | AddGRFString (GrfID grfid, GRFStringID 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 (GrfID grfid, GRFStringID stringid) |
| Returns the index for this stringid associated with its grfID. | |
| std::optional< std::string_view > | GetGRFStringFromGRFText (const GRFTextList &text_list) |
| Get a C-string from a GRFText-list. | |
| std::optional< std::string_view > | GetGRFStringFromGRFText (const GRFTextWrapper &text) |
| Get a C-string from a GRFText-list. | |
| std::string_view | GetGRFStringPtr (StringIndexInTab stringid) |
| Get a C-string from a stringid set by a newgrf. | |
| bool | CheckGrfLangID (uint8_t lang_id, uint8_t grf_version) |
| void | CleanUpStrings () |
| House cleaning. | |
| static void | HandleNewGRFStringControlCodes (std::string_view str, TextRefStack &stack, std::vector< StringParameter > ¶ms) |
| Handle control codes in a NewGRF string, processing the stack and filling parameters. | |
| static void | ProcessNewGRFStringControlCode (char32_t scc, StringConsumer &consumer, TextRefStack &stack, std::vector< StringParameter > ¶ms) |
| Process NewGRF string control code instructions. | |
| char32_t | RemapNewGRFStringControlCode (char32_t scc, StringConsumer &consumer) |
| Emit OpenTTD's internal string code for the different NewGRF string codes. | |
| std::vector< StringParameter > | GetGRFStringTextStackParameters (const GRFFile *grffile, StringID stringid, std::span< const int32_t > textstack) |
| Process the text ref stack for a GRF String and return its parameters. | |
| std::string | GetGRFStringWithTextStack (const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack) |
| Format a GRF string using the text ref stack for parameters. | |
Variables | |
| static TypedIndexContainer< std::vector< GRFTextEntry >, StringIndexInTab > | _grf_text |
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.
| using OldGRFLanguages = EnumBitSet<GRFLanguage, uint8_t> |
The bitmask of the old GRF languages, which are conveniently the same as the first few GRFLanguages.
Definition at line 40 of file newgrf_text.cpp.
|
static |
Add the new read string into our structure.
| grfid | The GRF to load the string for. |
| stringid | The GRF-local identifier of the string. |
| langid_to_add | The language to add them to. |
| allow_newlines | Whether newlines are allowed in the string. |
| text_to_add | The actual text of the string. |
| def_string | The fallback string if a translation for this string isn't available. |
Definition at line 522 of file newgrf_text.cpp.
References AddGRFTextToList(), MakeStringID(), TAB_SIZE_NEWGRF, TEXT_TAB_NEWGRF_START, and TranslateTTDPatchCodes().
Referenced by AddGRFString(), FeatureTownName(), and TranslateGRFStrings().
| StringID AddGRFString | ( | GrfID | grfid, |
| GRFStringID | 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.
| grfid | The GRF to load the string for. |
| stringid | The GRF-local identifier of the string. |
| langid_to_add | The language to add them to. |
| new_scheme | Is the NewGRF version 7 or higher? |
| allow_newlines | Whether newlines are allowed in the string. |
| text_to_add | The actual text of the string. |
| def_string | The fallback string if a translation for this string isn't available. |
Definition at line 556 of file newgrf_text.cpp.
References AddGRFString(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), English, French, German, Spanish, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
| void AddGRFTextToList | ( | GRFTextList & | list, |
| GRFLanguage | langid, | ||
| GrfID | 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 480 of file newgrf_text.cpp.
References AddGRFTextToList(), and TranslateTTDPatchCodes().
|
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 457 of file newgrf_text.cpp.
Referenced by AddGRFString(), AddGRFTextToList(), AddGRFTextToList(), AddGRFTextToList(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), ChangeGRFURL(), and HandleIncomingNetworkGameInfoGRFConfig().
| void AddGRFTextToList | ( | GRFTextWrapper & | list, |
| GRFLanguage | langid, | ||
| GrfID | 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 494 of file newgrf_text.cpp.
References AddGRFTextToList().
| 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 506 of file newgrf_text.cpp.
References AddGRFTextToList(), and Unspecified.
| bool CheckGrfLangID | ( | uint8_t | lang_id, |
| uint8_t | grf_version ) |
Definition at line 651 of file newgrf_text.cpp.
| void CleanUpStrings | ( | ) |
House cleaning.
Remove all strings.
Definition at line 671 of file newgrf_text.cpp.
Referenced by ResetNewGRFData().
| std::optional< std::string_view > 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. |
std::nullopt. Definition at line 603 of file newgrf_text.cpp.
References _current_language, American, English, and Unspecified.
Referenced by NewGRFParametersWindow::DrawWidget(), GRFConfig::GetDescription(), GetGRFStringFromGRFText(), GetGRFStringPtr(), GRFConfig::GetName(), GRFConfig::GetURL(), NewGRFParametersWindow::OnClick(), and NewGRFParametersWindow::UpdateWidgetSize().
| std::optional< std::string_view > 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 GRFTextWrapper to get the string from. |
std::nullopt. Definition at line 629 of file newgrf_text.cpp.
References GetGRFStringFromGRFText().
| StringID GetGRFStringID | ( | GrfID | grfid, |
| GRFStringID | stringid ) |
Returns the index for this stringid associated with its grfID.
| grfid | The GRF to find the string for. |
| stringid | The GRF-local identifier of the string. |
Definition at line 583 of file newgrf_text.cpp.
References MakeStringID(), and TEXT_TAB_NEWGRF_START.
Referenced by CheckTrainAttachment(), CmdStartStopVehicle(), GetAirportTextCallback(), GetCargoSubtypeText(), GetErrorMessageFromLocationCallbackResult(), GetGRFStringWithTextStack(), GetHouseName(), GetTileDesc_Town(), and MapGRFStringID().
| std::string_view GetGRFStringPtr | ( | StringIndexInTab | stringid | ) |
Get a C-string from a stringid set by a newgrf.
| stringid | The index of the string in the NewGRF string-tab. |
Definition at line 639 of file newgrf_text.cpp.
References GetGRFStringFromGRFText().
Referenced by GetStringWithArgs().
| std::vector< StringParameter > GetGRFStringTextStackParameters | ( | const GRFFile * | grffile, |
| StringID | stringid, | ||
| std::span< const int32_t > | textstack ) |
Process the text ref stack for a GRF String and return its parameters.
Definition at line 973 of file newgrf_text.cpp.
References HandleNewGRFStringControlCodes(), and INVALID_STRING_ID.
Referenced by GetErrorMessageFromLocationCallbackResult(), and GetGRFStringWithTextStack().
| std::string GetGRFStringWithTextStack | ( | const struct GRFFile * | grffile, |
| GRFStringID | grfstringid, | ||
| std::span< const int32_t > | textstack ) |
Format a GRF string using the text ref stack for parameters.
| grffile | GRFFile of string. |
| grfstringid | GRFStringID of string. |
| textstack | Text parameter stack. |
Definition at line 995 of file newgrf_text.cpp.
References GetGRFStringID(), GetGRFStringTextStackParameters(), and GetStringWithArgs().
Referenced by IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), FormatString(), GetCargoSuffix(), and GetNewGRFAdditionalText().
|
static |
Handle control codes in a NewGRF string, processing the stack and filling parameters.
| str | String to process. | |
| [in,out] | stack | Stack to use. |
| [out] | params | Parameters to fill. |
Definition at line 957 of file newgrf_text.cpp.
References StringConsumer::AnyBytesLeft(), ProcessNewGRFStringControlCode(), and StringConsumer::ReadUtf8().
Referenced by GetGRFStringTextStackParameters(), and ProcessNewGRFStringControlCode().
|
static |
Process NewGRF string control code instructions.
| scc | The string control code that has been read. | |
| consumer | The string that we are reading from. | |
| stack | The TextRefStack. | |
| [out] | params | Output parameters |
Definition at line 760 of file newgrf_text.cpp.
References TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, GetCargoTranslation(), HandleNewGRFStringControlCodes(), MapGRFStringID(), NUM_CARGO, StringConsumer::ReadUint16LE(), StringConsumer::ReadUint8(), StringConsumer::ReadUtf8(), 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, SCC_NEWGRF_ROTATE_TOP_4_WORDS, SCC_NEWGRF_STRINL, StringConsumer::Skip(), StringConsumer::SkipUint16LE(), and StringConsumer::SkipUint8().
Referenced by HandleNewGRFStringControlCodes().
| char32_t RemapNewGRFStringControlCode | ( | char32_t | scc, |
| StringConsumer & | consumer ) |
Emit OpenTTD's internal string code for the different NewGRF string codes.
| scc | NewGRF string code. |
| consumer | String consumer, moved forward if SCC_NEWGRF_PUSH_WORD is found. |
Definition at line 874 of file newgrf_text.cpp.
References 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_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, SCC_NEWGRF_ROTATE_TOP_4_WORDS, and StringConsumer::SkipUtf8().
Referenced by FormatString().
| std::string TranslateTTDPatchCodes | ( | GrfID | grfid, |
| GRFLanguage | 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 216 of file newgrf_text.cpp.
References StringConsumer::AnyBytesLeft(), CS_ALPHANUMERAL, LanguageMap::GetLanguageMap(), LanguageMap::GetMapping(), IsValidChar(), MapGRFStringID(), NFO_UTF8_IDENTIFIER, BaseStringBuilder::PutChar(), BaseStringBuilder::PutUtf8(), StringConsumer::ReadUint16LE(), StringConsumer::ReadUint8(), StringConsumer::ReadUtf8If(), 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, StringConsumer::SkipUint8(), and StringConsumer::TryReadUtf8().
Referenced by AddGRFString(), AddGRFTextToList(), and FeatureTownName().
|
static |
Definition at line 56 of file newgrf_text.cpp.