Changeset - r17978:c07585e51a28
[Not reviewed]
master
0 6 0
rubidium - 13 years ago 2011-08-21 12:53:13
rubidium@openttd.org
(svn r22797) -Add: progress bar for scanning NewGRFs
6 files changed with 141 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2500,48 +2500,53 @@ STR_NEWGRF_UNPAUSE_WARNING              
 

	
 
# NewGRF status
 
STR_NEWGRF_LIST_NONE                                            :None
 
STR_NEWGRF_LIST_ALL_FOUND                                       :All files present
 
STR_NEWGRF_LIST_COMPATIBLE                                      :{YELLOW}Found compatible files
 
STR_NEWGRF_LIST_MISSING                                         :{RED}Missing files
 

	
 
# NewGRF 'it's broken' warnings
 
STR_NEWGRF_BROKEN                                               :{WHITE}Behaviour of NewGRF '{0:RAW_STRING}' is likely to cause desyncs and/or crashes
 
STR_NEWGRF_BROKEN_POWERED_WAGON                                 :{WHITE}It changed powered-wagon state for '{1:ENGINE}' when not inside a depot
 
STR_NEWGRF_BROKEN_VEHICLE_LENGTH                                :{WHITE}It changed vehicle length for '{1:ENGINE}' when not inside a depot
 
STR_BROKEN_VEHICLE_LENGTH                                       :{WHITE}Train '{VEHICLE}' belonging to '{COMPANY}' has invalid length. It is probably caused by problems with NewGRFs. Game may desync or crash
 

	
 
STR_NEWGRF_BUGGY                                                :{WHITE}NewGRF '{0:RAW_STRING}' provides incorrect information
 
STR_NEWGRF_BUGGY_ARTICULATED_CARGO                              :{WHITE}Cargo/refit information for '{1:ENGINE}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly
 
STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK                    :{WHITE}'{1:STRING}' caused an endless loop in the production callback
 

	
 
# 'User removed essential NewGRFs'-placeholders for stuff without specs
 
STR_NEWGRF_INVALID_CARGO                                        :<invalid cargo>
 
STR_NEWGRF_INVALID_CARGO_ABBREV                                 :??
 
STR_NEWGRF_INVALID_CARGO_QUANTITY                               :{COMMA} of <invalid cargo>
 
STR_NEWGRF_INVALID_ENGINE                                       :<invalid vehicle model>
 
STR_NEWGRF_INVALID_INDUSTRYTYPE                                 :<invalid industry>
 

	
 
# NewGRF scanning window
 
STR_NEWGRF_SCAN_CAPTION                                         :{WHITE}Scanning NewGRFs
 
STR_NEWGRF_SCAN_MESSAGE                                         :{BLACK}Scanning NewGRFs. Depending on the amount this can take a while...
 
STR_NEWGRF_SCAN_STATUS                                          :{BLACK}{NUM} NewGRF{P "" s} scanned out of an estimated {NUM} NewGRF{P "" s}
 

	
 
# Sign list window
 
STR_SIGN_LIST_CAPTION                                           :{WHITE}Sign List - {COMMA} Sign{P "" s}
 
STR_SIGN_LIST_MATCH_CASE                                        :{BLACK}Match case
 
STR_SIGN_LIST_CLEAR                                             :{BLACK}Clear filter
 
STR_SIGN_LIST_MATCH_CASE_TOOLTIP                                :{BLACK}Toggle matching case when comparing sign names against the filter string
 
STR_SIGN_LIST_CLEAR_TOOLTIP                                     :{BLACK}Clear filter string
 

	
 
# Sign window
 
STR_EDIT_SIGN_CAPTION                                           :{WHITE}Edit sign text
 
STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP                                 :{BLACK}Go to next sign
 
STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP                             :{BLACK}Go to previous sign
 

	
 
STR_EDIT_SIGN_SIGN_OSKTITLE                                     :{BLACK}Enter a name for the sign
 

	
 
# Town directory window
 
STR_TOWN_DIRECTORY_CAPTION                                      :{WHITE}Towns
 
STR_TOWN_DIRECTORY_NONE                                         :{ORANGE}- None -
 
STR_TOWN_DIRECTORY_TOWN                                         :{ORANGE}{TOWN}{BLACK} ({COMMA})
 
STR_TOWN_DIRECTORY_LIST_TOOLTIP                                 :{BLACK}Town names - click on name to centre main view on town. Ctrl+Click opens a new viewport on town location
 
STR_TOWN_POPULATION                                             :{BLACK}World population: {COMMA}
 

	
 
# Town view window
 
STR_TOWN_VIEW_TOWN_CAPTION                                      :{WHITE}{TOWN}
 
STR_TOWN_VIEW_CITY_CAPTION                                      :{WHITE}{TOWN} (City)
src/newgrf_config.cpp
Show inline comments
 
@@ -522,94 +522,98 @@ compatible_grf:
 
				}
 
			}
 
		}
 
	}
 

	
 
	return res;
 
}
 

	
 
/** Helper for scanning for files with GRF as extension */
 
class GRFFileScanner : FileScanner {
 
	uint next_update; ///< The next (realtime tick) we do update the screen.
 
	uint num_scanned; ///< The number of GRFs we have scanned.
 

	
 
public:
 
	GRFFileScanner() : next_update(_realtime_tick), num_scanned(0)
 
	{
 
	}
 

	
 
	/* virtual */ bool AddFile(const char *filename, size_t basepath_length);
 

	
 
	/** Do the scan for GRFs. */
 
	static uint DoScan()
 
	{
 
		GRFFileScanner fs;
 
		return fs.Scan(".grf", DATA_DIR);
 
		int ret = fs.Scan(".grf", DATA_DIR);
 
		/* The number scanned and the number returned may not be the same;
 
		 * duplicate NewGRFs and base sets are ignored in the return value. */
 
		_settings_client.gui.last_newgrf_count = fs.num_scanned;
 
		return ret;
 
	}
 
};
 

	
 
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length)
 
{
 
	GRFConfig *c = new GRFConfig(filename + basepath_length);
 

	
 
	bool added = true;
 
	if (FillGRFDetails(c, false)) {
 
		if (_all_grfs == NULL) {
 
			_all_grfs = c;
 
		} else {
 
			/* Insert file into list at a position determined by its
 
			 * name, so the list is sorted as we go along */
 
			GRFConfig **pd, *d;
 
			bool stop = false;
 
			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
 
				if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
 
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
 
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
 
				 *  just after the first with the same name. Avoids doubles in the list. */
 
				if (strcasecmp(c->GetName(), d->GetName()) <= 0) {
 
					stop = true;
 
				} else if (stop) {
 
					break;
 
				}
 
			}
 
			if (added) {
 
				c->next = d;
 
				*pd = c;
 
			}
 
		}
 
	} else {
 
		added = false;
 
	}
 

	
 
	this->num_scanned++;
 
	if (this->next_update <= _realtime_tick) {
 
		_modal_progress_work_mutex->EndCritical();
 
		_modal_progress_paint_mutex->BeginCritical();
 

	
 
		const char *name = NULL;
 
		if (c->name != NULL) name = GetGRFStringFromGRFText(c->name->text);
 
		if (name == NULL) name = c->filename;
 
		DEBUG(grf, 0, "Scanning %i: %s", this->num_scanned, name);
 
		UpdateNewGRFScanStatus(this->num_scanned, name);
 

	
 
		_modal_progress_work_mutex->BeginCritical();
 
		_modal_progress_paint_mutex->EndCritical();
 

	
 
		this->next_update = _realtime_tick + 200;
 
	}
 

	
 
	if (!added) {
 
		/* File couldn't be opened, or is either not a NewGRF or is a
 
		 * 'system' NewGRF or it's already known, so forget about it. */
 
		delete c;
 
	}
 

	
 
	return added;
 
}
 

	
 
/**
 
 * Simple sorter for GRFS
 
 * @param p1 the first GRFConfig *
 
 * @param p2 the second GRFConfig *
 
 * @return the same strcmp would return for the name of the NewGRF.
 
 */
 
static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
 
{
src/newgrf_config.h
Show inline comments
 
@@ -197,25 +197,27 @@ struct NewGRFScanCallback {
 
};
 

	
 
void ScanNewGRFFiles(NewGRFScanCallback *callback);
 
void CheckForMissingSprites();
 
const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
 
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
 
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
 
void AppendStaticGRFConfigs(GRFConfig **dst);
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
 
/* In newgrf_gui.cpp */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
 

	
 
#ifdef ENABLE_NETWORK
 
/** For communication about GRFs over the network */
 
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
 
GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
 
#endif /* ENABLE_NETWORK */
 

	
 
void UpdateNewGRFScanStatus(uint num, const char *name);
 

	
 
#endif /* NEWGRF_CONFIG_H */
src/newgrf_gui.cpp
Show inline comments
 
@@ -1666,24 +1666,143 @@ static void NewGRFConfirmationCallback(W
 
		nw->avails.ForceRebuild();
 

	
 
		w->InvalidateData();
 

	
 
		ReInitAllWindows();
 
		DeleteWindowByClass(WC_BUILD_OBJECT);
 
	}
 
}
 

	
 

	
 

	
 
/**
 
 * Setup the NewGRF gui
 
 * @param editable allow the user to make changes to the grfconfig in the window
 
 * @param show_params show information about what parameters are set for the grf files
 
 * @param exec_changes if changes are made to the list (editable is true), apply these
 
 *        changes immediately or only update the list
 
 * @param config pointer to a linked-list of grfconfig's that will be shown
 
 */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
 
{
 
	DeleteWindowByClass(WC_GAME_OPTIONS);
 
	new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
 
}
 

	
 
/** The widgets for the scan progress. */
 
enum ScanProgressWindowWidgets {
 
	SPWW_PROGRESS_BAR,  ///< Simple progress bar.
 
	GPWW_PROGRESS_TEXT, ///< Text explaining what is happening.
 
};
 

	
 
/** Widgets for the progress window. */
 
static const NWidgetPart _nested_scan_progress_widgets[] = {
 
	NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	NWidget(WWT_PANEL, COLOUR_GREY),
 
		NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
 
			NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
 
				NWidget(WWT_LABEL, INVALID_COLOUR), SetDataTip(STR_NEWGRF_SCAN_MESSAGE, STR_NULL), SetFill(1, 0),
 
				NWidget(WWT_EMPTY, INVALID_COLOUR, SPWW_PROGRESS_BAR), SetFill(1, 0),
 
				NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_TEXT), SetFill(1, 0),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
/** Description of the widgets and other settings of the window. */
 
static const WindowDesc _scan_progress_desc(
 
	WDP_CENTER, 0, 0,
 
	WC_MODAL_PROGRESS, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets)
 
);
 

	
 
/** Window for showing the progress of NewGRF scanning. */
 
struct ScanProgressWindow : public Window {
 
	char *last_name; ///< The name of the last 'seen' NewGRF.
 
	int scanned;     ///< The number of NewGRFs that we have seen.
 

	
 
	/** Create the window. */
 
	ScanProgressWindow() : Window(), last_name(NULL), scanned(0)
 
	{
 
		this->InitNested(&_scan_progress_desc);
 
	}
 

	
 
	/** Free the last name buffer. */
 
	~ScanProgressWindow()
 
	{
 
		free(last_name);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case SPWW_PROGRESS_BAR: {
 
				SetDParam(0, 100);
 
				*size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
 
				/* We need some spacing for the 'border' */
 
				size->height += 8;
 
				size->width += 8;
 
				break;
 
			}
 

	
 
			case GPWW_PROGRESS_TEXT:
 
				SetDParam(0, 9999);
 
				SetDParam(1, 9999);
 
				/* We really don't know the width. We could determine it by scanning the NewGRFs,
 
				 * but this is the status window for scanning them... */
 
				size->width = max(400U, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width);
 
				size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
 
				break;
 
		}
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case SPWW_PROGRESS_BAR: {
 
				/* Draw the % complete with a bar and a text */
 
				DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
 
				uint percent = scanned * 100 / max(1U, _settings_client.gui.last_newgrf_count);
 
				DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
 
				SetDParam(0, percent);
 
				DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
 
				break;
 
			}
 

	
 
			case GPWW_PROGRESS_TEXT:
 
				SetDParam(0, this->scanned);
 
				SetDParam(1, _settings_client.gui.last_newgrf_count);
 
				DrawString(r.left, r.right, r.top, STR_NEWGRF_SCAN_STATUS, TC_FROMSTRING, SA_HOR_CENTER);
 

	
 
				DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, this->last_name == NULL ? "" : this->last_name, TC_BLACK, SA_HOR_CENTER);
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Update the NewGRF scan status.
 
	 * @param num  The number of NewGRFs scanned so far.
 
	 * @param name The name of the last scanned NewGRF.
 
	 */
 
	void UpdateNewGRFScanStatus(uint num, const char *name)
 
	{
 
		free(this->last_name);
 
		this->last_name = strdup(name);
 
		this->scanned = num;
 
		if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num;
 

	
 
		this->SetDirty();
 
	}
 
};
 

	
 
/**
 
 * Update the NewGRF scan status.
 
 * @param num  The number of NewGRFs scanned so far.
 
 * @param name The name of the last scanned NewGRF.
 
 */
 
void UpdateNewGRFScanStatus(uint num, const char *name)
 
{
 
	ScanProgressWindow *w  = dynamic_cast<ScanProgressWindow *>(FindWindowByClass(WC_MODAL_PROGRESS));
 
	if (w == NULL) w = new ScanProgressWindow();
 
	w->UpdateNewGRFScanStatus(num, name);
 
}
src/settings_type.h
Show inline comments
 
@@ -89,48 +89,49 @@ struct GUISettings {
 
	bool   population_in_label;              ///< show the population of a town in his label?
 
	uint8  right_mouse_btn_emulation;        ///< should we emulate right mouse clicking?
 
	uint8  scrollwheel_scrolling;            ///< scrolling using the scroll wheel?
 
	uint8  scrollwheel_multiplier;           ///< how much 'wheel' per incoming event from the OS?
 
	bool   timetable_arrival_departure;      ///< show arrivals and departures in vehicle timetables
 
	bool   left_mouse_btn_scrolling;         ///< left mouse button scroll
 
	bool   pause_on_newgame;                 ///< whether to start new games paused or not
 
	bool   enable_signal_gui;                ///< show the signal GUI when the signal button is pressed
 
	Year   coloured_news_year;               ///< when does newspaper become coloured?
 
	bool   timetable_in_ticks;               ///< whether to show the timetable in ticks rather than days
 
	bool   quick_goto;                       ///< Allow quick access to 'goto button' in vehicle orders window
 
	bool   auto_euro;                        ///< automatically switch to euro in 2002
 
	byte   drag_signals_density;             ///< many signals density
 
	Year   semaphore_build_before;           ///< build semaphore signals automatically before this year
 
	byte   news_message_timeout;             ///< how much longer than the news message "age" should we keep the message in the history
 
	bool   show_track_reservation;           ///< highlight reserved tracks.
 
	uint8  default_signal_type;              ///< the signal type to build by default.
 
	uint8  cycle_signal_types;               ///< what signal types to cycle with the build signal tool.
 
	byte   station_numtracks;                ///< the number of platforms to default on for rail stations
 
	byte   station_platlength;               ///< the platform length, in tiles, for rail stations
 
	bool   station_dragdrop;                 ///< whether drag and drop is enabled for stations
 
	bool   station_show_coverage;            ///< whether to highlight coverage area
 
	bool   persistent_buildingtools;         ///< keep the building tools active after usage
 
	bool   expenses_layout;                  ///< layout of expenses window
 
	uint32 last_newgrf_count;                ///< the numbers of NewGRFs we found during the last scan
 

	
 
	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
 
	uint16 network_chat_timeout;             ///< timeout of chat messages in seconds
 
#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 and allow modifying NewGRFs in an existing game
 
	bool   ai_developer_tools;               ///< activate AI developer tools
 
	bool   scenario_developer;               ///< activate scenario developer: allow modifying NewGRFs in an existing game
 
	bool   newgrf_show_old_versions;         ///< whether to show old versions in the NewGRF list
 
	uint8  newgrf_default_palette;           ///< default palette to use for NewGRFs without action 14 palette information
 

	
 
	/**
 
	 * Returns true when the user has sufficient privileges to edit newgrfs on a running game
 
	 * @return whether the user has sufficient privileges to edit newgrfs in an existing game
 
	 */
 
	bool UserIsAllowedToChangeNewGRFs() const
 
	{
 
		return this->scenario_developer || this->newgrf_developer_tools;
src/table/settings.ini
Show inline comments
 
@@ -2358,48 +2358,56 @@ max      = 7
 

	
 
[SDTC_BOOL]
 
var      = gui.station_dragdrop
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = true
 

	
 
[SDTC_BOOL]
 
var      = gui.station_show_coverage
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = false
 

	
 
[SDTC_BOOL]
 
var      = gui.persistent_buildingtools
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = true
 
str      = STR_CONFIG_SETTING_PERSISTENT_BUILDINGTOOLS
 

	
 
[SDTC_BOOL]
 
var      = gui.expenses_layout
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = false
 
str      = STR_CONFIG_SETTING_EXPENSES_LAYOUT
 
proc     = RedrawScreen
 

	
 
[SDTC_VAR]
 
var      = gui.last_newgrf_count
 
type     = SLE_UINT32
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = 100
 
min      = 0
 
max      = UINT32_MAX
 

	
 

	
 
; For the dedicated build we'll enable dates in logs by default.
 
[SDTC_BOOL]
 
ifdef    = DEDICATED
 
var      = gui.show_date_in_logs
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = true
 

	
 
[SDTC_BOOL]
 
ifndef   = DEDICATED
 
var      = gui.show_date_in_logs
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = false
 

	
 
[SDTC_VAR]
 
var      = gui.developer
 
type     = SLE_UINT8
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = 1
 
min      = 0
 
max      = 2
 

	
 
[SDTC_BOOL]
 
var      = gui.newgrf_developer_tools
0 comments (0 inline, 0 general)