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
 
@@ -2364,24 +2364,25 @@ STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP    
 
STR_NEWGRF_SETTINGS_FILE_TOOLTIP                                :{BLACK}A list of the NewGRF files that are installed. Click a file to change its parameters
 

	
 
STR_NEWGRF_SETTINGS_SET_PARAMETERS                              :{BLACK}Set parameters
 
STR_NEWGRF_SETTINGS_TOGGLE_PALETTE                              :{BLACK}Toggle palette
 
STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP                      :{BLACK}Toggle the palette of the selected NewGRF.{}Do this when the graphics from this NewGRF look pink in-game
 
STR_NEWGRF_SETTINGS_APPLY_CHANGES                               :{BLACK}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
 
STR_NEWGRF_SETTINGS_DISABLED                                    :{RED}Disabled
 

	
 
STR_NEWGRF_SETTINGS_PARAMETER_QUERY                             :{BLACK}Enter NewGRF parameters
 

	
 
# NewGRF parameters window
 
STR_NEWGRF_PARAMETERS_CAPTION                                   :{WHITE}Change NewGRF parameters
src/newgrf.cpp
Show inline comments
 
@@ -4860,25 +4860,25 @@ static void GRFInfo(ByteReader *buf)
 
		delete _cur_grfconfig->error;
 
		_cur_grfconfig->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
 

	
 
		_skip_sprites = -1;
 
		return;
 
	}
 

	
 
	_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> ...]
 
	 * <set>: <num-sprites> <first-sprite>
 
	 *
 
	 * B num-sets      How many sets of sprites to replace.
 
	 * Each set:
 
	 * B num-sprites   How many sprites are in this set
 
	 * W first-sprite  First sprite number to replace */
 
@@ -5943,24 +5943,36 @@ static bool ChangeGRFPalette(size_t len,
 
			case '*':
 
			case 'A': _cur_grfconfig->palette |= GRFP_GRF_ANY;     break;
 
			case 'W': _cur_grfconfig->palette |= GRFP_GRF_WINDOWS; break;
 
			case 'D': _cur_grfconfig->palette |= GRFP_GRF_DOS;     break;
 
			default:
 
				grfmsg(2, "StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
 
				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)
 
{
 
	AddGRFTextToList(&_cur_parameter->name, langid, _cur_grfconfig->ident.grfid, str);
 
	return true;
 
}
 

	
 
/** Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter. */
 
static bool ChangeGRFParamDescription(byte langid, const char *str)
 
@@ -6181,24 +6193,25 @@ static bool HandleParameterInfo(ByteRead
 
		/* Read all parameter-data and process each node. */
 
		if (!HandleNodes(buf, _tags_parameters)) return false;
 
		type = buf->ReadByte();
 
	}
 
	return true;
 
}
 

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

	
 

	
 
/**
 
 * Try to skip the current node and all subnodes (if it's a branch node).
src/newgrf_config.cpp
Show inline comments
 
@@ -30,24 +30,25 @@
 
GRFConfig::GRFConfig(const char *filename) :
 
	num_valid_params(lengthof(param))
 
{
 
	if (filename != NULL) this->filename = strdup(filename);
 
}
 

	
 
/**
 
 * 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)
 
{
 
	MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
 
	MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
 
	if (config.filename != NULL) this->filename = strdup(config.filename);
 
	this->name = DuplicateGRFText(config.name);
 
	this->info = DuplicateGRFText(config.info);
 
@@ -570,29 +571,32 @@ void ScanNewGRFFiles()
 
	NetworkAfterNewGRFScan();
 
#endif
 
}
 

	
 

	
 
/** Find a NewGRF in the scanned list.
 
 * @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 {
 
	UnknownGRF *next;
 
	char   name[NETWORK_GRF_NAME_LENGTH];
 
};
 

	
 
/**
 
 * Finds the name of a NewGRF in the list of names for unknown GRFs. An
src/newgrf_config.h
Show inline comments
 
@@ -130,24 +130,25 @@ struct GRFParameterInfo {
 
struct GRFConfig : ZeroedMemoryAllocator {
 
	GRFConfig(const char *filename = NULL);
 
	GRFConfig(const GRFConfig &config);
 
	~GRFConfig();
 

	
 
	GRFIdentifier ident;       ///< grfid and md5sum to uniquely identify newgrfs
 
	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)
 
	uint8 palette;             ///< GRFPalette, bitset
 
	SmallVector<GRFParameterInfo *, 4> param_info; ///< NOSAVE: extra information about the parameters
 

	
 
	struct GRFConfig *next;    ///< NOSAVE: Next item in the linked list
 

	
 
	bool IsOpenTTDBaseGRF() const;
src/newgrf_gui.cpp
Show inline comments
 
@@ -6,24 +6,25 @@
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file newgrf_gui.cpp GUI to change NewGRF settings. */
 

	
 
#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"
 
#include "core/geometry_func.hpp"
 
#include "newgrf_text.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
@@ -71,24 +72,29 @@ static void ShowNewGRFInfo(const GRFConf
 
	/* Draw filename or not if it is not known (GRF sent over internet) */
 
	if (c->filename != NULL) {
 
		SetDParamStr(0, c->filename);
 
		y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
 
	}
 

	
 
	/* 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 */
 
	if (show_params) {
 
		if (c->num_params > 0) {
 
			GRFBuildParamList(buff, c, lastof(buff));
 
			SetDParam(0, STR_JUST_RAW_STRING);
 
			SetDParamStr(1, buff);
 
		} else {
 
@@ -608,26 +614,25 @@ struct NewGRFWindow : public QueryString
 
				}
 
			} break;
 

	
 
			case SNGRFS_AVAIL_LIST: {
 
				GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
 

	
 
				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);
 
					y += step_height;
 
				}
 
				break;
 
			}
 

	
 
			case SNGRFS_NEWGRF_INFO_TITLE:
 
@@ -1063,46 +1068,68 @@ struct NewGRFWindow : public QueryString
 

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		this->avails.SetFilterState(!StrEmpty(this->edit_str_buf));
 
		this->avails.ForceRebuild();
 
		this->InvalidateData(0);
 
	}
 

	
 
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;
 
		if ((*a)->filename != NULL && strcasestr((*a)->filename, filter_string) != NULL) return true;
 
		if ((*a)->GetDescription() != NULL && strcasestr((*a)->GetDescription(), filter_string) != NULL) return true;
 
		return false;
 
	}
 

	
 
	void BuildAvailables()
 
	{
 
		if (!this->avails.NeedRebuild()) return;
 

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

	
 
		if (this->avail_sel != NULL) {
 
			this->avail_pos = this->avails.FindIndex(this->avail_sel);
 
			if (this->avail_pos < 0) this->avail_sel = NULL;
 
		}
 

	
src/settings_type.h
Show inline comments
 
@@ -102,24 +102,25 @@ struct GUISettings {
 

	
 
	uint16 console_backlog_timeout;          ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity.
 
	uint16 console_backlog_length;           ///< the minimum amount of items in the console backlog before items will be removed.
 
#ifdef ENABLE_NETWORK
 
	uint16 network_chat_box_width;           ///< width of the chat box in pixels
 
	uint8  network_chat_box_height;          ///< height of the chat box in lines
 
#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
 
	char  *digit_group_separator;            ///< thousand separator for non-currencies
 
	char  *digit_group_separator_currency;   ///< thousand separator for currencies
 
	char  *digit_decimal_separator;          ///< decimal separator
 
};
 

	
 
/** All settings related to the network. */
src/table/settings.h
Show inline comments
 
@@ -602,24 +602,25 @@ const SettingDesc _settings[] = {
 
	 SDTC_BOOL(gui.persistent_buildingtools,             S,  0,  true,                        STR_CONFIG_SETTING_PERSISTENT_BUILDINGTOOLS,    NULL),
 
	 SDTC_BOOL(gui.expenses_layout,                      S,  0, false,                        STR_CONFIG_SETTING_EXPENSES_LAYOUT,             RedrawScreen),
 

	
 
/* For the dedicated build we'll enable dates in logs by default. */
 
#ifdef DEDICATED
 
	 SDTC_BOOL(gui.show_date_in_logs,                    S,  0,  true,                        STR_NULL,                                       NULL),
 
#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),
 

	
 
	  SDTC_VAR(network.sync_freq,            SLE_UINT16,C|S,NO,   100,        0,      100, 0, STR_NULL,                                       NULL),
 
	  SDTC_VAR(network.frame_freq,            SLE_UINT8,C|S,NO,     0,        0,      100, 0, STR_NULL,                                       NULL),
 
	  SDTC_VAR(network.max_join_time,        SLE_UINT16, S, NO,   500,        0,    32000, 0, STR_NULL,                                       NULL),
 
	 SDTC_BOOL(network.pause_on_join,                    S, NO,  true,                        STR_NULL,                                       NULL),
 
	  SDTC_VAR(network.server_port,          SLE_UINT16, S, NO,NETWORK_DEFAULT_PORT,0,65535,0,STR_NULL,                                       NULL),
 
	 SDTC_BOOL(network.server_advertise,                 S, NO, false,                        STR_NULL,                                       NULL),
0 comments (0 inline, 0 general)