(svn r20249) -Codechange: change the newgrf name/description from a char* to a GRFText* to make translations possible

This commit is contained in:
yexo
2010-07-31 09:33:39 +00:00
parent 1ca16aa979
commit d3c1be9abd
7 changed files with 83 additions and 20 deletions

View File

@@ -125,6 +125,16 @@ public:
return new (strlen(text) + 1) GRFText(langid, text);
}
/**
* Create a copy of this GRFText.
* @param orig the grftext to copy
* @return an exact copy of the given text
*/
static GRFText *Copy(GRFText *orig)
{
return GRFText::New(orig->langid, orig->text);
}
/**
* Helper allocation function to disallow something.
* Don't allow simple 'news'; they wouldn't have enough memory.
@@ -352,6 +362,50 @@ void AddGRFTextToList(GRFText **list, GRFText *text_to_add)
*ptext = text_to_add;
}
/**
* Add a string to a GRFText list.
* @param list The list where the text should be added to.
* @param langid The language of the new text.
* @param grfid The grfid where this string is defined.
* @param text_to_add The text to add to the list.
* @note All text-codes will be translated.
*/
void AddGRFTextToList(struct GRFText **list, byte langid, uint32 grfid, const char *text_to_add)
{
char *translatedtext = TranslateTTDPatchCodes(grfid, text_to_add);
GRFText *newtext = GRFText::New(langid, translatedtext);
free(translatedtext);
AddGRFTextToList(list, newtext);
}
/**
* Add a GRFText to a GRFText list. The text should not contain any text-codes.
* The text will be added as a 'default language'-text.
* @param list The list where the text should be added to.
* @param text_to_add The text to add to the list.
*/
void AddGRFTextToList(struct GRFText **list, const char *text_to_add)
{
AddGRFTextToList(list, GRFText::New(0x7F, text_to_add));
}
/**
* Create a copy of this GRFText list.
* @param orig The GRFText list to copy.
* @return A duplicate of the given GRFText.
*/
GRFText *DuplicateGRFText(GRFText *orig)
{
GRFText *newtext = NULL;
GRFText **ptext = &newtext;
for (; orig != NULL; orig = orig->next) {
*ptext = GRFText::Copy(orig);
ptext = &(*ptext)->next;
}
return newtext;
}
/**
* Add the new read string into our structure.
*/