OpenTTD Source 20260711-master-g3fb3006dff
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
9
10#ifndef NEWGRF_TEXT_TYPE_H
11#define NEWGRF_TEXT_TYPE_H
12
14#include "newgrf_type.h"
15
18
19static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT{0xD000};
20
22static const char32_t NFO_UTF8_IDENTIFIER = 0x00DE;
23
25enum class GRFLanguage : uint8_t {
27 English = 1,
28 German = 2,
29 French = 3,
30 Spanish = 4,
31
32 Unspecified = 0x7F,
33 End = 0x7F,
34
36};
37
39struct GRFText {
41 std::string text;
42};
43
45using GRFTextList = std::vector<GRFText>;
47using GRFTextWrapper = std::shared_ptr<GRFTextList>;
48
52 struct Mapping {
53 uint8_t newgrf_id;
54 uint8_t openttd_id;
55 };
56
57 /* We need a vector and can't use SmallMap due to the fact that for "setting" a
58 * gender of a string or requesting a case for a substring we want to map from
59 * the NewGRF's internal ID to OpenTTD's ID whereas for the choice lists we map
60 * the genders/cases/plural OpenTTD IDs to the NewGRF's internal IDs. In this
61 * case a NewGRF developer/translator might want a different translation for
62 * both cases. Thus we are basically implementing a multi-map. */
63 std::vector<Mapping> gender_map;
64 std::vector<Mapping> case_map;
66
67 int GetMapping(int newgrf_id, bool gender) const;
68 int GetReverseMapping(int openttd_id, bool gender) const;
69 static const LanguageMap *GetLanguageMap(GrfID grfid, GRFLanguage language_id);
70};
71
72#endif /* NEWGRF_TEXT_TYPE_H */
GRFLanguage
Incomplete enumeration of the (New)GRF languages.
@ Unspecified
No specific language.
@ English
English (English UK).
@ End
End marker of the valid languages.
@ Fallback
Default fallback language.
@ American
American (English US).
@ Spanish
Spanish.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
std::shared_ptr< GRFTextList > GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
std::vector< GRFText > GRFTextList
A GRF text with a list of translations.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
static const char32_t NFO_UTF8_IDENTIFIER
This character (thorn) indicates a unicode string to NFO.
Commonly used types for the NewGRF implementation.
uint32_t GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:15
Type (helpers) for making a strong typedef that is a distinct type.
A GRF text with associated language ID.
GRFLanguage langid
The language associated with this GRFText.
std::string text
The actual (translated) text.
Mapping between NewGRF and OpenTTD IDs.
uint8_t newgrf_id
NewGRF's internal ID for a case/gender.
uint8_t openttd_id
OpenTTD's internal ID for a case/gender.
Mapping of language data between a NewGRF and OpenTTD.
std::vector< Mapping > gender_map
Mapping of NewGRF and OpenTTD IDs for genders.
int GetReverseMapping(int openttd_id, bool gender) const
Get the mapping from OpenTTD's internal ID to the NewGRF supplied ID.
int plural_form
The plural form used for this language.
static const LanguageMap * GetLanguageMap(GrfID grfid, GRFLanguage language_id)
Get the language map associated with a given NewGRF and language.
Definition newgrf.cpp:363
std::vector< Mapping > case_map
Mapping of NewGRF and OpenTTD IDs for cases.
int GetMapping(int newgrf_id, bool gender) const
Get the mapping from the NewGRF supplied ID to OpenTTD's internal ID.
Templated helper to make a type-safe 'typedef' representing a single POD value.