diff options
author | rubidium <rubidium@openttd.org> | 2010-07-31 14:40:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-07-31 14:40:50 +0000 |
commit | ac280af8bc75f89223238a77f871b1a610014219 (patch) | |
tree | f11e8dde3c5e08a29824a11429eb573a3373302a /src | |
parent | 5a2862814ac310e5e4629e0242def8ebf3a6da1c (diff) | |
download | openttd-ac280af8bc75f89223238a77f871b1a610014219.tar.xz |
(svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
Diffstat (limited to 'src')
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/newgrf.cpp | 15 | ||||
-rw-r--r-- | src/newgrf_config.cpp | 8 | ||||
-rw-r--r-- | src/newgrf_config.h | 1 | ||||
-rw-r--r-- | src/newgrf_gui.cpp | 35 | ||||
-rw-r--r-- | src/settings_type.h | 1 | ||||
-rw-r--r-- | src/table/settings.h | 1 |
7 files changed, 55 insertions, 7 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index d31c19a81..4a8c00adf 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2373,6 +2373,7 @@ STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP :{BLACK}Check wh STR_NEWGRF_SETTINGS_FILENAME :{BLACK}Filename: {SILVER}{RAW_STRING} STR_NEWGRF_SETTINGS_GRF_ID :{BLACK}GRF ID: {SILVER}{RAW_STRING} +STR_NEWGRF_SETTINGS_VERSION :{BLACK}Version: {SILVER}{NUM} STR_NEWGRF_SETTINGS_MD5SUM :{BLACK}MD5sum: {SILVER}{RAW_STRING} STR_NEWGRF_SETTINGS_PALETTE :{BLACK}Palette: {SILVER}{RAW_STRING} STR_NEWGRF_SETTINGS_PARAMETER :{BLACK}Parameters: {SILVER}{STRING1} diff --git a/src/newgrf.cpp b/src/newgrf.cpp index bb5f63660..bd4c913e2 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4869,7 +4869,7 @@ static void GRFInfo(ByteReader *buf) _cur_grfconfig->status = _cur_stage < GLS_RESERVE ? GCS_INITIALISED : GCS_ACTIVATED; /* Do swap the GRFID for displaying purposes since people expect that */ - DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08X - %s (palette: %s)", version, BSWAP32(grfid), name, (_cur_grfconfig->palette & GRFP_USE_MASK) ? "Windows" : "DOS"); + DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08X - %s (palette: %s, version: %i)", version, BSWAP32(grfid), name, (_cur_grfconfig->palette & GRFP_USE_MASK) ? "Windows" : "DOS", _cur_grfconfig->version); } /* Action 0x0A */ @@ -5952,6 +5952,18 @@ static bool ChangeGRFPalette(size_t len, ByteReader *buf) return true; } +/** Callback function for 'INFO'->'VRSN' to the version of the NewGRF. */ +static bool ChangeGRFVersion(size_t len, ByteReader *buf) +{ + if (len != 4) { + grfmsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE ", ignoring this field", len); + buf->Skip(len); + } else { + _cur_grfconfig->version = buf->ReadDWord(); + } + return true; +} + static GRFParameterInfo *_cur_parameter; ///< The parameter which info is currently changed by the newgrf. @@ -6190,6 +6202,7 @@ AllowedSubtags _tags_info[] = { AllowedSubtags('DESC', ChangeGRFDescription), AllowedSubtags('NPAR', ChangeGRFNumUsedParams), AllowedSubtags('PALS', ChangeGRFPalette), + AllowedSubtags('VRSN', ChangeGRFVersion), AllowedSubtags('PARA', HandleParameterInfo), AllowedSubtags() }; diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 41be0c1c0..f993accb4 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -39,6 +39,7 @@ GRFConfig::GRFConfig(const char *filename) : */ GRFConfig::GRFConfig(const GRFConfig &config) : ident(config.ident), + version(config.version), flags(config.flags & ~GCF_COPY), status(config.status), grf_bugs(config.grf_bugs), @@ -579,11 +580,14 @@ void ScanNewGRFFiles() */ const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) { + const GRFConfig *best = NULL; for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) { - if (c->ident.HasGrfIdentifier(grfid, md5sum)) return c; + if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue; + if (md5sum != NULL) return c; + if (best == NULL || c->version > best->version) best = c; } - return NULL; + return best; } #ifdef ENABLE_NETWORK diff --git a/src/newgrf_config.h b/src/newgrf_config.h index fe5e8c9c4..34e21808e 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -139,6 +139,7 @@ struct GRFConfig : ZeroedMemoryAllocator { struct GRFText *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08) GRFError *error; ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B) + uint32 version; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown uint8 flags; ///< NOSAVE: GCF_Flags, bitset GRFStatus status; ///< NOSAVE: GRFStatus, enum uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index bc6e32f7d..53f9f1650 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -15,6 +15,7 @@ #include "strings_func.h" #include "window_func.h" #include "gamelog.h" +#include "settings_type.h" #include "settings_func.h" #include "widgets/dropdown_type.h" #include "network/network.h" @@ -80,6 +81,11 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint SetDParamStr(0, buff); y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID); + if (c->version != 0) { + SetDParam(0, c->version); + y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION); + } + /* Prepare and draw MD5 sum */ md5sumToString(buff, lastof(buff), c->ident.md5sum); SetDParamStr(0, buff); @@ -617,8 +623,7 @@ struct NewGRFWindow : public QueryStringBaseWindow { uint min_index = this->vscroll2.GetPosition(); uint max_index = min(min_index + this->vscroll2.GetCapacity(), this->avails.Length()); - for (uint i = min_index; i < max_index; i++) - { + for (uint i = min_index; i < max_index; i++) { const GRFConfig *c = this->avails[i]; bool h = (c == this->avail_sel); const char *text = c->GetName(); @@ -1072,7 +1077,13 @@ private: /** Sort grfs by name. */ static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b) { - return strcasecmp((*a)->GetName(), (*b)->GetName()); + int i = strcasecmp((*a)->GetName(), (*b)->GetName()); + if (i != 0) return i; + + i = (*a)->version - (*b)->version; + if (i != 0) return i; + + return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum)); } /** Filter grfs by tags/name */ @@ -1093,7 +1104,23 @@ private: for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) { bool found = false; for (const GRFConfig *grf = this->actives; grf != NULL && !found; grf = grf->next) found = grf->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum); - if (!found) *this->avails.Append() = c; + if (found) continue; + + if (_settings_client.gui.newgrf_show_old_versions) { + *this->avails.Append() = c; + } else { + const GRFConfig *best = FindGRFConfig(c->ident.grfid, NULL); + /* + * If the best version is 0, then all NewGRF with this GRF ID + * have version 0, so for backward compatability reasons we + * want to show them all. + * If we are the best version, then we definitely want to + * show that NewGRF!. + */ + if (best->version == 0 || best->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum)) { + *this->avails.Append() = c; + } + } } this->avails.Filter(this->edit_str_buf); diff --git a/src/settings_type.h b/src/settings_type.h index c2d999cad..8e3b61db8 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -111,6 +111,7 @@ struct GUISettings { bool show_date_in_logs; ///< whether to show dates in console logs bool newgrf_developer_tools; ///< activate NewGRF developer tools bool ai_developer_tools; ///< activate AI developer tools + bool newgrf_show_old_versions; ///< whether to show old versions in the NewGRF list }; /** Settings related to currency/unit systems. */ diff --git a/src/table/settings.h b/src/table/settings.h index dbfc87ce0..255c7055e 100644 --- a/src/table/settings.h +++ b/src/table/settings.h @@ -611,6 +611,7 @@ const SettingDesc _settings[] = { SDTC_VAR(gui.developer, SLE_UINT8, S, 0, 1, 0, 2, 0, STR_NULL, NULL), SDTC_BOOL(gui.newgrf_developer_tools, S, 0, false, STR_NULL, ReinitWindows), SDTC_BOOL(gui.ai_developer_tools, S, 0, false, STR_NULL, NULL), + SDTC_BOOL(gui.newgrf_show_old_versions, S, 0, false, STR_NULL, NULL), SDTC_VAR(gui.console_backlog_timeout, SLE_UINT16, S, 0, 100, 10, 65500, 0, STR_NULL, NULL), SDTC_VAR(gui.console_backlog_length, SLE_UINT16, S, 0, 100, 10, 65500, 0, STR_NULL, NULL), #ifdef ENABLE_NETWORK |