OpenTTD Source: src/newgrf_text_type.h Source File

OpenTTD Source 15.0-RC2

newgrf_text_type.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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NEWGRF_TEXT_TYPE_H
11#define NEWGRF_TEXT_TYPE_H
12
13#include "core/strong_typedef_type.hpp"
14
16 using GRFStringID = StrongType::Typedef<uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer>;
17
18 static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT{0xD000};
19
21 static const char32_t NFO_UTF8_IDENTIFIER = 0x00DE;
22
24 struct GRFText {
25 uint8_t langid;
26 std::string text;
27};
28
30 using GRFTextList = std::vector<GRFText>;
32 using GRFTextWrapper = std::shared_ptr<GRFTextList>;
33
35 struct LanguageMap {
37 struct Mapping {
38 uint8_t newgrf_id;
39 uint8_t openttd_id;
40 };
41
42 /* We need a vector and can't use SmallMap due to the fact that for "setting" a
43 * gender of a string or requesting a case for a substring we want to map from
44 * the NewGRF's internal ID to OpenTTD's ID whereas for the choice lists we map
45 * the genders/cases/plural OpenTTD IDs to the NewGRF's internal IDs. In this
46 * case a NewGRF developer/translator might want a different translation for
47 * both cases. Thus we are basically implementing a multi-map. */
48 std::vector<Mapping> gender_map;
49 std::vector<Mapping> case_map;
50 int plural_form;
51
52 int GetMapping(int newgrf_id, bool gender) const;
53 int GetReverseMapping(int openttd_id, bool gender) const;
54 static const LanguageMap *GetLanguageMap(uint32_t grfid, uint8_t language_id);
55};
56
57#endif /* NEWGRF_TEXT_TYPE_H */
GRFTextWrapper
std::shared_ptr< GRFTextList > GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
Definition newgrf_text_type.h:32
GRFTextList
std::vector< GRFText > GRFTextList
A GRF text with a list of translations.
Definition newgrf_text_type.h:30
GRFSTR_MISC_GRF_TEXT
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Definition newgrf_text_type.h:18
NFO_UTF8_IDENTIFIER
static const char32_t NFO_UTF8_IDENTIFIER
This character (thorn) indicates a unicode string to NFO.
Definition newgrf_text_type.h:21
strong_typedef_type.hpp
Type (helpers) for making a strong typedef that is a distinct type.
GRFText
A GRF text with associated language ID.
Definition newgrf_text_type.h:24
GRFText::text
std::string text
The actual (translated) text.
Definition newgrf_text_type.h:26
GRFText::langid
uint8_t langid
The language associated with this GRFText.
Definition newgrf_text_type.h:25
LanguageMap::Mapping
Mapping between NewGRF and OpenTTD IDs.
Definition newgrf_text_type.h:37
LanguageMap::Mapping::newgrf_id
uint8_t newgrf_id
NewGRF's internal ID for a case/gender.
Definition newgrf_text_type.h:38
LanguageMap::Mapping::openttd_id
uint8_t openttd_id
OpenTTD's internal ID for a case/gender.
Definition newgrf_text_type.h:39
LanguageMap
Mapping of language data between a NewGRF and OpenTTD.
Definition newgrf_text_type.h:35
LanguageMap::gender_map
std::vector< Mapping > gender_map
Mapping of NewGRF and OpenTTD IDs for genders.
Definition newgrf_text_type.h:48
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:100
LanguageMap::plural_form
int plural_form
The plural form used for this language.
Definition newgrf_text_type.h:50
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:357
LanguageMap::case_map
std::vector< Mapping > case_map
Mapping of NewGRF and OpenTTD IDs for cases.
Definition newgrf_text_type.h:49
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:85
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer >