Mercurial > hg > openttd
changeset 6873:608145365c5d draft
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
language. Since only one error can be loaded anyway, if the language didn't
match you'd get "Undefined string". Also since we're only loading one language
there's no need to use AddGRFString any more.
author | maedhros <maedhros@openttd.org> |
---|---|
date | Tue, 12 Jun 2007 13:22:14 +0000 |
parents | 5b52562b4be1 |
children | a2a6f2050a65 |
files | src/newgrf.cpp src/newgrf_config.cpp src/newgrf_config.h src/newgrf_gui.cpp src/newgrf_text.cpp src/newgrf_text.h |
diffstat | 6 files changed, 41 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -18,6 +18,7 @@ #include "newgrf.h" #include "variables.h" #include "string.h" +#include "strings.h" #include "table/strings.h" #include "bridge.h" #include "town.h" @@ -3412,15 +3413,6 @@ STR_NEWGRF_ERROR_MSG_FATAL }; - /* AddGRFString expects the string to be referred to by an id in the newgrf - * file. Errors messages are never referred to however, so invent ids that - * are unlikely to be reached in a newgrf file so they don't overwrite - * anything else. */ - enum { - MESSAGE_STRING_ID = MAX_UVALUE(StringID) - 1, - MESSAGE_DATA_ID = MAX_UVALUE(StringID) - }; - if (!check_length(len, 6, "GRFLoadError")) return; /* For now we can only show one message per newgrf file. */ @@ -3432,6 +3424,9 @@ byte message_id = grf_load_byte(&buf); len -= 4; + /* Skip the error if it isn't valid for the current language. */ + if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return; + /* Skip the error until the activation stage unless bit 7 of the severity * is set. */ if (!HASBIT(severity, 7) && _cur_stage == GLS_INIT) { @@ -3461,7 +3456,6 @@ return; } - bool new_scheme = _cur_grffile->grf_version >= 7; GRFError *error = CallocT<GRFError>(1); error->severity = sevstr[severity]; @@ -3471,7 +3465,7 @@ const char *message = grf_load_string(&buf, len); len -= (strlen(message) + 1); - error->message = AddGRFString(_cur_grffile->grfid, MESSAGE_STRING_ID, lang, new_scheme, message, STR_UNDEFINED); + error->custom_message = TranslateTTDPatchCodes(message); } else { error->message = msgstr[message_id]; } @@ -3480,7 +3474,7 @@ const char *data = grf_load_string(&buf, len); len -= (strlen(data) + 1); - error->data = AddGRFString(_cur_grffile->grfid, MESSAGE_DATA_ID, lang, new_scheme, data, STR_UNDEFINED); + error->data = TranslateTTDPatchCodes(data); } /* Only two parameter numbers can be used in the string. */ @@ -4116,8 +4110,12 @@ /* If the file is not active but will be activated later, give an error * and disable this file. */ GRFError *error = CallocT<GRFError>(1); + + char tmp[256]; + GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp)); + error->data = strdup(tmp); + error->message = STR_NEWGRF_ERROR_LOAD_AFTER; - error->data = STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE; error->severity = STR_NEWGRF_ERROR_MSG_FATAL; if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error); @@ -4402,6 +4400,8 @@ { for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { if (!HASBIT(c->flags, GCF_COPY) && c->error != NULL) { + free(c->error->custom_message); + free(c->error->data); free(c->error); c->error = NULL; }
--- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -97,7 +97,12 @@ free((*config)->full_path); free((*config)->name); free((*config)->info); - free((*config)->error); + + if ((*config)->error != NULL) { + free((*config)->error->custom_message); + free((*config)->error->data); + free((*config)->error); + } } free(*config); *config = NULL; @@ -134,6 +139,8 @@ if (src->error != NULL) { c->error = CallocT<GRFError>(1); memcpy(c->error, src->error, sizeof(GRFError)); + if (src->error->data != NULL) c->error->data = strdup(src->error->data); + if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message); } *dst = c;
--- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -36,8 +36,9 @@ }; struct GRFError { + char *custom_message; + char *data; StringID message; - StringID data; StringID severity; uint8 num_params; uint8 param_number[2];
--- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -48,7 +48,7 @@ if (c->error != NULL) { SetDParamStr(0, c->filename); - SetDParam(1, c->error->data); + SetDParamStr(1, c->error->data); for (uint i = 0; i < c->error->num_params; i++) { uint32 param = 0; byte param_number = c->error->param_number[i]; @@ -59,7 +59,7 @@ } char message[512]; - GetString(message, c->error->message, lastof(message)); + GetString(message, c->error->custom_message != NULL ? BindCString(c->error->custom_message) : c->error->message, lastof(message)); SetDParamStr(0, message); y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
--- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -445,6 +445,20 @@ _currentLangID = ret; } +bool CheckGrfLangID(byte lang_id, byte grf_version) +{ + if (grf_version < 7) { + switch (_currentLangID) { + case GRFLX_GERMAN: return (lang_id & GRFLB_GERMAN) != 0; + case GRFLX_FRENCH: return (lang_id & GRFLB_FRENCH) != 0; + case GRFLX_SPANISH: return (lang_id & GRFLB_SPANISH) != 0; + default: return (lang_id & (GRFLB_ENGLISH | GRFLB_AMERICAN)) != 0; + } + } + + return (lang_id == _currentLangID || lang_id == GRFLX_UNSPECIFIED); +} + /** * House cleaning. * Remove all strings and reset the text counter.