Changeset - r12820:b9f50954e5f1
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-08-30 14:06:55
rubidium@openttd.org
(svn r17320) -Codechange: move the code to determine the string and set dparams of industries in the industry directory out of OnPaint
1 file changed with 36 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -905,6 +905,41 @@ protected:
 
		return (r == 0) ? IndustryNameSorter(a, b) : r;
 
	}
 

	
 
	/**
 
	 * Get the StringID to draw and set the appropriate DParams.
 
	 * @param i the industry to get the StringID of.
 
	 * @return the StringID.
 
	 */
 
	StringID GetIndustryString(const Industry *i)
 
	{
 
		const IndustrySpec *indsp = GetIndustrySpec(i->type);
 
		byte p = 0;
 

	
 
		/* Industry name */
 
		SetDParam(p++, i->index);
 

	
 
		/* Industry productions */
 
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
			if (i->produced_cargo[j] == CT_INVALID) continue;
 
			SetDParam(p++, i->produced_cargo[j]);
 
			SetDParam(p++, i->last_month_production[j]);
 
			SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, const_cast<Industry *>(i), i->type, indsp));
 
		}
 

	
 
		/* Transported productions */
 
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
			if (i->produced_cargo[j] == CT_INVALID) continue;
 
			SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
 
		}
 

	
 
		/* Drawing the right string */
 
		switch (p) {
 
			case 1:  return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
 
			case 5:  return STR_INDUSTRY_DIRECTORY_ITEM;
 
			default: return STR_INDUSTRY_DIRECTORY_ITEM_TWO;
 
		}
 
	}
 

	
 
public:
 
	IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
 
	{
 
@@ -938,32 +973,8 @@ public:
 
		int y = this->widget[IDW_INDUSTRY_LIST].top + 2; // start of the list-widget
 

	
 
		for (int n = this->vscroll.pos; n < max; ++n) {
 
			const Industry *i = this->industries[n];
 
			const IndustrySpec *indsp = GetIndustrySpec(i->type);
 
			byte p = 0;
 

	
 
			/* Industry name */
 
			SetDParam(p++, i->index);
 

	
 
			/* Industry productions */
 
			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
				if (i->produced_cargo[j] == CT_INVALID) continue;
 
				SetDParam(p++, i->produced_cargo[j]);
 
				SetDParam(p++, i->last_month_production[j]);
 
				SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, const_cast<Industry *>(i), i->type, indsp));
 
			}
 

	
 
			/* Transported productions */
 
			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
				if (i->produced_cargo[j] == CT_INVALID) continue;
 
				SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
 
			}
 

	
 
			/* Drawing the right string */
 
			StringID str = STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
 
			if (p != 1) str = (p == 5) ? STR_INDUSTRY_DIRECTORY_ITEM : STR_INDUSTRY_DIRECTORY_ITEM_TWO;
 
			StringID str = this->GetIndustryString(this->industries[n]);
 
			DrawString(this->widget[IDW_INDUSTRY_LIST].left + 2, this->widget[IDW_INDUSTRY_LIST].right - 2, y, str);
 

	
 
			y += this->industryline_height;
 
		}
 
	}
0 comments (0 inline, 0 general)