From 6ffae9357bc7ebc2fb8e4975755f3cbf7290b7e4 Mon Sep 17 00:00:00 2001 From: cirdan Date: Wed, 15 Nov 2017 21:17:53 +0100 Subject: [PATCH] Add an AddGRFString overload to do the actual work Add an AddGRFString overload to actually add a translated string to a string map. This will allow to rearrange the existing AddGRFString in next commit. --- src/newgrf_text.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index f132510c8..e0ff198a6 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -630,6 +630,26 @@ char *TranslateTTDPatchCodes (uint32 grfid, uint8 language_id, /** * Add the new read string into our structure. */ +static StringID AddGRFString (uint textid, byte langid, const char *text, + bool allow_newlines) +{ + GRFTextEntry *entry = &_grf_text[textid]; + GRFText *newtext = GRFText::create (text, entry->grfid, + langid, allow_newlines); + entry->map->add (langid, newtext); + + StringID str = MakeStringID (TEXT_TAB_NEWGRF_START, textid); + + grfmsg (3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s' (%X)", + textid, entry->grfid, entry->stringid, langid, + newtext->text, str); + + return str; +} + +/** + * Add the new read string into our structure. + */ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string) { uint id; @@ -661,8 +681,6 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne /* Too many strings allocated, return empty */ if (id == lengthof(_grf_text)) return STR_EMPTY; - GRFText *newtext = GRFText::create (text_to_add, grfid, langid_to_add, allow_newlines); - /* If we didn't find our stringid and grfid in the list, allocate a new id */ if (id == _num_grf_texts) _num_grf_texts++; @@ -672,11 +690,8 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne _grf_text[id].def_string = def_string; _grf_text[id].map = new GRFTextMap; } - _grf_text[id].map->add (langid_to_add, newtext); - - grfmsg (3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s' (%X)", id, grfid, stringid, langid_to_add, newtext->text, MakeStringID(TEXT_TAB_NEWGRF_START, id)); - return MakeStringID(TEXT_TAB_NEWGRF_START, id); + return AddGRFString (id, langid_to_add, text_to_add, allow_newlines); } /** -- 2.11.4.GIT