OpenTTD Source: src/newgrf_text.h Source File

OpenTTD Source 14.0-beta3

newgrf_text.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef NEWGRF_TEXT_H
11 #define NEWGRF_TEXT_H
12
13 #include "string_type.h"
14 #include "strings_type.h"
15 #include "table/control_codes.h"
16 #include <utility>
17
19 static const char32_t NFO_UTF8_IDENTIFIER = 0x00DE;
20
22 struct GRFText {
23 byte langid;
24 std::string text;
25 };
26
28 typedef std::vector<GRFText> GRFTextList;
30 typedef std::shared_ptr<GRFTextList> GRFTextWrapper;
31
32 StringID AddGRFString(uint32_t grfid, uint16_t stringid, byte langid, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string);
33 StringID GetGRFStringID(uint32_t grfid, StringID stringid);
34 const char *GetGRFStringFromGRFText(const GRFTextList &text_list);
35 const char *GetGRFStringFromGRFText(const GRFTextWrapper &text);
36 const char *GetGRFStringPtr(uint32_t stringid);
37 void CleanUpStrings();
38 void SetCurrentGrfLangID(byte language_id);
39 std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID);
40 void AddGRFTextToList(GRFTextList &list, byte langid, uint32_t grfid, bool allow_newlines, const char *text_to_add);
41 void AddGRFTextToList(GRFTextWrapper &list, byte langid, uint32_t grfid, bool allow_newlines, const char *text_to_add);
42 void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add);
43
44 bool CheckGrfLangID(byte lang_id, byte grf_version);
45
46 void StartTextRefStackUsage(const struct GRFFile *grffile, byte numEntries, const uint32_t *values = nullptr);
47 void StopTextRefStackUsage();
48 bool UsingNewGRFTextStack();
49 struct TextRefStack *CreateTextRefStackBackup();
50 void RestoreTextRefStackBackup(struct TextRefStack *backup);
51
53 struct LanguageMap {
55 struct Mapping {
56 byte newgrf_id;
57 byte openttd_id;
58 };
59
60 /* We need a vector and can't use SmallMap due to the fact that for "setting" a
61 * gender of a string or requesting a case for a substring we want to map from
62 * the NewGRF's internal ID to OpenTTD's ID whereas for the choice lists we map
63 * the genders/cases/plural OpenTTD IDs to the NewGRF's internal IDs. In this
64 * case a NewGRF developer/translator might want a different translation for
65 * both cases. Thus we are basically implementing a multi-map. */
66 std::vector<Mapping> gender_map;
67 std::vector<Mapping> case_map;
68 int plural_form;
69
70 int GetMapping(int newgrf_id, bool gender) const;
71 int GetReverseMapping(int openttd_id, bool gender) const;
72 static const LanguageMap *GetLanguageMap(uint32_t grfid, uint8_t language_id);
73 };
74
75 #endif /* NEWGRF_TEXT_H */
AddGRFString
StringID AddGRFString(uint32_t grfid, uint16_t 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.
Definition: newgrf_text.cpp:543
GRFText
A GRF text with associated language ID.
Definition: newgrf_text.h:22
LanguageMap::case_map
std::vector< Mapping > case_map
Mapping of NewGRF and OpenTTD IDs for cases.
Definition: newgrf_text.h:67
GRFTextList
std::vector< GRFText > GRFTextList
A GRF text with a list of translations.
Definition: newgrf_text.h:28
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
TranslateTTDPatchCodes
std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, const std::string &str, StringControlCode byte80=SCC_NEWGRF_PRINT_WORD_STRING_ID)
Translate TTDPatch string codes into something OpenTTD can handle (better).
Definition: newgrf_text.cpp:236
LanguageMap::plural_form
int plural_form
The plural form used for this language.
Definition: newgrf_text.h:68
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:798
GetGRFStringFromGRFText
const char * GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Definition: newgrf_text.cpp:606
strings_type.h
GRFText::text
std::string text
The actual (translated) text.
Definition: newgrf_text.h:24
control_codes.h
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:587
SCC_NEWGRF_PRINT_WORD_STRING_ID
@ SCC_NEWGRF_PRINT_WORD_STRING_ID
81: Read 2 bytes from the stack as String ID
Definition: control_codes.h:136
LanguageMap::Mapping::openttd_id
byte openttd_id
OpenTTD's internal ID for a case/gender.
Definition: newgrf_text.h:57
LanguageMap::gender_map
std::vector< Mapping > gender_map
Mapping of NewGRF and OpenTTD IDs for genders.
Definition: newgrf_text.h:66
CleanUpStrings
void CleanUpStrings()
House cleaning.
Definition: newgrf_text.cpp:682
AddGRFTextToList
void AddGRFTextToList(GRFTextList &list, byte langid, uint32_t grfid, bool allow_newlines, const char *text_to_add)
Add a string to a GRFText list.
Definition: newgrf_text.cpp:508
RestoreTextRefStackBackup
void RestoreTextRefStackBackup(struct TextRefStack *backup)
Restore a copy of the text stack to the used stack.
Definition: newgrf_text.cpp:774
string_type.h
UsingNewGRFTextStack
bool UsingNewGRFTextStack()
Check whether the NewGRF text stack is in use.
Definition: newgrf_text.cpp:756
LanguageMap::Mapping
Mapping between NewGRF and OpenTTD IDs.
Definition: newgrf_text.h:55
LanguageMap
Mapping of language data between a NewGRF and OpenTTD.
Definition: newgrf_text.h:53
SetCurrentGrfLangID
void SetCurrentGrfLangID(byte language_id)
Equivalence Setter function between game and newgrf langID.
Definition: newgrf_text.cpp:659
GetGRFStringPtr
const char * GetGRFStringPtr(uint32_t stringid)
Get a C-string from a stringid set by a newgrf.
Definition: newgrf_text.cpp:639
LanguageMap::GetMapping
int GetMapping(int newgrf_id, bool gender) const
Get the mapping from the NewGRF supplied ID to OpenTTD's internal ID.
Definition: newgrf_text.cpp:83
CreateTextRefStackBackup
struct TextRefStack * CreateTextRefStackBackup()
Create a backup of the current NewGRF text stack.
Definition: newgrf_text.cpp:765
StringControlCode
StringControlCode
List of string control codes used for string formatting, displaying, and by strgen to generate the la...
Definition: control_codes.h:17
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:815
LanguageMap::GetLanguageMap
static const LanguageMap * GetLanguageMap(uint32_t grfid, uint8_t language_id)
Get the language map associated with a given NewGRF and language.
Definition: newgrf.cpp:2628
GRFText::langid
byte langid
The language associated with this GRFText.
Definition: newgrf_text.h:23
NFO_UTF8_IDENTIFIER
static const char32_t NFO_UTF8_IDENTIFIER
This character, the thorn ('þ'), indicates a unicode string to NFO.
Definition: newgrf_text.h:19
LanguageMap::GetReverseMapping
int GetReverseMapping(int openttd_id, bool gender) const
Get the mapping from OpenTTD's internal ID to the NewGRF supplied ID.
Definition: newgrf_text.cpp:98
GRFTextWrapper
std::shared_ptr< GRFTextList > GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
Definition: newgrf_text.h:30
LanguageMap::Mapping::newgrf_id
byte newgrf_id
NewGRF's internal ID for a case/gender.
Definition: newgrf_text.h:56
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
TextRefStack
Definition: newgrf_text.cpp:687