(svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs

This commit is contained in:
rubidium 2010-07-31 14:40:50 +00:00
parent 5a2862814a
commit ac280af8bc
7 changed files with 55 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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