Show warning dialog if NewGRFs use too many string IDs.

Show when reloading/changing NewGRF config, or starting new game.
This commit is contained in:
Jonathan G Rennison 2016-12-08 23:48:53 +00:00
parent 6f4dbacf3e
commit 20a090b077
8 changed files with 35 additions and 1 deletions

View File

@ -1897,6 +1897,9 @@ DEF_CONSOLE_CMD(ConNewGRFReload)
}
ReloadNewGRFData();
extern void PostCheckNewGRFLoadWarnings();
PostCheckNewGRFLoadWarnings();
return true;
}

View File

@ -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)

View File

@ -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 :<invalid cargo>
STR_NEWGRF_INVALID_CARGO_ABBREV :??

View File

@ -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.

View File

@ -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. */

View File

@ -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);
}
}
/**

View File

@ -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);

View File

@ -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()