From 20a090b0776469b7cde48735fac13ff371ba34c4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 8 Dec 2016 23:48:53 +0000 Subject: [PATCH] Show warning dialog if NewGRFs use too many string IDs. Show when reloading/changing NewGRF config, or starting new game. --- src/console_cmds.cpp | 3 +++ src/gfxinit.cpp | 4 ++++ src/lang/english.txt | 3 +++ src/newgrf_config.cpp | 2 ++ src/newgrf_config.h | 2 ++ src/newgrf_gui.cpp | 10 ++++++++++ src/newgrf_text.cpp | 6 +++++- src/openttd.cpp | 6 ++++++ 8 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index c9d1608a7d..31217d4f42 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1897,6 +1897,9 @@ DEF_CONSOLE_CMD(ConNewGRFReload) } ReloadNewGRFData(); + + extern void PostCheckNewGRFLoadWarnings(); + PostCheckNewGRFLoadWarnings(); return true; } diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index ac7989fe67..2ad5aa36d5 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -451,6 +451,8 @@ void GfxLoadSprites() { DEBUG(sprite, 2, "Loading sprite set %d", _settings_game.game_creation.landscape); + _grf_bug_too_many_strings = false; + SwitchNewGRFBlitter(); ClearFontCache(); GfxInitSpriteMem(); @@ -460,6 +462,8 @@ void GfxLoadSprites() UpdateRouteStepSpriteSize(); UpdateCursorSize(); + + DEBUG(sprite, 2, "Completed loading sprite set %d", _settings_game.game_creation.landscape); } bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename) diff --git a/src/lang/english.txt b/src/lang/english.txt index dcf876c6f8..a8deb17a2b 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3319,6 +3319,9 @@ STR_NEWGRF_BUGGY_ARTICULATED_CARGO :{WHITE}Cargo/re STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK :{WHITE}'{1:STRING}' caused an endless loop in the production callback STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT :{WHITE}Callback {1:HEX} returned unknown/invalid result {2:HEX} +STR_NEWGRF_TOO_MANY_STRINGS :{WHITE}Not enough string IDs available for all NewGRFs. +STR_NEWGRF_TOO_MANY_STRINGS_DETAIL :{WHITE}Some names and text fields may be displayed incorrectly. Try using fewer NewGRFs. + # 'User removed essential NewGRFs'-placeholders for stuff without specs STR_NEWGRF_INVALID_CARGO : STR_NEWGRF_INVALID_CARGO_ABBREV :?? diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 19ac4d4a7e..376fb32469 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -193,6 +193,8 @@ GRFConfig *_grfconfig; GRFConfig *_grfconfig_newgame; GRFConfig *_grfconfig_static; +bool _grf_bug_too_many_strings = false; + /** * Construct a new GRFError. * @param severity The severity of this error. diff --git a/src/newgrf_config.h b/src/newgrf_config.h index e19d8d6085..6490bae232 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -205,6 +205,8 @@ extern GRFConfig *_grfconfig; ///< First item in list of current GRF set extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up extern GRFConfig *_grfconfig_static; ///< First item in list of static GRF set up +extern bool _grf_bug_too_many_strings;///< NewGRF bug: Insufficient available string IDs for GRFs + /** Callback for NewGRF scanning. */ struct NewGRFScanCallback { /** Make sure the right destructor gets called. */ diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index cc63f7b577..753f9b899f 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -607,6 +607,7 @@ static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map) static void NewGRFConfirmationCallback(Window *w, bool confirmed); static void ShowSavePresetWindow(const char *initial_text); +void PostCheckNewGRFLoadWarnings(); /** * Window for showing NewGRF files @@ -691,6 +692,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { CopyGRFConfigList(this->orig_list, this->actives, true); ResetGRFConfig(false); ReloadNewGRFData(); + PostCheckNewGRFLoadWarnings(); } /* Remove the temporary copy of grf-list used in window */ @@ -1113,6 +1115,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { CopyGRFConfigList(this->orig_list, this->actives, true); ResetGRFConfig(false); ReloadNewGRFData(); + PostCheckNewGRFLoadWarnings(); } this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window break; @@ -1975,6 +1978,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed) GamelogGRFUpdate(_grfconfig, nw->actives); // log GRF changes CopyGRFConfigList(nw->orig_list, nw->actives, false); ReloadNewGRFData(); + PostCheckNewGRFLoadWarnings(); GamelogStopAction(); /* Show new, updated list */ @@ -1993,6 +1997,12 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed) } } +void PostCheckNewGRFLoadWarnings() +{ + if (_grf_bug_too_many_strings) { + ShowErrorMessage(STR_NEWGRF_TOO_MANY_STRINGS, STR_NEWGRF_TOO_MANY_STRINGS_DETAIL, WL_WARNING); + } +} /** diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index daf9db4433..1fec4a52f9 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -23,6 +23,7 @@ #include "newgrf_storage.h" #include "newgrf_text.h" #include "newgrf_cargo.h" +#include "newgrf_config.h" #include "string_func.h" #include "date_type.h" #include "debug.h" @@ -674,7 +675,10 @@ 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; + if (id == lengthof(_grf_text)) { + _grf_bug_too_many_strings = true; + return STR_EMPTY; + } int len; translatedtext = TranslateTTDPatchCodes(grfid, langid_to_add, allow_newlines, text_to_add, &len); diff --git a/src/openttd.cpp b/src/openttd.cpp index fbef087a18..3dc8e98684 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -982,6 +982,9 @@ static void MakeNewGameDone() { SettingsDisableElrail(_settings_game.vehicle.disable_elrails); + extern void PostCheckNewGRFLoadWarnings(); + PostCheckNewGRFLoadWarnings(); + /* In a dedicated server, the server does not play */ if (!VideoDriver::GetInstance()->HasGUI()) { SetLocalCompany(COMPANY_SPECTATOR); @@ -1049,6 +1052,9 @@ static void MakeNewGame(bool from_heightmap, bool reset_settings) static void MakeNewEditorWorldDone() { SetLocalCompany(OWNER_NONE); + + extern void PostCheckNewGRFLoadWarnings(); + PostCheckNewGRFLoadWarnings(); } static void MakeNewEditorWorld()