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
 
@@ -2512,24 +2512,29 @@ STR_BROKEN_VEHICLE_LENGTH               
 

	
 
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
 

	
src/newgrf_config.cpp
Show inline comments
 
@@ -534,25 +534,29 @@ class GRFFileScanner : FileScanner {
 

	
 
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 {
 
@@ -579,25 +583,25 @@ bool GRFFileScanner::AddFile(const char 
 
	} 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;
 
	}
src/newgrf_config.h
Show inline comments
 
@@ -209,13 +209,15 @@ GRFListCompatibility IsGoodGRFConfigList
 
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
 
@@ -1678,12 +1678,131 @@ static void NewGRFConfirmationCallback(W
 
 * 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
 
@@ -101,24 +101,25 @@ struct GUISettings {
 
	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
src/table/settings.ini
Show inline comments
 
@@ -2370,24 +2370,32 @@ def      = false
 
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
0 comments (0 inline, 0 general)