mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-02 04:13:26 +00:00
(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.
This commit is contained in:
parent
ca20c1fa90
commit
bdcbe2af5c
13
newgrf.c
13
newgrf.c
@ -16,6 +16,7 @@
|
|||||||
#include "newgrf.h"
|
#include "newgrf.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "table/strings.h"
|
||||||
#include "bridge.h"
|
#include "bridge.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "newgrf_engine.h"
|
#include "newgrf_engine.h"
|
||||||
@ -1788,8 +1789,12 @@ static void VehicleNewName(byte *buf, int len)
|
|||||||
case GSF_ROAD:
|
case GSF_ROAD:
|
||||||
case GSF_SHIP:
|
case GSF_SHIP:
|
||||||
case GSF_AIRCRAFT: {
|
case GSF_AIRCRAFT: {
|
||||||
StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name);
|
if (id < TOTAL_NUM_ENGINES) {
|
||||||
if (id < TOTAL_NUM_ENGINES) SetCustomEngineName(id, string);
|
StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
|
||||||
|
SetCustomEngineName(id, string);
|
||||||
|
} else {
|
||||||
|
AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1800,7 +1805,7 @@ static void VehicleNewName(byte *buf, int len)
|
|||||||
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
||||||
} else {
|
} else {
|
||||||
StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
|
StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
|
||||||
SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name));
|
SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1808,7 +1813,7 @@ static void VehicleNewName(byte *buf, int len)
|
|||||||
if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
|
if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
|
||||||
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
||||||
} else {
|
} else {
|
||||||
_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name);
|
_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "openttd.h"
|
#include "openttd.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "strings.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
@ -165,7 +166,7 @@ static void TranslateTTDPatchCodes(char *str)
|
|||||||
/**
|
/**
|
||||||
* Add the new read string into our structure.
|
* Add the new read string into our structure.
|
||||||
*/
|
*/
|
||||||
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add)
|
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string)
|
||||||
{
|
{
|
||||||
GRFText *newtext;
|
GRFText *newtext;
|
||||||
uint id;
|
uint id;
|
||||||
@ -181,9 +182,9 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
|||||||
langid_to_add = GRFLX_ENGLISH;
|
langid_to_add = GRFLX_ENGLISH;
|
||||||
} else {
|
} else {
|
||||||
StringID ret = STR_EMPTY;
|
StringID ret = STR_EMPTY;
|
||||||
if (langid_to_add & GRFLB_GERMAN) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN, true, text_to_add);
|
if (langid_to_add & GRFLB_GERMAN) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN, true, text_to_add, def_string);
|
||||||
if (langid_to_add & GRFLB_FRENCH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH, true, text_to_add);
|
if (langid_to_add & GRFLB_FRENCH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH, true, text_to_add, def_string);
|
||||||
if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_SPANISH, true, text_to_add);
|
if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_SPANISH, true, text_to_add, def_string);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,6 +211,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
|||||||
if (_grf_text[id].textholder == NULL) {
|
if (_grf_text[id].textholder == NULL) {
|
||||||
_grf_text[id].grfid = grfid;
|
_grf_text[id].grfid = grfid;
|
||||||
_grf_text[id].stringid = stringid;
|
_grf_text[id].stringid = stringid;
|
||||||
|
_grf_text[id].def_string = def_string;
|
||||||
_grf_text[id].textholder = newtext;
|
_grf_text[id].textholder = newtext;
|
||||||
} else {
|
} else {
|
||||||
GRFText *textptr = _grf_text[id].textholder;
|
GRFText *textptr = _grf_text[id].textholder;
|
||||||
@ -242,17 +244,27 @@ StringID GetGRFStringID(uint32 grfid, uint16 stringid)
|
|||||||
char *GetGRFString(char *buff, uint16 stringid)
|
char *GetGRFString(char *buff, uint16 stringid)
|
||||||
{
|
{
|
||||||
GRFText *search_text;
|
GRFText *search_text;
|
||||||
|
GRFText *default_text = NULL;
|
||||||
|
|
||||||
assert(_grf_text[stringid].grfid != 0);
|
assert(_grf_text[stringid].grfid != 0);
|
||||||
/*Search the list of lang-strings of this stringid for current lang */
|
/*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) {
|
for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
|
||||||
if (search_text->langid == _currentLangID){
|
if (search_text->langid == _currentLangID) {
|
||||||
return strecpy(buff, search_text->text, NULL);
|
return strecpy(buff, search_text->text, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the current string is English or American, set it as the
|
||||||
|
* fallback language if the specific language isn't available. */
|
||||||
|
if (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN) {
|
||||||
|
default_text = search_text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use the first text if the specific language isn't available */
|
/* If there is a fallback string, return that */
|
||||||
return strecpy(buff, _grf_text[stringid].textholder->text, NULL);
|
if (default_text != NULL) return strecpy(buff, default_text->text, NULL);
|
||||||
|
|
||||||
|
/* Use the default string ID if the fallback string isn't available */
|
||||||
|
return GetString(buff, _grf_text[stringid].def_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,11 +26,12 @@ typedef struct GRFText {
|
|||||||
typedef struct GRFTextEntry {
|
typedef struct GRFTextEntry {
|
||||||
uint32 grfid;
|
uint32 grfid;
|
||||||
uint16 stringid;
|
uint16 stringid;
|
||||||
|
StringID def_string;
|
||||||
GRFText *textholder;
|
GRFText *textholder;
|
||||||
} GRFTextEntry;
|
} GRFTextEntry;
|
||||||
|
|
||||||
|
|
||||||
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add);
|
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add, StringID def_string);
|
||||||
StringID GetGRFStringID(uint32 grfid, uint16 stringid);
|
StringID GetGRFStringID(uint32 grfid, uint16 stringid);
|
||||||
char *GetGRFString(char *buff, uint16 stringid);
|
char *GetGRFString(char *buff, uint16 stringid);
|
||||||
void CleanUpStrings(void);
|
void CleanUpStrings(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user