Changeset - r14956:6a8fb13a8b4a
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-04-07 15:20:24
rubidium@openttd.org
(svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
1 file changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -67,53 +67,53 @@ struct GraphLegendWindow : Window {
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (!IsInsideMM(widget, GLW_FIRST_COMPANY, MAX_COMPANIES + GLW_FIRST_COMPANY)) return;
 

	
 
		CompanyID cid = (CompanyID)(widget - GLW_FIRST_COMPANY);
 

	
 
		if (!Company::IsValidID(cid)) return;
 

	
 
		bool rtl = _dynlang.text_dir == TD_RTL;
 

	
 
		DrawCompanyIcon(cid, rtl ? r.right - 16 : r.left + 2, r.top + 2 + (FONT_HEIGHT_NORMAL - 10) / 2);
 

	
 
		SetDParam(0, cid);
 
		SetDParam(1, cid);
 
		DrawString(r.left + (rtl ? WD_FRAMERECT_LEFT : 19), r.right - (rtl ? 19 : WD_FRAMERECT_RIGHT), r.top + WD_FRAMERECT_TOP, STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		if (!IsInsideMM(widget, GLW_FIRST_COMPANY, MAX_COMPANIES + GLW_FIRST_COMPANY)) return;
 

	
 
		ToggleBit(_legend_excluded_companies, widget - GLW_FIRST_COMPANY);
 
		this->ToggleWidgetLoweredState(widget);
 
		this->SetDirty();
 
		SetWindowDirty(WC_INCOME_GRAPH, 0);
 
		SetWindowDirty(WC_OPERATING_PROFIT, 0);
 
		SetWindowDirty(WC_DELIVERED_CARGO, 0);
 
		SetWindowDirty(WC_PERFORMANCE_HISTORY, 0);
 
		SetWindowDirty(WC_COMPANY_VALUE, 0);
 
		InvalidateWindowData(WC_INCOME_GRAPH, 0);
 
		InvalidateWindowData(WC_OPERATING_PROFIT, 0);
 
		InvalidateWindowData(WC_DELIVERED_CARGO, 0);
 
		InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
 
		InvalidateWindowData(WC_COMPANY_VALUE, 0);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (Company::IsValidID(data)) return;
 

	
 
		SetBit(_legend_excluded_companies, data);
 
		this->RaiseWidget(data + GLW_FIRST_COMPANY);
 
	}
 
};
 

	
 
/**
 
 * Construct a vertical list of buttons, one for each company.
 
 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
 
 * @return Panel with company buttons.
 
 * @post \c *biggest_index contains the largest used index in the tree.
 
 */
 
static NWidgetBase *MakeNWidgetCompanyLines(int *biggest_index)
 
{
 
	NWidgetVertical *vert = new NWidgetVertical();
 

	
 
	for (int widnum = GLW_FIRST_COMPANY; widnum <= GLW_LAST_COMPANY; widnum++) {
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
 
		panel->SetMinimalSize(246, FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
@@ -505,48 +505,53 @@ public:
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != this->graph_widget) return;
 

	
 
		DrawGraph(r);
 
	}
 

	
 
	virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
 
	{
 
		return INVALID_DATAPOINT;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* Clicked on legend? */
 
		if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		this->UpdateStatistics(false);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		this->OnTick();
 
	}
 

	
 
	/**
 
	 * Update the statistics.
 
	 * @param initialize Initialize the data structure.
 
	 */
 
	void UpdateStatistics(bool initialize)
 
	{
 
		uint excluded_companies = _legend_excluded_companies;
 

	
 
		/* Exclude the companies which aren't valid */
 
		for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
			if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
 
		}
 

	
 
		byte nums = 0;
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
 
		}
 

	
 
		int mo = (_cur_month / 3 - nums) * 3;
 
		int yr = _cur_year;
 
		while (mo < 0) {
 
			yr--;
 
			mo += 12;
 
@@ -935,48 +940,53 @@ struct PaymentRatesGraphWindow : BaseGra
 
				this->RaiseWidget(CPW_ENABLE_CARGOS);
 
				this->SetDirty();
 
			} break;
 

	
 
			default:
 
				if (widget >= CPW_CARGO_FIRST) {
 
					int i = widget - CPW_CARGO_FIRST;
 
					ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
 
					this->ToggleWidgetLoweredState(widget);
 
					this->UpdateExcludedData();
 
					/* Raise the two "all" buttons, as we have done a specific choice. */
 
					this->RaiseWidget(CPW_ENABLE_CARGOS);
 
					this->RaiseWidget(CPW_DISABLE_CARGOS);
 
					this->SetDirty();
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		/* Override default OnTick */
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		this->OnHundredthTick();
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
		this->UpdateExcludedData();
 

	
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			this->colours[i] = cs->legend_colour;
 
			for (uint j = 0; j != 20; j++) {
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
 
			}
 
			i++;
 
		}
 
		this->num_dataset = i;
 
	}
 
};
 

	
 
/** Construct the row containing the digit keys. */
 
static NWidgetBase *MakeCargoButtons(int *biggest_index)
 
{
 
	NWidgetVertical *ver = new NWidgetVertical;
 

	
 
	for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
 
		NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL);
0 comments (0 inline, 0 general)