author | rubidium |
Fri, 20 Apr 2007 08:00:30 +0000 | |
changeset 6500 | f12678890222 |
parent 6481 | 85ad87daf4b0 |
child 6564 | 07bd66a5d176 |
permissions | -rw-r--r-- |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
1 |
/* $Id$ */ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
2 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
3 |
/** @file newgrf_text.cpp |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
4 |
* Implementation of Action 04 "universal holder" structure and functions. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
5 |
* This file implements a linked-lists of strings, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
6 |
* holding everything that the newgrf action 04 will send over to OpenTTD. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
7 |
* One of the biggest problems is that Dynamic lang Array uses ISO codes |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
8 |
* as way to identifying current user lang, while newgrf uses bit shift codes |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
9 |
* not related to ISO. So equivalence functionnality had to be set. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
10 |
*/ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
11 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
12 |
#include "stdafx.h" |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
13 |
#include "debug.h" |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
14 |
#include "openttd.h" |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
15 |
#include "string.h" |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
16 |
#include "strings.h" |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
17 |
#include "variables.h" |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
18 |
#include "macros.h" |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
19 |
#include "table/strings.h" |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5344
diff
changeset
|
20 |
#include "newgrf.h" |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
21 |
#include "newgrf_text.h" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
22 |
#include "table/control_codes.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
23 |
#include "helpers.hpp" |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
24 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
25 |
#define GRFTAB 28 |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
26 |
#define TABSIZE 11 |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
27 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
28 |
/** |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
29 |
* Explains the newgrf shift bit positionning. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
30 |
* the grf base will not be used in order to find the string, but rather for |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
31 |
* jumping from standard langID scheme to the new one. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
32 |
*/ |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
33 |
enum grf_base_languages { |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
34 |
GRFLB_AMERICAN = 0x01, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
35 |
GRFLB_ENGLISH = 0x02, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
36 |
GRFLB_GERMAN = 0x04, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
37 |
GRFLB_FRENCH = 0x08, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
38 |
GRFLB_SPANISH = 0x10, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
39 |
GRFLB_GENERIC = 0x80, |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
40 |
}; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
41 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
42 |
enum grf_extended_languages { |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
43 |
GRFLX_AMERICAN = 0x00, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
44 |
GRFLX_ENGLISH = 0x01, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
45 |
GRFLX_GERMAN = 0x02, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
46 |
GRFLX_FRENCH = 0x03, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
47 |
GRFLX_SPANISH = 0x04, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
48 |
GRFLX_RUSSIAN = 0x07, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
49 |
GRFLX_CZECH = 0x15, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
50 |
GRFLX_SLOVAK = 0x16, |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
51 |
GRFLX_AFRIKAANS = 0x1B, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
52 |
GRFLX_GREEK = 0x1E, |
3605 | 53 |
GRFLX_DUTCH = 0x1F, |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
54 |
GRFLX_CATALAN = 0x22, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
55 |
GRFLX_HUNGARIAN = 0x24, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
56 |
GRFLX_ITALIAN = 0x27, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
57 |
GRFLX_ROMANIAN = 0x28, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
58 |
GRFLX_ICELANDIC = 0x29, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
59 |
GRFLX_LATVIAN = 0x2A, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
60 |
GRFLX_LITHUANIAN = 0x2B, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
61 |
GRFLX_SLOVENIAN = 0x2C, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
62 |
GRFLX_DANISH = 0x2D, |
3605 | 63 |
GRFLX_SWEDISH = 0x2E, |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
64 |
GRFLX_NORWEGIAN = 0x2F, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
65 |
GRFLX_POLISH = 0x30, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
66 |
GRFLX_GALICIAN = 0x31, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
67 |
GRFLX_FRISIAN = 0x32, |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
68 |
GRFLX_UKRAINIAN = 0x33, |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
69 |
GRFLX_ESTONIAN = 0x34, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
70 |
GRFLX_FINNISH = 0x35, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
71 |
GRFLX_PORTUGUESE = 0x36, |
3605 | 72 |
GRFLX_BRAZILIAN = 0x37, |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
73 |
GRFLX_CROATIAN = 0x38, |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
74 |
GRFLX_TURKISH = 0x3E, |
3641
88699e48a03e
(svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents:
3630
diff
changeset
|
75 |
GRFLX_UNSPECIFIED = 0x7F, |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
76 |
}; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
77 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
78 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
79 |
struct iso_grf { |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
80 |
char code[6]; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
81 |
byte grfLangID; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
82 |
}; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
83 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
84 |
/** |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
85 |
* ISO code VS NewGrf langID conversion array. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
86 |
* This array is used in two ways: |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
87 |
* 1-its ISO part is matching OpenTTD dynamic language id |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
88 |
* with newgrf bit positionning language id |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
89 |
* 2-its shift part is used to know what is the shift to |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
90 |
* watch for when inserting new strings, hence analysing newgrf langid |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
91 |
*/ |
3605 | 92 |
const iso_grf iso_codes[] = { |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
93 |
{"en_US", GRFLX_AMERICAN}, |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
94 |
{"en_GB", GRFLX_ENGLISH}, |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
95 |
{"de_DE", GRFLX_GERMAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
96 |
{"fr_FR", GRFLX_FRENCH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
97 |
{"es_ES", GRFLX_SPANISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
98 |
{"af_ZA", GRFLX_AFRIKAANS}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
99 |
{"hr_HR", GRFLX_CROATIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
100 |
{"cs_CS", GRFLX_CZECH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
101 |
{"ca_ES", GRFLX_CATALAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
102 |
{"da_DA", GRFLX_DANISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
103 |
{"nl_NL", GRFLX_DUTCH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
104 |
{"et_ET", GRFLX_ESTONIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
105 |
{"fi_FI", GRFLX_FINNISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
106 |
{"fy_NL", GRFLX_FRISIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
107 |
{"gl_ES", GRFLX_GALICIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
108 |
{"el_GR", GRFLX_GREEK}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
109 |
{"hu_HU", GRFLX_HUNGARIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
110 |
{"is_IS", GRFLX_ICELANDIC}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
111 |
{"it_IT", GRFLX_ITALIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
112 |
{"lv_LV", GRFLX_LATVIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
113 |
{"lt_LT", GRFLX_LITHUANIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
114 |
{"nb_NO", GRFLX_NORWEGIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
115 |
{"pl_PL", GRFLX_POLISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
116 |
{"pt_PT", GRFLX_PORTUGUESE}, |
3605 | 117 |
{"pt_BR", GRFLX_BRAZILIAN}, |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
118 |
{"ro_RO", GRFLX_ROMANIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
119 |
{"ru_RU", GRFLX_RUSSIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
120 |
{"sk_SK", GRFLX_SLOVAK}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
121 |
{"sl_SL", GRFLX_SLOVENIAN}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
122 |
{"sv_SE", GRFLX_SWEDISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
123 |
{"tr_TR", GRFLX_TURKISH}, |
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
124 |
{"uk_UA", GRFLX_UKRAINIAN}, |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
125 |
{"gen", GRFLB_GENERIC} ///< this is not iso code, but there has to be something... |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
126 |
}; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
127 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
128 |
|
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
129 |
/** |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
130 |
* Element of the linked list. |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
131 |
* Each of those elements represent the string, |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
132 |
* but according to a different lang. |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
133 |
*/ |
5655 | 134 |
struct GRFText { |
135 |
public: |
|
136 |
static GRFText* New(byte langid, const char* text) |
|
137 |
{ |
|
138 |
return new(strlen(text) + 1) GRFText(langid, text); |
|
139 |
} |
|
140 |
||
141 |
private: |
|
142 |
GRFText(byte langid_, const char* text_) : next(NULL), langid(langid_) |
|
143 |
{ |
|
144 |
strcpy(text, text_); |
|
145 |
} |
|
146 |
||
147 |
void* operator new(size_t size, size_t extra) |
|
148 |
{ |
|
149 |
return ::operator new(size + extra); |
|
150 |
} |
|
151 |
||
5657
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
152 |
public: |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
153 |
/* dummy operator delete to silence VC8: |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
154 |
* 'void *GRFText::operator new(size_t,size_t)' : no matching operator delete found; |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
155 |
* memory will not be freed if initialization throws an exception */ |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
156 |
void operator delete(void *p, size_t extra) |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
157 |
{ |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
158 |
return ::operator delete(p); |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
159 |
} |
0d1c1303bb94
(svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents:
5655
diff
changeset
|
160 |
|
5655 | 161 |
public: |
162 |
GRFText *next; |
|
163 |
byte langid; |
|
164 |
char text[VARARRAY_SIZE]; |
|
165 |
}; |
|
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
166 |
|
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
167 |
|
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
168 |
/** |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
169 |
* Holder of the above structure. |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
170 |
* Putting both grfid and stringid together allows us to avoid duplicates, |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
171 |
* since it is NOT SUPPOSED to happen. |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
172 |
*/ |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
173 |
struct GRFTextEntry { |
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
174 |
uint32 grfid; |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
175 |
uint16 stringid; |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
176 |
StringID def_string; |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
177 |
GRFText *textholder; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
178 |
}; |
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
179 |
|
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
180 |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
181 |
static uint _num_grf_texts = 0; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
182 |
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3]; |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
183 |
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used. |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
184 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
185 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
5208
diff
changeset
|
186 |
char *TranslateTTDPatchCodes(const char *str) |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
187 |
{ |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
188 |
char *tmp = MallocT<char>(strlen(str) * 10 + 1); // Allocate space to allow for expansion |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
189 |
char *d = tmp; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
190 |
bool unicode = false; |
5208
3875a79e5596
(svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents:
5204
diff
changeset
|
191 |
WChar c; |
3875a79e5596
(svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents:
5204
diff
changeset
|
192 |
size_t len = Utf8Decode(&c, str); |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
193 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
194 |
if (c == 0x00DE) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
195 |
/* The thorn ('þ') indicates a unicode string to TTDPatch */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
196 |
unicode = true; |
5208
3875a79e5596
(svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents:
5204
diff
changeset
|
197 |
str += len; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
198 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
199 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
200 |
for (;;) { |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
201 |
const char *tmp = str; // Used for UTF-8 decoding |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
202 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
203 |
c = (byte)*str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
204 |
if (c == 0) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
205 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
206 |
switch (c) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
207 |
case 0x01: |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
208 |
d += Utf8Encode(d, SCC_SETX); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
209 |
*d++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
210 |
break; |
5344
7d75e667692a
(svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents:
5228
diff
changeset
|
211 |
case 0x0A: break; |
7d75e667692a
(svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents:
5228
diff
changeset
|
212 |
case 0x0D: *d++ = 0x0A; break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
213 |
case 0x0E: d += Utf8Encode(d, SCC_TINYFONT); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
214 |
case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
215 |
case 0x1F: |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
216 |
d += Utf8Encode(d, SCC_SETXY); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
217 |
*d++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
218 |
*d++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
219 |
break; |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
220 |
case 0x7B: |
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
221 |
case 0x7C: |
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
222 |
case 0x7D: |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
223 |
case 0x7E: d += Utf8Encode(d, SCC_NUM); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
224 |
case 0x7F: d += Utf8Encode(d, SCC_CURRENCY); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
225 |
case 0x80: d += Utf8Encode(d, SCC_STRING); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
226 |
case 0x81: { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
227 |
StringID string; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
228 |
string = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
229 |
string |= *str++ << 8; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
230 |
d += Utf8Encode(d, SCC_STRING_ID); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
231 |
d += Utf8Encode(d, string); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
232 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
233 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
234 |
case 0x82: d += Utf8Encode(d, SCC_DATE_TINY); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
235 |
case 0x83: d += Utf8Encode(d, SCC_DATE_SHORT); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
236 |
case 0x84: d += Utf8Encode(d, SCC_VELOCITY); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
237 |
case 0x85: d += Utf8Encode(d, SCC_SKIP); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
238 |
case 0x86: /* "Rotate down top 4 words on stack" */ break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
239 |
case 0x87: d += Utf8Encode(d, SCC_VOLUME); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
240 |
case 0x88: d += Utf8Encode(d, SCC_BLUE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
241 |
case 0x89: d += Utf8Encode(d, SCC_SILVER); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
242 |
case 0x8A: d += Utf8Encode(d, SCC_GOLD); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
243 |
case 0x8B: d += Utf8Encode(d, SCC_RED); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
244 |
case 0x8C: d += Utf8Encode(d, SCC_PURPLE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
245 |
case 0x8D: d += Utf8Encode(d, SCC_LTBROWN); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
246 |
case 0x8E: d += Utf8Encode(d, SCC_ORANGE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
247 |
case 0x8F: d += Utf8Encode(d, SCC_GREEN); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
248 |
case 0x90: d += Utf8Encode(d, SCC_YELLOW); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
249 |
case 0x91: d += Utf8Encode(d, SCC_DKGREEN); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
250 |
case 0x92: d += Utf8Encode(d, SCC_CREAM); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
251 |
case 0x93: d += Utf8Encode(d, SCC_BROWN); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
252 |
case 0x94: d += Utf8Encode(d, SCC_WHITE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
253 |
case 0x95: d += Utf8Encode(d, SCC_LTBLUE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
254 |
case 0x96: d += Utf8Encode(d, SCC_GRAY); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
255 |
case 0x97: d += Utf8Encode(d, SCC_DKBLUE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
256 |
case 0x98: d += Utf8Encode(d, SCC_BLACK); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
257 |
case 0x9E: d += Utf8Encode(d, 0x20AC); break; // Euro |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
258 |
case 0x9F: d += Utf8Encode(d, 0x0178); break; // Y with diaeresis |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
259 |
case 0xA0: d += Utf8Encode(d, SCC_UPARROW); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
260 |
case 0xAA: d += Utf8Encode(d, SCC_DOWNARROW); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
261 |
case 0xAC: d += Utf8Encode(d, SCC_CHECKMARK); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
262 |
case 0xAD: d += Utf8Encode(d, SCC_CROSS); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
263 |
case 0xAF: d += Utf8Encode(d, SCC_RIGHTARROW); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
264 |
case 0xB4: d += Utf8Encode(d, SCC_TRAIN); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
265 |
case 0xB5: d += Utf8Encode(d, SCC_LORRY); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
266 |
case 0xB6: d += Utf8Encode(d, SCC_BUS); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
267 |
case 0xB7: d += Utf8Encode(d, SCC_PLANE); break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
268 |
case 0xB8: d += Utf8Encode(d, SCC_SHIP); break; |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
269 |
default: |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
270 |
if (unicode) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
271 |
d += Utf8Encode(d, Utf8Consume(&tmp)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
272 |
str = tmp; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
273 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
274 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
275 |
|
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
276 |
/* Validate any unhandled character */ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
277 |
if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?'; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
278 |
d += Utf8Encode(d, c); |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
279 |
break; |
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
280 |
} |
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
281 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
282 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
283 |
*d = '\0'; |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
284 |
tmp = ReallocT(tmp, strlen(tmp) + 1); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
285 |
return tmp; |
3646
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
286 |
} |
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
287 |
|
291be46d399e
(svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents:
3641
diff
changeset
|
288 |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
289 |
/** |
3641
88699e48a03e
(svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents:
3630
diff
changeset
|
290 |
* Add the new read string into our structure. |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
291 |
*/ |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
292 |
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string) |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
293 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
294 |
char *translatedtext; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
295 |
uint id; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
296 |
|
3641
88699e48a03e
(svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents:
3630
diff
changeset
|
297 |
/* When working with the old language scheme (grf_version is less than 7) and |
3603
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
298 |
* English or American is among the set bits, simply add it as English in |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
299 |
* the new scheme, i.e. as langid = 1. |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
300 |
* If English is set, it is pretty safe to assume the translations are not |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
301 |
* actually translated. |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
302 |
*/ |
3641
88699e48a03e
(svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents:
3630
diff
changeset
|
303 |
if (!new_scheme) { |
3603
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
304 |
if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) { |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
305 |
langid_to_add = GRFLX_ENGLISH; |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
306 |
} else { |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
307 |
StringID ret = STR_EMPTY; |
5047
05c7e74ff3e5
(svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents:
4992
diff
changeset
|
308 |
if (langid_to_add & GRFLB_GERMAN) ret = AddGRFString(grfid, stringid, GRFLX_GERMAN, true, text_to_add, def_string); |
05c7e74ff3e5
(svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents:
4992
diff
changeset
|
309 |
if (langid_to_add & GRFLB_FRENCH) ret = AddGRFString(grfid, stringid, GRFLX_FRENCH, true, text_to_add, def_string); |
05c7e74ff3e5
(svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents:
4992
diff
changeset
|
310 |
if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, text_to_add, def_string); |
3603
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
311 |
return ret; |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
312 |
} |
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
313 |
} |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
314 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
315 |
for (id = 0; id < _num_grf_texts; id++) { |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
316 |
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) { |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
317 |
break; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
318 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
319 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
320 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
321 |
/* Too many strings allocated, return empty */ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
322 |
if (id == lengthof(_grf_text)) return STR_EMPTY; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
323 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
324 |
translatedtext = TranslateTTDPatchCodes(text_to_add); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
325 |
|
5655 | 326 |
GRFText *newtext = GRFText::New(langid_to_add, translatedtext); |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
327 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5047
diff
changeset
|
328 |
free(translatedtext); |
3856
00418a7438be
(svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents:
3821
diff
changeset
|
329 |
|
3603
245bd93ea8e5
(svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents:
3602
diff
changeset
|
330 |
/* If we didn't find our stringid and grfid in the list, allocate a new id */ |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
331 |
if (id == _num_grf_texts) _num_grf_texts++; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
332 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
333 |
if (_grf_text[id].textholder == NULL) { |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
334 |
_grf_text[id].grfid = grfid; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
335 |
_grf_text[id].stringid = stringid; |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
336 |
_grf_text[id].def_string = def_string; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
337 |
_grf_text[id].textholder = newtext; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
338 |
} else { |
4711
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
339 |
GRFText **ptext, *text; |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
340 |
bool replaced = false; |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
341 |
|
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
342 |
/* Loop through all languages and see if we can replace a string */ |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
343 |
for (ptext = &_grf_text[id].textholder; (text = *ptext) != NULL; ptext = &text->next) { |
4992
bd2716c79584
(svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents:
4915
diff
changeset
|
344 |
if (text->langid != langid_to_add) continue; |
4711
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
345 |
newtext->next = text->next; |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
346 |
*ptext = newtext; |
5655 | 347 |
delete text; |
4711
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
348 |
replaced = true; |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
349 |
break; |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
350 |
} |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
351 |
|
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
352 |
/* If a string wasn't replaced, then we must append the new string */ |
28fbbec5f258
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents:
4710
diff
changeset
|
353 |
if (!replaced) *ptext = newtext; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
354 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
355 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5344
diff
changeset
|
356 |
grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
357 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
358 |
return (GRFTAB << TABSIZE) + id; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
359 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
360 |
|
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
361 |
/* Used to remember the grfid that the last retrieved string came from */ |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
362 |
static uint32 _last_grfid = 0; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
363 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
364 |
/** |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
365 |
* Returns the index for this stringid associated with its grfID |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
366 |
*/ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
367 |
StringID GetGRFStringID(uint32 grfid, uint16 stringid) |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
368 |
{ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
369 |
uint id; |
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
370 |
|
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
371 |
/* grfid is zero when we're being called via an include */ |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
372 |
if (grfid == 0) grfid = _last_grfid; |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
373 |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
374 |
for (id = 0; id < _num_grf_texts; id++) { |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
375 |
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) { |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
376 |
return (GRFTAB << TABSIZE) + id; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
377 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
378 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
379 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
380 |
return STR_UNDEFINED; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
381 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
382 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
383 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4711
diff
changeset
|
384 |
char *GetGRFString(char *buff, uint16 stringid, const char* last) |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
385 |
{ |
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
386 |
const GRFText *default_text = NULL; |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
387 |
const GRFText *search_text; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
388 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
389 |
assert(_grf_text[stringid].grfid != 0); |
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
390 |
|
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
391 |
/* Remember this grfid in case the string has included text */ |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
392 |
_last_grfid = _grf_text[stringid].grfid; |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4624
diff
changeset
|
393 |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
394 |
/*Search the list of lang-strings of this stringid for current lang */ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
395 |
for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) { |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
396 |
if (search_text->langid == _currentLangID) { |
4915
447bd240200d
(svn r6888) - Fix (r6884): Missed a couple of strecpy()s in newgrf text handling
peter1138
parents:
4912
diff
changeset
|
397 |
return strecpy(buff, search_text->text, last); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
398 |
} |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
399 |
|
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
400 |
/* If the current string is English or American, set it as the |
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
401 |
* fallback language if the specific language isn't available. */ |
4992
bd2716c79584
(svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents:
4915
diff
changeset
|
402 |
if (search_text->langid == GRFLX_UNSPECIFIED || (default_text == NULL && (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN))) { |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
403 |
default_text = search_text; |
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
404 |
} |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
405 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
406 |
|
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
407 |
/* If there is a fallback string, return that */ |
4915
447bd240200d
(svn r6888) - Fix (r6884): Missed a couple of strecpy()s in newgrf text handling
peter1138
parents:
4912
diff
changeset
|
408 |
if (default_text != NULL) return strecpy(buff, default_text->text, last); |
3821
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
409 |
|
57db5bab0f24
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents:
3646
diff
changeset
|
410 |
/* Use the default string ID if the fallback string isn't available */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4711
diff
changeset
|
411 |
return GetString(buff, _grf_text[stringid].def_string, last); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
412 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
413 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
414 |
/** |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
415 |
* Equivalence Setter function between game and newgrf langID. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
416 |
* This function will adjust _currentLangID as to what is the LangID |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
417 |
* of the current language set by the user. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
418 |
* The array iso_codes will be used to find that match. |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
419 |
* If not found, it will have to be standard english |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
420 |
* This function is called after the user changed language, |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6348
diff
changeset
|
421 |
* from strings.cpp:ReadLanguagePack |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6348
diff
changeset
|
422 |
* @param iso_name iso code of current selection |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
423 |
*/ |
3605 | 424 |
void SetCurrentGrfLangID(const char *iso_name) |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
425 |
{ |
3605 | 426 |
/* Use English by default, if we can't match up the iso_code. */ |
4305
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
427 |
byte ret = GRFLX_ENGLISH; |
a28f3849ceae
(svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents:
4299
diff
changeset
|
428 |
byte i; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
429 |
|
3605 | 430 |
for (i=0; i < lengthof(iso_codes); i++) { |
3868
2de0afd113ff
(svn r4905) - NewGRF: fix typo that prevented non-english NewGRF text from working.
peter1138
parents:
3856
diff
changeset
|
431 |
if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code)) == 0) { |
3605 | 432 |
/* We found a match, so let's use it. */ |
433 |
ret = i; |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
434 |
break; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
435 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
436 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
437 |
_currentLangID = ret; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
438 |
} |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
439 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
440 |
/** |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
441 |
* House cleaning. |
3602
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
442 |
* Remove all strings and reset the text counter. |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
443 |
*/ |
6247 | 444 |
void CleanUpStrings() |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
445 |
{ |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
446 |
uint id; |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
447 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
448 |
for (id = 0; id < _num_grf_texts; id++) { |
3602
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
449 |
GRFText *grftext = _grf_text[id].textholder; |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
450 |
while (grftext != NULL) { |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
451 |
GRFText *grftext2 = grftext->next; |
5655 | 452 |
delete grftext; |
3602
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
453 |
grftext = grftext2; |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
454 |
} |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
455 |
_grf_text[id].grfid = 0; |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
456 |
_grf_text[id].stringid = 0; |
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
457 |
_grf_text[id].textholder = NULL; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
458 |
} |
3602
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
459 |
|
cf57727a41d4
(svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents:
3601
diff
changeset
|
460 |
_num_grf_texts = 0; |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff
changeset
|
461 |
} |