|
@@ -120,12 +120,37 @@ const iso_grf iso_codes[] = {
|
|
|
{"tr_TR", GRFLX_TURKISH},
|
|
|
{"uk_UA", GRFLX_UKRAINIAN},
|
|
|
{"gen", GRFLB_GENERIC} //this is not iso code, but there has to be something...
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Element of the linked list.
|
|
|
* Each of those elements represent the string,
|
|
|
* but according to a different lang.
|
|
|
*/
|
|
|
typedef struct GRFText {
|
|
|
struct GRFText *next;
|
|
|
byte langid;
|
|
|
char text[VARARRAY_SIZE];
|
|
|
} GRFText;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Holder of the above structure.
|
|
|
* Putting both grfid and stringid together allows us to avoid duplicates,
|
|
|
* since it is NOT SUPPOSED to happen.
|
|
|
*/
|
|
|
typedef struct GRFTextEntry {
|
|
|
uint32 grfid;
|
|
|
uint16 stringid;
|
|
|
StringID def_string;
|
|
|
GRFText *textholder;
|
|
|
} GRFTextEntry;
|
|
|
|
|
|
|
|
|
static uint _num_grf_texts = 0;
|
|
|
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
|
|
|
static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used.
|
|
|
|
|
|
|
|
|
static void TranslateTTDPatchCodes(char *str)
|
|
@@ -203,16 +228,16 @@ StringID AddGRFString(uint32 grfid, uint
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Too many strings allocated, return empty */
|
|
|
if (id == lengthof(_grf_text)) return STR_EMPTY;
|
|
|
|
|
|
newtext = calloc(1, sizeof(*newtext));
|
|
|
newtext = malloc(sizeof(*newtext) + strlen(text_to_add) + 1);
|
|
|
newtext->next = NULL;
|
|
|
newtext->langid = GB(langid_to_add, 0, 6);
|
|
|
newtext->text = strdup(text_to_add);
|
|
|
newtext->next = NULL;
|
|
|
strcpy(newtext->text, text_to_add);
|
|
|
|
|
|
TranslateTTDPatchCodes(newtext->text);
|
|
|
|
|
|
/* If we didn't find our stringid and grfid in the list, allocate a new id */
|
|
|
if (id == _num_grf_texts) _num_grf_texts++;
|
|
|
|
|
@@ -248,14 +273,14 @@ StringID GetGRFStringID(uint32 grfid, ui
|
|
|
return STR_UNDEFINED;
|
|
|
}
|
|
|
|
|
|
|
|
|
char *GetGRFString(char *buff, uint16 stringid)
|
|
|
{
|
|
|
GRFText *search_text;
|
|
|
GRFText *default_text = NULL;
|
|
|
const GRFText *default_text = NULL;
|
|
|
const GRFText *search_text;
|
|
|
|
|
|
assert(_grf_text[stringid].grfid != 0);
|
|
|
/*Search the list of lang-strings of this stringid for current lang */
|
|
|
for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
|
|
|
if (search_text->langid == _currentLangID) {
|
|
|
return strecpy(buff, search_text->text, NULL);
|
|
@@ -284,16 +309,15 @@ char *GetGRFString(char *buff, uint16 st
|
|
|
* This function is called after the user changed language,
|
|
|
* from strings.c:ReadLanguagePack
|
|
|
* @param iso code of current selection
|
|
|
*/
|
|
|
void SetCurrentGrfLangID(const char *iso_name)
|
|
|
{
|
|
|
byte ret,i;
|
|
|
|
|
|
/* Use English by default, if we can't match up the iso_code. */
|
|
|
ret = GRFLX_ENGLISH;
|
|
|
byte ret = GRFLX_ENGLISH;
|
|
|
byte i;
|
|
|
|
|
|
for (i=0; i < lengthof(iso_codes); i++) {
|
|
|
if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code)) == 0) {
|
|
|
/* We found a match, so let's use it. */
|
|
|
ret = i;
|
|
|
break;
|
|
@@ -311,13 +335,12 @@ void CleanUpStrings(void)
|
|
|
uint id;
|
|
|
|
|
|
for (id = 0; id < _num_grf_texts; id++) {
|
|
|
GRFText *grftext = _grf_text[id].textholder;
|
|
|
while (grftext != NULL) {
|
|
|
GRFText *grftext2 = grftext->next;
|
|
|
free(grftext->text);
|
|
|
free(grftext);
|
|
|
grftext = grftext2;
|
|
|
}
|
|
|
_grf_text[id].grfid = 0;
|
|
|
_grf_text[id].stringid = 0;
|
|
|
_grf_text[id].textholder = NULL;
|