Changeset - r14929:7421ef7e6635
[Not reviewed]
master
0 2 0
terkhen - 14 years ago 2010-04-02 14:11:10
terkhen@openttd.org
(svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
2 files changed with 49 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -785,48 +785,50 @@ static const NWidgetPart _nested_company
 
};
 

	
 
static const WindowDesc _company_value_graph_desc(
 
	WDP_AUTO, 0, 0,
 
	WC_COMPANY_VALUE, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_company_value_graph_widgets, lengthof(_nested_company_value_graph_widgets)
 
);
 

	
 
void ShowCompanyValueGraph()
 
{
 
	AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
 
}
 

	
 
/*****************/
 
/* PAYMENT RATES */
 
/*****************/
 

	
 
/** Widget numbers of the cargo payment rates. */
 
enum CargoPaymentRatesWidgets {
 
	CPW_BACKGROUND,
 
	CPW_HEADER,
 
	CPW_GRAPH,
 
	CPW_FOOTER,
 
	CPW_ENABLE_CARGOS,
 
	CPW_DISABLE_CARGOS,
 
	CPW_CARGO_FIRST,
 
};
 

	
 
struct PaymentRatesGraphWindow : BaseGraphWindow {
 
	bool first_init; ///< This value is true until the first initialization of the window has finished.
 
	PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(CPW_GRAPH, false, STR_JUST_CURRCOMPACT)
 
	{
 
		this->first_init = true;
 
		this->num_on_x_axis = 20;
 
		this->num_vert_lines = 20;
 
		this->month = 0xFF;
 
		this->x_values_start     = 10;
 
		this->x_values_increment = 10;
 

	
 
		/* Initialise the dataset */
 
		this->OnHundredthTick();
 

	
 
		this->InitNested(desc, window_number);
 

	
 
		this->UpdateLoweredWidgets();
 
	}
 

	
 
	virtual void OnInit()
 
@@ -883,54 +885,88 @@ struct PaymentRatesGraphWindow : BaseGra
 
			return;
 
		}
 

	
 
		const CargoSpec *cs = _sorted_cargo_specs[widget - CPW_CARGO_FIRST];
 
		bool rtl = _dynlang.text_dir == TD_RTL;
 

	
 
		/* Since the buttons have no text, no images,
 
		 * both the text and the coloured box have to be manually painted.
 
		 * clk_dif will move one pixel down and one pixel to the right
 
		 * when the button is clicked */
 
		byte clk_dif = this->IsWidgetLowered(widget) ? 1 : 0;
 
		int x = r.left + WD_FRAMERECT_LEFT;
 
		int y = r.top;
 

	
 
		int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
 

	
 
		GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, 0);
 
		GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
 
		SetDParam(0, cs->name);
 
		DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		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();
 
			this->SetDirty();
 
		switch (widget) {
 
			case CPW_ENABLE_CARGOS:
 
				/* Remove all cargos from the excluded lists. */
 
				_legend_excluded_cargo = 0;
 
				this->excluded_data = 0;
 
				this->UpdateLoweredWidgets();
 
				/* Toggle appeareance indicating the choice. */
 
				this->LowerWidget(CPW_ENABLE_CARGOS);
 
				this->RaiseWidget(CPW_DISABLE_CARGOS);
 
				this->SetDirty();
 
				break;
 

	
 
			case CPW_DISABLE_CARGOS: {
 
				/* Add all cargos to the excluded lists. */
 
				int i = 0;
 
				const CargoSpec *cs;
 
				FOR_ALL_SORTED_CARGOSPECS(cs) {
 
					SetBit(_legend_excluded_cargo, cs->Index());
 
					SetBit(this->excluded_data, i);
 
					i++;
 
				}
 
				this->UpdateLoweredWidgets();
 
				/* Toggle appeareance indicating the choice. */
 
				this->LowerWidget(CPW_DISABLE_CARGOS);
 
				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 OnHundredthTick()
 
	{
 
		this->UpdateExcludedData();
 

	
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_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;
 
	}
 
};
 
@@ -949,48 +985,51 @@ static NWidgetBase *MakeCargoButtons(int
 
	}
 
	*biggest_index = CPW_CARGO_FIRST + _sorted_cargo_specs_size - 1;
 
	return ver;
 
}
 

	
 

	
 
static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, CPW_BACKGROUND), SetMinimalSize(568, 128), SetResize(0, 1),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(NWID_SPACER), SetFill(1, 0),
 
				NWidget(WWT_TEXT, COLOUR_GREY, CPW_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
 
				NWidget(NWID_SPACER), SetFill(1, 0),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_EMPTY, COLOUR_GREY, CPW_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1),
 
				NWidget(NWID_VERTICAL),
 
					NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0),
 
						NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CPW_ENABLE_CARGOS), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL),SetFill(1, 0),
 
						NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CPW_DISABLE_CARGOS), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL),SetFill(1, 0),
 
						NWidget(NWID_SPACER), SetMinimalSize(0, 4), SetFill(0, 0),
 
						NWidgetFunction(MakeCargoButtons),
 
					NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
 
				EndContainer(),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(NWID_SPACER), SetFill(1, 0),
 
				NWidget(WWT_TEXT, COLOUR_GREY, CPW_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
 
				NWidget(NWID_SPACER), SetFill(1, 0),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static const WindowDesc _cargo_payment_rates_desc(
 
	WDP_AUTO, 0, 0,
 
	WC_PAYMENT_RATES, WC_NONE,
 
	0,
 
	_nested_cargo_payment_rates_widgets, lengthof(_nested_cargo_payment_rates_widgets)
 
);
 

	
 

	
 
void ShowCargoPaymentRates()
 
{
src/lang/english.txt
Show inline comments
 
@@ -501,48 +501,52 @@ STR_MONTH_JUL                           
 
STR_MONTH_AUG                                                   :August
 
STR_MONTH_SEP                                                   :September
 
STR_MONTH_OCT                                                   :October
 
STR_MONTH_NOV                                                   :November
 
STR_MONTH_DEC                                                   :December
 
############ range for months ends
 

	
 
# Graph window
 
STR_GRAPH_KEY_BUTTON                                            :{BLACK}Key
 
STR_GRAPH_KEY_TOOLTIP                                           :{BLACK}Show key to graphs
 
STR_GRAPH_X_LABEL_MONTH                                         :{TINYFONT}{STRING}{} {STRING}
 
STR_GRAPH_X_LABEL_MONTH_YEAR                                    :{TINYFONT}{STRING}{} {STRING}{}{NUM}
 
STR_GRAPH_Y_LABEL                                               :{TINYFONT}{STRING2}
 
STR_GRAPH_Y_LABEL_NUMBER                                        :{TINYFONT}{COMMA}
 

	
 
STR_GRAPH_OPERATING_PROFIT_CAPTION                              :{WHITE}Operating Profit Graph
 
STR_GRAPH_INCOME_CAPTION                                        :{WHITE}Income Graph
 
STR_GRAPH_CARGO_DELIVERED_CAPTION                               :{WHITE}Units of cargo delivered
 
STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION                   :{WHITE}Company performance ratings (maximum rating=1000)
 
STR_GRAPH_COMPANY_VALUES_CAPTION                                :{WHITE}Company values
 

	
 
STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION                           :{WHITE}Cargo Payment Rates
 
STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL                           :{TINYFONT}{BLACK}Days in transit
 
STR_GRAPH_CARGO_PAYMENT_RATES_TITLE                             :{TINYFONT}{BLACK}Payment for delivering 10 units (or 10,000 litres) of cargo a distance of 20 squares
 
STR_GRAPH_CARGO_ENABLE_ALL                                      :{TINYFONT}{BLACK}Enable all
 
STR_GRAPH_CARGO_DISABLE_ALL                                     :{TINYFONT}{BLACK}Disable all
 
STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL                              :{BLACK}Display all cargos on the cargo payment rates graph
 
STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL                             :{BLACK}Display no cargos on the cargo payment rates graph
 
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO                            :{BLACK}Toggle graph for cargo type on/off
 
STR_GRAPH_CARGO_PAYMENT_CARGO                                   :{TINYFONT}{BLACK}{STRING}
 

	
 
STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP                            :{BLACK}Show detailed performance ratings
 

	
 
# Graph key window
 
STR_GRAPH_KEY_CAPTION                                           :{WHITE}Key to company graphs
 
STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP                         :{BLACK}Click here to toggle company's entry on graph on/off
 

	
 
# Company league window
 
STR_COMPANY_LEAGUE_TABLE_CAPTION                                :{WHITE}Company League Table
 
STR_COMPANY_LEAGUE_COMPANY_NAME                                 :{ORANGE}{COMPANY} {BLACK}{COMPANYNUM} '{STRING}'
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER                   :Engineer
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER            :Traffic Manager
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR      :Transport Coordinator
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR           :Route Supervisor
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR                   :Director
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE            :Chief Executive
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN                   :Chairman
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT                  :President
 
STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON                     :Tycoon
 

	
 
# Performance detail window
 
STR_PERFORMANCE_DETAIL                                          :{WHITE}Detailed performance rating
0 comments (0 inline, 0 general)