Changeset - r15589:fd456a62bb1c
[Not reviewed]
master
0 7 0
rubidium - 14 years ago 2010-07-31 14:40:50
rubidium@openttd.org
(svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
7 files changed with 55 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2370,12 +2370,13 @@ STR_NEWGRF_SETTINGS_APPLY_CHANGES       
 

	
 
STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON                 :{BLACK}Find missing content online
 
STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP                :{BLACK}Check whether the missing content can be found online
 

	
 
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}
 

	
 
STR_NEWGRF_SETTINGS_NO_INFO                                     :{BLACK}No information available
 
STR_NEWGRF_SETTINGS_NOT_FOUND                                   :{RED}Matching file not found
src/newgrf.cpp
Show inline comments
 
@@ -4866,13 +4866,13 @@ static void GRFInfo(ByteReader *buf)
 

	
 
	_cur_grffile->grfid = grfid;
 
	_cur_grffile->grf_version = version;
 
	_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 */
 
static void SpriteReplace(ByteReader *buf)
 
{
 
	/* <0A> <num-sets> <set1> [<set2> ...]
 
@@ -5949,12 +5949,24 @@ static bool ChangeGRFPalette(size_t len,
 
				break;
 
		}
 
	}
 
	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.
 

	
 
/** Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter. */
 
static bool ChangeGRFParamName(byte langid, const char *str)
 
{
 
@@ -6187,12 +6199,13 @@ static bool HandleParameterInfo(ByteRead
 

	
 
AllowedSubtags _tags_info[] = {
 
	AllowedSubtags('NAME', ChangeGRFName),
 
	AllowedSubtags('DESC', ChangeGRFDescription),
 
	AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
 
	AllowedSubtags('PALS', ChangeGRFPalette),
 
	AllowedSubtags('VRSN', ChangeGRFVersion),
 
	AllowedSubtags('PARA', HandleParameterInfo),
 
	AllowedSubtags()
 
};
 

	
 
AllowedSubtags _tags_root[] = {
 
	AllowedSubtags('INFO', _tags_info),
src/newgrf_config.cpp
Show inline comments
 
@@ -36,12 +36,13 @@ GRFConfig::GRFConfig(const char *filenam
 
/**
 
 * Create a new GRFConfig that is a deep copy of an existing config.
 
 * @param config The GRFConfig object to make a copy of.
 
 */
 
GRFConfig::GRFConfig(const GRFConfig &config) :
 
	ident(config.ident),
 
	version(config.version),
 
	flags(config.flags & ~GCF_COPY),
 
	status(config.status),
 
	grf_bugs(config.grf_bugs),
 
	num_params(config.num_params),
 
	num_valid_params(config.num_valid_params),
 
	palette(config.palette)
 
@@ -576,17 +577,20 @@ void ScanNewGRFFiles()
 
 * @param grfid GRFID to look for,
 
 * @param md5sum Expected MD5 sum (set to \c NULL if not relevant).
 
 * @return The matching grf, if it exists in #_all_grfs, else \c NULL.
 
 */
 
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
 

	
 
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
 
struct UnknownGRF : public GRFIdentifier {
src/newgrf_config.h
Show inline comments
 
@@ -136,12 +136,13 @@ struct GRFConfig : ZeroedMemoryAllocator
 
	uint8 original_md5sum[16]; ///< MD5 checksum of original file if only a 'compatible' file was loaded
 
	char *filename;            ///< Filename - either with or without full path
 
	struct GRFText *name;      ///< NOSAVE: GRF name (Action 0x08)
 
	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
 
	uint32 param[0x80];        ///< GRF parameters
 
	uint8 num_params;          ///< Number of used parameters
 
	uint8 num_valid_params;    ///< NOSAVE: Number of valid parameters (action 0x14)
src/newgrf_gui.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#include "stdafx.h"
 
#include "gui.h"
 
#include "newgrf.h"
 
#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"
 
#include "network/network_content.h"
 
#include "sortlist_type.h"
 
#include "querystring_gui.h"
 
@@ -77,12 +78,17 @@ static void ShowNewGRFInfo(const GRFConf
 
	/* Prepare and draw GRF ID */
 
	char buff[256];
 
	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
 
	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);
 
	y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
 

	
 
	/* Show GRF parameter list */
 
@@ -614,14 +620,13 @@ struct NewGRFWindow : public QueryString
 
				uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_AVAIL_LIST)->resize_y;
 
				int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
 
				uint y = r.top + WD_FRAMERECT_TOP;
 
				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();
 

	
 
					if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156);
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + offset_y, text, h ? TC_WHITE : TC_SILVER);
 
@@ -1069,13 +1074,19 @@ struct NewGRFWindow : public QueryString
 
	}
 

	
 
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 */
 
	static bool CDECL TagNameFilter(const GRFConfig * const *a, const char *filter_string)
 
	{
 
		if (strcasestr((*a)->GetName(), filter_string) != NULL) return true;
 
@@ -1090,13 +1101,29 @@ private:
 

	
 
		this->avails.Clear();
 

	
 
		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);
 
		this->avails.Compact();
 
		this->avails.RebuildDone();
 
		this->avails.Sort();
src/settings_type.h
Show inline comments
 
@@ -108,12 +108,13 @@ struct GUISettings {
 
#endif
 

	
 
	uint8  developer;                        ///< print non-fatal warnings in console (>= 1), copy debug output to console (== 2)
 
	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. */
 
struct LocaleSettings {
 
	byte   currency;                         ///< currency we currently use
 
	byte   units;                            ///< unit system we show everything
src/table/settings.h
Show inline comments
 
@@ -608,12 +608,13 @@ const SettingDesc _settings[] = {
 
#else
 
	 SDTC_BOOL(gui.show_date_in_logs,                    S,  0, false,                        STR_NULL,                                       NULL),
 
#endif
 
	  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
 
	  SDTC_VAR(gui.network_chat_box_width,   SLE_UINT16, S,  0,   620,      200,    65535, 0, STR_NULL,                                       NULL),
 
	  SDTC_VAR(gui.network_chat_box_height,   SLE_UINT8, S,  0,    25,        5,      255, 0, STR_NULL,                                       NULL),
 

	
0 comments (0 inline, 0 general)