Changeset - r16857:43d6cf775e19
[Not reviewed]
master
0 1 0
rubidium - 13 years ago 2010-12-22 19:52:23
rubidium@openttd.org
(svn r21601) -Fix [FS#4323]: company league table used stats from two quarters ago instead of last quarter
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -1139,90 +1139,90 @@ private:
 
	uint ordinal_width; ///< The width of the ordinal number
 
	uint text_width;    ///< The width of the actual text
 

	
 
	/**
 
	 * (Re)Build the company league list
 
	 */
 
	void BuildCompanyList()
 
	{
 
		if (!this->companies.NeedRebuild()) return;
 

	
 
		this->companies.Clear();
 

	
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			*this->companies.Append() = c;
 
		}
 

	
 
		this->companies.Compact();
 
		this->companies.RebuildDone();
 
	}
 

	
 
	/** Sort the company league by performance history */
 
	static int CDECL PerformanceSorter(const Company * const *c1, const Company * const *c2)
 
	{
 
		return (*c2)->old_economy[1].performance_history - (*c1)->old_economy[1].performance_history;
 
		return (*c2)->old_economy[0].performance_history - (*c1)->old_economy[0].performance_history;
 
	}
 

	
 
public:
 
	CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
 
	{
 
		this->InitNested(desc, window_number);
 
		this->companies.ForceRebuild();
 
		this->companies.NeedResort();
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->BuildCompanyList();
 
		this->companies.Sort(&PerformanceSorter);
 

	
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != CLW_BACKGROUND) return;
 

	
 
		uint y = r.top + WD_FRAMERECT_TOP;
 
		int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - 10) / 2;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		uint ordinal_left  = rtl ? r.right - WD_FRAMERECT_LEFT - this->ordinal_width : r.left + WD_FRAMERECT_LEFT;
 
		uint ordinal_right = rtl ? r.right - WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->ordinal_width;
 
		uint icon_left     = r.left + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + (rtl ? this->text_width : this->ordinal_width);
 
		uint text_left     = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
 
		uint text_right    = rtl ? r.left + WD_FRAMERECT_LEFT + this->text_width : r.right - WD_FRAMERECT_LEFT;
 

	
 
		for (uint i = 0; i != this->companies.Length(); i++) {
 
			const Company *c = this->companies[i];
 
			DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
 

	
 
			DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
 

	
 
			SetDParam(0, c->index);
 
			SetDParam(1, c->index);
 
			SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[1].performance_history));
 
			SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
 
			DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME);
 
			y += FONT_HEIGHT_NORMAL;
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != CLW_BACKGROUND) return;
 

	
 
		this->ordinal_width = 0;
 
		for (uint i = 0; i < MAX_COMPANIES; i++) {
 
			this->ordinal_width = max(this->ordinal_width, GetStringBoundingBox(STR_ORDINAL_NUMBER_1ST + i).width);
 
		}
 
		this->ordinal_width += 5; // Keep some extra spacing
 

	
 
		uint widest_width = 0;
 
		uint widest_title = 0;
 
		for (uint i = 0; i < lengthof(_performance_titles); i++) {
 
			uint width = GetStringBoundingBox(_performance_titles[i]).width;
 
			if (width > widest_width) {
 
				widest_title = i;
 
				widest_width = width;
 
			}
 
		}
0 comments (0 inline, 0 general)